debu From: Jon Smirl --- core/net/mac/sicslowmac.c | 2 + core/net/sicslowpan.c | 4 ++- core/net/uip6.c | 9 ++++++ cpu/mc1322x/isr.c | 3 ++ cpu/mc1322x/isr.h | 3 ++ cpu/mc1322x/maca.c | 1 - cpu/mc1322x/uart1.c | 30 ++++++++++++++++++++- examples/udp-receiver-ipv6/example-udp-receiver.c | 1 + platform/mc1322x/contiki-mc1322x-main.c | 18 ++++++------- 9 files changed, 57 insertions(+), 14 deletions(-) diff --git a/core/net/mac/sicslowmac.c b/core/net/mac/sicslowmac.c index 48890f0..d9f24dd 100644 --- a/core/net/mac/sicslowmac.c +++ b/core/net/mac/sicslowmac.c @@ -50,7 +50,7 @@ #include "net/rime/packetbuf.h" #include "lib/random.h" -#define DEBUG 1 +#define DEBUG 0 #if DEBUG #include diff --git a/core/net/sicslowpan.c b/core/net/sicslowpan.c index 69d2edb..a056c9b 100644 --- a/core/net/sicslowpan.c +++ b/core/net/sicslowpan.c @@ -54,7 +54,7 @@ #include "net/rime.h" #include "net/sicslowpan.h" -#define DEBUG 1 +#define DEBUG 0 #if DEBUG /* PRINTFI and PRINTFO are defined for input and output to debug one without changing the timing of the other */ u8_t p; @@ -1318,6 +1318,7 @@ input(const struct mac_driver *r) frag_tag = GET16(RIME_FRAG_PTR, RIME_FRAG_TAG); PRINTFI("size %d, tag %d, offset %d)\n", frag_size, frag_tag, frag_offset); + printf("1\n"); rime_hdr_len += SICSLOWPAN_FRAG1_HDR_LEN; break; @@ -1335,6 +1336,7 @@ input(const struct mac_driver *r) frag_size = GET16(RIME_FRAG_PTR, RIME_FRAG_DISPATCH_SIZE) & 0x07ff; PRINTFI("size %d, tag %d, offset %d)\n", frag_size, frag_tag, frag_offset); + printf("N\n"); rime_hdr_len += SICSLOWPAN_FRAGN_HDR_LEN; break; default: diff --git a/core/net/uip6.c b/core/net/uip6.c index b63cea6..f3b20e6 100644 --- a/core/net/uip6.c +++ b/core/net/uip6.c @@ -1368,6 +1368,15 @@ uip_process(u8_t flag) connection is bound to a remote port. Finally, if the connection is bound to a remote IP address, the source IP address of the packet is checked. */ +printf("uip_udp_conn %x uip_udp_conn->lport %x UIP_UDP_BUF->destport %x uip_udp_conn->rport %x UIP_UDP_BUF->srcport %x\n", +uip_udp_conn, uip_udp_conn->lport, UIP_UDP_BUF->destport, uip_udp_conn->rport, UIP_UDP_BUF->srcport); +printf("uip_udp_conn->ripaddr "); + PRINT6ADDR(&uip_udp_conn->ripaddr); + PRINTF("\n"); +printf("UIP_IP_BUF->srcipaddr "); + PRINT6ADDR(&UIP_IP_BUF->srcipaddr); + PRINTF("\n"); + if(uip_udp_conn->lport != 0 && UIP_UDP_BUF->destport == uip_udp_conn->lport && (uip_udp_conn->rport == 0 || diff --git a/cpu/mc1322x/isr.c b/cpu/mc1322x/isr.c index 180fbd3..ac07d0b 100644 --- a/cpu/mc1322x/isr.c +++ b/cpu/mc1322x/isr.c @@ -25,6 +25,9 @@ void irq(void) if(tmr2_isr != 0) { tmr2_isr(); } if(tmr3_isr != 0) { tmr3_isr(); } } + if(uart1_irq()) { + if(uart1_isr != 0) { uart1_isr(); } + } if(crm_irq()) { PRINTF("crm irq\n\r"); if(rtc_wu_evt() && (rtc_isr != 0)) { rtc_isr(); } diff --git a/cpu/mc1322x/isr.h b/cpu/mc1322x/isr.h index 2b4a157..2717470 100644 --- a/cpu/mc1322x/isr.h +++ b/cpu/mc1322x/isr.h @@ -42,8 +42,11 @@ extern void tmr3_isr(void) __attribute__((weak)); extern void rtc_isr(void) __attribute__((weak)); +extern void uart1_isr(void) __attribute__((weak)); + #define crm_irq() (bit_is_set(reg32(INTSRC),INT_NUM_CRM)) +#define uart1_irq() (bit_is_set(reg32(INTSRC),INT_NUM_UART1)) #endif diff --git a/cpu/mc1322x/maca.c b/cpu/mc1322x/maca.c index 4a75bff..64ae8dd 100644 --- a/cpu/mc1322x/maca.c +++ b/cpu/mc1322x/maca.c @@ -112,7 +112,6 @@ int maca_read(void *buf, unsigned short bufsize) { volatile uint32_t rx_size; rx_size = reg32(MACA_GETRXLVL) - 2; -printf("maca_read %d\n", rx_size); if(rx_size < bufsize) bufsize = rx_size; #if MACA_RAW_MODE PRINTF("maca read: in raw mode bufsize 0x%0x \n\r",bufsize); diff --git a/cpu/mc1322x/uart1.c b/cpu/mc1322x/uart1.c index 3400d35..624b834 100644 --- a/cpu/mc1322x/uart1.c +++ b/cpu/mc1322x/uart1.c @@ -3,6 +3,9 @@ #include "utils.h" #include "gpio.h" +char tx_buf[1024]; +int head, tail; + void uart1_init(void) { uint8_t i; @@ -23,11 +26,34 @@ void uart1_init(void) { reg32(UART1_CON) = 0x00000003; /* enable receive and transmit */ reg32(GPIO_FUNC_SEL0) = ( (0x01 << (14*2)) | (0x01 << (15*2)) ); /* set GPIO15-14 to UART (UART1 TX and RX)*/ + /* interrupt when 28 bytes are free */ + reg32(UT1CON) = 28; + + head = tail = 0; +} + +void uart1_isr(void) { + while( reg32(UT1CON) != 0 ) { + if (head == tail) + return; + reg32(UART1_DATA) = tx_buf[tail]; + tail++; + if (tail >= sizeof(tx_buf)) + tail = 0; + } } int uart1_putchar(int c) { - while( reg32(UT1CON) == 31 ); - reg32(UART1_DATA) = c; + int h = head; + h = head + 1; + if (h > sizeof(tx_buf)) + h = 0; + if (h == tail) /* drop chars when no room */ + return; + tx_buf[head] = c; + head = h; + + uart1_isr(); return c; } diff --git a/examples/udp-receiver-ipv6/example-udp-receiver.c b/examples/udp-receiver-ipv6/example-udp-receiver.c index d476434..60f14df 100644 --- a/examples/udp-receiver-ipv6/example-udp-receiver.c +++ b/examples/udp-receiver-ipv6/example-udp-receiver.c @@ -90,6 +90,7 @@ PROCESS_THREAD(udp_process_receiver, ev, data) udpconn = udp_new(&ipaddr, HTONS(0xF0B0+1), NULL); udp_bind(udpconn, HTONS(0xF0B0)); +printf("updconn %x lport %x rport %x\n", udpconn, udpconn->lport, udpconn->rport); PRINTF("Created connection with remote peer "); PRINT6ADDR(&udpconn->ripaddr); diff --git a/platform/mc1322x/contiki-mc1322x-main.c b/platform/mc1322x/contiki-mc1322x-main.c index 2c96915..35bd233 100644 --- a/platform/mc1322x/contiki-mc1322x-main.c +++ b/platform/mc1322x/contiki-mc1322x-main.c @@ -224,9 +224,6 @@ main(void) } printf("%d\n", addr.u8[i]); - /* Autostart processes */ - autostart_start(autostart_processes); - //Give ourselves a prefix //init_net(); @@ -266,10 +263,10 @@ main(void) //slip_set_input_callback(set_gateway); - { - uip_ipaddr_t hostaddr, netmask; +// { +// uip_ipaddr_t hostaddr, netmask; - uip_init(); +// uip_init(); // uip_ipaddr(&hostaddr, 172,16, // rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); @@ -283,9 +280,9 @@ main(void) //uip_over_mesh_set_gateway_netif(&slipif); //uip_fw_default(&meshif); //uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); - printf("uIP started with IP address %d.%d.%d.%d\n", - uip_ipaddr_to_quad(&hostaddr)); - } +// printf("uIP started with IP address %d.%d.%d.%d\n", +// uip_ipaddr_to_quad(&hostaddr)); +// } #endif /* WITH_UIP */ PRINTF("Local IPv6 address: "); @@ -294,6 +291,9 @@ main(void) printf("System online.\n\r"); + /* Autostart processes */ + autostart_start(autostart_processes); + /* Main scheduler loop */ while(1) { process_run();