From 78450aeab6fc8ea044b99f2450ac7d893cc15fbf Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 16 Mar 2012 18:00:58 +0000 Subject: [PATCH 01/21] Fixed mis-formatted printfs --- examples/cc2530dk/udp-ipv6/server.c | 2 +- examples/sensinode/udp-ipv6/server.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cc2530dk/udp-ipv6/server.c b/examples/cc2530dk/udp-ipv6/server.c index 2d9ff70b7..524fc9cf6 100644 --- a/examples/cc2530dk/udp-ipv6/server.c +++ b/examples/cc2530dk/udp-ipv6/server.c @@ -70,7 +70,7 @@ tcpip_handler(void) leds_on(LEDS_RED); len = uip_datalen(); memcpy(buf, uip_appdata, len); - PRINTF("%u bytes from [", len, *(uint16_t *)buf); + PRINTF("%u bytes from [", len); PRINT6ADDR(&UIP_IP_BUF->srcipaddr); PRINTF("]:%u\n", UIP_HTONS(UIP_UDP_BUF->srcport)); #if SERVER_REPLY diff --git a/examples/sensinode/udp-ipv6/server.c b/examples/sensinode/udp-ipv6/server.c index f3ab93202..62ea84939 100644 --- a/examples/sensinode/udp-ipv6/server.c +++ b/examples/sensinode/udp-ipv6/server.c @@ -77,7 +77,7 @@ tcpip_handler(void) leds_on(LEDS_RED); len = uip_datalen(); memcpy(buf, uip_appdata, len); - PRINTF("%u bytes from [", len, *(uint16_t *)buf); + PRINTF("%u bytes from [", len); PRINT6ADDR(&UIP_IP_BUF->srcipaddr); PRINTF("]:%u", UIP_HTONS(UIP_UDP_BUF->srcport)); PRINTF(" V=%u", *buf); From 9475737f4bfe6868f9584d9812d1aea42c5303a4 Mon Sep 17 00:00:00 2001 From: Vasilis Michopoulos Date: Tue, 27 Mar 2012 15:58:50 +0100 Subject: [PATCH 02/21] Changed some sensinode/cc2530 examples to use uip-debug.h instead of the old #define DEBUG N --- examples/cc2530dk/udp-ipv6/ping6.c | 12 ++---------- examples/sensinode/udp-ipv6/ping6.c | 12 ++---------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/examples/cc2530dk/udp-ipv6/ping6.c b/examples/cc2530dk/udp-ipv6/ping6.c index f4cc073ab..ae2a2b59a 100644 --- a/examples/cc2530dk/udp-ipv6/ping6.c +++ b/examples/cc2530dk/udp-ipv6/ping6.c @@ -36,16 +36,8 @@ #include "dev/button-sensor.h" #include "debug.h" -#define DEBUG 1 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15]) -#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",lladdr->addr[0], lladdr->addr[1], lladdr->addr[2], lladdr->addr[3],lladdr->addr[4], lladdr->addr[5]) -#else -#define PRINTF(...) -#define PRINT6ADDR(addr) -#endif +#define DEBUG DEBUG_NONE +#include "net/uip-debug.h" #define PING6_NB 5 #define PING6_DATALEN 16 diff --git a/examples/sensinode/udp-ipv6/ping6.c b/examples/sensinode/udp-ipv6/ping6.c index a88ebc7dc..611cae02a 100644 --- a/examples/sensinode/udp-ipv6/ping6.c +++ b/examples/sensinode/udp-ipv6/ping6.c @@ -38,16 +38,8 @@ #include "sensinode-debug.h" #endif -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15]) -#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",lladdr->addr[0], lladdr->addr[1], lladdr->addr[2], lladdr->addr[3],lladdr->addr[4], lladdr->addr[5]) -#else -#define PRINTF(...) -#define PRINT6ADDR(addr) -#endif +#define DEBUG DEBUG_NONE +#include "net/uip-debug.h" #define PING6_NB 5 #define PING6_DATALEN 16 From 4f1e251603da607f8f5df3fb2dc542efe3d34fd0 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Thu, 29 Mar 2012 11:07:04 +0100 Subject: [PATCH 03/21] Some uN_t had crept back in cc2530dk and sensinode. Changed to uintN_t plus a bit of code formatting --- cpu/cc2430/8051def.h | 5 ----- cpu/cc253x/8051def.h | 4 ---- examples/cc2530dk/udp-ipv6/ping6.c | 8 ++++---- examples/sensinode/clock_test.c | 10 +++++----- examples/sensinode/event-post/event-post.h | 14 +++++++------- examples/sensinode/timer-test.c | 2 +- examples/sensinode/udp-ipv6/ping6.c | 8 ++++---- platform/cc2530dk/viztool.c | 1 - platform/sensinode/viztool.c | 1 - 9 files changed, 21 insertions(+), 32 deletions(-) diff --git a/cpu/cc2430/8051def.h b/cpu/cc2430/8051def.h index 069a42c79..32528d30f 100644 --- a/cpu/cc2430/8051def.h +++ b/cpu/cc2430/8051def.h @@ -40,13 +40,8 @@ #define CC_CONF_FUNCTION_POINTER_KEYWORD __reentrant /* Generic types. */ -typedef unsigned char u8_t; /* 8 bit type */ -typedef unsigned short u16_t; /* 16 bit type */ -typedef unsigned long u32_t; /* 32 bit type */ -typedef signed long s32_t; /* 32 bit type */ typedef unsigned short uip_stats_t; - /* Time type. */ typedef unsigned short clock_time_t; #define MAX_TICKS (~((clock_time_t)0) / 2) diff --git a/cpu/cc253x/8051def.h b/cpu/cc253x/8051def.h index 7314edcd7..24b66c723 100644 --- a/cpu/cc253x/8051def.h +++ b/cpu/cc253x/8051def.h @@ -40,10 +40,6 @@ #define CC_CONF_FUNCTION_POINTER_KEYWORD __reentrant /* Generic types. */ -typedef unsigned char u8_t; /* 8 bit type */ -typedef unsigned short u16_t; /* 16 bit type */ -typedef unsigned long u32_t; /* 32 bit type */ -typedef signed long s32_t; /* 32 bit type */ typedef unsigned short uip_stats_t; /* Compiler configurations */ diff --git a/examples/cc2530dk/udp-ipv6/ping6.c b/examples/cc2530dk/udp-ipv6/ping6.c index ae2a2b59a..ca4213c61 100644 --- a/examples/cc2530dk/udp-ipv6/ping6.c +++ b/examples/cc2530dk/udp-ipv6/ping6.c @@ -46,8 +46,8 @@ #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) static struct etimer ping6_periodic_timer; -static u8_t count = 0; -static u16_t addr[8]; +static uint8_t count = 0; +static uint16_t addr[8]; static uip_ipaddr_t dest_addr; PROCESS(ping6_process, "PING6 process"); @@ -74,8 +74,8 @@ ping6handler() uip_len = UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN + UIP_IPH_LEN + PING6_DATALEN; - UIP_IP_BUF->len[0] = (u8_t)((uip_len - 40) >> 8); - UIP_IP_BUF->len[1] = (u8_t)((uip_len - 40) & 0x00FF); + UIP_IP_BUF->len[0] = (uint8_t)((uip_len - 40) >> 8); + UIP_IP_BUF->len[1] = (uint8_t)((uip_len - 40) & 0x00FF); UIP_ICMP_BUF->icmpchksum = 0; UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum(); diff --git a/examples/sensinode/clock_test.c b/examples/sensinode/clock_test.c index 758b4d040..24d3c6417 100644 --- a/examples/sensinode/clock_test.c +++ b/examples/sensinode/clock_test.c @@ -19,7 +19,7 @@ PROCESS_THREAD(clock_test_process, ev, data) static struct etimer et; static clock_time_t count, start_count, end_count, diff; static unsigned long sec; - static u8_t i; + static uint8_t i; PROCESS_BEGIN(); @@ -41,8 +41,8 @@ PROCESS_THREAD(clock_test_process, ev, data) PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); etimer_reset(&et); - count = clock_time(); - printf("%u ticks\n", count); + count = clock_time(); + printf("%u ticks\n", count); leds_toggle(LEDS_RED); i++; @@ -55,8 +55,8 @@ PROCESS_THREAD(clock_test_process, ev, data) PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); etimer_reset(&et); - sec = clock_seconds(); - printf("%u seconds\n", (u16_t) sec); + sec = clock_seconds(); + printf("%u seconds\n", (uint16_t) sec); leds_toggle(LEDS_GREEN); i++; diff --git a/examples/sensinode/event-post/event-post.h b/examples/sensinode/event-post/event-post.h index 2d640441a..f43934438 100644 --- a/examples/sensinode/event-post/event-post.h +++ b/examples/sensinode/event-post/event-post.h @@ -10,13 +10,13 @@ #define EVENT_POST_H_ struct event_struct { - short s_val; - int i_val; - long l_val; - long long ll_val; - u8_t u8_val; - u16_t u16_val; - u32_t u32_val; + short s_val; + int i_val; + long l_val; + long long ll_val; + uint8_t u8_val; + uint16_t u16_val; + uint32_t u32_val; }; #endif /* EVENT_POST_H_ */ diff --git a/examples/sensinode/timer-test.c b/examples/sensinode/timer-test.c index 163574326..3afc53320 100644 --- a/examples/sensinode/timer-test.c +++ b/examples/sensinode/timer-test.c @@ -111,7 +111,7 @@ PROCESS_THREAD(clock_test_process, ev, data) etimer_reset(&et); sec = clock_seconds(); - printf("%u seconds\n", (u16_t) sec); + printf("%u seconds\n", (uint16_t) sec); leds_toggle(LEDS_GREEN); i++; diff --git a/examples/sensinode/udp-ipv6/ping6.c b/examples/sensinode/udp-ipv6/ping6.c index 611cae02a..6c8d4450c 100644 --- a/examples/sensinode/udp-ipv6/ping6.c +++ b/examples/sensinode/udp-ipv6/ping6.c @@ -48,8 +48,8 @@ #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) static struct etimer ping6_periodic_timer; -static u8_t count = 0; -static u16_t addr[8]; +static uint8_t count = 0; +static uint16_t addr[8]; static uip_ipaddr_t dest_addr; PROCESS(ping6_process, "PING6 process"); @@ -76,8 +76,8 @@ ping6handler() uip_len = UIP_ICMPH_LEN + UIP_ICMP6_ECHO_REQUEST_LEN + UIP_IPH_LEN + PING6_DATALEN; - UIP_IP_BUF->len[0] = (u8_t)((uip_len - 40) >> 8); - UIP_IP_BUF->len[1] = (u8_t)((uip_len - 40) & 0x00FF); + UIP_IP_BUF->len[0] = (uint8_t)((uip_len - 40) >> 8); + UIP_IP_BUF->len[1] = (uint8_t)((uip_len - 40) & 0x00FF); UIP_ICMP_BUF->icmpchksum = 0; UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum(); diff --git a/platform/cc2530dk/viztool.c b/platform/cc2530dk/viztool.c index 777ffc855..bfa354982 100644 --- a/platform/cc2530dk/viztool.c +++ b/platform/cc2530dk/viztool.c @@ -71,7 +71,6 @@ extern uip_ds6_netif_t uip_ds6_if; extern uip_ds6_route_t uip_ds6_routing_table[UIP_DS6_ROUTE_NB]; extern uip_ds6_nbr_t uip_ds6_nbr_cache[UIP_DS6_NBR_NB]; extern uip_ds6_defrt_t uip_ds6_defrt_list[UIP_DS6_DEFRT_NB]; -extern u16_t uip_len; /*---------------------------------------------------------------------------*/ static uint8_t process_request() diff --git a/platform/sensinode/viztool.c b/platform/sensinode/viztool.c index 777ffc855..bfa354982 100644 --- a/platform/sensinode/viztool.c +++ b/platform/sensinode/viztool.c @@ -71,7 +71,6 @@ extern uip_ds6_netif_t uip_ds6_if; extern uip_ds6_route_t uip_ds6_routing_table[UIP_DS6_ROUTE_NB]; extern uip_ds6_nbr_t uip_ds6_nbr_cache[UIP_DS6_NBR_NB]; extern uip_ds6_defrt_t uip_ds6_defrt_list[UIP_DS6_DEFRT_NB]; -extern u16_t uip_len; /*---------------------------------------------------------------------------*/ static uint8_t process_request() From 5afdd1940368d9fb6694917f643cb782dc89939e Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Thu, 29 Mar 2012 11:28:46 +0100 Subject: [PATCH 04/21] Adjusted check to determine if we are being built with SDCC Since rev #7342, SDCC defines __SDCC_mcs51 instead of SDCC_mcs51. We check for either --- cpu/cc253x/8051def.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/cc253x/8051def.h b/cpu/cc253x/8051def.h index 24b66c723..21a4ffcf7 100644 --- a/cpu/cc253x/8051def.h +++ b/cpu/cc253x/8051def.h @@ -47,7 +47,7 @@ typedef unsigned short uip_stats_t; #define CLIF /* Single asm instruction without messing up syntax highlighting */ -#if defined SDCC_mcs51 +#if defined(__SDCC_mcs51) || defined(SDCC_mcs51) #define ASM(x) __asm \ x \ __endasm From 23e7f242f68e678af2e352ae69a0132988fd53f4 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Thu, 29 Mar 2012 12:57:56 +0100 Subject: [PATCH 05/21] Changes to the ping part of the cc2530 and Sensinode udp-ipv6 examples - Remove obsolete variable declarations - prettier printf output - cc2530 example turns on printfs --- examples/cc2530dk/udp-ipv6/ping6.c | 7 +++---- examples/sensinode/udp-ipv6/ping6.c | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/examples/cc2530dk/udp-ipv6/ping6.c b/examples/cc2530dk/udp-ipv6/ping6.c index ca4213c61..bab5db911 100644 --- a/examples/cc2530dk/udp-ipv6/ping6.c +++ b/examples/cc2530dk/udp-ipv6/ping6.c @@ -36,7 +36,7 @@ #include "dev/button-sensor.h" #include "debug.h" -#define DEBUG DEBUG_NONE +#define DEBUG DEBUG_PRINT #include "net/uip-debug.h" #define PING6_NB 5 @@ -47,7 +47,6 @@ static struct etimer ping6_periodic_timer; static uint8_t count = 0; -static uint16_t addr[8]; static uip_ipaddr_t dest_addr; PROCESS(ping6_process, "PING6 process"); @@ -81,9 +80,9 @@ ping6handler() UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum(); - PRINTF("Echo Request to"); + PRINTF("Echo Request to "); PRINT6ADDR(&UIP_IP_BUF->destipaddr); - PRINTF("from"); + PRINTF(" from "); PRINT6ADDR(&UIP_IP_BUF->srcipaddr); PRINTF("\n"); UIP_STAT(++uip_stat.icmp.sent); diff --git a/examples/sensinode/udp-ipv6/ping6.c b/examples/sensinode/udp-ipv6/ping6.c index 6c8d4450c..48ec952f9 100644 --- a/examples/sensinode/udp-ipv6/ping6.c +++ b/examples/sensinode/udp-ipv6/ping6.c @@ -49,7 +49,6 @@ static struct etimer ping6_periodic_timer; static uint8_t count = 0; -static uint16_t addr[8]; static uip_ipaddr_t dest_addr; PROCESS(ping6_process, "PING6 process"); @@ -83,9 +82,9 @@ ping6handler() UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum(); - PRINTF("Echo Request to"); + PRINTF("Echo Request to "); PRINT6ADDR(&UIP_IP_BUF->destipaddr); - PRINTF("from"); + PRINTF(" from "); PRINT6ADDR(&UIP_IP_BUF->srcipaddr); PRINTF("\n"); UIP_STAT(++uip_stat.icmp.sent); From 7854ee499aaf19e0849a46e91caaa7408110bc89 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Thu, 29 Mar 2012 11:22:56 +0100 Subject: [PATCH 06/21] Wrapped cc2x30 SOFT_RESET() macro inside do {...} while(0) --- cpu/cc2430/8051def.h | 4 ++-- cpu/cc253x/8051def.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cpu/cc2430/8051def.h b/cpu/cc2430/8051def.h index 32528d30f..a7327ed92 100644 --- a/cpu/cc2430/8051def.h +++ b/cpu/cc2430/8051def.h @@ -75,8 +75,8 @@ typedef unsigned short clock_time_t; __endasm; \ } -/* Macro for a soft reset. In many respects better than H/W reboot via W/D */ -#define SOFT_RESET() {((void (__code *) (void)) 0x0000) ();} +/* Macro for a soft reset. */ +#define SOFT_RESET() do {((void (__code *) (void)) 0x0000) ();} while(0) /* We don't provide architecture-specific checksum calculations */ #define UIP_ARCH_ADD32 0 diff --git a/cpu/cc253x/8051def.h b/cpu/cc253x/8051def.h index 21a4ffcf7..7ac0b84ef 100644 --- a/cpu/cc253x/8051def.h +++ b/cpu/cc253x/8051def.h @@ -59,8 +59,8 @@ typedef unsigned short uip_stats_t; #define DISABLE_INTERRUPTS() do {EA = 0;} while(0) #define ENABLE_INTERRUPTS() do {EA = 1;} while(0) -/* Macro for a soft reset. In many respects better than H/W reboot via W/D */ -#define SOFT_RESET() {((void (__code *) (void)) 0x0000) ();} +/* Macro for a soft reset. */ +#define SOFT_RESET() do {((void (__code *) (void)) 0x0000) ();} while(0) /* We don't provide architecture-specific checksum calculations */ #define UIP_ARCH_ADD32 0 From c7c7bcbf813ced8d21ef4bceb27a831e59d4bba3 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Fri, 23 Mar 2012 14:01:16 +0100 Subject: [PATCH 07/21] Branched and added custom address to Makefile. --- examples/er-rest-example/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/er-rest-example/Makefile b/examples/er-rest-example/Makefile index 1cdae1b5e..38029c574 100644 --- a/examples/er-rest-example/Makefile +++ b/examples/er-rest-example/Makefile @@ -25,7 +25,7 @@ else ${info INFO: compiling without RPL} UIP_CONF_RPL=0 CFLAGS += -DUIP_CONF_ND6_DEF_MAXDADNS=0 -CFLAGS += -DHARD_CODED_ADDRESS=\"fdfd::10\" +CFLAGS += -DHARD_CODED_ADDRESS=\"2001:620:8:1010::10\" CFLAGS += -DUIP_CONF_BUFFER_SIZE=1280 endif From d102d8c607cab252d9d96310113331df38bb1c20 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Fri, 23 Mar 2012 14:49:52 +0100 Subject: [PATCH 08/21] Changed separate API and fixed token bug. --- apps/er-coap-07/er-coap-07-engine.c | 40 ++++++++-------- apps/er-coap-07/er-coap-07-separate.c | 55 ++++++++++++---------- apps/er-coap-07/er-coap-07-separate.h | 3 +- examples/er-rest-example/plugtest-server.c | 9 ++-- 4 files changed, 54 insertions(+), 53 deletions(-) diff --git a/apps/er-coap-07/er-coap-07-engine.c b/apps/er-coap-07/er-coap-07-engine.c index a6a1dc573..5301cacd7 100644 --- a/apps/er-coap-07/er-coap-07-engine.c +++ b/apps/er-coap-07/er-coap-07-engine.c @@ -67,13 +67,13 @@ PROCESS(coap_receiver, "CoAP Receiver"); -/*-----------------------------------------------------------------------------------*/ -/*- Variables -----------------------------------------------------------------------*/ -/*-----------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/*- Variables ----------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ static service_callback_t service_cbk = NULL; -/*-----------------------------------------------------------------------------------*/ -/*-----------------------------------------------------------------------------------*/ -/*-----------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ static int handle_incoming_data(void) @@ -279,27 +279,27 @@ handle_incoming_data(void) return coap_error_code; } -/*-----------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ void coap_receiver_init() { process_start(&coap_receiver, NULL); } -/*-----------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ void coap_set_service_callback(service_callback_t callback) { service_cbk = callback; } -/*-----------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ rest_resource_flags_t coap_get_rest_method(void *packet) { return (rest_resource_flags_t)(1 << (((coap_packet_t *)packet)->code - 1)); } -/*-----------------------------------------------------------------------------------*/ -/*- Server part ---------------------------------------------------------------------*/ -/*-----------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/*- Server part --------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ /* The discover resource is automatically included for CoAP. */ RESOURCE(well_known_core, METHOD_GET, ".well-known/core", "ct=40"); @@ -408,7 +408,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t *offset += preferred_size; } } -/*-----------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ PROCESS_THREAD(coap_receiver, ev, data) { PROCESS_BEGIN(); @@ -433,15 +433,15 @@ PROCESS_THREAD(coap_receiver, ev, data) PROCESS_END(); } -/*-----------------------------------------------------------------------------------*/ -/*- Client part ---------------------------------------------------------------------*/ -/*-----------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/*- Client part --------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ void blocking_request_callback(void *callback_data, void *response) { struct request_state_t *state = (struct request_state_t *) callback_data; state->response = (coap_packet_t*) response; process_poll(state->process); } -/*-----------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ PT_THREAD(coap_blocking_request(struct request_state_t *state, process_event_t ev, uip_ipaddr_t *remote_ipaddr, uint16_t remote_port, coap_packet_t *request, @@ -509,9 +509,9 @@ PT_THREAD(coap_blocking_request(struct request_state_t *state, process_event_t e PT_END(&state->pt); } -/*-----------------------------------------------------------------------------------*/ -/*- Engine Interface ----------------------------------------------------------------*/ -/*-----------------------------------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ +/*- Engine Interface ---------------------------------------------------------*/ +/*----------------------------------------------------------------------------*/ const struct rest_implementation coap_rest_implementation = { "CoAP-07", diff --git a/apps/er-coap-07/er-coap-07-separate.c b/apps/er-coap-07/er-coap-07-separate.c index 528b0c112..b9bca9abc 100644 --- a/apps/er-coap-07/er-coap-07-separate.c +++ b/apps/er-coap-07/er-coap-07-separate.c @@ -53,41 +53,40 @@ #define PRINTLLADDR(addr) #endif -/*-----------------------------------------------------------------------------------*/ -int coap_separate_handler(resource_t *resource, void *request, void *response) -{ - coap_packet_t *const coap_req = (coap_packet_t *) request; - - PRINTF("Separate response for /%s MID %u\n", resource->url, coap_res->mid); - - /* Only ack CON requests. */ - if (coap_req->type==COAP_TYPE_CON) - { - /* send separate ACK. */ - coap_packet_t ack[1]; - /* ACK with empty code (0) */ - coap_init_message(ack, COAP_TYPE_ACK, 0, coap_req->mid); - /* Serializing into IPBUF: Only overwrites header parts that are already parsed into the request struct. */ - coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, (uip_appdata), coap_serialize_message(ack, uip_appdata)); - } - - /* Pre-handlers could skip the handling by returning 0. */ - return 1; -} - +/*----------------------------------------------------------------------------*/ int -coap_separate_yield(void *request, coap_separate_t *separate_store) +coap_separate_reject() +{ + coap_error_code = SERVICE_UNAVAILABLE_5_03; + coap_error_message = "AlreadyInUse"; +} +/*----------------------------------------------------------------------------*/ +int +coap_separate_accept(void *request, coap_separate_t *separate_store) { coap_packet_t *const coap_req = (coap_packet_t *) request; coap_transaction_t *const t = coap_get_transaction_by_mid(coap_req->mid); + PRINTF("Separate ACCEPT: /%.*s MID %u\n", coap_req->uri_path_len, coap_req->uri_path, coap_req->mid); if (t) { + /* Send separate ACK for CON. */ + if (coap_req->type==COAP_TYPE_CON) + { + coap_packet_t ack[1]; + /* ACK with empty code (0) */ + coap_init_message(ack, COAP_TYPE_ACK, 0, coap_req->mid); + /* Serializing into IPBUF: Only overwrites header parts that are already parsed into the request struct. */ + coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, (uip_appdata), coap_serialize_message(ack, uip_appdata)); + } + + /* Store remote address. */ uip_ipaddr_copy(&separate_store->addr, &t->addr); separate_store->port = t->port; + /* Store correct response type. */ separate_store->type = coap_req->type==COAP_TYPE_CON ? COAP_TYPE_CON : COAP_TYPE_NON; - separate_store->mid = coap_get_mid(); // if it was NON, we burned one MID in the engine... + separate_store->mid = coap_get_mid(); /* if it was a NON, we burned one MID in the engine... */ memcpy(separate_store->token, coap_req->token, coap_req->token_len); separate_store->token_len = coap_req->token_len; @@ -102,13 +101,17 @@ coap_separate_yield(void *request, coap_separate_t *separate_store) } else { + PRINTF("ERROR: Response transaction for separate request not found!\n"); return 0; } } - +/*----------------------------------------------------------------------------*/ void coap_separate_resume(void *response, coap_separate_t *separate_store, uint8_t code) { coap_init_message(response, separate_store->type, code, separate_store->mid); - coap_set_header_token(response, separate_store->token, separate_store->token_len); + if (separate_store->token_len) + { + coap_set_header_token(response, separate_store->token, separate_store->token_len); + } } diff --git a/apps/er-coap-07/er-coap-07-separate.h b/apps/er-coap-07/er-coap-07-separate.h index 7eade7e56..62b25c095 100644 --- a/apps/er-coap-07/er-coap-07-separate.h +++ b/apps/er-coap-07/er-coap-07-separate.h @@ -59,7 +59,8 @@ typedef struct coap_separate { } coap_separate_t; int coap_separate_handler(resource_t *resource, void *request, void *response); -int coap_separate_yield(void *request, coap_separate_t *separate_store); +int coap_separate_reject(); +int coap_separate_accept(void *request, coap_separate_t *separate_store); void coap_separate_resume(void *response, coap_separate_t *separate_store, uint8_t code); #endif /* COAP_SEPARATE_H_ */ diff --git a/examples/er-rest-example/plugtest-server.c b/examples/er-rest-example/plugtest-server.c index 2994cb6f7..550d1c0c4 100644 --- a/examples/er-rest-example/plugtest-server.c +++ b/examples/er-rest-example/plugtest-server.c @@ -207,10 +207,8 @@ separate_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer PRINTF("/separate "); if (separate_active) { - PRINTF("BUSY "); - REST.set_response_status(response, REST.status.SERVICE_UNAVAILABLE); - const char *msg = "AlreadyInUse"; - REST.set_response_payload(response, msg, strlen(msg)); + PRINTF("REJECTED "); + coap_separate_reject(); } else { @@ -218,7 +216,7 @@ separate_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer separate_active = 1; /* Take over and skip response by engine. */ - coap_separate_yield(request, &separate_store->request_metadata); + coap_separate_accept(request, &separate_store->request_metadata); /* Be aware to respect the Block2 option, which is also stored in the coap_separate_t. */ snprintf(separate_store->buffer, MAX_PLUGFEST_PAYLOAD, "Type: %u\nCode: %u\nMID: %u", coap_req->type, coap_req->code, coap_req->mid); @@ -537,7 +535,6 @@ PROCESS_THREAD(plugtest_server, ev, data) rest_activate_resource(&resource_query); #endif #if REST_RES_SEPARATE - rest_set_pre_handler(&resource_separate, coap_separate_handler); rest_activate_periodic_resource(&periodic_resource_separate); #endif #if REST_RES_LARGE From 949ba03bdad521340f3d4d6761c31d78919a6c60 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Fri, 23 Mar 2012 16:29:25 +0100 Subject: [PATCH 09/21] Changed notify API to passing a notification message. --- apps/er-coap-07/er-coap-07-observing.c | 50 +++++++++------- apps/er-coap-07/er-coap-07-observing.h | 2 +- apps/er-coap-07/er-coap-07-transactions.c | 8 ++- apps/erbium/erbium.h | 57 +++++++++---------- examples/er-rest-example/plugtest-server.c | 29 +++++----- .../er-rest-example/rest-server-example.c | 43 +++++++------- 6 files changed, 101 insertions(+), 88 deletions(-) diff --git a/apps/er-coap-07/er-coap-07-observing.c b/apps/er-coap-07/er-coap-07-observing.c index 11eef1935..5c8b5e465 100644 --- a/apps/er-coap-07/er-coap-07-observing.c +++ b/apps/er-coap-07/er-coap-07-observing.c @@ -164,43 +164,51 @@ coap_remove_observer_by_mid(uip_ipaddr_t *addr, uint16_t port, uint16_t mid) } /*-----------------------------------------------------------------------------------*/ void -coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payload, size_t payload_len) +coap_notify_observers(resource_t *resource, uint16_t obs_counter, void *notification) { + coap_packet_t *const coap_res = (coap_packet_t *) notification; coap_observer_t* obs = NULL; + uint8_t preferred_type = coap_res->type; + + PRINTF("Observing: Notification from %s\n", resource->url); + + /* Iterate over observers. */ for (obs = (coap_observer_t*)list_head(observers_list); obs; obs = obs->next) { - if (obs->url==url) /* using RESOURCE url pointer as handle */ + if (obs->url==resource->url) /* using RESOURCE url pointer as handle */ { coap_transaction_t *transaction = NULL; - /*TODO implement special transaction for CON, sharing the same buffer to allow for more observers */ + /*TODO implement special transaction for CON, sharing the same buffer to allow for more observers. */ if ( (transaction = coap_new_transaction(coap_get_mid(), &obs->addr, obs->port)) ) { - /* Use CON to check whether client is still there/interested after COAP_OBSERVING_REFRESH_INTERVAL. */ - if (stimer_expired(&obs->refresh_timer)) - { - PRINTF("Observing: Refresh client with CON\n"); - type = COAP_TYPE_CON; - stimer_restart(&obs->refresh_timer); - } - - /* prepare response */ - coap_packet_t push[1]; /* This way the packet can be treated as pointer as usual. */ - coap_init_message(push, (coap_message_type_t)type, CONTENT_2_05, transaction->mid ); - coap_set_header_observe(push, observe); - coap_set_header_token(push, obs->token, obs->token_len); - coap_set_payload(push, payload, payload_len); - transaction->packet_len = coap_serialize_message(push, transaction->packet); - - PRINTF("Observing: Notify from /%s for ", url); + PRINTF(" Observer "); PRINT6ADDR(&obs->addr); PRINTF(":%u\n", obs->port); - PRINTF(" %.*s\n", payload_len, payload); /* Update last MID for RST matching. */ obs->last_mid = transaction->mid; + /* Prepare response */ + coap_res->mid = transaction->mid; + coap_set_header_observe(coap_res, obs_counter); + coap_set_header_token(coap_res, obs->token, obs->token_len); + + /* Use CON to check whether client is still there/interested after COAP_OBSERVING_REFRESH_INTERVAL. */ + if (stimer_expired(&obs->refresh_timer)) + { + PRINTF(" Refreshing with CON\n"); + coap_res->type = COAP_TYPE_CON; + stimer_restart(&obs->refresh_timer); + } + else + { + coap_res->type = preferred_type; + } + + transaction->packet_len = coap_serialize_message(coap_res, transaction->packet); + coap_send_transaction(transaction); } } diff --git a/apps/er-coap-07/er-coap-07-observing.h b/apps/er-coap-07/er-coap-07-observing.h index 7b09ba83e..a17ad86bd 100644 --- a/apps/er-coap-07/er-coap-07-observing.h +++ b/apps/er-coap-07/er-coap-07-observing.h @@ -75,7 +75,7 @@ int coap_remove_observer_by_token(uip_ipaddr_t *addr, uint16_t port, uint8_t *to int coap_remove_observer_by_url(uip_ipaddr_t *addr, uint16_t port, const char *url); int coap_remove_observer_by_mid(uip_ipaddr_t *addr, uint16_t port, uint16_t mid); -void coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payload, size_t payload_len); +void coap_notify_observers(resource_t *resource, uint16_t obs_counter, void *notification); void coap_observe_handler(resource_t *resource, void *request, void *response); diff --git a/apps/er-coap-07/er-coap-07-transactions.c b/apps/er-coap-07/er-coap-07-transactions.c index 10070a29e..2a11002d4 100644 --- a/apps/er-coap-07/er-coap-07-transactions.c +++ b/apps/er-coap-07/er-coap-07-transactions.c @@ -105,6 +105,7 @@ coap_send_transaction(coap_transaction_t *t) { if (t->retrans_countermid); if (t->retrans_counter==0) @@ -118,7 +119,10 @@ coap_send_transaction(coap_transaction_t *t) PRINTF("Doubled (%u) interval %f\n", t->retrans_counter, (float)t->retrans_timer.timer.interval/CLOCK_SECOND); } - /*FIXME hack, maybe there is a better way, but avoid posting everything to the process */ + /*FIXME + * Hack: Setting timer for responsible process. + * Maybe there is a better way, but avoid posting everything to the process. + */ struct process *process_actual = PROCESS_CURRENT(); process_current = transaction_handler_process; etimer_restart(&t->retrans_timer); /* interval updated above */ @@ -128,7 +132,7 @@ coap_send_transaction(coap_transaction_t *t) } else { - /* timeout */ + /* Timed out. */ PRINTF("Timeout\n"); restful_response_handler callback = t->callback; void *callback_data = t->callback_data; diff --git a/apps/erbium/erbium.h b/apps/erbium/erbium.h index 7e491c3f8..72b995db0 100644 --- a/apps/erbium/erbium.h +++ b/apps/erbium/erbium.h @@ -75,7 +75,7 @@ struct periodic_resource_s; typedef void (*restful_handler) (void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); typedef int (*restful_pre_handler) (struct resource_s *resource, void* request, void* response); typedef void (*restful_post_handler) (struct resource_s *resource, void* request, void* response); -typedef int (*restful_periodic_handler) (struct resource_s* resource); +typedef void (*restful_periodic_handler) (struct resource_s* resource); typedef void (*restful_response_handler) (void *data, void* response); /* Signature of the rest-engine service function. */ @@ -134,6 +134,31 @@ struct rest_implementation_type unsigned int APPLICATION_X_OBIX_BINARY; }; +/* + * Data structure representing a resource in REST. + */ +struct resource_s { + struct resource_s *next; /* for LIST, points to next resource defined */ + rest_resource_flags_t flags; /* handled RESTful methods */ + const char* url; /*handled URL*/ + const char* attributes; /* link-format attributes */ + restful_handler handler; /* handler function */ + restful_pre_handler pre_handler; /* to be called before handler, may perform initializations */ + restful_post_handler post_handler; /* to be called after handler, may perform finalizations (cleanup, etc) */ + void* user_data; /* pointer to user specific data */ + unsigned int benchmark; /* to benchmark resource handler, used for separate response */ +}; +typedef struct resource_s resource_t; + +struct periodic_resource_s { + struct periodic_resource_s *next; /* for LIST, points to next resource defined */ + resource_t *resource; + uint32_t period; + struct etimer periodic_timer; + restful_periodic_handler periodic_handler; +}; +typedef struct periodic_resource_s periodic_resource_t; + struct rest_implementation { char *name; @@ -199,7 +224,7 @@ struct rest_implementation { int (* get_post_variable)(void *request, const char *name, const char **value); /** Send the payload to all subscribers of the resource at url. */ - void (* notify_subscribers)(const char *url, int implementation_secific_mode, uint32_t counter, uint8_t *payload, size_t payload_len); + void (* notify_subscribers)(resource_t *resource, uint16_t counter, void *notification); /** The handler for resource subscriptions. */ restful_post_handler subscription_handler; @@ -222,32 +247,6 @@ struct rest_implementation { */ extern const struct rest_implementation REST; -/* - * Data structure representing a resource in REST. - */ -struct resource_s { - struct resource_s *next; /* for LIST, points to next resource defined */ - rest_resource_flags_t flags; /* handled RESTful methods */ - const char* url; /*handled URL*/ - const char* attributes; /* link-format attributes */ - restful_handler handler; /* handler function */ - restful_pre_handler pre_handler; /* to be called before handler, may perform initializations */ - restful_post_handler post_handler; /* to be called after handler, may perform finalizations (cleanup, etc) */ - void* user_data; /* pointer to user specific data */ - unsigned int benchmark; /* to benchmark resource handler, used for separate response */ -}; -typedef struct resource_s resource_t; - -struct periodic_resource_s { - struct periodic_resource_s *next; /* for LIST, points to next resource defined */ - resource_t *resource; - uint32_t period; - struct etimer periodic_timer; - restful_periodic_handler periodic_handler; -}; -typedef struct periodic_resource_s periodic_resource_t; - - /* * Macro to define a Resource * Resources are statically defined for the sake of efficiency and better memory management. @@ -282,7 +281,7 @@ int name##_event_handler(resource_t*) #define PERIODIC_RESOURCE(name, flags, url, attributes, period) \ void name##_handler(void *, void *, uint8_t *, uint16_t, int32_t *); \ resource_t resource_##name = {NULL, flags, url, attributes, name##_handler, NULL, NULL, NULL}; \ -int name##_periodic_handler(resource_t*); \ +void name##_periodic_handler(resource_t*); \ periodic_resource_t periodic_resource_##name = {NULL, &resource_##name, period, {{0}}, name##_periodic_handler} diff --git a/examples/er-rest-example/plugtest-server.c b/examples/er-rest-example/plugtest-server.c index 550d1c0c4..0d4eb5c7b 100644 --- a/examples/er-rest-example/plugtest-server.c +++ b/examples/er-rest-example/plugtest-server.c @@ -225,7 +225,7 @@ separate_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer PRINTF("(%s %u)\n", coap_req->type==COAP_TYPE_CON?"CON":"NON", coap_req->mid); } -int +void separate_periodic_handler(resource_t *resource) { if (separate_active) @@ -256,14 +256,10 @@ separate_periodic_handler(resource_t *resource) /* The engine will clear the transaction (right after send for NON, after acked for CON). */ separate_active = 0; - - return 1; } else { PRINTF("ERROR (transaction)\n"); } } /* if (separate_active) */ - - return 0; } #endif @@ -364,7 +360,7 @@ large_update_handler(void* request, void* response, uint8_t *buffer, uint16_t pr *offset = -1; } } else { - const uint8_t *incoming = NULL; + uint8_t *incoming = NULL; size_t len = 0; unsigned int ct = REST.get_header_content_type(request); @@ -415,9 +411,8 @@ void large_create_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { coap_packet_t *const coap_req = (coap_packet_t *) request; - uint8_t method = REST.get_method_type(request); - const uint8_t *incoming = NULL; + uint8_t *incoming = NULL; size_t len = 0; unsigned int ct = REST.get_header_content_type(request); @@ -461,7 +456,7 @@ large_create_handler(void* request, void* response, uint8_t *buffer, uint16_t pr */ PERIODIC_RESOURCE(obs, METHOD_GET, "obs", "title=\"Observable resource which changes every 5 seconds\";obs;rt=\"observe\"", 5*CLOCK_SECOND); -static uint32_t obs_counter = 0; +static uint16_t obs_counter = 0; static char obs_content[16]; void @@ -479,18 +474,20 @@ obs_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_s * Additionally, a handler function named [resource name]_handler must be implemented for each PERIODIC_RESOURCE. * It will be called by the REST manager process with the defined period. */ -int +void obs_periodic_handler(resource_t *r) { + ++obs_counter; - PRINTF("TICK /%s\n", r->url); - obs_counter = obs_counter + 1; + PRINTF("TICK %u for /%s\n", obs_counter, r->url); + + /* Build notification. */ + coap_packet_t notification[1]; /* This way the packet can be treated as pointer as usual. */ + coap_init_message(notification, COAP_TYPE_NON, CONTENT_2_05, 0 ); + coap_set_payload(notification, obs_content, snprintf(obs_content, sizeof(obs_content), "TICK %u", obs_counter)); /* Notify the registered observers with the given message type, observe option, and payload. */ - REST.notify_subscribers(r->url, 1, obs_counter, (uint8_t *)obs_content, snprintf(obs_content, sizeof(obs_content), "TICK %lu", obs_counter)); - /* |-> implementation-specific, e.g. CoAP: 0=CON and 1=NON notification */ - - return 1; + REST.notify_subscribers(r, obs_counter, notification); } #endif diff --git a/examples/er-rest-example/rest-server-example.c b/examples/er-rest-example/rest-server-example.c index f7f2e3b55..a958c1d2a 100644 --- a/examples/er-rest-example/rest-server-example.c +++ b/examples/er-rest-example/rest-server-example.c @@ -465,20 +465,23 @@ pushing_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr * Additionally, a handler function named [resource name]_handler must be implemented for each PERIODIC_RESOURCE. * It will be called by the REST manager process with the defined period. */ -int +void pushing_periodic_handler(resource_t *r) { - static uint32_t periodic_i = 0; - static char content[16]; + static uint16_t obs_counter = 0; + static char content[11]; - PRINTF("TICK /%s\n", r->url); - periodic_i = periodic_i + 1; + ++obs_counter; + + PRINTF("TICK %u for /%s\n", periodic_i, r->url); + + /* Build notification. */ + coap_packet_t notification[1]; /* This way the packet can be treated as pointer as usual. */ + coap_init_message(notification, COAP_TYPE_NON, CONTENT_2_05, 0 ); + coap_set_payload(notification, content, snprintf(content, sizeof(content), "TICK %u", obs_counter)); /* Notify the registered observers with the given message type, observe option, and payload. */ - REST.notify_subscribers(r->url, 1, periodic_i, (uint8_t *)content, snprintf(content, sizeof(content), "TICK %lu", periodic_i)); - /* |-> implementation-specific, e.g. CoAP: 0=CON and 1=NON notification */ - - return 1; + REST.notify_subscribers(r, obs_counter, notification); } #endif @@ -503,21 +506,23 @@ event_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred /* Additionally, a handler function named [resource name]_event_handler must be implemented for each PERIODIC_RESOURCE defined. * It will be called by the REST manager process with the defined period. */ -int +void event_event_handler(resource_t *r) { - static uint32_t event_i = 0; - static char content[10]; + static uint16_t event_counter = 0; + static char content[12]; - PRINTF("EVENT /%s\n", r->url); - ++event_i; + ++event_counter; - /* Notify registered observers with the given message type, observe option, and payload. - * The token will be set automatically. */ + PRINTF("TICK %u for /%s\n", event_counter, r->url); - // FIXME provide a rest_notify_subscribers call; how to manage specific options such as COAP_TYPE? - REST.notify_subscribers(r->url, 0, event_i, content, snprintf(content, sizeof(content), "EVENT %lu", event_i)); - return 1; + /* Build notification. */ + coap_packet_t notification[1]; /* This way the packet can be treated as pointer as usual. */ + coap_init_message(notification, COAP_TYPE_CON, CONTENT_2_05, 0 ); + coap_set_payload(notification, content, snprintf(content, sizeof(content), "EVENT %u", event_counter)); + + /* Notify the registered observers with the given message type, observe option, and payload. */ + REST.notify_subscribers(r, event_counter, notification); } #endif /* PLATFORM_HAS_BUTTON */ From c023faead2c48f37e099ff8c5bb2dc2f8b802ceb Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Fri, 23 Mar 2012 16:37:11 +0100 Subject: [PATCH 10/21] Added Content-Type to observe notifications. --- apps/erbium/erbium.h | 2 +- examples/er-rest-example/plugtest-server.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/erbium/erbium.h b/apps/erbium/erbium.h index 72b995db0..2a511e8e1 100644 --- a/apps/erbium/erbium.h +++ b/apps/erbium/erbium.h @@ -259,7 +259,7 @@ resource_t resource_##name = {NULL, flags, url, attributes, name##_handler, NULL * Macro to define a sub-resource * Make sure to define its parent resource beforehand and set 'parent' to that name. */ -#define SUB_RESOURCE(name, flags, url, attributes, parent) \ +#define SUB_RESOURCE(name, flags, url, attributes, parent) \ resource_t resource_##name = {NULL, flags, url, attributes, parent##_handler, NULL, NULL, NULL} /* diff --git a/examples/er-rest-example/plugtest-server.c b/examples/er-rest-example/plugtest-server.c index 0d4eb5c7b..1375681d2 100644 --- a/examples/er-rest-example/plugtest-server.c +++ b/examples/er-rest-example/plugtest-server.c @@ -482,9 +482,12 @@ obs_periodic_handler(resource_t *r) PRINTF("TICK %u for /%s\n", obs_counter, r->url); /* Build notification. */ + /*TODO: REST.new_response() */ coap_packet_t notification[1]; /* This way the packet can be treated as pointer as usual. */ coap_init_message(notification, COAP_TYPE_NON, CONTENT_2_05, 0 ); - coap_set_payload(notification, obs_content, snprintf(obs_content, sizeof(obs_content), "TICK %u", obs_counter)); + + REST.set_response_payload(notification, obs_content, snprintf(obs_content, sizeof(obs_content), "TICK %u", obs_counter)); + REST.set_header_content_type(notification, REST.type.TEXT_PLAIN); /* Notify the registered observers with the given message type, observe option, and payload. */ REST.notify_subscribers(r, obs_counter, notification); From 8f9247560ae1e55b4bb077c5bbb21236caf145d5 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Fri, 23 Mar 2012 16:51:48 +0100 Subject: [PATCH 11/21] Managed consistent representation generation for /obs. --- examples/er-rest-example/plugtest-server.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/er-rest-example/plugtest-server.c b/examples/er-rest-example/plugtest-server.c index 1375681d2..051b44be0 100644 --- a/examples/er-rest-example/plugtest-server.c +++ b/examples/er-rest-example/plugtest-server.c @@ -465,7 +465,7 @@ obs_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_s REST.set_header_content_type(response, REST.type.TEXT_PLAIN); REST.set_header_max_age(response, 5); - REST.set_response_payload(response, buffer, snprintf((char *)buffer, MAX_PLUGFEST_PAYLOAD, "TICK %lu", obs_counter)); + REST.set_response_payload(response, obs_content, snprintf(obs_content, MAX_PLUGFEST_PAYLOAD, "TICK %lu", obs_counter)); /* A post_handler that handles subscriptions will be called for periodic resources by the REST framework. */ } @@ -486,8 +486,8 @@ obs_periodic_handler(resource_t *r) coap_packet_t notification[1]; /* This way the packet can be treated as pointer as usual. */ coap_init_message(notification, COAP_TYPE_NON, CONTENT_2_05, 0 ); - REST.set_response_payload(notification, obs_content, snprintf(obs_content, sizeof(obs_content), "TICK %u", obs_counter)); - REST.set_header_content_type(notification, REST.type.TEXT_PLAIN); + /* Better use a generator function for both handlers that only takes *resonse. */ + obs_handler(NULL, notification, NULL, 0, NULL); /* Notify the registered observers with the given message type, observe option, and payload. */ REST.notify_subscribers(r, obs_counter, notification); From 3b2fe65c66ab9e7bd28df31ec1140d4c333b71d9 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Sat, 24 Mar 2012 01:59:43 +0100 Subject: [PATCH 12/21] Added rt filtering for Link Format. --- apps/er-coap-07/er-coap-07-engine.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/er-coap-07/er-coap-07-engine.c b/apps/er-coap-07/er-coap-07-engine.c index 5301cacd7..8b2e4ca71 100644 --- a/apps/er-coap-07/er-coap-07-engine.c +++ b/apps/er-coap-07/er-coap-07-engine.c @@ -311,8 +311,19 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t size_t tmplen = 0; resource_t* resource = NULL; + /* For filtering. */ + const char *filter = NULL; + int len = coap_get_query_variable(request, "rt", &filter); + char *rt = NULL; + for (resource = (resource_t*)list_head(rest_get_resources()); resource; resource = resource->next) { + /* Filtering */ + if (len && ((rt=strstr(resource->attributes, "rt=\""))==NULL || memcmp(rt+4, filter, len-1)!=0 || (filter[len-1]!='*' && (filter[len-1]!=rt[3+len] || rt[4+len]!='"')))) + { + continue; + } + PRINTF("res: /%s (%p)\npos: s%d, o%d, b%d\n", resource->url, resource, strpos, *offset, bufpos); if (strpos >= *offset && bufpos < preferred_size) @@ -390,7 +401,7 @@ well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t coap_set_payload(response, buffer, bufpos ); coap_set_header_content_type(response, APPLICATION_LINK_FORMAT); } - else + else if (strpos>0) { PRINTF("well_known_core_handler(): bufpos<=0\n"); From ed929947845a1bf101db03a8eaf9ccb6d55a9496 Mon Sep 17 00:00:00 2001 From: Matthias Kovatsch Date: Thu, 29 Mar 2012 18:05:07 +0200 Subject: [PATCH 13/21] Clean-up and fix for rest-server-example. --- apps/er-coap-07/er-coap-07-observing.c | 3 +++ apps/er-coap-07/er-coap-07-separate.c | 2 +- apps/er-coap-07/er-coap-07-separate.h | 2 +- apps/erbium/erbium.h | 4 ++-- examples/er-rest-example/Makefile | 6 +++--- examples/er-rest-example/rest-server-example.c | 9 +++------ 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/er-coap-07/er-coap-07-observing.c b/apps/er-coap-07/er-coap-07-observing.c index 5c8b5e465..23fae45c4 100644 --- a/apps/er-coap-07/er-coap-07-observing.c +++ b/apps/er-coap-07/er-coap-07-observing.c @@ -60,6 +60,9 @@ LIST(observers_list); coap_observer_t * coap_add_observer(uip_ipaddr_t *addr, uint16_t port, const uint8_t *token, size_t token_len, const char *url) { + /* Remove existing observe relationship, if any. */ + coap_remove_observer_by_url(addr, port, url); + coap_observer_t *o = memb_alloc(&observers_memb); if (o) diff --git a/apps/er-coap-07/er-coap-07-separate.c b/apps/er-coap-07/er-coap-07-separate.c index b9bca9abc..7a2a7b859 100644 --- a/apps/er-coap-07/er-coap-07-separate.c +++ b/apps/er-coap-07/er-coap-07-separate.c @@ -54,7 +54,7 @@ #endif /*----------------------------------------------------------------------------*/ -int +void coap_separate_reject() { coap_error_code = SERVICE_UNAVAILABLE_5_03; diff --git a/apps/er-coap-07/er-coap-07-separate.h b/apps/er-coap-07/er-coap-07-separate.h index 62b25c095..896485d42 100644 --- a/apps/er-coap-07/er-coap-07-separate.h +++ b/apps/er-coap-07/er-coap-07-separate.h @@ -59,7 +59,7 @@ typedef struct coap_separate { } coap_separate_t; int coap_separate_handler(resource_t *resource, void *request, void *response); -int coap_separate_reject(); +void coap_separate_reject(); int coap_separate_accept(void *request, coap_separate_t *separate_store); void coap_separate_resume(void *response, coap_separate_t *separate_store, uint8_t code); diff --git a/apps/erbium/erbium.h b/apps/erbium/erbium.h index 2a511e8e1..bf0cb8eee 100644 --- a/apps/erbium/erbium.h +++ b/apps/erbium/erbium.h @@ -269,8 +269,8 @@ resource_t resource_##name = {NULL, flags, url, attributes, parent##_handler, NU */ #define EVENT_RESOURCE(name, flags, url, attributes) \ void name##_handler(void *, void *, uint8_t *, uint16_t, int32_t *); \ -resource_t resource_##name = {NULL, flags, url, attributes, name##_handler, NULL, NULL, NULL}; \ -int name##_event_handler(resource_t*) +void name##_event_handler(resource_t*); \ +resource_t resource_##name = {NULL, flags, url, attributes, name##_handler, NULL, NULL, NULL} /* * Macro to define a periodic resource diff --git a/examples/er-rest-example/Makefile b/examples/er-rest-example/Makefile index 38029c574..979e9f477 100644 --- a/examples/er-rest-example/Makefile +++ b/examples/er-rest-example/Makefile @@ -5,8 +5,10 @@ CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" # for static routing, if enabled ifneq ($(TARGET), minimal-net) +ifneq ($(TARGET), native) PROJECT_SOURCEFILES += static-routing.c endif +endif # variable for root Makefile.include WITH_UIP6=1 @@ -25,7 +27,7 @@ else ${info INFO: compiling without RPL} UIP_CONF_RPL=0 CFLAGS += -DUIP_CONF_ND6_DEF_MAXDADNS=0 -CFLAGS += -DHARD_CODED_ADDRESS=\"2001:620:8:1010::10\" +CFLAGS += -DHARD_CODED_ADDRESS=\"fdfd::10\" CFLAGS += -DUIP_CONF_BUFFER_SIZE=1280 endif @@ -37,13 +39,11 @@ ifeq ($(WITH_COAP), 7) ${info INFO: compiling with CoAP-07} CFLAGS += -DWITH_COAP=7 CFLAGS += -DREST=coap_rest_implementation -CFLAGS += -DUIP_CONF_TCP=0 APPS += er-coap-07 else ifeq ($(WITH_COAP), 3) ${info INFO: compiling with CoAP-03} CFLAGS += -DWITH_COAP=3 CFLAGS += -DREST=coap_rest_implementation -CFLAGS += -DUIP_CONF_TCP=0 APPS += er-coap-03 else ${info INFO: compiling with HTTP} diff --git a/examples/er-rest-example/rest-server-example.c b/examples/er-rest-example/rest-server-example.c index a958c1d2a..911069d88 100644 --- a/examples/er-rest-example/rest-server-example.c +++ b/examples/er-rest-example/rest-server-example.c @@ -381,16 +381,14 @@ separate_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer */ if (separate_active) { - REST.set_response_status(response, REST.status.SERVICE_UNAVAILABLE); - const char *msg = "AlreadyInUse"; - REST.set_response_payload(response, msg, strlen(msg)); + coap_separate_reject(); } else { separate_active = 1; /* Take over and skip response by engine. */ - coap_separate_yield(request, &separate_store->request_metadata); + coap_separate_accept(request, &separate_store->request_metadata); /* Be aware to respect the Block2 option, which is also stored in the coap_separate_t. */ /* @@ -710,8 +708,7 @@ PROCESS_THREAD(rest_server_example, ev, data) rest_activate_event_resource(&resource_event); #endif #if defined (PLATFORM_HAS_BUTTON) && REST_RES_SEPARATE && WITH_COAP > 3 - /* Use this pre-handler for separate response resources. */ - rest_set_pre_handler(&resource_separate, coap_separate_handler); + /* No pre-handler anymore, user coap_separate_accept() and coap_separate_reject(). */ rest_activate_resource(&resource_separate); #endif #if defined (PLATFORM_HAS_BUTTON) && (REST_RES_EVENT || (REST_RES_SEPARATE && WITH_COAP > 3)) From 2507ba4e8d372fb631ecea694441c6eb11f6b482 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Sat, 31 Mar 2012 01:25:27 +0200 Subject: [PATCH 14/21] Avoid using memcpy on unaligned uint16_t variables, because certain compilers will optimize this code to a direct copy instruction that will result in unaligned memory access. Thanks to Angelo Compagnucci for reporting this problem. --- core/net/rime/broadcast-announcement.c | 26 ++++++++++++-------------- core/net/rime/collect.c | 20 +++++++++----------- core/net/rime/neighbor-discovery.c | 11 +++++------ core/net/rime/polite-announcement.c | 26 ++++++++++++++++---------- 4 files changed, 42 insertions(+), 41 deletions(-) diff --git a/core/net/rime/broadcast-announcement.c b/core/net/rime/broadcast-announcement.c index fab26ce36..d7540a5a2 100644 --- a/core/net/rime/broadcast-announcement.c +++ b/core/net/rime/broadcast-announcement.c @@ -56,7 +56,6 @@ #endif #include -#include #include struct announcement_data { @@ -131,32 +130,31 @@ static void adv_packet_received(struct broadcast_conn *ibc, const rimeaddr_t *from) { struct announcement_msg adata; + struct announcement_data data; + uint8_t *ptr; int i; + ptr = packetbuf_dataptr(); + /* Copy number of announcements */ - memcpy(&adata, packetbuf_dataptr(), sizeof(struct announcement_msg)); + memcpy(&adata, ptr, sizeof(struct announcement_msg)); PRINTF("%d.%d: adv_packet_received from %d.%d with %d announcements\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], from->u8[0], from->u8[1], adata.num); - if(adata.num / sizeof(struct announcement_data) > sizeof(struct announcement_msg)) { + if(ANNOUNCEMENT_MSG_HEADERLEN + adata.num * sizeof(struct announcement_data) > packetbuf_datalen()) { /* The number of announcements is too large - corrupt packet has been received. */ - printf("adata.num way out there: %d\n", adata.num); + PRINTF("adata.num way out there: %d\n", adata.num); return; } - - for(i = 0; i < adata.num; ++i) { - struct announcement_data data; + ptr += ANNOUNCEMENT_MSG_HEADERLEN; + for(i = 0; i < adata.num; ++i) { /* Copy announcements */ - memcpy(&data.id, &((struct announcement_msg *)packetbuf_dataptr())->data[i].id, - sizeof(uint16_t)); - memcpy(&data.value, &((struct announcement_msg *)packetbuf_dataptr())->data[i].value, - sizeof(uint16_t)); - announcement_heard(from, - data.id, - data.value); + memcpy(&data, ptr, sizeof(struct announcement_data)); + announcement_heard(from, data.id, data.value); + ptr += sizeof(struct announcement_data); } } /*---------------------------------------------------------------------------*/ diff --git a/core/net/rime/collect.c b/core/net/rime/collect.c index a73059cac..7047d8df2 100644 --- a/core/net/rime/collect.c +++ b/core/net/rime/collect.c @@ -758,8 +758,7 @@ send_next_packet(struct collect_conn *tc) static void handle_ack(struct collect_conn *tc) { - struct ack_msg *msg; - uint16_t rtmetric; + struct ack_msg msg; struct collect_neighbor *n; PRINTF("handle_ack: sender %d.%d current_parent %d.%d, id %d seqno %d\n", @@ -778,8 +777,7 @@ handle_ack(struct collect_conn *tc) (int)(((100 * (clock_time() - tc->send_time)) / CLOCK_SECOND) % 100));*/ stats.ackrecv++; - msg = packetbuf_dataptr(); - memcpy(&rtmetric, &msg->rtmetric, sizeof(uint16_t)); + memcpy(&msg, packetbuf_dataptr(), sizeof(struct ack_msg)); /* It is possible that we receive an ACK for a packet that we think we have not yet sent: if our transmission was received by @@ -797,7 +795,7 @@ handle_ack(struct collect_conn *tc) if(n != NULL) { collect_neighbor_tx(n, tc->transmissions); - collect_neighbor_update_rtmetric(n, rtmetric); + collect_neighbor_update_rtmetric(n, msg.rtmetric); update_rtmetric(tc); } @@ -805,8 +803,8 @@ handle_ack(struct collect_conn *tc) rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], tc->current_parent.u8[0], tc->current_parent.u8[1], tc->transmissions, - msg->flags, - rtmetric); + msg.flags, + msg.rtmetric); /* The ack contains information about the state of the packet and of the node that received it. We do different things depending @@ -814,20 +812,20 @@ handle_ack(struct collect_conn *tc) the receiving node was congested. If so, we add a maximum transmission number to its routing metric, which increases the chance that another parent will be chosen. */ - if(msg->flags & ACK_FLAGS_CONGESTED) { + if(msg.flags & ACK_FLAGS_CONGESTED) { PRINTF("ACK flag indicated parent was congested.\n"); collect_neighbor_set_congested(n); collect_neighbor_tx(n, tc->max_rexmits * 2); update_rtmetric(tc); } - if((msg->flags & ACK_FLAGS_DROPPED) == 0) { + if((msg.flags & ACK_FLAGS_DROPPED) == 0) { /* If the packet was successfully received, we send the next packet. */ send_next_packet(tc); } else { /* If the packet was lost due to its lifetime being exceeded, there is not much more we can do with the packet, so we send the next one instead. */ - if((msg->flags & ACK_FLAGS_LIFETIME_EXCEEDED)) { + if((msg.flags & ACK_FLAGS_LIFETIME_EXCEEDED)) { send_next_packet(tc); } else { /* If the packet was dropped, but without the node being @@ -845,7 +843,7 @@ handle_ack(struct collect_conn *tc) /* Our neighbor's rtmetric needs to be updated, so we bump our advertisements. */ - if(msg->flags & ACK_FLAGS_RTMETRIC_NEEDS_UPDATE) { + if(msg.flags & ACK_FLAGS_RTMETRIC_NEEDS_UPDATE) { bump_advertisement(tc); } set_keepalive_timer(tc); diff --git a/core/net/rime/neighbor-discovery.c b/core/net/rime/neighbor-discovery.c index f9691b1d8..4b60e51ef 100644 --- a/core/net/rime/neighbor-discovery.c +++ b/core/net/rime/neighbor-discovery.c @@ -96,23 +96,22 @@ static void adv_packet_received(struct broadcast_conn *ibc, const rimeaddr_t *from) { struct neighbor_discovery_conn *c = (struct neighbor_discovery_conn *)ibc; - struct adv_msg *msg = packetbuf_dataptr(); - uint16_t val; + struct adv_msg msg; - memcpy(&val, &msg->val, sizeof(val)); + memcpy(&msg, packetbuf_dataptr(), sizeof(struct adv_msg)); PRINTF("%d.%d: adv_packet_received from %d.%d with val %d\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], - from->u8[0], from->u8[1], val); + from->u8[0], from->u8[1], msg.val); /* If we receive an announcement with a lower value than ours, we cancel our own announcement. */ - if(val < c->val) { + if(msg.val < c->val) { /* ctimer_stop(&c->send_timer);*/ } if(c->u->recv) { - c->u->recv(c, from, val); + c->u->recv(c, from, msg.val); } } /*---------------------------------------------------------------------------*/ diff --git a/core/net/rime/polite-announcement.c b/core/net/rime/polite-announcement.c index 2a6e7ae7e..f7a7b5241 100644 --- a/core/net/rime/polite-announcement.c +++ b/core/net/rime/polite-announcement.c @@ -125,25 +125,31 @@ static void adv_packet_received(struct ipolite_conn *ipolite, const rimeaddr_t *from) { struct announcement_msg adata; + struct announcement_data data; + uint8_t *ptr; int i; + ptr = packetbuf_dataptr(); + /* Copy number of announcements */ - memcpy(&adata, packetbuf_dataptr(), sizeof(struct announcement_msg)); + memcpy(&adata, ptr, sizeof(struct announcement_msg)); PRINTF("%d.%d: adv_packet_received from %d.%d with %d announcements\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], from->u8[0], from->u8[1], adata.num); - for(i = 0; i < adata.num; ++i) { - struct announcement_data data; + if(ANNOUNCEMENT_MSG_HEADERLEN + adata.num * sizeof(struct announcement_data) > packetbuf_datalen()) { + /* The number of announcements is too large - corrupt packet has + been received. */ + PRINTF("adata.num way out there: %d\n", adata.num); + return; + } + ptr += ANNOUNCEMENT_MSG_HEADERLEN; + for(i = 0; i < adata.num; ++i) { /* Copy announcements */ - memcpy(&data.id, &((struct announcement_msg *)packetbuf_dataptr())->data[i].id, - sizeof(uint16_t)); - memcpy(&data.value, &((struct announcement_msg *)packetbuf_dataptr())->data[i].value, - sizeof(uint16_t)); - announcement_heard(from, - data.id, - data.value); + memcpy(&data, ptr, sizeof(struct announcement_data)); + announcement_heard(from, data.id, data.value); + ptr += sizeof(struct announcement_data); } } /*---------------------------------------------------------------------------*/ From 5d8f63a61baadc1a33d707ecd802afbeecb8d747 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Apr 2012 17:44:44 +0100 Subject: [PATCH 15/21] We've not been using the cc2430 converter for a while now --- cpu/cc2430/converter/Makefile | 39 ------ cpu/cc2430/converter/converter.c | 227 ------------------------------- cpu/cc2430/converter/converter.h | 13 -- cpu/cc2430/converter/ihex.c | 70 ---------- cpu/cc2430/converter/ihex.h | 7 - 5 files changed, 356 deletions(-) delete mode 100644 cpu/cc2430/converter/Makefile delete mode 100644 cpu/cc2430/converter/converter.c delete mode 100644 cpu/cc2430/converter/converter.h delete mode 100644 cpu/cc2430/converter/ihex.c delete mode 100644 cpu/cc2430/converter/ihex.h diff --git a/cpu/cc2430/converter/Makefile b/cpu/cc2430/converter/Makefile deleted file mode 100644 index 7d58f8eeb..000000000 --- a/cpu/cc2430/converter/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -EXE_MAKE=$(notdir $(shell which "make.exe" 2>/dev/null)) -ifeq "$(EXE_MAKE)" "make.exe" -PLATFORM=windows -else -PLATFORM=linux -endif - -OBJECTS = ihex.o converter.o -SUBDIRS = - -CFLAGS = -Wall -D_REENTRANT -I. -LDFLAGS = -L. -D_REENTRANT -lpthread -ifeq "$(PLATFORM)" "linux" -SUFFIX= -else -SUFFIX=.exe -endif - -TARGET = converter$(SUFFIX) - -all: binary - -binary: $(TARGET) - strip $(TARGET) - -$(TARGET): $(OBJECTS) - gcc -o $(TARGET) $(OBJECTS) $(LDFLAGS) - -.c.o: - gcc -c -o $(<:.c=.o) -O2 -Wall $(CFLAGS) $< - -platform-test: - @echo $(PLATFORM) - -old-strip: - if [ -x $(TARGET).exe ]; then $(PLATFORM)strip $(TARGET).exe; else $(PLATFORM)strip $(TARGET); fi - -clean: - rm -f $(TARGET) $(OBJECTS) diff --git a/cpu/cc2430/converter/converter.c b/cpu/cc2430/converter/converter.c deleted file mode 100644 index 56d12ecc9..000000000 --- a/cpu/cc2430/converter/converter.c +++ /dev/null @@ -1,227 +0,0 @@ -#include -#include -#include -#include - -#include "converter.h" - -#include - -extern int cdi_programmer(conf_opts_t *conf, char *filename); - -void usage(char *prg_name) -{ - printf("\nUsage: %s -f ihex file\n", prg_name); - printf("General options:\n"); - printf(" -v/--version Get converter version\n"); -} - -conf_opts_t conf_opts; - -static int option_index = 0; - -int do_exit = 0; - -#define OPTIONS_STRING "vhf:" -/* long option list */ -static struct option long_options[] = -{ - {"version", 0, NULL, 'v'}, - {"file", 1, NULL, 'f'}, - {"help", 0, NULL, 'h'}, - {0, 0, 0, 0} -}; - -int parse_opts(int count, char* param[]) -{ - int opt; - int error=0; - - conf_opts.target_type = UNDEFINED; - while ((opt = getopt_long(count, param, OPTIONS_STRING, - long_options, &option_index)) != -1) - { - switch(opt) - { - case 'v': - conf_opts.target_type = VERSION; - break; - - case 'h': - conf_opts.target_type = UNDEFINED; - break; - - case 'f': - strcpy(conf_opts.ihex_file, optarg); - conf_opts.target_type = CONVERT; - break; - } - } - - if (!error && (conf_opts.target_type == CONVERT) ) - { - printf("File: %s.\n", conf_opts.ihex_file); - } - - return error; -} - -int main(int argc, char *argv[]) -{ - int error = 0; - - conf_opts.target_type = 0; - - - printf("Sensinode hex file converter "CONVERTER_VERSION "\n"); - if ( (argc < 1) || (error = parse_opts(argc, argv)) ) - { - usage(argv[0]); - if (error < 0) return error; - else return 0; - } - - if(conf_opts.target_type == CONVERT) - { /*Convert*/ - int pages; - int sdcc_file = 0; - - FILE *ihex = 0; - unsigned char check = 0; - unsigned long ext_addr=0; - unsigned short int addr=0; - unsigned char page_buffer[128*1024]; - unsigned char page_table[64]; - unsigned char buffer[256]; - int i; - int retval = 0; - - bzero(buffer, sizeof(buffer)); - - /*initialize page data*/ - memset(page_table, 0, 64); - memset(page_buffer, 0xFF, sizeof(page_buffer)); - pages = 0; - - ihex = fopen(conf_opts.ihex_file, "rb"); - if (ihex == 0) - { - printf("Can't open file.\n"); - return -1; - } - error = 0; - while((!error) && ((retval = fscanf(ihex, "%s", buffer)) == 1) ) - { - unsigned char data_len = 0; - - if (memcmp(&buffer[7], "00", 2) == 0) - { /*Data record*/ - i=0; - sscanf((char *)&buffer[1], "%2hhx", &data_len); - sscanf((char *)&(buffer[3]),"%4hx", &addr); - while(i= 0x0002) sdcc_file = 1; - - if (ext_addr) ext_addr--; - ext_addr *= 0x8000; - } - } - fclose(ihex); - if (retval == -1) - { - printf("Read error\n"); - } - if (sdcc_file == 0) - { - printf("Not a SDCC banked file.\n"); - return 0; - } - printf("Writing %d pages.\n", pages); - { /*cut off extension*/ - char *ptr = strrchr(conf_opts.ihex_file, '.'); - if (ptr != NULL) - { - *ptr = 0; - } - } - strcat(conf_opts.ihex_file, ".hex"); - printf("Output file: %s.\n", conf_opts.ihex_file); - ihex = fopen(conf_opts.ihex_file, "wb"); - ext_addr=0; - addr = 0; - if (pages) - { - int j; - error = 0; - for (i=0; i<64; i++) - { - addr = (i & 0x1F) * 2048; - if ( ((i / 32) * 0x10000) != ext_addr) - { /*write out ext addr*/ - /*printf("Ext: %4.4X\n", ((i / 32) * 0x10000));*/ - ext_addr = (i / 32) * 0x10000; - fprintf(ihex, ":02000004%4.4X%2.2X\r\n", - (int)(ext_addr>>16), (int)(0xFA-(ext_addr>>16))); - } - - if (page_table[i] != 0) - { - /*printf("%4.4X", addr & 0xF800);*/ - for (j=0; j<2048; j++) - { - addr =(i & 0x1F) * 2048 + j; - if ((j & 0x1F) == 0) - { - check = 0; - check -= 0x20; - check -= (uint8_t) (addr >> 8); - check -= (uint8_t) (addr); - fprintf(ihex, ":20%4.4X00", (int) addr); - } - fprintf(ihex, "%2.2X", page_buffer[ext_addr+addr]); - check -= page_buffer[ext_addr+addr]; - if ((j & 0x1F) == 0x1F) - { - fprintf(ihex, "%2.2X\r\n", check); - } - } - } - /* - if ((i & 0x07) == 0x07) printf("\n"); - else printf(" "); - */ - } - fprintf(ihex, ":00000001FF\r\n"); - printf("Write complete.\n"); - } - fclose(ihex); - } - else if(conf_opts.target_type == UNDEFINED) - { - usage(argv[0]); - } - return error; -} diff --git a/cpu/cc2430/converter/converter.h b/cpu/cc2430/converter/converter.h deleted file mode 100644 index cde769b72..000000000 --- a/cpu/cc2430/converter/converter.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef CONVERTER_H -#define CONVERTER_H - -#define CONVERTER_VERSION "v1.4" - -typedef struct { - int target_type; - char ihex_file[128]; -}conf_opts_t; - -enum target { UNDEFINED, VERSION, CONVERT }; - -#endif diff --git a/cpu/cc2430/converter/ihex.c b/cpu/cc2430/converter/ihex.c deleted file mode 100644 index fbed240b2..000000000 --- a/cpu/cc2430/converter/ihex.c +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include -#include -#include - -#include - -int hexfile_parse(char *line, unsigned int *type, unsigned int *addr, unsigned char *buffer) -{ - unsigned int row_len = 0; - unsigned int row_index = 7; - unsigned int i; - int tmp; - - uint8_t cksum = 0; - int retval = 0; - - retval = sscanf(line, ":%2x%4x%2x", &row_len, addr, type); - - cksum += row_len; - cksum += *addr >> 8; - cksum += *addr & 0xFF; - cksum += *type; - - i = 0; - if (retval == 3) - { - while(i < row_len) - { - - if (sscanf(&line[row_index], "%2x", &tmp) == 1) - { - cksum += tmp; - buffer[i++] = (unsigned char) tmp; - row_index += 2; - } - else return -1; - } - if (sscanf(&line[row_index], "%2x", &tmp) == 1) - { - if ((cksum + (uint8_t) tmp) == 0) return row_len; - } - } - return -1; -} - -int hexfile_out(char *line, unsigned int type, unsigned int address, unsigned char *data, unsigned int bytes) -{ - uint8_t cksum = 0; - uint8_t i = 0; - char tmp[8]; - - sprintf(line, ":%2.2X%4.4X%2.2X", bytes, address, type); - cksum -= bytes; - cksum -= address >> 8; - cksum -= address & 0xFF; - cksum -= type; - - for (i=0; i Date: Sun, 1 Apr 2012 19:54:41 +0100 Subject: [PATCH 16/21] Deleted the old Sensinode 'read mac from flash' routine. Since the introduction of a purpose-written routine, the old generic one (which was written in asm) was never being used. There was a configuration directive which allowed us to switch between the two. All references to this configuration directive have also been removed. --- cpu/cc2430/dev/bus.c | 76 --------------------- cpu/cc2430/dev/bus.h | 3 - platform/sensinode/contiki-conf.h | 6 -- platform/sensinode/contiki-sensinode-main.c | 18 ----- 4 files changed, 103 deletions(-) diff --git a/cpu/cc2430/dev/bus.c b/cpu/cc2430/dev/bus.c index 0274ce3d6..299cc677c 100644 --- a/cpu/cc2430/dev/bus.c +++ b/cpu/cc2430/dev/bus.c @@ -57,79 +57,3 @@ bus_init (void) clock_init(); } /*---------------------------------------------------------------------------*/ -/** - * Read a block of code memory. - * The code must be placed in the lowest bank of flash. - * - * \param address address to read from flash - * \param buffer buffer to store data - * \param size number of bytes to read - */ -#if !SHORTCUTS_CONF_FLASH_READ -void -flash_read(uint8_t *buf, uint32_t address, uint8_t size) -{ - buf; /*dptr0*/ - address; /*stack-6*/ - size; /*stack-7*/ - - buf; - - DISABLE_INTERRUPTS(); - __asm - mov dpl, r2 - mov dph, r3 - mov a, r0 - push acc - mov a, r2 - push acc - mov a, _MEMCTR - push acc - - mov a, _bp - add a, #0xf9 ;stack - 7 = size - mov r0,a - mov a, @r0 ;r2 = size - mov r2, a ;r2 = size - - inc r0 - mov a, @r0 - mov _DPL1, a ;DPTR1 = address & 0x7FFF | 0x8000 - inc r0 - mov a, @r0 - orl a, #0x80 - mov _DPH1, a - inc r0 ;MEMCTR = ((address >> 15 & 3) << 4) | 0x01 (bank select) - mov a, @r0 - dec r0 - rrc a - mov a, @r0 - rrc a - rr a - rr a - anl a, #0x30 - orl a, #1 - mov _MEMCTR,a -lp1: - mov _DPS, #1 ;active DPTR = 1 - clr a - movc a, @a+dptr ;read flash (DPTR1) - inc dptr - mov _DPS, #0 ;active DPTR = 0 - movx @dptr,a ;write to DPTR0 - inc dptr - djnz r2,lp1 ;while (--size) - - pop acc - mov _MEMCTR, a ;restore bank - - pop acc - mov r2,a - pop acc - mov r0,a - __endasm; - ENABLE_INTERRUPTS(); - DPL1 = *buf++; -} -#endif -/*---------------------------------------------------------------------------*/ diff --git a/cpu/cc2430/dev/bus.h b/cpu/cc2430/dev/bus.h index 6c20dac54..b6aec1671 100644 --- a/cpu/cc2430/dev/bus.h +++ b/cpu/cc2430/dev/bus.h @@ -49,9 +49,6 @@ #define inline void bus_init(void); -#if !SHORTCUTS_CONF_FLASH_READ -void flash_read(uint8_t *buf, uint32_t address, uint8_t size); -#endif void clock_ISR( void ) __interrupt (ST_VECTOR); #endif /* __BUS_H__ */ diff --git a/platform/sensinode/contiki-conf.h b/platform/sensinode/contiki-conf.h index 894c2174a..e40f70b8c 100644 --- a/platform/sensinode/contiki-conf.h +++ b/platform/sensinode/contiki-conf.h @@ -95,12 +95,6 @@ */ #define SHORTCUTS_CONF_NETSTACK 1 -/* - * Directly read mac from flash with a __code pointer, instead of using the - * generic flash_read() routine. This reduces HOME code size - */ -#define SHORTCUTS_CONF_FLASH_READ 1 - /* * Sensors * It is harmless to #define XYZ 1 diff --git a/platform/sensinode/contiki-sensinode-main.c b/platform/sensinode/contiki-sensinode-main.c index a1f9abb9d..48d27269f 100644 --- a/platform/sensinode/contiki-sensinode-main.c +++ b/platform/sensinode/contiki-sensinode-main.c @@ -99,12 +99,7 @@ set_rime_addr(void) uint8_t *addr_long = NULL; uint16_t addr_short = 0; char i; - -#if SHORTCUTS_CONF_FLASH_READ __code unsigned char * macp; -#else - static uint8_t ft_buffer[8]; -#endif PUTSTRING("Rime is 0x"); PUTHEX(sizeof(rimeaddr_t)); @@ -112,7 +107,6 @@ set_rime_addr(void) if(node_id == 0) { PUTSTRING("Reading MAC from flash\n"); -#if SHORTCUTS_CONF_FLASH_READ /* * The MAC is always stored in 0x1FFF8 of our flash. This maps to address * 0xFFF8 of our CODE segment, when BANK3 is selected. @@ -138,18 +132,6 @@ set_rime_addr(void) /* Remap 0x8000 – 0xFFFF to BANK1 */ FMAP = 1; ENABLE_INTERRUPTS(); -#else - /* - * Or use the more generic flash_read() routine which can read from any - * address of our flash - */ - flash_read(ft_buffer, 0x1FFF8, 8); - - /* Flip the byte order and store MSB first */ - for(i = (RIMEADDR_SIZE - 1); i >= 0; --i) { - rimeaddr_node_addr.u8[RIMEADDR_SIZE - 1 - i] = ft_buffer[i]; - } -#endif } else { PUTSTRING("Setting manual address from node_id\n"); From e02c287f1562770a69737883b9968698a603d9d8 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Apr 2012 20:45:27 +0100 Subject: [PATCH 17/21] Solved a text encoding issue --- platform/sensinode/contiki-sensinode-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/sensinode/contiki-sensinode-main.c b/platform/sensinode/contiki-sensinode-main.c index 48d27269f..5d6267c94 100644 --- a/platform/sensinode/contiki-sensinode-main.c +++ b/platform/sensinode/contiki-sensinode-main.c @@ -118,7 +118,7 @@ set_rime_addr(void) /* Don't interrupt us to make sure no BANK switching happens while working */ DISABLE_INTERRUPTS(); - /* Switch to BANK3, map CODE: 0x8000 – 0xFFFF to FLASH: 0x18000 – 0x1FFFF */ + /* Switch to BANK3, map CODE: 0x8000 - 0xFFFF to FLASH: 0x18000 - 0x1FFFF */ FMAP = 3; /* Set our pointer to the correct address and fetch 8 bytes of MAC */ @@ -129,7 +129,7 @@ set_rime_addr(void) macp++; } - /* Remap 0x8000 – 0xFFFF to BANK1 */ + /* Remap 0x8000 - 0xFFFF to BANK1 */ FMAP = 1; ENABLE_INTERRUPTS(); From bce34e4b9a10db748953bafb148a3ef96dc6ea92 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Apr 2012 20:08:23 +0100 Subject: [PATCH 18/21] For cc2x30, moved CLOCK_CONF_SENCOND to the cpu dir. The value is not really configurable by the platform so having it in contiki-conf.h didn't make huge sense. --- cpu/cc2430/8051def.h | 2 ++ cpu/cc253x/8051def.h | 8 +++++++- platform/cc2530dk/contiki-conf.h | 6 ------ platform/sensinode/contiki-conf.h | 3 --- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cpu/cc2430/8051def.h b/cpu/cc2430/8051def.h index a7327ed92..3201cba6e 100644 --- a/cpu/cc2430/8051def.h +++ b/cpu/cc2430/8051def.h @@ -45,6 +45,8 @@ typedef unsigned short uip_stats_t; /* Time type. */ typedef unsigned short clock_time_t; #define MAX_TICKS (~((clock_time_t)0) / 2) +/* Defines tick counts for a second. */ +#define CLOCK_CONF_SECOND 128 /* Compiler configurations */ #define CCIF diff --git a/cpu/cc253x/8051def.h b/cpu/cc253x/8051def.h index 7ac0b84ef..e19fd8d31 100644 --- a/cpu/cc253x/8051def.h +++ b/cpu/cc253x/8051def.h @@ -1,7 +1,7 @@ /* * \file * This file contains a set of configuration for using SDCC as a compiler. - * Modified from z80 port for cc2430 port. + * This is based on the cc2430 file (which in turn is based on the z80 one) * * \author * Takahide Matsutsuka (Original) @@ -42,6 +42,12 @@ /* Generic types. */ typedef unsigned short uip_stats_t; +/* Time type. */ +typedef unsigned short clock_time_t; +#define MAX_TICKS (~((clock_time_t)0) / 2) +/* Defines tick counts for a second. */ +#define CLOCK_CONF_SECOND 128 + /* Compiler configurations */ #define CCIF #define CLIF diff --git a/platform/cc2530dk/contiki-conf.h b/platform/cc2530dk/contiki-conf.h index 4eae96016..bae8c34ad 100644 --- a/platform/cc2530dk/contiki-conf.h +++ b/platform/cc2530dk/contiki-conf.h @@ -10,12 +10,6 @@ #include "project-conf.h" #endif /* PROJECT_CONF_H */ -/* Time type. */ -typedef unsigned short clock_time_t; - -/* Defines tick counts for a second. */ -#define CLOCK_CONF_SECOND 128 - /* Energest Module */ #ifndef ENERGEST_CONF_ON #define ENERGEST_CONF_ON 0 diff --git a/platform/sensinode/contiki-conf.h b/platform/sensinode/contiki-conf.h index e40f70b8c..3148605de 100644 --- a/platform/sensinode/contiki-conf.h +++ b/platform/sensinode/contiki-conf.h @@ -10,9 +10,6 @@ #include "project-conf.h" #endif /* PROJECT_CONF_H */ -/* Defines tick counts for a second. */ -#define CLOCK_CONF_SECOND 128 - /* The clock ISR is stack-hungry and may cause crashes. * Define this as 0 if you are suffering from frequent stack overflows */ #ifndef CLOCK_CONF_ACCURATE From 977bc548f37593d5af3323a7a3f7614529d44908 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Mon, 2 Apr 2012 00:22:58 +0100 Subject: [PATCH 19/21] Renamed sensinode-debug to debug --- examples/sensinode/energy-scan/energy-scan.c | 2 +- examples/sensinode/sensors-ipv6/sensors-driver.c | 2 +- examples/sensinode/sensors-ipv6/sensors-ipv6.c | 2 +- examples/sensinode/sensors/sensors-example.c | 2 +- examples/sensinode/serial-flash/flash.c | 2 +- examples/sensinode/udp-ipv6/client.c | 2 +- examples/sensinode/udp-ipv6/ping6.c | 2 +- examples/sensinode/udp-ipv6/server.c | 2 +- platform/sensinode/Makefile.sensinode | 2 +- platform/sensinode/contiki-sensinode-main.c | 2 +- platform/sensinode/{sensinode-debug.c => debug.c} | 2 +- platform/sensinode/{sensinode-debug.h => debug.h} | 6 +++--- 12 files changed, 14 insertions(+), 14 deletions(-) rename platform/sensinode/{sensinode-debug.c => debug.c} (97%) rename platform/sensinode/{sensinode-debug.h => debug.h} (95%) diff --git a/examples/sensinode/energy-scan/energy-scan.c b/examples/sensinode/energy-scan/energy-scan.c index 07393d507..bb73f18a1 100644 --- a/examples/sensinode/energy-scan/energy-scan.c +++ b/examples/sensinode/energy-scan/energy-scan.c @@ -40,7 +40,7 @@ #include "contiki.h" #include "cc2430_sfr.h" -#include "sensinode-debug.h" +#include "debug.h" #include "dev/cc2430_rf.h" #include diff --git a/examples/sensinode/sensors-ipv6/sensors-driver.c b/examples/sensinode/sensors-ipv6/sensors-driver.c index 01e118eb2..148d2b3a4 100644 --- a/examples/sensinode/sensors-ipv6/sensors-driver.c +++ b/examples/sensinode/sensors-ipv6/sensors-driver.c @@ -46,7 +46,7 @@ #include "dev/leds.h" #if CONTIKI_TARGET_SENSINODE #include "dev/sensinode-sensors.h" -#include "sensinode-debug.h" +#include "debug.h" #endif #define DEBUG 0 diff --git a/examples/sensinode/sensors-ipv6/sensors-ipv6.c b/examples/sensinode/sensors-ipv6/sensors-ipv6.c index ca9589fb4..bf07a595c 100644 --- a/examples/sensinode/sensors-ipv6/sensors-ipv6.c +++ b/examples/sensinode/sensors-ipv6/sensors-ipv6.c @@ -58,7 +58,7 @@ #include #if CONTIKI_TARGET_SENSINODE -#include "sensinode-debug.h" +#include "debug.h" #include "dev/sensinode-sensors.h" #else #define putstring(s) diff --git a/examples/sensinode/sensors/sensors-example.c b/examples/sensinode/sensors/sensors-example.c index ecbaddb17..33277b77d 100644 --- a/examples/sensinode/sensors/sensors-example.c +++ b/examples/sensinode/sensors/sensors-example.c @@ -96,7 +96,7 @@ #if DEBUG #include #if CONTIKI_TARGET_SENSINODE -#include "sensinode-debug.h" +#include "debug.h" #endif /* CONTIKI_TARGET_SENSINODE */ #define PRINTF(...) printf(__VA_ARGS__) #else /* DEBUG */ diff --git a/examples/sensinode/serial-flash/flash.c b/examples/sensinode/serial-flash/flash.c index 6593de3ee..a796b7513 100644 --- a/examples/sensinode/serial-flash/flash.c +++ b/examples/sensinode/serial-flash/flash.c @@ -49,7 +49,7 @@ #define DEBUG 1 #if DEBUG #include -#include "sensinode-debug.h" +#include "debug.h" #define PRINTF(...) printf(__VA_ARGS__) #define PUTBIN(b) putbin(b) #else diff --git a/examples/sensinode/udp-ipv6/client.c b/examples/sensinode/udp-ipv6/client.c index c20643c54..0cb13e3f6 100644 --- a/examples/sensinode/udp-ipv6/client.c +++ b/examples/sensinode/udp-ipv6/client.c @@ -36,7 +36,7 @@ #if CONTIKI_TARGET_SENSINODE #include "dev/sensinode-sensors.h" -#include "sensinode-debug.h" +#include "debug.h" #else #define putstring(s) #define puthex(s) diff --git a/examples/sensinode/udp-ipv6/ping6.c b/examples/sensinode/udp-ipv6/ping6.c index 48ec952f9..396edbc94 100644 --- a/examples/sensinode/udp-ipv6/ping6.c +++ b/examples/sensinode/udp-ipv6/ping6.c @@ -35,7 +35,7 @@ #if CONTIKI_TARGET_SENSINODE #include "dev/sensinode-sensors.h" -#include "sensinode-debug.h" +#include "debug.h" #endif #define DEBUG DEBUG_NONE diff --git a/examples/sensinode/udp-ipv6/server.c b/examples/sensinode/udp-ipv6/server.c index 62ea84939..ebe0f590f 100644 --- a/examples/sensinode/udp-ipv6/server.c +++ b/examples/sensinode/udp-ipv6/server.c @@ -41,7 +41,7 @@ #if CONTIKI_TARGET_SENSINODE #include "dev/sensinode-sensors.h" -#include "sensinode-debug.h" +#include "debug.h" #else #define putstring(s) #endif diff --git a/platform/sensinode/Makefile.sensinode b/platform/sensinode/Makefile.sensinode index a1daf96e6..133e6fdde 100644 --- a/platform/sensinode/Makefile.sensinode +++ b/platform/sensinode/Makefile.sensinode @@ -40,7 +40,7 @@ CONTIKI_TARGET_SOURCEFILES = contiki-sensinode-main.c CONTIKI_TARGET_SOURCEFILES += leds.c leds-arch.c serial-line.c sensors.c CONTIKI_TARGET_SOURCEFILES += sensinode-sensors.c button-sensor.c adc-sensor.c CONTIKI_TARGET_SOURCEFILES += n740.c models.c m25p16.c slip-arch.c slip.c -CONTIKI_TARGET_SOURCEFILES += putchar.c sensinode-debug.c +CONTIKI_TARGET_SOURCEFILES += putchar.c debug.c CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) diff --git a/platform/sensinode/contiki-sensinode-main.c b/platform/sensinode/contiki-sensinode-main.c index 5d6267c94..dbe481900 100644 --- a/platform/sensinode/contiki-sensinode-main.c +++ b/platform/sensinode/contiki-sensinode-main.c @@ -15,7 +15,7 @@ #include "net/rime.h" #include "net/netstack.h" #include "net/mac/frame802154.h" -#include "sensinode-debug.h" +#include "debug.h" #include "dev/watchdog-cc2430.h" #include "dev/sensinode-sensors.h" #include "disco.h" diff --git a/platform/sensinode/sensinode-debug.c b/platform/sensinode/debug.c similarity index 97% rename from platform/sensinode/sensinode-debug.c rename to platform/sensinode/debug.c index 031e0ccb5..b1e3a2710 100644 --- a/platform/sensinode/sensinode-debug.c +++ b/platform/sensinode/debug.c @@ -13,7 +13,7 @@ #include "cc2430_sfr.h" #include "8051def.h" -#include "sensinode-debug.h" +#include "debug.h" static const char hexconv[] = "0123456789abcdef"; static const char binconv[] = "01"; diff --git a/platform/sensinode/sensinode-debug.h b/platform/sensinode/debug.h similarity index 95% rename from platform/sensinode/sensinode-debug.h rename to platform/sensinode/debug.h index 683f1ba44..4c5dc135b 100644 --- a/platform/sensinode/sensinode-debug.h +++ b/platform/sensinode/debug.h @@ -40,8 +40,8 @@ * George Oikonomou - */ -#ifndef SENSINODE_DEBUG_H_ -#define SENSINODE_DEBUG_H_ +#ifndef DEBUG_H_ +#define DEBUG_H_ #include "8051def.h" #include "dev/uart1.h" @@ -51,4 +51,4 @@ void putstring(char *s); void puthex(uint8_t c); void putbin(uint8_t c); -#endif /* SENSINODE_DEBUG_H_ */ +#endif /* DEBUG_H_ */ From 2d0d54c3804a905161005b98cd2940690f6999d4 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Apr 2012 21:08:24 +0100 Subject: [PATCH 20/21] Removed obsolete #if config from cc2530dk's main Unlike cc2430, the cc2530 RF driver never generates interrupts. This configuration in main() was a remnant of the porting from the sensinode main, which does in fact need it. Also updated comments in contiki-conf to reflect that shortcuts don't influence the RF --- platform/cc2530dk/contiki-conf.h | 4 ---- platform/cc2530dk/contiki-main.c | 2 -- 2 files changed, 6 deletions(-) diff --git a/platform/cc2530dk/contiki-conf.h b/platform/cc2530dk/contiki-conf.h index bae8c34ad..9713ca56e 100644 --- a/platform/cc2530dk/contiki-conf.h +++ b/platform/cc2530dk/contiki-conf.h @@ -64,10 +64,6 @@ /* Code Shortcuts */ /* - * When set, the RF driver is no longer a contiki process and the RX ISR is - * disabled. Instead of polling the radio process when data arrives, we - * periodically check for data by directly invoking the driver from main() - * When set, this directive also configures the following bypasses: * - process_post_synch() in tcpip_input() (we call packet_input()) * - process_post_synch() in tcpip_uipcall (we call the relevant pthread) diff --git a/platform/cc2530dk/contiki-main.c b/platform/cc2530dk/contiki-main.c index e5b89a682..bbf469dff 100644 --- a/platform/cc2530dk/contiki-main.c +++ b/platform/cc2530dk/contiki-main.c @@ -254,7 +254,6 @@ main(void) watchdog_periodic(); r = process_run(); } while(r > 0); -#if SHORTCUTS_CONF_NETSTACK len = NETSTACK_RADIO.pending_packet(); if(len) { packetbuf_clear(); @@ -264,7 +263,6 @@ main(void) NETSTACK_RDC.input(); } } -#endif #if LPM_MODE #if (LPM_MODE==LPM_MODE_PM2) From 5240519dd94c928c6b6068d83a3a84fab426e729 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 1 Apr 2012 21:43:22 +0100 Subject: [PATCH 21/21] Renamed a config define to better match contiki's naming philosophy --- cpu/cc2430/dev/cc2430_rf.c | 14 +++++++------- cpu/cc2430/dev/cc2430_rf.h | 2 +- cpu/cc2430/dev/cc2430_rf_intr.c | 2 +- platform/cc2530dk/contiki-conf.h | 4 ++-- platform/sensinode/contiki-conf.h | 6 +++--- platform/sensinode/contiki-sensinode-main.c | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cpu/cc2430/dev/cc2430_rf.c b/cpu/cc2430/dev/cc2430_rf.c index 934bb7a23..835365afe 100644 --- a/cpu/cc2430/dev/cc2430_rf.c +++ b/cpu/cc2430/dev/cc2430_rf.c @@ -98,7 +98,7 @@ uint8_t rf_error = 0; #endif /*---------------------------------------------------------------------------*/ -#if !SHORTCUTS_CONF_NETSTACK +#if !NETSTACK_CONF_SHORTCUTS PROCESS(cc2430_rf_process, "CC2430 RF driver"); #endif /*---------------------------------------------------------------------------*/ @@ -152,7 +152,7 @@ flush_rx() cc2430_rf_command(ISFLUSHRX); cc2430_rf_command(ISFLUSHRX); -#if !SHORTCUTS_CONF_NETSTACK +#if !NETSTACK_CONF_SHORTCUTS IEN2 |= RFIE; #endif #if CC2430_RFERR_INTERRUPT @@ -338,7 +338,7 @@ init(void) RFIF &= ~(IRQ_FIFOP); S1CON &= ~(RFIF_0 | RFIF_1); -#if !SHORTCUTS_CONF_NETSTACK +#if !NETSTACK_CONF_SHORTCUTS IEN2 |= RFIE; #endif @@ -351,7 +351,7 @@ init(void) RF_RX_LED_OFF(); rf_initialized = 1; -#if !SHORTCUTS_CONF_NETSTACK +#if !NETSTACK_CONF_SHORTCUTS process_start(&cc2430_rf_process, NULL); #endif @@ -476,7 +476,7 @@ read(void *buf, unsigned short bufsize) #endif /* CC2420_CONF_CHECKSUM */ /* Don't interrupt us while emptying the FIFO */ -#if !SHORTCUTS_CONF_NETSTACK +#if !NETSTACK_CONF_SHORTCUTS IEN2 &= ~RFIE; #endif #if CC2430_RFERR_INTERRUPT @@ -576,7 +576,7 @@ read(void *buf, unsigned short bufsize) RF_RX_LED_OFF(); -#if !SHORTCUTS_CONF_NETSTACK +#if !NETSTACK_CONF_SHORTCUTS IEN2 |= RFIE; #endif #if CC2430_RFERR_INTERRUPT @@ -688,7 +688,7 @@ const struct radio_driver cc2430_rf_driver = off, }; /*---------------------------------------------------------------------------*/ -#if !SHORTCUTS_CONF_NETSTACK +#if !NETSTACK_CONF_SHORTCUTS /*---------------------------------------------------------------------------*/ PROCESS_THREAD(cc2430_rf_process, ev, data) { diff --git a/cpu/cc2430/dev/cc2430_rf.h b/cpu/cc2430/dev/cc2430_rf.h index f64129e09..eecb26ead 100644 --- a/cpu/cc2430/dev/cc2430_rf.h +++ b/cpu/cc2430/dev/cc2430_rf.h @@ -77,7 +77,7 @@ int8_t cc2430_rf_channel_set(uint8_t channel); uint8_t cc2430_rf_power_set(uint8_t new_power); void cc2430_rf_set_addr(unsigned pan, unsigned addr, const uint8_t *ieee_addr); -#if !SHORTCUTS_CONF_NETSTACK +#if !NETSTACK_CONF_SHORTCUTS extern void cc2430_rf_ISR( void ) __interrupt (RF_VECTOR); #endif #if CC2430_RFERR_INTERRUPT diff --git a/cpu/cc2430/dev/cc2430_rf_intr.c b/cpu/cc2430/dev/cc2430_rf_intr.c index 296024115..510c93f1a 100644 --- a/cpu/cc2430/dev/cc2430_rf_intr.c +++ b/cpu/cc2430/dev/cc2430_rf_intr.c @@ -50,7 +50,7 @@ uint8_t rf_error = 0; PROCESS_NAME(cc2430_rf_process); -#if !SHORTCUTS_CONF_NETSTACK +#if !NETSTACK_CONF_SHORTCUTS /*---------------------------------------------------------------------------*/ /** * RF interrupt service routine. diff --git a/platform/cc2530dk/contiki-conf.h b/platform/cc2530dk/contiki-conf.h index 9713ca56e..647cb39b3 100644 --- a/platform/cc2530dk/contiki-conf.h +++ b/platform/cc2530dk/contiki-conf.h @@ -69,9 +69,9 @@ * - process_post_synch() in tcpip_uipcall (we call the relevant pthread) * - mac_call_sent_callback() is replaced with sent() in various places * - * These are good things to do, we reduce stack usage, RAM size and code size + * These are good things to do, they reduce stack usage and prevent crashes */ -#define SHORTCUTS_CONF_NETSTACK 1 +#define NETSTACK_CONF_SHORTCUTS 1 /* * Sensors diff --git a/platform/sensinode/contiki-conf.h b/platform/sensinode/contiki-conf.h index 3148605de..278ba74de 100644 --- a/platform/sensinode/contiki-conf.h +++ b/platform/sensinode/contiki-conf.h @@ -82,15 +82,15 @@ * When set, the RF driver is no longer a contiki process and the RX ISR is * disabled. Instead of polling the radio process when data arrives, we * periodically check for data by directly invoking the driver from main() - + * * When set, this directive also configures the following bypasses: * - process_post_synch() in tcpip_input() (we call packet_input()) * - process_post_synch() in tcpip_uipcall (we call the relevant pthread) * - mac_call_sent_callback() is replaced with sent() in various places * - * These are good things to do, we reduce stack usage, RAM size and code size + * These are good things to do, they reduce stack usage and prevent crashes */ -#define SHORTCUTS_CONF_NETSTACK 1 +#define NETSTACK_CONF_SHORTCUTS 1 /* * Sensors diff --git a/platform/sensinode/contiki-sensinode-main.c b/platform/sensinode/contiki-sensinode-main.c index dbe481900..66d2d0e75 100644 --- a/platform/sensinode/contiki-sensinode-main.c +++ b/platform/sensinode/contiki-sensinode-main.c @@ -32,7 +32,7 @@ PROCESS_NAME(viztool_process); PROCESS_NAME(batmon_process); #endif -#if SHORTCUTS_CONF_NETSTACK +#if NETSTACK_CONF_SHORTCUTS static __data int len; #endif @@ -306,7 +306,7 @@ main(void) #endif r = process_run(); } while(r > 0); -#if SHORTCUTS_CONF_NETSTACK +#if NETSTACK_CONF_SHORTCUTS len = NETSTACK_RADIO.pending_packet(); if(len) { packetbuf_clear();