Merge branch 'master' of ssh://contiki.git.sourceforge.net/gitroot/contiki/contiki

This commit is contained in:
nvt 2012-03-12 19:23:37 +01:00
commit 9fb93cd7b7
105 changed files with 1572 additions and 1325 deletions

View file

@ -107,11 +107,8 @@ PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFI
ifdef APPS
APPDIRS += ${wildcard ${addprefix $(CONTIKI)/apps/, $(APPS)} \
${addprefix $(CONTIKI)/platform/$(TARGET)/apps/, $(APPS)} \
${addprefix , $(APPS)}}
APPINCLUDES = ${foreach APP, $(APPS), ${wildcard ${foreach DIR, $(APPDIRS), $(DIR)/Makefile.$(APP)} \
$(CONTIKI)/apps/$(APP)/Makefile.$(APP) \
$(CONTIKI)/platform/$(TARGET)/apps/$(APP)/Makefile.$(APP) \
$(APP)/Makefile.$(APP)}}
$(APPS)}
APPINCLUDES = ${foreach APP, $(APPS), ${wildcard ${foreach DIR, $(APPDIRS), $(DIR)/Makefile.$(APP)}}}
-include $(APPINCLUDES)
APP_SOURCES = ${foreach APP, $(APPS), $($(APP)_src)}
DSC_SOURCES = ${foreach APP, $(APPS), $($(APP)_dsc)}

View file

@ -57,15 +57,12 @@
int coap_separate_handler(resource_t *resource, void *request, void *response)
{
coap_packet_t *const coap_req = (coap_packet_t *) request;
coap_packet_t *const coap_res = (coap_packet_t *) response;
PRINTF("Separate response for /%s MID %u\n", resource->url, coap_res->mid);
/* Only ack CON requests. */
if (coap_req->type==COAP_TYPE_CON)
{
coap_transaction_t *const t = coap_get_transaction_by_mid(coap_res->mid);
/* send separate ACK. */
coap_packet_t ack[1];
/* ACK with empty code (0) */
@ -79,7 +76,7 @@ int coap_separate_handler(resource_t *resource, void *request, void *response)
}
int
coap_separate_response(void *request, coap_separate_t *separate_store)
coap_separate_yield(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);
@ -96,9 +93,7 @@ coap_separate_response(void *request, coap_separate_t *separate_store)
separate_store->token_len = coap_req->token_len;
separate_store->block2_num = coap_req->block2_num;
separate_store->block2_more = coap_req->block2_more;
separate_store->block2_size = coap_req->block2_size;
separate_store->block2_offset = coap_req->block2_offset;
/* Signal the engine to skip automatic response and clear transaction by engine. */
coap_error_code = MANUAL_RESPONSE;
@ -110,3 +105,10 @@ coap_separate_response(void *request, coap_separate_t *separate_store)
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);
}

View file

@ -54,13 +54,12 @@ typedef struct coap_separate {
/* separate + blockwise is untested! */
uint32_t block2_num;
uint8_t block2_more;
uint16_t block2_size;
uint32_t block2_offset;
} coap_separate_t;
int coap_separate_handler(resource_t *resource, void *request, void *response);
int coap_separate_response(void *response, coap_separate_t *separate_store);
int coap_separate_yield(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_ */

View file

@ -555,6 +555,11 @@ PT_THREAD(neighbors(struct httpd_state *s, char *ptr))
#if WEBSERVER_CONF_ROUTES
extern uip_ds6_route_t uip_ds6_routing_table[];
#if WEBSERVER_CONF_ROUTE_LINKS
static const char httpd_cgi_rtesl1[] HTTPD_STRING_ATTR = "<a href=http://[";
static const char httpd_cgi_rtesl2[] HTTPD_STRING_ATTR = "]/status.shtml>";
static const char httpd_cgi_rtesl3[] HTTPD_STRING_ATTR = "</a>";
#endif
/*---------------------------------------------------------------------------*/
static unsigned short
make_routes(void *p)
@ -573,9 +578,6 @@ struct httpd_state *s=p;
j++;
#if WEBSERVER_CONF_ROUTE_LINKS
static const char httpd_cgi_rtesl1[] HTTPD_STRING_ATTR = "<a href=http://[";
static const char httpd_cgi_rtesl2[] HTTPD_STRING_ATTR = "]/status.shtml>";
static const char httpd_cgi_rtesl3[] HTTPD_STRING_ATTR = "</a>";
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtesl1);
numprinted += httpd_cgi_sprint_ip6(uip_ds6_routing_table[i].ipaddr, uip_appdata + numprinted);
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtesl2);
@ -592,7 +594,7 @@ static const char httpd_cgi_rtesl3[] HTTPD_STRING_ATTR = "</a>";
} else {
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtes3);
}
/* If buffer nearly full, send it and wait for the next call. Could be a retransmission, or the next segment */
/* If buffer near full, send it and wait for the next call. Could be a retransmission, or the next segment */
if(numprinted > (uip_mss() - 200)) {
s->savei=i;s->savej=j;
return numprinted;
@ -607,7 +609,40 @@ static const char httpd_cgi_rtesl3[] HTTPD_STRING_ATTR = "</a>";
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_addrf);
}
#endif
{
static const char httpd_cgi_defr1[] HTTPD_STRING_ATTR = "\n<big><b>RPL Parent</b></big>\n";
static const char httpd_cgi_defr2[] HTTPD_STRING_ATTR = " (%u sec)\n";
#if 0
uip_ip6addr_t *nexthop = uip_ds6_defrt_choose();
if (nexthop) {
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_defr1);
numprinted += httpd_cgi_sprint_ip6(*nexthop, uip_appdata + numprinted);
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_defr2,nexthop->lifetime.start+nexthop->lifetime.interval-clock_seconds());
}
#else
uip_ds6_defrt_t *locdefrt;
extern uip_ds6_defrt_t uip_ds6_defrt_list[UIP_DS6_DEFRT_NB];
for(locdefrt = uip_ds6_defrt_list;
locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) {
if(locdefrt->isused) {
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_defr1);
#if WEBSERVER_CONF_ROUTE_LINKS && 0
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtesl1);
numprinted += httpd_cgi_sprint_ip6(locdefrt->ipaddr, uip_appdata + numprinted);
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtesl2);
numprinted += httpd_cgi_sprint_ip6(locdefrt->ipaddr, uip_appdata + numprinted);
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_rtesl3);
#else
numprinted += httpd_cgi_sprint_ip6(locdefrt->ipaddr, uip_appdata + numprinted);
#endif
numprinted += httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_defr2,locdefrt->lifetime.start+locdefrt->lifetime.interval-clock_seconds());
// break;
}
}
#endif
}
/* Signal that this was the last segment */
s->savei = 0;
return numprinted;
@ -717,8 +752,6 @@ uint8_t c;
adc_disable();
#endif
snprintf(sensor_extvoltage, sizeof(sensor_extvoltage),"%u mV",1200*0xfff/adc_reading[8]);
static const char httpd_cgi_sensorv[] HTTPD_STRING_ATTR = "<em>ADC chans :</em> %u %u %u %u %u %u %u %u \n";
numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_sensorv,
adc_reading[0],adc_reading[1],adc_reading[2],adc_reading[3],adc_reading[4],adc_reading[5],adc_reading[6],adc_reading[7]);
@ -770,7 +803,7 @@ generate_stats(void *arg)
uint32_t seconds=clock_seconds();
static const char httpd_cgi_stats[] HTTPD_STRING_ATTR = "\n<big><b>Statistics</b></big>\n";
numprinted=httpd_snprintf((char *)uip_appdata + numprinted, uip_mss() - numprinted, httpd_cgi_stats);
numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_stats);
#if ENERGEST_CONF_ON
{uint8_t p1,p2;
@ -1024,10 +1057,27 @@ PT_THREAD(ajax_call(struct httpd_state *s, char *ptr))
static int iter;
static char buf[128];
static uint8_t numprinted;
uint16_t dt;
PSOCK_BEGIN(&s->sout);
/*TODO:pick up time from ? parameter */
timer_set(&t, 2*CLOCK_SECOND);
#if WEBSERVER_CONF_PASSQUERY
/* Get update time from ? string, if present */
{
uint8_t i;uint16_t dt=0;
for (i=0;i<WEBSERVER_CONF_PASSQUERY;i++) {
if (httpd_query[i] < '0' || httpd_query[i] > '9') break;
dt = dt*10 + httpd_query[i]-'0';
}
if (dt < 1) dt = 1;
// printf("dt %u\n",dt);
timer_set(&t, dt*CLOCK_SECOND);
httpd_query[i]=0; //necessary?
if (dt > WEBSERVER_CONF_TIMEOUT/2) s->ajax_timeout = 2*dt; else s->ajax_timeout = WEBSERVER_CONF_TIMEOUT;
}
#else
timer_set(&t, 2*CLOCK_SECOND);
#endif
iter = 0;
while(1) {
@ -1064,7 +1114,8 @@ PT_THREAD(ajax_call(struct httpd_state *s, char *ptr))
adc_disable();
#endif
#if 0
#if 1
numprinted = snprintf(buf, sizeof(buf),"b(%u);adc(%u,%u,%u,%u,%u,%u,%u,%u);",
1200*0xfff/adc_reading[8],adc_reading[0],adc_reading[1],adc_reading[2],adc_reading[3],adc_reading[4],adc_reading[5],adc_reading[6],adc_reading[7]);
#else
@ -1074,14 +1125,14 @@ PT_THREAD(ajax_call(struct httpd_state *s, char *ptr))
}
if (iter<3) {
static const char httpd_cgi_ajax11[] HTTPD_STRING_ATTR = "wt('Econtag [";
static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "]');";
static const char httpd_cgi_ajax12[] HTTPD_STRING_ATTR = "]');";
numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajax11);
#if WEBSERVER_CONF_PRINTADDR
/* Note address table is filled from the end down */
{int i;
for (i=0; i<UIP_DS6_ADDR_NB;i++) {
if (uip_ds6_if.addr_list[i].isused) {
numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted);
numprinted += httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr, buf + numprinted);
break;
}
}
@ -1256,8 +1307,15 @@ static uint16_t c0=0x3ff,c1=0x3ff,c2=0x3ff,c3=0x3ff,c4=0x3ff,c5=0x3ff,c6=0x3ff,c
#if ENERGEST_CONF_ON
{
#if 1
/* Send on times in percent since last update. Handle 16 bit rtimer wraparound. */
/* Javascript must convert based on platform cpu, tx, rx power, e.g. 20ma*3v3=66mW*(% on time/100) */
/* Send on times in percent since last update. Handle 16 bit rtimer wraparound.
* Javascript must convert based on platform cpu, tx, rx power.
* e.g. for cpu drawing 1.2ma@3v3, cp = 1.2*3.3*(% on time)/100 = 0.0396*c;
* Low power mode l is essentially zero for cpus that sleep.
* function p(c,l,t,r){cp=0.013*c;lt=0.465*t;lr=0.400*r;n=cp+lt+lr;//128rfa1@3v3,3dBm
* function p(c,l,t,r){cp=0.013*c;lt=0.317*t;lr=0.400*r;n=cp+lt+lr;//128rfa1@3v3,0dBm
* function p(c,l,t,r){cp=0.109*c;lt=0.848*t;lr=0.617*r;n=cp+lt+lr;//mc1322x@3v3,0dBm
* Precision can be increased by multiplying by another 100 before sending.
*/
static rtimer_clock_t last_send;
rtimer_clock_t delta_time;
static unsigned long last_cpu, last_lpm, last_listen, last_transmit;
@ -1267,10 +1325,10 @@ static uint16_t c0=0x3ff,c1=0x3ff,c2=0x3ff,c3=0x3ff,c4=0x3ff,c5=0x3ff,c6=0x3ff,c
last_send=RTIMER_NOW();
static const char httpd_cgi_ajaxe1[] HTTPD_STRING_ATTR = "p(%lu,%lu,%lu,%lu);";
numprinted += httpd_snprintf(buf+numprinted, sizeof(buf)-numprinted,httpd_cgi_ajaxe1,
(100UL*(energest_total_time[ENERGEST_TYPE_CPU].current - last_cpu))/delta_time,
(100UL*(energest_total_time[ENERGEST_TYPE_LPM].current - last_lpm))/delta_time,
(100UL*(energest_total_time[ENERGEST_TYPE_TRANSMIT].current - last_transmit))/delta_time,
(100UL*(energest_total_time[ENERGEST_TYPE_LISTEN].current - last_listen))/delta_time);
(10000UL*(energest_total_time[ENERGEST_TYPE_CPU].current - last_cpu))/delta_time,
(10000UL*(energest_total_time[ENERGEST_TYPE_LPM].current - last_lpm))/delta_time,
(10000UL*(energest_total_time[ENERGEST_TYPE_TRANSMIT].current - last_transmit))/delta_time,
(10000UL*(energest_total_time[ENERGEST_TYPE_LISTEN].current - last_listen))/delta_time);
last_cpu = energest_total_time[ENERGEST_TYPE_CPU].current;
last_lpm = energest_total_time[ENERGEST_TYPE_LPM].current;
last_transmit = energest_total_time[ENERGEST_TYPE_TRANSMIT].current;
@ -1299,8 +1357,14 @@ static uint16_t c0=0x3ff,c1=0x3ff,c2=0x3ff,c3=0x3ff,c4=0x3ff,c5=0x3ff,c6=0x3ff,c
#endif /* ENERGEST_CONF_ON */
PSOCK_SEND_STR(&s->sout, buf);
/* Can do fixed intervals or fixed starting points */
#if FIXED_INTERVALS
timer_restart(&t);
PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t));
PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t));
#else
PSOCK_WAIT_UNTIL(&s->sout, timer_expired(&t));
timer_reset(&t);
#endif
}
PSOCK_END(&s->sout);
}

View file

@ -3,6 +3,7 @@
function e(el){return document.getElementById(el);}
function ls(){try{r=new XMLHttpRequest();}catch(e){alert("Browswer does not support Ajax");return false;}r.open("GET","/ajaxdata.shtml",true);
x=0;r.onreadystatechange=function(){e('date').innerHTML=(new Date()).toTimeString();if(r.readyState>0){j=r.responseText.substr(x);x+=j.length;eval(j);}};r.send(null);}
function tb(x){var t=e('ss');if(x||t.value=="RUN"){t.value="STOP";ls();}else{t.value="RUN";r.abort();}}
function s(el,n,max,text){e(el).innerHTML='<table width=504 border=0 cellpadding=1 cellspacing=0>'+'<tr><td width=200>'+text+'</td>'+'<td width='+(10+300*n/max)+' bgcolor="gray">&nbsp;</td>'+'<td width='+(310-300*n/max)+' bgcolor="lightgray">&nbsp;</td>'+'</table>';}
function wt(m){document.title=m;e('v').innerHTML=m;}
function dc(n,d){return n.toFixed(d);}
@ -12,7 +13,7 @@ function ax(m){s('ax',m+2000,4000,'Acceleration (X-axis) '+m+'mg');}
function ay(m){s('ay',m+2000,4000,'Acceleration (Y-axis) '+m+'mg');}
function az(m){s('az',m+2000,4000,'Acceleration (Z-axis) '+m+'mg');}
function rs(m){s('rs',n,100,'RSSI '+n);}
function p(c,l,t,r){cp=0.136*c;lt=0.478*t;lr=0.412*r;n=cp+lt+lr;//128rfa1@3v3
function p(c,l,t,r){cp=0.00109*c;lt=0.00848*t;lr=0.00617*r;n=cp+lt+lr;//mc1322x
s('p',n,200,'Power consumption '+dc(n,2)+' mW');
s('pc',cp,100,'CPU power '+dc(cp,2)+' mW');
s('pr',lr,200,'Radio RX power '+dc(lr,2)+' mW');

View file

@ -1,6 +1,8 @@
%! header
%!: /ajax.js
<input type="button" value="RUN" onclick="ls()"><input type="button" value="STOP" onclick="r.abort()"><br><span id="date"></span>
<input id="ss" type="button" value="STOP" onclick="tb(0)">
Interval <input id="tc" type="text" style="width:60;text-align:right;" maxlength="5" value="10" onchange="tb(1)"> seconds<br>
<span id="date"></span>
<div id="v"></div>
<pre><span id="rims"></span><div id="ener"></div></pre>
<h2>Sensors</h2>

View file

@ -1,10 +1,14 @@
%! header
<h4>Addresses</h4>
<pre><big><b>Addresses</b></big>
%! addresses
<h4>Neighbors</h4>
<big><b>Neighbors</b></big>
%! neighbors
<h4>Routes</h4>
<big><b>Routes</b></big>
%! routes
<h4>Sensors</h4>
<big><b>Sensors</b></big>
%! sensors
%! file-stats .
</pre>
%! file-stats .

View file

@ -1,10 +1,14 @@
%! header
<p>Addresses<br>
<pre><big><b>Addresses</b></big>
%! addresses
<p>Neighbors<br>
<big><b>Neighbors</b></big>
%! neighbors
<p>Routes<br>
<big><b>Routes</b></big>
%! routes
<p>Sensors<br>
<big><b>Sensors</b></big>
%! sensors
%! file-stats .
</pre>
%! file-stats .

View file

@ -94,7 +94,6 @@ static
PT_THREAD(send_file(struct httpd_state *s))
{
PSOCK_BEGIN(&s->sout);
do {
PSOCK_GENERATOR_SEND(&s->sout, generate, s);
s->file.len -= s->len;
@ -488,11 +487,18 @@ httpd_appcall(void *state)
PT_INIT(&s->outputpt);
s->state = STATE_WAITING;
s->timer = 0;
#if WEBSERVER_CONF_AJAX
s->ajax_timeout = WEBSERVER_CONF_TIMEOUT;
#endif
handle_connection(s);
} else if(s != NULL) {
if(uip_poll()) {
++s->timer;
if(s->timer >= 20) {
#if WEBSERVER_CONF_AJAX
if(s->timer >= s->ajax_timeout) {
#else
if(s->timer >= WEBSERVER_CONF_TIMEOUT) {
#endif
uip_abort();
memb_free(&conns, s);
}

View file

@ -76,6 +76,8 @@
#define WEBSERVER_CONF_CONNS 2
#define WEBSERVER_CONF_NAMESIZE 16
#define WEBSERVER_CONF_BUFSIZE 40
/* Short tcp timeouts allow new connections sooner */
#define WEBSERVER_CONF_TIMEOUT 20
/* Allow include in .shtml pages, e.g. %!: /header.html */
#define WEBSERVER_CONF_INCLUDE 1
/* Allow cgi in .shtml pages, e.g. %! file-stats . */
@ -116,13 +118,13 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY];
#define WEBSERVER_CONF_LOG 0
/* Include referrer in log */
#define WEBSERVER_CONF_REFERER 0
/*-----------------------------------------------------------------------------*/
#elif WEBSERVER_CONF_NANO==2
/* webserver-mini having more content */
#define WEBSERVER_CONF_CONNS 2
#define WEBSERVER_CONF_NAMESIZE 20
#define WEBSERVER_CONF_BUFSIZE 40
#define WEBSERVER_CONF_TIMEOUT 20
/* Allow include in .shtml pages, e.g. %!: /header.html */
#define WEBSERVER_CONF_INCLUDE 1
/* Allow cgi in .shtml pages, e.g. %! file-stats . */
@ -148,7 +150,7 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY];
//#define WEBSERVER_CONF_TICTACTOE 1 //Needs passquery of at least 10 chars
#define WEBSERVER_CONF_AJAX 1
#define WEBSERVER_CONF_SHOW_ROOM 0
//#define WEBSERVER_CONF_PASSQUERY 10
#define WEBSERVER_CONF_PASSQUERY 10
#if WEBSERVER_CONF_PASSQUERY
extern char httpd_query[WEBSERVER_CONF_PASSQUERY];
#endif
@ -171,6 +173,7 @@ extern char httpd_query[WEBSERVER_CONF_PASSQUERY];
#define WEBSERVER_CONF_CONNS 6
#define WEBSERVER_CONF_NAMESIZE 20
#define WEBSERVER_CONF_BUFSIZE 40
#define WEBSERVER_CONF_TIMEOUT 20
/* Allow include in .shtml pages, e.g. %!: /header.html */
#define WEBSERVER_CONF_INCLUDE 1
/* Allow cgi in .shtml pages, e.g. %! file-stats . */
@ -285,6 +288,9 @@ struct httpd_state {
#if WEBSERVER_CONF_LOADTIME
clock_time_t pagetime;
#endif
#if WEBSERVER_CONF_AJAX
uint16_t ajax_timeout;
#endif
#if WEBSERVER_CONF_NEIGHBORS || WEBSERVER_CONF_ROUTES
uint8_t starti,savei,startj,savej;
#endif

View file

@ -244,11 +244,7 @@ dio_input(void)
PRINTF("RPL: Neighbor already in neighbor cache\n");
}
buffer_length = uip_len - uip_l2_l3_icmp_hdr_len;
#if RPL_CONF_ADJUST_LLH_LEN
buffer_length += UIP_LLH_LEN; /* Add jackdaw, minimal-net ethernet header */
#endif
buffer_length = uip_len - uip_l3_icmp_hdr_len;
/* Process the DIO base option. */
i = 0;
@ -579,11 +575,8 @@ dao_input(void)
PRINTF("\n");
buffer = UIP_ICMP_PAYLOAD;
buffer_length = uip_len - uip_l2_l3_icmp_hdr_len;
buffer_length = uip_len - uip_l3_icmp_hdr_len;
#if RPL_CONF_ADJUST_LLH_LEN
buffer_length += UIP_LLH_LEN; /* Add jackdaw, minimal-net ethernet header */
#endif
pos = 0;
instance_id = buffer[pos++];
@ -801,7 +794,7 @@ dao_ack_input(void)
uint8_t status;
buffer = UIP_ICMP_PAYLOAD;
buffer_length = uip_len - uip_l2_l3_icmp_hdr_len;
buffer_length = uip_len - uip_l3_icmp_hdr_len;
instance_id = buffer[0];
sequence = buffer[2];

View file

@ -224,7 +224,9 @@ uip_ds6_periodic(void)
if(locnbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) {
PRINTF("PROBE END\n");
if((locdefrt = uip_ds6_defrt_lookup(&locnbr->ipaddr)) != NULL) {
uip_ds6_defrt_rm(locdefrt);
if (!locdefrt->isinfinite) {
uip_ds6_defrt_rm(locdefrt);
}
}
uip_ds6_nbr_rm(locnbr);
} else if(stimer_expired(&locnbr->sendns) && (uip_len == 0)) {

View file

@ -1048,7 +1048,7 @@ uip_process(uint8_t flag)
if(flag == UIP_UDP_TIMER) {
if(uip_udp_conn->lport != 0) {
uip_conn = NULL;
uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN];
uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN];
uip_len = uip_slen = 0;
uip_flags = UIP_POLL;
UIP_UDP_APPCALL();
@ -1447,7 +1447,7 @@ uip_process(uint8_t flag)
send. */
#if UIP_UDP_CHECKSUMS
uip_len = uip_len - UIP_IPUDPH_LEN;
uip_appdata = &uip_buf[UIP_IPUDPH_LEN];
uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN];
if(UIP_UDP_BUF->udpchksum != 0 && uip_udpchksum() != 0xffff) {
UIP_STAT(++uip_stat.udp.drop);
UIP_STAT(++uip_stat.udp.chkerr);
@ -1500,7 +1500,7 @@ uip_process(uint8_t flag)
uip_conn = NULL;
uip_flags = UIP_NEWDATA;
uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN];
uip_sappdata = uip_appdata = &uip_buf[UIP_IPUDPH_LEN + UIP_LLH_LEN];
uip_slen = 0;
UIP_UDP_APPCALL();

View file

@ -71,10 +71,19 @@ CUSTOM_RULE_C_TO_O = 1
%.o: %.c
$(CC) $(CFLAGS) $< -o $@
define FINALIZE_CYGWIN_DEPENDENCY
sed -e 's/ \([A-Z]\):\\/ \/cygdrive\/\L\1\//' -e 's/\\/\//g' \
<$(@:.o=.P) >$(@:.o=.d); \
rm -f $(@:.o=.P)
endef
CUSTOM_RULE_C_TO_OBJECTDIR_O = 1
$(OBJECTDIR)/%.o: %.c
$(CC) $(CFLAGS) $< -o $@
# @$(FINALIZE_DEPENDENCY)
$(CC) $(CFLAGS) $< --dependencies=m $(@:.o=.P) -o $@
ifeq ($(HOST_OS),Windows)
@$(FINALIZE_CYGWIN_DEPENDENCY)
endif
CUSTOM_RULE_C_TO_CO = 1
%.co: %.c
$(CC) $(CFLAGS) -DAUTOSTART_ENABLE $< -o $@
@ -82,6 +91,7 @@ CUSTOM_RULE_C_TO_CO = 1
AROPTS = -o
else
GCC = 1
CC = msp430-gcc
LD = msp430-gcc
@ -129,8 +139,13 @@ PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)}
%.firmware: %.${TARGET}
mv $< $@
ifdef IAR
%.ihex: %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
$(LD) $(LDFLAGSNO) -Fintel-extended -yn $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@
else
%.ihex: %.$(TARGET)
$(OBJCOPY) $^ -O ihex $@
endif
%.mspsim: %.${TARGET}
java -jar ${CONTIKI}/tools/mspsim/mspsim.jar -platform=${TARGET} $<

View file

@ -31,6 +31,7 @@
#include "contiki.h"
#include "dev/button.h"
#include "isr_compat.h"
#define BUTTON_PORT 2
#define BUTTON_PIN 7
@ -57,8 +58,7 @@ button_init(struct process *proc)
P2IE &= ~BV(BUTTON_PIN);
}
interrupt(PORT2_VECTOR)
__button_interrupt(void)
ISR(PORT2, __button_interrupt)
{
static struct timer debouncetimer;

View file

@ -32,6 +32,7 @@
#include "contiki.h"
#include "dev/spi.h"
#include "dev/cc2420.h"
#include "isr_compat.h"
extern volatile uint8_t cc2420_sfd_counter;
extern volatile uint16_t cc2420_sfd_start_time;
@ -39,13 +40,7 @@ extern volatile uint16_t cc2420_sfd_end_time;
/*---------------------------------------------------------------------------*/
/* SFD interrupt for timestamping radio packets */
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=TIMERB1_VECTOR
__interrupt void
#else
interrupt(TIMERB1_VECTOR)
#endif
cc24240_timerb1_interrupt(void)
ISR(TIMERB1, cc2420_timerb1_interrupt)
{
int tbiv;
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -34,6 +34,7 @@
#include "dev/spi.h"
#include "dev/cc2420.h"
#include "isr_compat.h"
#ifdef CC2420_CONF_SFD_TIMESTAMPS
#define CONF_SFD_TIMESTAMPS CC2420_CONF_SFD_TIMESTAMPS
@ -48,14 +49,7 @@
#endif
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=CC2420_IRQ_VECTOR
__interrupt void
#else
interrupt(CC2420_IRQ_VECTOR)
#endif
cc24240_port1_interrupt(void)
ISR(CC2420_IRQ, cc2420_port1_interrupt)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
@ -65,7 +59,6 @@ cc24240_port1_interrupt(void)
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
/*---------------------------------------------------------------------------*/
void
cc2420_arch_init(void)

View file

@ -30,6 +30,7 @@
#include "contiki.h"
#include "dev/spi.h"
#include "dev/cc2520.h"
#include "isr_compat.h"
extern volatile uint8_t cc2520_sfd_counter;
extern volatile uint16_t cc2520_sfd_start_time;
@ -37,13 +38,7 @@ extern volatile uint16_t cc2520_sfd_end_time;
/*---------------------------------------------------------------------------*/
/* SFD interrupt for timestamping radio packets */
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=TIMERB1_VECTOR
__interrupt void
#else
interrupt(TIMERB1_VECTOR)
#endif
cc2520_timerb1_interrupt(void)
ISR(TIMERB1, cc2520_timerb1_interrupt)
{
int tbiv;
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -32,6 +32,7 @@
#include "dev/spi.h"
#include "dev/cc2520.h"
#include "isr_compat.h"
#ifdef CC2520_CONF_SFD_TIMESTAMPS
#define CONF_SFD_TIMESTAMPS CC2520_CONF_SFD_TIMESTAMPS
@ -46,13 +47,7 @@
#endif
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=CC2520_IRQ_VECTOR
__interrupt void
#else
interrupt(CC2520_IRQ_VECTOR)
#endif
cc2520_port1_interrupt(void)
ISR(CC2520_IRQ, cc2520_port1_interrupt)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -35,6 +35,7 @@
#include "sys/etimer.h"
#include "rtimer-arch.h"
#include "dev/watchdog.h"
#include "isr_compat.h"
#define INTERVAL (RTIMER_ARCH_SECOND / CLOCK_SECOND)
@ -46,13 +47,7 @@ static volatile clock_time_t count = 0;
/* last_tar is used for calculating clock_fine */
static volatile uint16_t last_tar = 0;
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=TIMERA1_VECTOR
__interrupt void
#else
interrupt(TIMERA1_VECTOR)
#endif
timera1 (void)
ISR(TIMERA1, timera1)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -44,6 +44,7 @@
#include "sys/rtimer.h"
#include "sys/process.h"
#include "dev/watchdog.h"
#include "isr_compat.h"
#define DEBUG 0
#if DEBUG
@ -54,13 +55,7 @@
#endif
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=TIMERA0_VECTOR
__interrupt void
#else
interrupt(TIMERA0_VECTOR)
#endif
timera0 (void)
ISR(TIMERA0, timera0)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -39,6 +39,7 @@
#include "dev/watchdog.h"
#include "sys/ctimer.h"
#include "lib/ringbuf.h"
#include "isr_compat.h"
static int (*uart1_input_handler)(unsigned char c);
static volatile uint8_t rx_in_progress;
@ -236,13 +237,7 @@ uart1_init(unsigned long ubr)
}
/*---------------------------------------------------------------------------*/
#if !RX_WITH_DMA
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=UART1RX_VECTOR
__interrupt void
#else
interrupt(UART1RX_VECTOR)
#endif
uart1_rx_interrupt(void)
ISR(UART1RX, uart1_rx_interrupt)
{
uint8_t c;
ENERGEST_ON(ENERGEST_TYPE_IRQ);
@ -273,13 +268,7 @@ uart1_rx_interrupt(void)
#endif /* !RX_WITH_DMA */
/*---------------------------------------------------------------------------*/
#if TX_WITH_INTERRUPT
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=UART1TX_VECTOR
__interrupt void
#else
interrupt(UART1TX_VECTOR)
#endif
uart1_tx_interrupt(void)
ISR(UART1TX, uart1_tx_interrupt)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -41,6 +41,7 @@
#include "dev/watchdog.h"
#include "lib/ringbuf.h"
#include "dev/leds.h"
#include "isr_compat.h"
static int (*uart0_input_handler)(unsigned char c);
@ -138,14 +139,7 @@ uart0_init(unsigned long ubr)
#endif /* TX_WITH_INTERRUPT */
}
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=USCIAB0RX_VECTOR
__interrupt void
#else
interrupt(USCIAB0RX_VECTOR)
#endif
uart0_rx_interrupt(void)
ISR(USCIAB0RX, uart0_rx_interrupt)
{
uint8_t c;
@ -165,13 +159,7 @@ uart0_rx_interrupt(void)
}
/*---------------------------------------------------------------------------*/
#if TX_WITH_INTERRUPT
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=USCIAB0TX_VECTOR
__interrupt void
#else
interrupt(USCIAB0TX_VECTOR)
#endif
uart0_tx_interrupt(void)
ISR(USCIAB0TX, uart0_tx_interrupt)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
if((IFG2 & UCA0TXIFG)){

View file

@ -37,8 +37,8 @@
#include "sys/energest.h"
#include "dev/uart1.h"
#include "dev/watchdog.h"
#include "lib/ringbuf.h"
#include "isr_compat.h"
static int (*uart1_input_handler)(unsigned char c);
@ -120,8 +120,7 @@ uart1_init(unsigned long ubr)
}
/*---------------------------------------------------------------------------*/
interrupt(USCIAB1RX_VECTOR)
uart1_rx_interrupt(void)
ISR(USCIAB1RX, uart1_rx_interrupt)
{
uint8_t c;
ENERGEST_ON(ENERGEST_TYPE_IRQ);
@ -141,8 +140,7 @@ uart1_rx_interrupt(void)
}
/*---------------------------------------------------------------------------*/
#if TX_WITH_INTERRUPT
interrupt(USCIAB1TX_VECTOR)
uart1_tx_interrupt(void)
ISR(USCIAB1TX, uart1_tx_interrupt)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
if(IFG2 & UCA0TXIFG) {

View file

@ -35,6 +35,7 @@
#include "sys/etimer.h"
#include "rtimer-arch.h"
#include "dev/watchdog.h"
#include "isr_compat.h"
#define INTERVAL (RTIMER_ARCH_SECOND / CLOCK_SECOND)
@ -46,13 +47,7 @@ static volatile clock_time_t count = 0;
/* last_tar is used for calculating clock_fine, last_ccr might be better? */
static volatile uint16_t last_tar = 0;
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=TIMER1_A1_VECTOR
__interrupt void
#else
interrupt(TIMER1_A1_VECTOR)
#endif
timera1 (void)
ISR(TIMER1_A1, timera1)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -41,6 +41,7 @@
#include "sys/rtimer.h"
#include "sys/process.h"
#include "dev/watchdog.h"
#include "isr_compat.h"
#define DEBUG 0
#if DEBUG
@ -51,13 +52,7 @@
#endif
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=TIMER1_A0_VECTOR
__interrupt void
#else
interrupt(TIMER1_A0_VECTOR)
#endif
timera0 (void)
ISR(TIMER1_A0, timera0)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -38,6 +38,7 @@
#include "sys/energest.h"
#include "dev/uart0.h"
#include "dev/watchdog.h"
#include "isr_compat.h"
static int (*uart0_input_handler)(unsigned char c);
@ -98,18 +99,12 @@ uart0_init(unsigned long ubr)
UCA0IE |= UCRXIE; /* Enable UCA0 RX interrupt */
}
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=USCI_A0_VECTOR
__interrupt void
#else
interrupt(USCI_A0_VECTOR)
#endif
uart0_rx_interrupt(void)
ISR(USCI_A0, uart0_rx_interrupt)
{
uint8_t c;
ENERGEST_ON(ENERGEST_TYPE_IRQ);
if (UCA0IV == 2) {
if(UCA0IV == 2) {
if(UCA0STAT & UCRXERR) {
c = UCA0RXBUF; /* Clear error flags by forcing a dummy read. */
} else {

View file

@ -38,6 +38,7 @@
#include "sys/energest.h"
#include "dev/uart1.h"
#include "dev/watchdog.h"
#include "isr_compat.h"
static int (*uart1_input_handler)(unsigned char c);
@ -103,13 +104,7 @@ uart1_init(unsigned long ubr)
UCA1IE |= UCRXIE; /* Enable UCA1 RX interrupt */
}
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=USCI_A1_VECTOR
__interrupt void
#else
interrupt(USCI_A1_VECTOR)
#endif
uart1_rx_interrupt(void)
ISR(USCI_A1, uart1_rx_interrupt)
{
uint8_t c;

87
cpu/msp430/isr_compat.h Normal file
View file

@ -0,0 +1,87 @@
/*
* Copyright (c) 2005 Steve Underwood
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS `AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef _ISR_COMPAT_H_
#define _ISR_COMPAT_H_
/* Cross compiler interrupt service routine compatibility definitions */
/* This code currently allows for:
MSPGCC - the GNU tools for the MSP430
Quadravox AQ430
IAR Version 1 (old syntax)
IAR Versions 2, 3, 4, 5 (new syntax)
Rowley Crossworks
Code Composer Essentials
These macros allow us to define interrupt routines for all
compilers with a common syntax:
ISR(<interrupt>, <routine name>)
{
}
e.g.
ISR(ADC12, adc_service_routine)
{
ADC12CTL0 &= ~ENC;
ADC12CTL0 |= ENC;
}
*/
/* 2012-03-02: minor update to support IAR version 4 and 5 */
/* A tricky #define to stringify _Pragma parameters */
#define __PRAGMA__(x) _Pragma(#x)
#if defined(__GNUC__) && defined(__MSP430__)
/* This is the MSPGCC compiler */
#define ISR(a,b) interrupt(a ## _VECTOR) b(void)
#elif defined(__AQCOMPILER__)
/* This is the Quadravox compiler */
#define ISR(a,b) void _INTERRUPT[a ## _VECTOR] b(void)
#elif defined(__IAR_SYSTEMS_ICC__) && (((__TID__ >> 8) & 0x7f) == 43) && (__VER__ < 200)
/* This is V1.xx of the IAR compiler. */
#define ISR(a,b) interrupt[a ## _VECTOR] void b(void)
#elif defined(__IAR_SYSTEMS_ICC__) && (((__TID__ >> 8) & 0x7f) == 43) && (__VER__ < 600)
/* This is V2.xx, V3.xx, V4.xx, V5.xx of the IAR compiler. */
#define ISR(a,b) \
__PRAGMA__(vector=a ##_VECTOR) \
__interrupt void b(void)
#elif defined(__CROSSWORKS_MSP430)
/* This is the Rowley Crossworks compiler */
#define ISR(a,b) void b __interrupt[a ## _VECTOR](void)
#elif defined(__TI_COMPILER_VERSION__)
/* This is the Code Composer Essentials compiler. */
#define ISR(a,b) __interrupt void b(void); \
a ## _ISR(b) \
__interrupt void b(void)
#else
#error Compiler not recognised.
#endif
#endif

View file

@ -33,6 +33,7 @@
#include "contiki.h"
#include "dev/watchdog.h"
#include "isr_compat.h"
static int counter = 0;
@ -70,13 +71,7 @@ printstring(char *s)
#endif /* CONTIKI_TARGET_SKY */
#endif /* PRINT_STACK_ON_REBOOT */
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=WDT_VECTOR
__interrupt void
#else
interrupt(WDT_VECTOR)
#endif
watchdog_interrupt(void)
ISR(WDT, watchdog_interrupt)
{
#ifdef CONTIKI_TARGET_SKY
#if PRINT_STACK_ON_REBOOT

View file

@ -349,7 +349,7 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
}
#endif
#if REST_RES_SEPARATE && WITH_COAP > 3
#if defined (PLATFORM_HAS_BUTTON) && REST_RES_SEPARATE && WITH_COAP > 3
/* Required to manually (=not by the engine) handle the response transaction. */
#include "er-coap-07-separate.h"
#include "er-coap-07-transactions.h"
@ -390,7 +390,8 @@ separate_handler(void* request, void* response, uint8_t *buffer, uint16_t prefer
separate_active = 1;
/* Take over and skip response by engine. */
coap_separate_response(request, &separate_store->request_metadata);
coap_separate_yield(request, &separate_store->request_metadata);
/* Be aware to respect the Block2 option, which is also stored in the coap_separate_t. */
/*
* At the moment, only the minimal information is stored in the store (client address, port, token, MID, type, and Block2).
@ -410,10 +411,18 @@ separate_finalize_handler()
if ( (transaction = coap_new_transaction(separate_store->request_metadata.mid, &separate_store->request_metadata.addr, separate_store->request_metadata.port)) )
{
coap_packet_t response[1]; /* This way the packet can be treated as pointer as usual. */
coap_init_message(response, separate_store->request_metadata.type, CONTENT_2_05, separate_store->request_metadata.mid);
/* Restore the request information for the response. */
coap_separate_resume(response, &separate_store->request_metadata, CONTENT_2_05);
coap_set_payload(response, separate_store->buffer, strlen(separate_store->buffer));
/*
* Be aware to respect the Block2 option, which is also stored in the coap_separate_t.
* As it is a critical option, this example resource pretends to handle it for compliance.
*/
coap_set_header_block2(response, separate_store->request_metadata.block2_num, 0, separate_store->request_metadata.block2_size);
/* Warning: No check for serialization error. */
transaction->packet_len = coap_serialize_message(response, transaction->packet);
coap_send_transaction(transaction);
@ -692,14 +701,16 @@ PROCESS_THREAD(rest_server_example, ev, data)
#if REST_RES_PUSHING
rest_activate_periodic_resource(&periodic_resource_pushing);
#endif
#if REST_RES_SEPARATE && WITH_COAP > 3
#if defined (PLATFORM_HAS_BUTTON) && REST_RES_EVENT
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);
rest_activate_resource(&resource_separate);
#endif
#if defined (PLATFORM_HAS_BUTTON) && REST_RES_EVENT
#if defined (PLATFORM_HAS_BUTTON) && (REST_RES_EVENT || (REST_RES_SEPARATE && WITH_COAP > 3))
SENSORS_ACTIVATE(button_sensor);
rest_activate_event_resource(&resource_event);
#endif
#if defined (PLATFORM_HAS_LEDS)
#if REST_RES_LEDS

View file

@ -125,13 +125,13 @@ void
ifconf(const char *tundev, const char *ipaddr)
{
#ifdef linux
ssystem("ifconfig %s inet6 `hostname` up", tundev);
ssystem("ifconfig %s inet `hostname` up", tundev);
ssystem("ifconfig %s add %s", tundev, ipaddr);
#elif defined(__APPLE__)
ssystem("ifconfig %s inet6 %s up", tundev, ipaddr);
ssystem("sysctl -w net.inet.ip.forwarding=1");
#else
ssystem("ifconfig %s inet6 `hostname` %s up", tundev, ipaddr);
ssystem("ifconfig %s inet `hostname` %s up", tundev, ipaddr);
ssystem("sysctl -w net.inet.ip.forwarding=1");
#endif /* !linux */

View file

@ -392,7 +392,6 @@ extern void mac_log_802_15_4_rx(const uint8_t* buffer, size_t total_len);
#define RF230_MAX_TX_POWER 15
#define RF230_MIN_RX_POWER 30
*/
#define RPL_CONF_ADJUST_LLH_LEN 1
#define UIP_CONF_ROUTER 1
#define UIP_CONF_ND6_SEND_RA 0
#define UIP_CONF_ND6_REACHABLE_TIME 600000

View file

@ -106,9 +106,9 @@ ifdef SYMBOLS
endif ## SYMBOLS
ifdef REDEF_PRINTF
@echo Redefining printf
-$(foreach OBJ,$^, objcopy --redefine-sym printf=log_printf $(OBJ); )
-$(foreach OBJ,$^, objcopy --redefine-sym puts=log_puts $(OBJ); )
-$(foreach OBJ,$^, objcopy --redefine-sym putchar=log_putchar $(OBJ); )
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym printf=log_printf $(OBJ); )
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym puts=log_puts $(OBJ); )
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym putchar=log_putchar $(OBJ); )
endif ## REDEF_PRINTF
$(LINK_COMMAND_1) $^ $(LINK_COMMAND_2)

View file

@ -148,10 +148,28 @@ radio_read(void *buf, unsigned short bufsize)
}
/*---------------------------------------------------------------------------*/
static int
channel_clear(void)
{
if(simSignalStrength > CCA_SS_THRESHOLD) {
return 0;
}
return 1;
}
/*---------------------------------------------------------------------------*/
static int
radio_send(const void *payload, unsigned short payload_len)
{
int radiostate = simRadioHWOn;
/* XXX Simulate turnaround time of 1ms? */
#define WITH_TURNAROUND 1
#if WITH_TURNAROUND
printf("WITH_TURNAROUND\n");
simProcessRunValue = 1;
cooja_mt_yield();
printf("WITH_TURNAROUND post\n");
#endif /* WITH_TURNAROUND */
if(!simRadioHWOn) {
/* Turn on radio temporarily */
simRadioHWOn = 1;
@ -166,6 +184,15 @@ radio_send(const void *payload, unsigned short payload_len)
return RADIO_TX_ERR;
}
/* XXX Transmit only on CCA? */
#define WITH_SEND_CCA 1
#if WITH_SEND_CCA
if (!channel_clear()) {
printf("WITH_SEND_CCA return\n");
return RADIO_TX_COLLISION;
}
#endif /* WITH_SEND_CCA */
/* Copy packet data to temporary storage */
memcpy(simOutDataBuffer, payload, payload_len);
simOutSize = payload_len;
@ -208,15 +235,6 @@ pending_packet(void)
return !simReceiving && simInSize > 0;
}
/*---------------------------------------------------------------------------*/
static int
channel_clear(void)
{
if(simSignalStrength > CCA_SS_THRESHOLD) {
return 0;
}
return 1;
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cooja_radio_process, ev, data)
{
int len;

View file

@ -17,7 +17,7 @@ endif
CONTIKI_TARGET_SOURCEFILES += $(SENSORS) $(ESB) \
contiki-esb-default-init-lowlevel.c \
contiki-esb-default-init-apps.c \
rs232.c rs232-putchar.c fader.c $(CONTIKI_TARGET_MAIN)
rs232.c rs232-putchar.c fader.c
ifdef WITH_CODEPROP
CONTIKI_TARGET_DIRS += ../../apps/codeprop
@ -30,7 +30,7 @@ CFLAGS+=-Os -g
endif
ifdef IAR
CFLAGS+=-e --vla -Ohz --multiplier=16s --core=430 --double=32
CFLAGS += -D__MSP430F149__=1 -e --vla -Ohz --multiplier=16s --core=430 --double=32
CFLAGSNO = --dlib_config "$(IAR_PATH)/LIB/DLIB/dl430fn.h" $(CFLAGSWERROR)
endif
@ -53,6 +53,11 @@ include $(CONTIKI)/platform/$(TARGET)/apps/Makefile.apps
MCU=msp430x149
include $(CONTIKI)/cpu/msp430/Makefile.msp430
ifdef IAR
LDFLAGSNO += -B -xm "$(IAR_PATH)/lib/dlib/dl430fn.r43" -f "$(IAR_PATH)/config/lnk430f149.xcl" -l contiki-$(TARGET).map -s __program_start -D_STACK_SIZE=80 -D_DATA16_HEAP_SIZE=80 -D_DATA20_HEAP_SIZE=80
LDFLAGS += $(LDFLAGSNO) -Felf -yn
endif # IAR
contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
# $(AR) rcf $@ $^

View file

@ -1,6 +1,10 @@
#ifndef __CONTIKI_CONF_H__
#define __CONTIKI_CONF_H__
#define PLATFORM_HAS_LEDS 1
#define PLATFORM_HAS_BUTTON 1
#define PLATFORM_HAS_BATTERY 1
/* DCO speed resynchronization for more robust UART, etc. */
#define DCOSYNCH_CONF_ENABLED 1
#define DCOSYNCH_CONF_PERIOD 30
@ -11,15 +15,6 @@
#define PROFILE_CONF_ON 0
#define ENERGEST_CONF_ON 1
#ifdef __IAR_SYSTEMS_ICC__
#define __MSP430F149__ 1
#define __MSP430__ 1
#define CC_CONF_INLINE
#define BV(x) (1 << x)
#else
#define CC_CONF_INLINE inline
#endif
#define HAVE_STDINT_H
#include "msp430def.h"

View file

@ -305,8 +305,6 @@ main(void)
watchdog_start();
}
}
return 0;
}
/*---------------------------------------------------------------------------*/
/* char *arg_alloc(char size) {return NULL;} */

View file

@ -33,7 +33,7 @@
#include "dev/button-sensor.h"
#include "dev/hwconf.h"
#include <signal.h>
#include "isr_compat.h"
const struct sensors_sensor button_sensor;
@ -43,8 +43,7 @@ HWCONF_PIN(BUTTON, 2, 7);
HWCONF_IRQ(BUTTON, 2, 7);
/*---------------------------------------------------------------------------*/
interrupt(PORT2_VECTOR)
irq_p2(void)
ISR(PORT2, irq_p2)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -78,6 +78,7 @@ Contributors: Thomas Pietsch, Bjoern Lichtblau
#include "dev/leds.h"
#include "dev/beep.h"
#include "isr_compat.h"
PROCESS(ir_process, "IR receiver");
process_event_t ir_event_received;
@ -202,7 +203,7 @@ static void clearDataAvailableBit(void){ recvdata &= 0xEFFF; }
/// Timer B0 interrupt service routine
interrupt(TIMERB1_VECTOR) Timer_B1 (void) {
ISR(TIMERB1, Timer_B1) {
/*P2OUT = (P2OUT & 0xf7) | (8 - (P2OUT & 0x08));*/

View file

@ -34,6 +34,7 @@
#include "lib/sensors.h"
#include "dev/irq.h"
#include "dev/lpm.h"
#include "isr_compat.h"
#define ADC12MCTL_NO(adcno) ((unsigned char *) ADC12MCTL0_)[adcno]
@ -42,8 +43,7 @@ static int (* port1_irq[8])(void);
static unsigned char adcflags;
/*---------------------------------------------------------------------------*/
interrupt(PORT1_VECTOR)
irq_p1(void)
ISR(PORT1, irq_p1)
{
int i;
ENERGEST_ON(ENERGEST_TYPE_IRQ);
@ -58,8 +58,7 @@ interrupt(PORT1_VECTOR)
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
/*---------------------------------------------------------------------------*/
interrupt (ADC_VECTOR)
irq_adc(void)
ISR(ADC, irq_adc)
{
int i;
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -47,12 +47,12 @@
#include <string.h>
#include "contiki-esb.h"
#include "isr_compat.h"
static int (* input_handler)(unsigned char) = NULL;
/*---------------------------------------------------------------------------*/
interrupt(UART1RX_VECTOR)
rs232_rx_usart1(void)
ISR(UART1RX, rs232_rx_usart1)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
/* Check status register for receive errors. - before reading RXBUF since

View file

@ -59,6 +59,7 @@
#include "lib/crc16.h"
#include "net/netstack.h"
#include "net/rime/rimestats.h"
#include "isr_compat.h"
#include <string.h>
@ -385,8 +386,7 @@ tr1001_init(void)
return 1;
}
/*---------------------------------------------------------------------------*/
interrupt (UART0RX_VECTOR)
tr1001_rxhandler(void)
ISR(UART0RX, tr1001_rxhandler)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
tr1001_default_rxhandler_pt(RXBUF0);

View file

@ -59,6 +59,7 @@
#include "lib/crc16.h"
#include "net/netstack.h"
#include "net/rime/rimestats.h"
#include "isr_compat.h"
#include <string.h>
@ -376,8 +377,7 @@ tr1001_init(void)
return 1;
}
/*---------------------------------------------------------------------------*/
interrupt (UART0RX_VECTOR)
tr1001_rxhandler(void)
ISR(UART0RX, tr1001_rxhandler)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
tr1001_default_rxhandler_pt(RXBUF0);

View file

@ -1,19 +1,8 @@
# $Id: Makefile.z1,v 1.4 2010/11/07 08:40:24 enricmcalvo Exp $
# msp430flasher -n msp430x5437 -w "Firmware.txt" -v -z [VCC]
ifndef IAR
GCC=1
endif
ifdef GCC
CFLAGS+=-Os -g
else
IAR=1
endif
ifdef IAR
CFLAGS+=-e --vla -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X --data_model small --double=32 -D__MSP430F5438A__
CFLAGS += --diag_suppress=Pa050
CFLAGS+=-e --vla -Ohz --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40 --core=430X --data_model small --double=32 -D__MSP430F5438A__=1
#CFLAGS+=--no_cse --no_unroll --no_inline --no_code_motion --no_tbaa --debug -D__MSP430F5438A__ -e --double=32 --dlib_config 'C:\Program Files (x86)\IAR Systems\Embedded Workbench 6.0 Evaluation\430\LIB\DLIB\dl430xsfn.h' --core=430X --data_model=small -Ol --multiplier=32 --multiplier_location=4C0 --hw_workaround=CPU40
endif
@ -43,7 +32,7 @@ help:
@echo make help - shows this help
@echo make TARGET=exp5438 savetarget - stores selection of target to avoid using TARGET= on every make invokation
@echo make program.upload - compiles and uploads program to connected board
@echo make program.upload GCC=1 - uses the mspgcc compiler instead of IAR
@echo make program.upload IAR=1 - uses the IAR compiler instead of mspgcc
@echo make program.upload NODEID=x - uploads with node_id set to x
CONTIKI_TARGET_DIRS = . dev apps net
@ -70,19 +59,12 @@ contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
ifdef IAR
STACKSIZE=300
LDFLAGS_ELF=-B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f5437.xcl" -l contiki-$(TARGET).map -Felf -yn -s __program_start -D_STACK_SIZE=$(STACKSIZE) -D_DATA16_HEAP_SIZE=$(STACKSIZE) -D_DATA20_HEAP_SIZE=$(STACKSIZE)
LDFLAGSNO += -B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f5437.xcl" -l contiki-$(TARGET).map -s __program_start -D_STACK_SIZE=$(STACKSIZE) -D_DATA16_HEAP_SIZE=$(STACKSIZE) -D_DATA20_HEAP_SIZE=$(STACKSIZE)
LDFLAGS += $(LDFLAGSNO) -Felf -yn
endif
LDFLAGS_HEX=-B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f5437.xcl" -l contiki-$(TARGET).map -Fintel-extended -s __program_start -D_STACK_SIZE=$(STACKSIZE) -D_DATA16_HEAP_SIZE=$(STACKSIZE) -D_DATA20_HEAP_SIZE=$(STACKSIZE)
LDFLAGS+=$(LDFLAGS_ELF)
%.hex: %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
$(LD) $(LDFLAGS_HEX) $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@
else
%.hex: %.ihex
mv $< $@
endif
%.upload: %.hex
msp430flasher -n msp430x5438a -e ERASE_MAIN -w $< -v -z [VCC]

View file

@ -31,19 +31,12 @@
#include "contiki.h"
#ifdef __IAR_SYSTEMS_ICC__
#include <msp430.h>
#else
#include <io.h>
#include <signal.h>
#endif
#include "contiki-net.h"
#include "dev/spi.h"
#include "dev/cc2420.h"
#include "dev/leds.h"
#include "isr_compat.h"
#ifndef CONF_SFD_TIMESTAMPS
#define CONF_SFD_TIMESTAMPS 0
@ -54,13 +47,7 @@
#endif
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=CC2420_IRQ_VECTOR
__interrupt void
#else
interrupt(CC2420_IRQ_VECTOR)
#endif
cc24240_fifop_interrupt(void)
ISR(CC2420_IRQ, cc24240_fifop_interrupt)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -32,18 +32,11 @@
*/
#include "contiki-conf.h"
#ifdef __IAR_SYSTEMS_ICC__
#include <msp430.h>
#else
#include <io.h>
#include <signal.h>
#endif
#include "sys/energest.h"
#include "sys/clock.h"
#include "sys/etimer.h"
#include "rtimer-arch.h"
#include "isr_compat.h"
#include "dev/leds.h"
@ -57,13 +50,7 @@ static volatile clock_time_t count = 0;
/* last_tar is used for calculating clock_fine, last_ccr might be better? */
static unsigned short last_tar = 0;
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=TIMER1_A1_VECTOR
__interrupt void
#else
interrupt(TIMER1_A1_VECTOR)
#endif
timera1 (void)
ISR(TIMER1_A1, timera1)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -30,13 +30,6 @@
*/
#include "contiki.h"
#ifdef __IAR_SYSTEMS_ICC__
#include <msp430.h>
#else
#include <io.h>
#include <signal.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdarg.h>

View file

@ -36,13 +36,6 @@
*/
#include "contiki.h"
#ifdef __IAR_SYSTEMS_ICC__
#include <msp430.h>
#else
#include <io.h>
#include <signal.h>
#endif
#include <stdlib.h>
#include "dev/flash.h"

View file

@ -35,11 +35,6 @@
******************************************************************************/
#include "contiki-conf.h"
#ifdef __IAR_SYSTEMS_ICC__
#include <msp430.h>
#else
#include <io.h>
#endif
#include "hal_MSP-EXP430F5438.h"
#include "hal_lcd_fonts.h"

View file

@ -42,12 +42,6 @@
#include "contiki-conf.h"
#include "dev/leds.h"
#ifdef __IAR_SYSTEMS_ICC__
#include <msp430.h>
#else
#include <io.h>
#endif
/* LED ports */
#define LEDS_CONF_RED 0x01
#define LEDS_CONF_GREEN 0x02

View file

@ -31,12 +31,6 @@
* @(#)$Id: msp430.c,v 1.1 2010/08/24 16:26:38 joxe Exp $
*/
#include "contiki.h"
#ifdef __IAR_SYSTEMS_ICC__
#include <msp430.h>
#else
#include <io.h>
#include <signal.h>
#endif
#include "dev/watchdog.h"
#include "dev/leds.h"
#include "net/uip.h"

View file

@ -44,19 +44,6 @@
* changeable!
*/
#define TYNDALL 1
/* Test for IAR compiler */
#ifdef __IAR_SYSTEMS_ICC__
#include <intrinsics.h>
#include <in430.h>
#define dint() __disable_interrupt()
#define eint() __enable_interrupt()
#define __MSP430F5437__ 1
#define __MSP430__ 1
#define CC_CONF_INLINE
#define BV(x) (1 << x)
#else
#define CC_CONF_INLINE inline
#endif
/* CPU target speed in Hz */
#define F_CPU 8000000uL // 8MHz by default

View file

@ -39,17 +39,11 @@
*/
#include "contiki.h"
#ifdef __IAR_SYSTEMS_ICC__
#include <msp430.h>
#else
#include <io.h>
#include <signal.h>
#endif
#include "sys/energest.h"
#include "sys/rtimer.h"
#include "sys/process.h"
#include "dev/watchdog.h"
#include "isr_compat.h"
#define DEBUG 0
#if DEBUG
@ -60,13 +54,8 @@
#endif
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=TIMER1_A0_VECTOR
__interrupt void
#else
interrupt(TIMER1_A0_VECTOR)
#endif
timera0 (void) {
ISR(TIMER1_A0, timera0)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
watchdog_start();

View file

@ -30,17 +30,12 @@
*/
#include "contiki-conf.h"
#ifdef __IAR_SYSTEMS_ICC__
#include <msp430.h>
#else
#include <io.h>
#endif
/*
* This is SPI initialization code for the MSP430X architecture.
*
*/
unsigned char spi_busy = 0;
/* unsigned char spi_busy = 0; */
/*---------------------------------------------------------------------------*/
/*
* Initialize SPI bus.

View file

@ -36,13 +36,6 @@
*/
#include "contiki.h"
#ifdef __IAR_SYSTEMS_ICC__
#include <msp430.h>
#else
#include <io.h>
#include <signal.h>
#endif
#include <stdlib.h>
#include "sys/energest.h"
@ -50,6 +43,7 @@
#include "dev/watchdog.h"
#include "lib/ringbuf.h"
#include "dev/leds.h"
#include "isr_compat.h"
static int (*uart1_input_handler)(unsigned char c);
@ -114,13 +108,7 @@ uart1_init(unsigned long ubr)
UCA1IE |= UCRXIE; /* Enable UCA1 RX interrupt */
}
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=USCI_A1_VECTOR
__interrupt void
#else
interrupt(USCI_A1_VECTOR)
#endif
uart1_rx_interrupt(void)
ISR(USCI_A1, uart1_rx_interrupt)
{
uint8_t c;

View file

@ -32,13 +32,8 @@
*/
#include "contiki-conf.h"
#ifdef __IAR_SYSTEMS_ICC__
#include <msp430.h>
#else
#include <io.h>
#include <signal.h>
#endif
#include "dev/watchdog.h"
#include "isr_compat.h"
static int counter = 0;
@ -76,13 +71,7 @@ printstring(char *s)
#endif /* CONTIKI_TARGET_SKY */
#endif /* PRINT_STACK_ON_REBOOT */
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=WDT_VECTOR
__interrupt void
#else
interrupt(WDT_VECTOR)
#endif
watchdog_interrupt(void)
ISR(WDT, watchdog_interrupt)
{
#ifdef CONTIKI_TARGET_SKY
#if PRINT_STACK_ON_REBOOT

View file

@ -60,8 +60,6 @@
#define CCIF
#define CLIF
#define CC_CONF_INLINE inline
#define HAVE_STDINT_H
#include "msp430def.h"

View file

@ -97,7 +97,6 @@ typedef unsigned short uip_stats_t;
* They should all attach to a minimal-net rpl border that uses the same primary interface.
* For multihop testing, configure intermediate notes as routers.
*/
#define RPL_CONF_ADJUST_LLH_LEN 1
#define HARD_CODED_ADDRESS "bbbb::10" //the prefix is ignored for a rpl node
#define UIP_CONF_ROUTER 0
#define UIP_CONF_ND6_SEND_RA 0

View file

@ -38,8 +38,6 @@
*/
#include "contiki.h"
#include <msp430/adc12.h>
#include "contiki-msb430.h"
void

View file

@ -1,7 +1,7 @@
#ifndef CC1020_INTERNAL_H
#define CC1020_INTERNAL_H
#include <signal.h>
#include "contiki.h"
#define CC1020_MAIN 0x00
#define CC1020_INTERFACE 0x01

View file

@ -41,7 +41,6 @@
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include "contiki.h"
#include "contiki-msb430.h"
@ -52,6 +51,7 @@
#include "net/rime/rimestats.h"
#include "dev/dma.h"
#include "sys/energest.h"
#include "isr_compat.h"
#define DEBUG 0
#if DEBUG
@ -458,7 +458,7 @@ PROCESS_THREAD(cc1020_receiver_process, ev, data)
PROCESS_END();
}
interrupt(UART0RX_VECTOR) cc1020_rxhandler(void)
ISR(UART0RX, cc1020_rxhandler)
{
static signed char syncbs;
static union {

View file

@ -41,10 +41,11 @@
#include "contiki-msb430.h"
#include "dev/cc1020.h"
#include "dev/dma.h"
#include "isr_compat.h"
static void (*callbacks[DMA_LINES])(void);
interrupt(DACDMA_VECTOR) irq_dacdma(void)
ISR(DACDMA, irq_dacdma)
{
if(DMA0CTL & DMAIFG) {
DMA0CTL &= ~(DMAIFG | DMAIE);

View file

@ -51,10 +51,8 @@ Berlin, 2007
* across both blocks are not allowed.
*/
#include <string.h>
#include <signal.h>
#include <stdarg.h>
#include "contiki-conf.h"
#include <msp430/flash.h>
#include "infomem.h"
void

View file

@ -55,6 +55,7 @@ Berlin, 2007
#include <string.h>
#include "dev/msb430-uart1.h"
#include "dev/lpm.h"
#include "isr_compat.h"
#ifndef U1ME
#define U1ME ME2
@ -204,8 +205,7 @@ uart_get_mode(void)
return uart_mode;
}
/*---------------------------------------------------------------------------*/
interrupt(UART1RX_VECTOR)
uart_rx(void)
ISR(UART1RX, uart_rx)
{
uart_handler_t handler = uart_handler[uart_mode];
int c;

View file

@ -59,8 +59,6 @@
#define CCIF
#define CLIF
#define CC_CONF_INLINE inline
#define HAVE_STDINT_H
#include "msp430def.h"

View file

@ -17,12 +17,9 @@ endif
ifdef IAR
CFLAGS += -D__MSP430F1611__=1 -e --vla -Ohz --multiplier=16s --core=430 --double=32
CFLAGSNO = --dlib_config "$(IAR_PATH)/LIB/DLIB/dl430fn.h" $(CFLAGSWERROR)
endif
CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS) #$(CONTIKI_TARGET_MAIN)
CONTIKI_TARGET_SOURCEFILES += contiki-sky-platform.c
CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS)
MCU=msp430x1611
include $(CONTIKI)/cpu/msp430/Makefile.msp430
@ -32,12 +29,9 @@ contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
ifdef IAR
ifdef ELF
LDFLAGS += -B -xm "$(IAR_PATH)/lib/dlib/dl430fn.r43" -f "$(IAR_PATH)/config/lnk430f1611.xcl" -l contiki-$(TARGET).map -Felf -yn -s __program_start -D_STACK_SIZE=80 -D_DATA16_HEAP_SIZE=80 -D_DATA20_HEAP_SIZE=80
else
LDFLAGS += -B -xm "$(IAR_PATH)/lib/dlib/dl430fn.r43" -f "$(IAR_PATH)/config/lnk430f1611.xcl" -l contiki-$(TARGET).map -Fintel-extended -s __program_start -D_STACK_SIZE=80 -D_DATA16_HEAP_SIZE=80 -D_DATA20_HEAP_SIZE=80
endif
endif
LDFLAGSNO += -B -xm "$(IAR_PATH)/lib/dlib/dl430fn.r43" -f "$(IAR_PATH)/config/lnk430f1611.xcl" -l contiki-$(TARGET).map -s __program_start -D_STACK_SIZE=80 -D_DATA16_HEAP_SIZE=80 -D_DATA20_HEAP_SIZE=80
LDFLAGS += $(LDFLAGSNO) -Felf -yn
endif # IAR
NUMPAR=20
IHEXFILE=tmpimage.ihex

View file

@ -34,6 +34,7 @@
#include "lib/sensors.h"
#include "dev/hwconf.h"
#include "dev/button-sensor.h"
#include "isr_compat.h"
const struct sensors_sensor button_sensor;
@ -44,13 +45,7 @@ HWCONF_PIN(BUTTON, 2, 7);
HWCONF_IRQ(BUTTON, 2, 7);
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=PORT2_VECTOR
__interrupt void
#else
interrupt(PORT2_VECTOR)
#endif
irq_p2(void)
ISR(PORT2, irq_p2)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -34,19 +34,15 @@ MCU=msp430x5437
include $(CONTIKI)/cpu/msp430/Makefile.msp430
ifdef IAR
LDFLAGS += -B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f5437.xcl" -l contiki-$(TARGET).map -Fintel-extended -s __program_start -D_STACK_SIZE=80 -D_DATA16_HEAP_SIZE=80 -D_DATA20_HEAP_SIZE=80
LDFLAGSNO += -B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f5437.xcl" -l contiki-$(TARGET).map -s __program_start -D_STACK_SIZE=80 -D_DATA16_HEAP_SIZE=80 -D_DATA20_HEAP_SIZE=80
LDFLAGS += $(LDFLAGSNO) -Felf -yn
endif
contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}
# $(AR) rcf $@ $^
ifdef IAR
%.hex: %.$(TARGET)
mv $< $@
else
%.hex: %.ihex
mv $< $@
endif
%.upload: %.hex
msp430flasher -n msp430x5437 -e ERASE_MAIN -w $< -v -z [VCC]

View file

@ -31,6 +31,7 @@
#include "lib/sensors.h"
#include "dev/hwconf.h"
#include "dev/button-sensor.h"
#include "isr_compat.h"
const struct sensors_sensor button_sensor;
@ -41,13 +42,7 @@ HWCONF_PIN(BUTTON, 2, 7);
HWCONF_IRQ(BUTTON, 2, 7);
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=PORT2_VECTOR
__interrupt void
#else
interrupt(PORT2_VECTOR)
#endif
irq_p2(void)
ISR(PORT2, irq_p2)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -1,7 +1,5 @@
# $Id: Makefile.z1,v 1.5 2011/02/26 enricmcalvo Exp $
PROJECT_SOURCEFILES += i2cmaster.c adxl345.c
ifdef GCC
CFLAGS+=-Os -g
endif
@ -13,9 +11,6 @@ LDFLAGS += -Wl,--defsym -Wl,__P1SEL2=0x0041 -Wl,--defsym -Wl,__P5SEL2=0x0045
endif
CLEAN += symbols.c symbols.h
#CFLAGS += -ffunction-sections
#LDFLAGS += -Wl,--gc-sections,--undefined=_reset_vector__,--undefined=InterruptVectors,--undefined=_copy_data_init__,--undefined=_clear_bss_init__,--undefined=_end_of_init__
ARCH=msp430.c leds.c watchdog.c xmem.c \
spi.c cc2420.c cc2420-aes.c cc2420-arch.c cc2420-arch-sfd.c\
@ -39,14 +34,15 @@ CFLAGS += -DMACID=$(nodemac)
endif
CONTIKI_TARGET_SOURCEFILES += $(ARCH) $(UIPDRIVERS)
CONTIKI_TARGET_SOURCEFILES += contiki-z1-platform.c
CONTIKI_TARGET_SOURCEFILES += i2cmaster.c adxl345.c
MCU=msp430x2617
include $(CONTIKI)/cpu/msp430/Makefile.msp430
# Add LDFLAGS after IAR_PATH is set
ifdef IAR
LDFLAGS += -B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f2617.xcl" -l contiki-$(TARGET).map -Fintel-extended -s __program_start -D_STACK_SIZE=80 -D_DATA16_HEAP_SIZE=80 -D_DATA20_HEAP_SIZE=80
LDFLAGSNO += -B -xm "$(IAR_PATH)/lib/dlib/dl430xsfn.r43" -f "$(IAR_PATH)/config/lnk430f2617.xcl" -l contiki-$(TARGET).map -s __program_start -D_STACK_SIZE=80 -D_DATA16_HEAP_SIZE=80 -D_DATA20_HEAP_SIZE=80
LDFLAGS += $(LDFLAGSNO) -Felf -yn
endif
contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}

View file

@ -44,6 +44,7 @@
#include "adxl345.h"
#include "cc2420.h"
#include "i2cmaster.h"
#include "isr_compat.h"
/* Callback pointers when interrupt occurs */
void (*accm_int1_cb)(uint8_t reg);
@ -375,13 +376,8 @@ PROCESS_THREAD(accmeter_process, ev, data) {
#if 1
static struct timer suppressTimer1, suppressTimer2;
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=PORT1_VECTOR
__interrupt void
#else
interrupt (PORT1_VECTOR)
#endif
port1_isr (void) {
ISR(PORT1, port1_isr)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
/* ADXL345_IFG.x goes high when interrupt occurs, use to check what interrupted */
if ((ADXL345_IFG & ADXL345_INT1_PIN) && !(ADXL345_IFG & BV(CC2420_FIFOP_PIN))){

View file

@ -35,6 +35,7 @@
#include "lib/sensors.h"
#include "dev/hwconf.h"
#include "dev/button-sensor.h"
#include "isr_compat.h"
const struct sensors_sensor button_sensor;
@ -45,14 +46,7 @@ HWCONF_PIN(BUTTON, 2, 5);
HWCONF_IRQ(BUTTON, 2, 5);
/*---------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=PORT2_VECTOR
__interrupt void
#else
interrupt(PORT2_VECTOR)
#endif
irq_p2(void)
ISR(PORT2, irq_p2)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);

View file

@ -33,6 +33,7 @@
#include "contiki-net.h"
#include "dev/spi.h"
#include "dev/cc2420.h"
#include "isr_compat.h"
#ifndef CONF_SFD_TIMESTAMPS
#define CONF_SFD_TIMESTAMPS 0
@ -45,8 +46,7 @@
/*---------------------------------------------------------------------------*/
#if 0
// this is now handled in the ADXL345 accelerometer code as it uses irq on port1 too.
interrupt(CC2420_IRQ_VECTOR)
cc24240_port1_interrupt(void)
ISR(CC2420_IRQ, cc24240_port1_interrupt)
{
ENERGEST_ON(ENERGEST_TYPE_IRQ);
if(cc2420_interrupt()) {

View file

@ -39,6 +39,7 @@
*/
#include "i2cmaster.h"
#include "isr_compat.h"
signed char tx_byte_ctr, rx_byte_ctr;
unsigned char rx_buf[2];
@ -201,13 +202,8 @@ i2c_transmit_n(uint8_t byte_ctr, uint8_t *tx_buf) {
}
/*----------------------------------------------------------------------------*/
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=USCIAB1TX_VECTOR
__interrupt void
#else
interrupt (USCIAB1TX_VECTOR)
#endif
i2c_tx_interrupt (void) {
ISR(USCIAB1TX, i2c_tx_interrupt)
{
// TX Part
if (UC1IFG & UCB1TXIFG) { // TX int. condition
if (tx_byte_ctr == 0) {
@ -237,18 +233,11 @@ i2c_tx_interrupt (void) {
#endif
}
#ifdef __IAR_SYSTEMS_ICC__
#pragma vector=USCIAB1RX_VECTOR
__interrupt void
#else
interrupt (USCIAB1RX_VECTOR)
#endif
i2c_rx_interrupt(void) {
if (UCB1STAT & UCNACKIFG){
ISR(USCIAB1RX, i2c_rx_interrupt)
{
if(UCB1STAT & UCNACKIFG) {
PRINTFDEBUG("!!! NACK received in RX\n");
UCB1CTL1 |= UCTXSTP;
UCB1STAT &= ~UCNACKIFG;
}
}

View file

@ -170,4 +170,17 @@ public class AvrMoteMemory implements MoteMemory, AddressMemory {
public boolean variableExists(String varName) {
return memoryMap.getLocation(varName) != null;
}
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm) {
logger.warn("Not implemented");
return false;
}
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm) {
}
public int parseInt(byte[] memorySegment) {
logger.warn("Not implemented");
return 0;
}
}

View file

@ -270,9 +270,4 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote {
public String toString() {
return "MicaZ " + getID();
}
public MemoryMonitor createMemoryMonitor(MemoryEventHandler meh) {
logger.fatal("Not implemented");
return null;
}
}

View file

@ -300,6 +300,11 @@ public class MRM extends AbstractRadioMedium {
for (RadioConnection conn : conns) {
for (Radio dstRadio : ((MRMRadioConnection) conn).getDestinations()) {
double signalStrength = ((MRMRadioConnection) conn).getDestinationSignalStrength(dstRadio);
if (conn.getSource().getChannel() >= 0 &&
dstRadio.getChannel() >= 0 &&
conn.getSource().getChannel() != dstRadio.getChannel()) {
continue;
}
if (dstRadio.getCurrentSignalStrength() < signalStrength) {
dstRadio.setCurrentSignalStrength(signalStrength);
}
@ -313,6 +318,11 @@ public class MRM extends AbstractRadioMedium {
if (intfRadio.getCurrentSignalStrength() < signalStrength) {
intfRadio.setCurrentSignalStrength(signalStrength);
}
if (conn.getSource().getChannel() >= 0 &&
intfRadio.getChannel() >= 0 &&
conn.getSource().getChannel() != intfRadio.getChannel()) {
continue;
}
if (!intfRadio.isInterfered()) {
/*logger.warn("Radio was not interfered: " + intfRadio);*/

View file

@ -238,7 +238,7 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
/* Create mote address memory */
MapTable map = ((MspMoteType)getType()).getELF().getMap();
MapEntry[] allEntries = map.getAllEntries();
myMemory = new MspMoteMemory(allEntries, myCpu);
myMemory = new MspMoteMemory(this, allEntries, myCpu);
heapStartAddress = map.heapStartAddress;
myCpu.reset();
@ -539,84 +539,4 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
/*return executeCLICommand("line " + myCpu.getPC());*/
}
public MemoryMonitor createMemoryMonitor(final MemoryEventHandler meh) {
return new MemoryMonitor() {
private boolean started = false;
private int address = -1;
private int size = -1;
private CPUMonitor myMonitor = null;
private boolean isPointer = false;
private MemoryMonitor pointedMemory = null;
public boolean start(int address, int size) {
if (started) {
return started;
}
final MemoryMonitor thisMonitor = this;
myMonitor = new CPUMonitor() {
public void cpuAction(int type, int adr, int data) {
MemoryEventType t;
if (type == CPUMonitor.MEMORY_WRITE) {
t = MemoryEventType.WRITE;
} else if (type == CPUMonitor.MEMORY_READ) {
t = MemoryEventType.READ;
} else {
t = MemoryEventType.UNKNOWN;
}
meh.event(thisMonitor, t, adr, data);
}
};
/* TODO Make sure no other part of Cooja overrides this! */
for (int a = address; a < address+size; a++) {
myCpu.addWatchPoint(a, myMonitor);
}
this.address = address;
this.size = size;
started = true;
return started;
}
public void stop() {
if (!started) {
return;
}
started = false;
for (int a = address; a < address+size; a++) {
myCpu.removeWatchPoint(a, myMonitor);
}
}
public Mote getMote() {
return MspMote.this;
}
public int getAddress() {
return address;
}
public int getSize() {
return size;
}
public boolean isPointer() {
return isPointer;
}
public void setPointer(boolean isPointer, MemoryMonitor pointedMemory) {
this.isPointer = isPointer;
this.pointedMemory = pointedMemory;
}
public MemoryMonitor getPointedMemory() {
return pointedMemory;
}
private BufferAccess lastBufferAccess = null;
public void setLastBufferAccess(BufferAccess ba) {
this.lastBufferAccess = ba;
}
public BufferAccess getLastBufferAccess() {
return lastBufferAccess;
}
};
}
}

View file

@ -29,11 +29,16 @@
package se.sics.cooja.mspmote;
import java.util.*;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import se.sics.cooja.AddressMemory;
import se.sics.cooja.Mote;
import se.sics.cooja.MoteMemory;
import se.sics.cooja.MoteTimeEvent;
import se.sics.cooja.TimeEvent;
import se.sics.mspsim.core.CPUMonitor;
import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.util.MapEntry;
@ -42,8 +47,10 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
private final ArrayList<MapEntry> mapEntries;
private MSP430 cpu;
private Mote mote;
public MspMoteMemory(MapEntry[] allEntries, MSP430 cpu) {
public MspMoteMemory(Mote mote, MapEntry[] allEntries, MSP430 cpu) {
this.mote = mote;
this.mapEntries = new ArrayList<MapEntry>();
for (MapEntry entry: allEntries) {
@ -130,13 +137,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
int varAddr = entry.getAddress();
byte[] varData = getMemorySegment(varAddr, 2);
int retVal = 0;
int pos = 0;
retVal += ((varData[pos++] & 0xFF)) << 8;
retVal += ((varData[pos++] & 0xFF)) << 0;
return Integer.reverseBytes(retVal) >> 16; // Crop two bytes
return parseInt(varData);
}
public void setIntValueOf(String varName, int newVal) throws UnknownVariableException {
@ -179,7 +180,6 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
MapEntry entry = getMapEntry(varName);
int varAddr = entry.getAddress();
// TODO Check if small/big-endian when coming from JNI?
return getMemorySegment(varAddr, length);
}
@ -187,8 +187,74 @@ public class MspMoteMemory implements MoteMemory, AddressMemory {
MapEntry entry = getMapEntry(varName);
int varAddr = entry.getAddress();
// TODO Check if small/big-endian when coming from JNI?
setMemorySegment(varAddr, data);
}
private ArrayList<MemoryCPUMonitor> cpuMonitorArray = new ArrayList<MemoryCPUMonitor>();
class MemoryCPUMonitor implements CPUMonitor {
public final MemoryMonitor mm;
public final int address;
public final int size;
public MemoryCPUMonitor(MemoryMonitor mm, int address, int size) {
this.mm = mm;
this.address = address;
this.size = size;
}
public void cpuAction(int type, final int adr, int data) {
final MemoryEventType t;
if (type == CPUMonitor.MEMORY_WRITE) {
t = MemoryEventType.WRITE;
} else {
t = MemoryEventType.READ;
}
/* XXX Workaround to avoid using soon-obsolete data argument.
* This causes a delay between memory rw and listener notifications */
TimeEvent e = new MoteTimeEvent(mote, 0) {
public void execute(long time) {
mm.memoryChanged(MspMoteMemory.this, t, adr);
}
};
mote.getSimulation().scheduleEvent(e, mote.getSimulation().getSimulationTime());
}
}
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm) {
MemoryCPUMonitor t = new MemoryCPUMonitor(mm, address, size);
cpuMonitorArray.add(t);
for (int a = address; a < address+size; a++) {
cpu.addWatchPoint(a, t);
}
return true;
}
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm) {
for (MemoryCPUMonitor mcm: cpuMonitorArray) {
if (mcm.mm != mm || mcm.address != address || mcm.size != size) {
continue;
}
for (int a = address; a < address+size; a++) {
cpu.removeWatchPoint(a, mcm);
}
cpuMonitorArray.remove(mcm);
break;
}
}
public int parseInt(byte[] memorySegment) {
if (memorySegment.length < 2) {
return -1;
}
int retVal = 0;
int pos = 0;
retVal += ((memorySegment[pos++] & 0xFF)) << 8;
retVal += ((memorySegment[pos++] & 0xFF)) << 0;
return Integer.reverseBytes(retVal) >> 16;
}
}

View file

@ -82,8 +82,8 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
private RadioPacket lastOutgoingPacket = null;
private RadioPacket lastIncomingPacket = null;
public SkyByteRadio(Mote mote) {
this.mote = (MspMote)mote;
public SkyByteRadio(Mote m) {
this.mote = (MspMote)m;
this.cc2420 = (CC2420) this.mote.getCPU().getChip(CC2420.class);
if (cc2420 == null) {
throw new IllegalStateException("Mote is not equipped with a CC2420");
@ -98,6 +98,7 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.TRANSMISSION_STARTED;
isTransmitting = true;
len = 0;
/*logger.debug("----- SKY TRANSMISSION STARTED -----");*/
setChanged();
notifyObservers();
@ -133,9 +134,6 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
setChanged();
notifyObservers();
// System.out.println("## CC2420 Transmission finished...");
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
/*logger.debug("----- SKY TRANSMISSION FINISHED -----");*/
isTransmitting = false;
@ -150,36 +148,59 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
cc2420.addOperatingModeListener(new OperatingModeListener() {
public void modeChanged(Chip source, int mode) {
if (isReceiverOn()) {
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.HW_ON;
setChanged();
notifyObservers();
} else {
/* Radio was turned off during transmission.
* May for example happen if watchdog triggers */
if (isTransmitting()) {
logger.fatal("Turning off radio while transmitting");
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
/*logger.debug("----- SKY TRANSMISSION FINISHED -----");*/
isTransmitting = false;
lastEvent = RadioEvent.TRANSMISSION_FINISHED;
setChanged();
notifyObservers();
}
lastEvent = RadioEvent.HW_OFF;
radioOff();
}
}
});
cc2420.setChannelListener(new CC2420.ChannelListener() {
public void changedChannel(int channel) {
/* XXX Currently assumes zero channel switch time */
lastEvent = RadioEvent.UNKNOWN;
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
setChanged();
notifyObservers();
}
});
}
cc2420.setChannelListener(new CC2420.ChannelListener() {
public void changedChannel(int channel) {
/* XXX Currently assumes zero channel switch time */
lastEvent = RadioEvent.UNKNOWN;
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
setChanged();
notifyObservers();
}
});
private void radioOff() {
/* Radio was turned off during transmission.
* May for example happen if watchdog triggers */
if (isTransmitting()) {
logger.warn("Turning off radio while transmitting, ending packet prematurely");
/* Simulate end of packet */
lastOutgoingPacket = new RadioPacket() {
public byte[] getPacketData() {
return new byte[0];
}
};
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.PACKET_TRANSMITTED;
/*logger.debug("----- SKY PACKET TRANSMITTED -----");*/
setChanged();
notifyObservers();
/* Register that transmission ended in radio medium */
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
/*logger.debug("----- SKY TRANSMISSION FINISHED -----");*/
isTransmitting = false;
lastEvent = RadioEvent.TRANSMISSION_FINISHED;
setChanged();
notifyObservers();
}
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.HW_OFF;
setChanged();
notifyObservers();
}
/* Packet radio support */

View file

@ -108,6 +108,20 @@ The COOJA Simulator
</java>
</target>
<target name="run64" depends="init, compile, jar, copy configs">
<java fork="yes" dir="${build}" classname="se.sics.cooja.GUI" maxmemory="512m">
<sysproperty key="user.language" value="en"/>
<jvmarg value="-d64 -XX:+ShowMessageBoxOnError"/>
<arg line="${args}"/>
<env key="LD_LIBRARY_PATH" value="."/>
<classpath>
<pathelement path="${build}"/>
<pathelement location="lib/jdom.jar"/>
<pathelement location="lib/log4j.jar"/>
</classpath>
</java>
</target>
<target name="run_errorbox" depends="init, compile, jar, copy configs">
<java fork="yes" dir="${build}" classname="se.sics.cooja.GUI" maxmemory="512m">
<sysproperty key="user.language" value="en"/>

View file

@ -6,6 +6,7 @@ PATH_AR = ar
PATH_SHELL = sh
PATH_C_COMPILER = gcc
PATH_OBJDUMP=objdump
PATH_OBJCOPY=objcopy
OBJDUMP_ARGS=-h
CMD_GREP_PROCESSES = grep "^PROCESS_THREAD[ ]*([^,]*,[^,]*,[^)]*)" -o -H
REGEXP_PARSE_PROCESSES = ([^/]*.c):PROCESS_THREAD[ ]*\\(([^,]*),[^,]*,[^)]*\\)

View file

@ -6,6 +6,7 @@ PATH_AR = ar
PATH_SHELL = sh
PATH_C_COMPILER = gcc
PATH_OBJDUMP=objdump
PATH_OBJCOPY=objcopy
OBJDUMP_ARGS=-h
CMD_GREP_PROCESSES = grep "^PROCESS_THREAD[ ]*([^,]*,[^,]*,[^)]*)" -o -H
REGEXP_PARSE_PROCESSES = ([^/]*.c):PROCESS_THREAD[ ]*\\(([^,]*),[^,]*,[^)]*\\)

View file

@ -6,6 +6,7 @@ PATH_AR = ar
PATH_SHELL = sh
PATH_C_COMPILER = gcc
PATH_OBJDUMP=objdump
PATH_OBJCOPY=objcopy
OBJDUMP_ARGS=-h
CMD_GREP_PROCESSES = grep "^PROCESS_THREAD[ ]*([^,]*,[^,]*,[^)]*)" -o -H
REGEXP_PARSE_PROCESSES = ([^/]*.c):PROCESS_THREAD[ ]*\\(([^,]*),[^,]*,[^)]*\\)

View file

@ -6,6 +6,7 @@ PATH_AR = ar
PATH_SHELL = sh
PATH_C_COMPILER = gcc
PATH_OBJDUMP= objdump
PATH_OBJCOPY=objcopy
OBJDUMP_ARGS= -h
CMD_GREP_PROCESSES = grep "^PROCESS_THREAD[ ]*([^,]*,[^,]*,[^)]*)" -o -H
REGEXP_PARSE_PROCESSES = ([^/]*.c):PROCESS_THREAD[ ]*\\(([^,]*),[^,]*,[^)]*\\)

View file

@ -6,6 +6,7 @@ PATH_AR=ar
PATH_SHELL = sh
PATH_C_COMPILER = gcc
PATH_OBJDUMP=objdump
PATH_OBJCOPY=objcopy
OBJDUMP_ARGS=-h
CMD_GREP_PROCESSES = grep '^PROCESS_THREAD[ ]*([^,]*,[^,]*,[^)]*)' -o -d skip -D skip -H -r
REGEXP_PARSE_PROCESSES = ([^/]*.c):PROCESS_THREAD[ ]*\\(([^,]*),[^,]*,[^)]*\\)
@ -24,7 +25,7 @@ PATH_JAVAC = javac
DEFAULT_PROJECTDIRS = [CONTIKI_DIR]/tools/cooja/apps/mrm;[CONTIKI_DIR]/tools/cooja/apps/mspsim;[CONTIKI_DIR]/tools/cooja/apps/avrora;[CONTIKI_DIR]/tools/cooja/apps/serial_socket;[CONTIKI_DIR]/tools/cooja/apps/collect-view
PARSE_WITH_COMMAND = true
PARSE_COMMAND=nm -C $(LIBFILE)
PARSE_COMMAND=nm -n -C $(LIBFILE)
MAPFILE_DATA_START = ^.data[ \t]*0x([0-9A-Fa-f]*)[ \t]*0x[0-9A-Fa-f]*[ \t]*$
MAPFILE_DATA_SIZE = ^.data[ \t]*0x[0-9A-Fa-f]*[ \t]*0x([0-9A-Fa-f]*)[ \t]*$
MAPFILE_BSS_START = ^.bss[ \t]*0x([0-9A-Fa-f]*)[ \t]*0x[0-9A-Fa-f]*[ \t]*$
@ -35,7 +36,7 @@ MAPFILE_VAR_ADDRESS_2 = [ \t]*$
MAPFILE_VAR_SIZE_1 = ^
MAPFILE_VAR_SIZE_2 = [ \t]*(0x[0-9A-Fa-f]*)[ \t]*[^ ]*[ \t]*$
COMMAND_VAR_NAME_ADDRESS = ^([0-9A-Fa-f][0-9A-Fa-f]*)[ \t][^Tt][ \t]([^ ._][^ ]*)
COMMAND_DATA_START = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_start__$
COMMAND_DATA_END = ^([0-9A-Fa-f]*)[ \t]D[ \t]_data_end__$
COMMAND_BSS_START = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_start__$
COMMAND_BSS_END = ^([0-9A-Fa-f]*)[ \t]B[ \t]_bss_end__$
COMMAND_DATA_START = ^([0-9A-Fa-f]*)[ \t]D[ \t].*_data_start__$
COMMAND_DATA_END = ^([0-9A-Fa-f]*)[ \t]D[ \t].*_data_end__$
COMMAND_BSS_START = ^([0-9A-Fa-f]*)[ \t]B[ \t].*_bss_start__$
COMMAND_BSS_END = ^([0-9A-Fa-f]*)[ \t]B[ \t].*_bss_end__$

View file

@ -34,9 +34,12 @@
#include <stdint.h>
#include <string.h>
/* This is a stripped version of platform/cooja/contiki-cooja-main.c, used by
* Cooja's Contiki Mote Configuration Wizard */
const struct simInterface *simInterfaces[] = {NULL};
long ref_var; /* Placed somewhere in the BSS section */
long referenceVar; /* Placed somewhere in the BSS section */
/* Variables with known memory addresses */
int var1=1;
@ -60,8 +63,9 @@ Java_se_sics_cooja_corecomm_[CLASS_NAME]_getMemory(JNIEnv *env, jobject obj, jin
mem_arr,
0,
(size_t) length,
(jbyte *) (((long)rel_addr) + ref_var)
(jbyte *) (((long)rel_addr) + referenceVar)
);
}
/*---------------------------------------------------------------------------*/
JNIEXPORT void JNICALL
@ -69,7 +73,7 @@ Java_se_sics_cooja_corecomm_[CLASS_NAME]_setMemory(JNIEnv *env, jobject obj, jin
{
jbyte *mem = (*env)->GetByteArrayElements(env, mem_arr, 0);
memcpy(
(char*) (((long)rel_addr) + ref_var),
(char*) (((long)rel_addr) + referenceVar),
mem,
length);
(*env)->ReleaseByteArrayElements(env, mem_arr, mem, 0);
@ -85,5 +89,5 @@ Java_se_sics_cooja_corecomm_[CLASS_NAME]_tick(JNIEnv *env, jobject obj)
JNIEXPORT void JNICALL
Java_se_sics_cooja_corecomm_[CLASS_NAME]_setReferenceAddress(JNIEnv *env, jobject obj, jint addr)
{
ref_var = (((long)&ref_var) - ((long)addr));
referenceVar = (((long)&referenceVar) - ((long)addr));
}

View file

@ -245,6 +245,7 @@ public class GUI extends Observable {
"PATH_LINKER", "LINK_COMMAND_1", "LINK_COMMAND_2",
"PATH_AR", "AR_COMMAND_1", "AR_COMMAND_2",
"PATH_OBJDUMP", "OBJDUMP_ARGS",
"PATH_OBJCOPY",
"PATH_JAVAC",
"CONTIKI_STANDARD_PROCESSES",
@ -929,7 +930,7 @@ public class GUI extends Observable {
menuItem.setToolTipText("Not available in applet version");
}
menuItem = new JMenuItem("Compiler configuration wizard");
menuItem = new JMenuItem("Contiki mote configuration wizard");
menuItem.setActionCommand("configuration wizard");
menuItem.addActionListener(guiEventHandler);
menu.add(menuItem);
@ -940,14 +941,6 @@ public class GUI extends Observable {
menu.add(new JMenuItem(showBufferSettingsAction));
menu.addSeparator();
menuItem = new JMenuItem("Java version: "
+ System.getProperty("java.version") + " ("
+ System.getProperty("java.vendor") + ")");
menuItem.setEnabled(false);
menu.add(menuItem);
/* Help */
menu = new JMenu("Help");
menu.setMnemonic(KeyEvent.VK_H);
@ -957,6 +950,22 @@ public class GUI extends Observable {
menu.add(checkBox);
menuBar.add(menu);
menu.addSeparator();
menuItem = new JMenuItem("Java version: "
+ System.getProperty("java.version") + " ("
+ System.getProperty("java.vendor") + ")");
menuItem.setEnabled(false);
menu.add(menuItem);
menuItem = new JMenuItem("System's \"os.arch\": "
+ System.getProperty("os.arch"));
menuItem.setEnabled(false);
menu.add(menuItem);
menuItem = new JMenuItem("System's \"sun.arch.data.model\": "
+ System.getProperty("sun.arch.data.model"));
menuItem.setEnabled(false);
menu.add(menuItem);
// Mote plugins popup menu (not available via menu bar)
if (menuMotePluginClasses == null) {
menuMotePluginClasses = new Vector<Class<? extends Plugin>>();

View file

@ -147,5 +147,11 @@ public abstract class MoteInterface extends Observable {
*/
public void removed() {
}
/**
* Called when all mote interfaces have been added to mote.
*/
public void added() {
}
}

View file

@ -31,6 +31,7 @@
package se.sics.cooja;
/**
* This interface represents a mote memory.
*
@ -44,7 +45,7 @@ package se.sics.cooja;
* @see se.sics.cooja.SectionMoteMemory
* @author Fredrik Osterlind
*/
public interface MoteMemory {
public interface MoteMemory extends AddressMemory {
/**
* Clears the entire memory.
@ -77,4 +78,14 @@ public interface MoteMemory {
*/
public int getTotalSize();
public abstract int parseInt(byte[] memorySegment);
public enum MemoryEventType { READ, WRITE };
public interface MemoryMonitor {
public void memoryChanged(MoteMemory memory, MemoryEventType type, int address);
}
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm);
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm);
}

View file

@ -23,22 +23,21 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: SectionMoteMemory.java,v 1.7 2010/01/20 13:33:33 fros4943 Exp $
*/
package se.sics.cooja;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Arrays;
import java.util.HashMap;
import org.apache.log4j.Logger;
/**
* Represents a mote memory consisting of non-overlapping memory sections with
* variables' memory addresses.
* symbol addresses.
* <p>
* When an unhandled memory segment is set a new section is automatically
* When an non-existing memory segment is written, a new section is automatically
* created for this segment.
* <p>
*
@ -48,28 +47,36 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
private static Logger logger = Logger.getLogger(SectionMoteMemory.class);
private ArrayList<MoteMemorySection> sections = new ArrayList<MoteMemorySection>();
/* readonly memory is never written to Contiki core, and is used to provide
* access to, for instance, strings */
private ArrayList<MoteMemorySection> readonlySections = new ArrayList<MoteMemorySection>();
private final Properties addresses;
private final HashMap<String, Integer> addresses;
/* used to map Cooja's address space to native (Contiki's) addresses */
private final int offset;
/**
* Create a new mote memory with information about which variables exist and
* their relative memory addresses.
*
* @param addresses Variable addresses
* @param addresses Symbol addresses
* @param offset Offset for internally used addresses
*/
public SectionMoteMemory(Properties addresses) {
public SectionMoteMemory(HashMap<String, Integer> addresses, int offset) {
this.addresses = addresses;
this.offset = offset;
}
public String[] getVariableNames() {
return addresses.values().toArray(new String[0]);
return addresses.keySet().toArray(new String[0]);
}
public int getVariableAddress(String varName) throws UnknownVariableException {
/* Cooja address space */
if (!addresses.containsKey(varName)) {
throw new UnknownVariableException(varName);
}
return ((Integer) addresses.get(varName)).intValue();
return addresses.get(varName).intValue() + offset;
}
public int getIntegerLength() {
@ -81,16 +88,35 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
}
public byte[] getMemorySegment(int address, int size) {
/* Cooja address space */
address -= offset;
for (MoteMemorySection section : sections) {
if (section.includesAddr(address)
&& section.includesAddr(address + size - 1)) {
return section.getMemorySegment(address, size);
}
}
/* Check if in readonly section */
for (MoteMemorySection section : readonlySections) {
if (section.includesAddr(address)
&& section.includesAddr(address + size - 1)) {
return section.getMemorySegment(address, size);
}
}
return null;
}
public void setMemorySegmentNative(int address, byte[] data) {
setMemorySegment(address+offset, data);
}
public void setMemorySegment(int address, byte[] data) {
/* Cooja address space */
address -= offset;
/* TODO XXX Sections may overlap */
for (MoteMemorySection section : sections) {
if (section.includesAddr(address)
@ -102,6 +128,13 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
sections.add(new MoteMemorySection(address, data));
}
public void setReadonlyMemorySegment(int address, byte[] data) {
/* Cooja address space */
address -= offset;
readonlySections.add(new MoteMemorySection(address, data));
}
public int getTotalSize() {
int totalSize = 0;
for (MoteMemorySection section : sections) {
@ -120,67 +153,27 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
}
/**
* Removes a memory segment from this memory. The section containing the
* segment may be split into two sections.
* Get start address of given section in native address space.
*
* @param startAddr Start address
* @param size Length
*/
public void removeSegmentFromMemory(int startAddr, int size) {
for (MoteMemorySection section : sections) {
// Find section containing segment to remove
if (section.includesAddr(startAddr)
&& section.includesAddr(startAddr + size - 1)) {
MoteMemorySection oldSection = section;
byte[] dataFirstPart = oldSection.getMemorySegment(
oldSection.startAddr, (startAddr - oldSection.startAddr));
byte[] dataSecondPart = oldSection
.getMemorySegment(startAddr + size, (oldSection.startAddr
+ oldSection.getSize() - (startAddr + size)));
MoteMemorySection newSectionFirstPart = new MoteMemorySection(
oldSection.startAddr, dataFirstPart);
MoteMemorySection newSectionSecondPart = new MoteMemorySection(
startAddr + size, dataSecondPart);
// Remove old section, add new sections
sections.remove(oldSection);
if (newSectionFirstPart.getSize() > 0) {
sections.add(newSectionFirstPart);
}
if (newSectionSecondPart.getSize() > 0) {
sections.add(newSectionSecondPart);
}
}
}
}
/**
* Get start address of section at given position.
*
* @param sectionNr
* Section position
* @param sectionNr Section position
* @return Start address of section
*/
public int getStartAddrOfSection(int sectionNr) {
public int getSectionNativeAddress(int sectionNr) {
if (sectionNr >= sections.size()) {
return 0;
return -1;
}
return sections.get(sectionNr).getStartAddr();
}
/**
* Get size of section at given position.
*
* @param sectionNr
* Section position
* @param sectionNr Section position
* @return Size of section
*/
public int getSizeOfSection(int sectionNr) {
if (sectionNr >= sections.size()) {
return 0;
return -1;
}
return sections.get(sectionNr).getSize();
@ -189,8 +182,7 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
/**
* Get data of section at given position.
*
* @param sectionNr
* Section position
* @param sectionNr Section position
* @return Data at section
*/
public byte[] getDataOfSection(int sectionNr) {
@ -206,42 +198,22 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
}
public int getIntValueOf(String varName) throws UnknownVariableException {
// Get start address of variable
if (!addresses.containsKey(varName)) {
throw new UnknownVariableException(varName);
}
int varAddr = ((Integer) addresses.get(varName)).intValue();
int varAddr = getVariableAddress(varName);
byte[] varData = getMemorySegment(varAddr, 4);
if (varData == null) {
throw new UnknownVariableException(varName);
}
int retVal = 0;
int pos = 0;
retVal += ((varData[pos++] & 0xFF)) << 24;
retVal += ((varData[pos++] & 0xFF)) << 16;
retVal += ((varData[pos++] & 0xFF)) << 8;
retVal += ((varData[pos++] & 0xFF)) << 0;
/* TODO Correct for all platforms? */
retVal = Integer.reverseBytes(retVal);
return retVal;
return parseInt(varData);
}
public void setIntValueOf(String varName, int newVal) throws UnknownVariableException {
// Get start address of variable
if (!addresses.containsKey(varName)) {
throw new UnknownVariableException(varName);
}
int varAddr = ((Integer) addresses.get(varName)).intValue();
int varAddr = getVariableAddress(varName);
/* TODO Correct for all platforms? */
int newValToSet = Integer.reverseBytes(newVal);
// Create byte array
int pos = 0;
byte[] varData = new byte[4];
@ -254,12 +226,7 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
}
public byte getByteValueOf(String varName) throws UnknownVariableException {
// Get start address of variable
if (!addresses.containsKey(varName)) {
throw new UnknownVariableException(varName);
}
int varAddr = ((Integer) addresses.get(varName)).intValue();
int varAddr = getVariableAddress(varName);
byte[] varData = getMemorySegment(varAddr, 1);
if (varData == null) {
@ -270,12 +237,7 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
}
public void setByteValueOf(String varName, byte newVal) throws UnknownVariableException {
// Get start address of variable
if (!addresses.containsKey(varName)) {
throw new UnknownVariableException(varName);
}
int varAddr = ((Integer) addresses.get(varName)).intValue();
int varAddr = getVariableAddress(varName);
byte[] varData = new byte[1];
varData[0] = newVal;
@ -284,24 +246,12 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
}
public byte[] getByteArray(String varName, int length) throws UnknownVariableException {
// Get start address of variable
if (!addresses.containsKey(varName)) {
throw new UnknownVariableException(varName);
}
int varAddr = ((Integer) addresses.get(varName)).intValue();
// TODO Check if small/big-endian when coming from JNI?
int varAddr = getVariableAddress(varName);
return getMemorySegment(varAddr, length);
}
public void setByteArray(String varName, byte[] data) throws UnknownVariableException {
// Get start address of variable
if (!addresses.containsKey(varName)) {
throw new UnknownVariableException(varName);
}
int varAddr = ((Integer) addresses.get(varName)).intValue();
// TODO Check if small/big-endian when coming from JNI?
int varAddr = getVariableAddress(varName);
setMemorySegment(varAddr, data);
}
@ -310,10 +260,9 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
*
* @author Fredrik Osterlind
*/
private class MoteMemorySection {
private static class MoteMemorySection {
private byte[] data = null;
private int startAddr;
private final int startAddr;
/**
* Create a new memory section.
@ -408,14 +357,75 @@ public class SectionMoteMemory implements MoteMemory, AddressMemory {
}
public SectionMoteMemory clone() {
ArrayList<MoteMemorySection> clones = new ArrayList<MoteMemorySection>();
ArrayList<MoteMemorySection> sectionsClone = new ArrayList<MoteMemorySection>();
for (MoteMemorySection section : sections) {
clones.add(section.clone());
sectionsClone.add(section.clone());
}
SectionMoteMemory clone = new SectionMoteMemory(addresses);
clone.sections = clones;
SectionMoteMemory clone = new SectionMoteMemory(addresses, offset);
clone.sections = sectionsClone;
clone.readonlySections = readonlySections;
return clone;
}
}
private ArrayList<PolledMemorySegments> polledMemories = new ArrayList<PolledMemorySegments>();
public void pollForMemoryChanges() {
for (PolledMemorySegments mem: polledMemories.toArray(new PolledMemorySegments[0])) {
mem.notifyIfChanged();
}
}
private class PolledMemorySegments {
public final MemoryMonitor mm;
public final int address;
public final int size;
private byte[] oldMem;
public PolledMemorySegments(MemoryMonitor mm, int address, int size) {
this.mm = mm;
this.address = address;
this.size = size;
oldMem = getMemorySegment(address, size);
}
private void notifyIfChanged() {
byte[] newMem = getMemorySegment(address, size);
if (Arrays.equals(oldMem, newMem)) {
return;
}
mm.memoryChanged(SectionMoteMemory.this, MemoryEventType.WRITE, address);
oldMem = newMem;
}
}
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm) {
PolledMemorySegments t = new PolledMemorySegments(mm, address, size);
polledMemories.add(t);
return true;
}
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm) {
for (PolledMemorySegments mcm: polledMemories) {
if (mcm.mm != mm || mcm.address != address || mcm.size != size) {
continue;
}
polledMemories.remove(mcm);
break;
}
}
public int parseInt(byte[] memorySegment) {
int retVal = 0;
int pos = 0;
retVal += ((memorySegment[pos++] & 0xFF)) << 24;
retVal += ((memorySegment[pos++] & 0xFF)) << 16;
retVal += ((memorySegment[pos++] & 0xFF)) << 8;
retVal += ((memorySegment[pos++] & 0xFF)) << 0;
retVal = Integer.reverseBytes(retVal);
return retVal;
}
}

View file

@ -790,6 +790,12 @@ public class Simulation extends Observable implements Runnable {
motes.add(mote);
currentRadioMedium.registerMote(mote, Simulation.this);
/* Notify mote interfaces that node was added */
for (MoteInterface i: mote.getInterfaces().getInterfaces()) {
i.added();
}
setChanged();
notifyObservers(mote);
}

View file

@ -152,8 +152,9 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
/* Copy mote memory from Contiki */
myType.getCoreMemory(myMemory);
/* Poll mote interfaces */
myMemory.pollForMemoryChanges();
myInterfaceHandler.doActiveActionsAfterTick();
myInterfaceHandler.doPassiveActionsAfterTick();
}

View file

@ -45,7 +45,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
import java.util.HashMap;
import java.util.Random;
import java.util.Vector;
import java.util.regex.Matcher;
@ -199,13 +199,8 @@ public class ContikiMoteType implements MoteType {
// Type specific class configuration
private ProjectConfig myConfig = null;
private int relAddressOfReferenceVariable = 0;
private CoreComm myCoreComm = null;
// Variable name to address mappings
private Properties varAddresses = new Properties();
// Initial memory for all motes of this type
private SectionMoteMemory initialMemory = null;
@ -403,14 +398,16 @@ public class ContikiMoteType implements MoteType {
int dataSectionAddr = -1, dataSectionSize = -1;
int bssSectionAddr = -1, bssSectionSize = -1;
int commonSectionAddr = -1, commonSectionSize = -1;
int readonlySectionAddr = -1, readonlySectionSize = -1;
HashMap<String, Integer> addresses = new HashMap<String, Integer>();
if (useCommand) {
/* Parse command output */
String[] output = loadCommandData(getContikiFirmwareFile());
if (output == null) {
throw new MoteTypeCreationException("No parse command output loaded");
}
boolean parseOK = parseCommandData(output, varAddresses);
boolean parseOK = parseCommandData(output, addresses);
if (!parseOK) {
logger.fatal("Command output parsing failed");
throw new MoteTypeCreationException("Command output parsing failed");
@ -422,6 +419,14 @@ public class ContikiMoteType implements MoteType {
bssSectionSize = parseCommandBssSectionSize(output);
commonSectionAddr = parseCommandCommonSectionAddr(output);
commonSectionSize = parseCommandCommonSectionSize(output);
try {
readonlySectionAddr = parseCommandReadonlySectionAddr(output);
readonlySectionSize = parseCommandReadonlySectionSize(output);
} catch (Exception e) {
readonlySectionAddr = -1;
readonlySectionSize = -1;
}
} else {
/* Parse command output */
@ -434,7 +439,7 @@ public class ContikiMoteType implements MoteType {
logger.fatal("No map data could be loaded");
throw new MoteTypeCreationException("No map data could be loaded: " + mapFile);
}
boolean parseOK = parseMapFileData(mapData, varAddresses);
boolean parseOK = parseMapFileData(mapData, addresses);
if (!parseOK) {
logger.fatal("Map data parsing failed");
throw new MoteTypeCreationException("Map data parsing failed: " + mapFile);
@ -446,52 +451,99 @@ public class ContikiMoteType implements MoteType {
bssSectionSize = parseMapBssSectionSize(mapData);
commonSectionAddr = parseMapCommonSectionAddr(mapData);
commonSectionSize = parseMapCommonSectionSize(mapData);
readonlySectionAddr = -1;
readonlySectionSize = -1;
}
if (varAddresses.size() == 0) {
if (dataSectionAddr >= 0) {
logger.info(getContikiFirmwareFile().getName() +
": data section at 0x" + Integer.toHexString(dataSectionAddr) +
" (" + dataSectionSize + " bytes)");
} else {
logger.fatal(getContikiFirmwareFile().getName() + ": no data section found");
}
if (bssSectionAddr >= 0) {
logger.info(getContikiFirmwareFile().getName() +
": BSS section at 0x" + Integer.toHexString(bssSectionAddr) +
" (" + bssSectionSize + " bytes)");
} else {
logger.fatal(getContikiFirmwareFile().getName() + ": no BSS section found");
}
if (commonSectionAddr >= 0) {
logger.info(getContikiFirmwareFile().getName() +
": common section at 0x" + Integer.toHexString(commonSectionAddr) +
" (" + commonSectionSize + " bytes)");
} else {
logger.info(getContikiFirmwareFile().getName() + ": no common section found");
}
if (readonlySectionAddr >= 0) {
logger.info(getContikiFirmwareFile().getName() +
": readonly section at 0x" + Integer.toHexString(readonlySectionAddr) +
" (" + readonlySectionSize + " bytes)");
} else {
logger.warn(getContikiFirmwareFile().getName() + ": no readonly section found");
}
if (addresses.size() == 0) {
throw new MoteTypeCreationException("Library variables parsing failed");
}
try {
/* Relative <-> absolute addresses offset */
relAddressOfReferenceVariable = (Integer) varAddresses.get("referenceVar");
} catch (Exception e) {
throw (MoteTypeCreationException) new MoteTypeCreationException(
"JNI call error: " + e.getMessage()).initCause(e);
}
if (dataSectionAddr <= 0 || dataSectionSize <= 0
|| bssSectionAddr <= 0 || bssSectionSize <= 0) {
throw new MoteTypeCreationException("Library section addresses parsing failed");
}
myCoreComm.setReferenceAddress(relAddressOfReferenceVariable);
try {
/* Relative <-> absolute addresses offset */
int referenceVar = (Integer) addresses.get("referenceVar");
myCoreComm.setReferenceAddress(referenceVar);
} catch (Exception e) {
throw (MoteTypeCreationException) new MoteTypeCreationException(
"JNI call error: " + e.getMessage()).initCause(e);
}
/* We first need the value of Contiki's referenceVar, which tells us the
* memory offset between Contiki's variable and the relative addresses that
* were calculated directly from the library file.
*
* This offset will be used in Cooja in the memory abstraction to match
* Contiki's and Cooja's address spaces */
int offset;
{
SectionMoteMemory tmp = new SectionMoteMemory(addresses, 0);
byte[] data = new byte[dataSectionSize];
getCoreMemory(dataSectionAddr, dataSectionSize, data);
tmp.setMemorySegment(dataSectionAddr, data);
byte[] bss = new byte[bssSectionSize];
getCoreMemory(bssSectionAddr, bssSectionSize, bss);
tmp.setMemorySegment(bssSectionAddr, bss);
offset = tmp.getIntValueOf("referenceVar");
logger.info(getContikiFirmwareFile().getName() +
": offsetting Contiki mote address space: " + offset);
}
/* Create initial memory: data+bss+optional common */
initialMemory = new SectionMoteMemory(varAddresses);
initialMemory = new SectionMoteMemory(addresses, offset);
byte[] initialDataSection = new byte[dataSectionSize];
getCoreMemory(dataSectionAddr, dataSectionSize, initialDataSection);
initialMemory.setMemorySegment(dataSectionAddr, initialDataSection);
logger.info(getContikiFirmwareFile().getName() +
": data section at 0x" + Integer.toHexString(dataSectionAddr) +
" (" + dataSectionSize + " bytes)");
initialMemory.setMemorySegmentNative(dataSectionAddr, initialDataSection);
byte[] initialBssSection = new byte[bssSectionSize];
getCoreMemory(bssSectionAddr, bssSectionSize, initialBssSection);
initialMemory.setMemorySegment(bssSectionAddr, initialBssSection);
logger.info(getContikiFirmwareFile().getName() +
": BSS section at 0x" + Integer.toHexString(bssSectionAddr) +
" (" + bssSectionSize + " bytes)");
initialMemory.setMemorySegmentNative(bssSectionAddr, initialBssSection);
if (commonSectionAddr > 0 && commonSectionSize > 0) {
if (commonSectionAddr >= 0 && commonSectionSize > 0) {
byte[] initialCommonSection = new byte[commonSectionSize];
getCoreMemory(commonSectionAddr, commonSectionSize, initialCommonSection);
initialMemory.setMemorySegment(commonSectionAddr, initialCommonSection);
logger.info(getContikiFirmwareFile().getName() +
": common section at 0x" + Integer.toHexString(commonSectionAddr) +
" (" + commonSectionSize + " bytes)");
initialMemory.setMemorySegmentNative(commonSectionAddr, initialCommonSection);
}
/* Read "read-only" memory */
if (readonlySectionAddr >= 0 && readonlySectionSize > 0) {
byte[] readonlySection = new byte[readonlySectionSize];
getCoreMemory(readonlySectionAddr, readonlySectionSize, readonlySection);
initialMemory.setReadonlyMemorySegment(readonlySectionAddr+offset, readonlySection);
}
}
@ -524,7 +576,7 @@ public class ContikiMoteType implements MoteType {
public void setCoreMemory(SectionMoteMemory mem) {
for (int i = 0; i < mem.getNumberOfSections(); i++) {
setCoreMemory(
mem.getStartAddrOfSection(i),
mem.getSectionNativeAddress(i) /* native address space */,
mem.getSizeOfSection(i), mem.getDataOfSection(i));
}
}
@ -538,8 +590,7 @@ public class ContikiMoteType implements MoteType {
* @param varAddresses
* Properties that should contain the name to addresses mappings.
*/
public static boolean parseMapFileData(String[] mapFileData,
Properties varAddresses) {
public static boolean parseMapFileData(String[] mapFileData, HashMap<String, Integer> varAddresses) {
String[] varNames = getMapFileVarNames(mapFileData);
if (varNames == null || varNames.length == 0) {
return false;
@ -565,7 +616,7 @@ public class ContikiMoteType implements MoteType {
* @param output Command output
* @param addresses Variable addresses mappings
*/
public static boolean parseCommandData(String[] output, Properties addresses) {
public static boolean parseCommandData(String[] output, HashMap<String, Integer> addresses) {
int nrNew = 0, nrOld = 0, nrMismatch = 0;
Pattern pattern =
@ -615,10 +666,9 @@ public class ContikiMoteType implements MoteType {
*/
public void getCoreMemory(SectionMoteMemory mem) {
for (int i = 0; i < mem.getNumberOfSections(); i++) {
int startAddr = mem.getStartAddrOfSection(i);
int startAddr = mem.getSectionNativeAddress(i); /* native address space */
int size = mem.getSizeOfSection(i);
byte[] data = mem.getDataOfSection(i);
getCoreMemory(startAddr, size, data);
}
}
@ -689,12 +739,10 @@ public class ContikiMoteType implements MoteType {
* @param varName Name of variable
* @return Relative memory address of variable or -1 if not found
*/
public static int getMapFileVarAddress(String[] mapFileData, String varName, Properties varAddresses) {
int varAddr;
String varAddrString;
if ((varAddrString = varAddresses.getProperty(varName)) != null) {
varAddr = Integer.parseInt(varAddrString);
return varAddr;
private static int getMapFileVarAddress(String[] mapFileData, String varName, HashMap<String, Integer> varAddresses) {
Integer varAddrInteger;
if ((varAddrInteger = varAddresses.get(varName)) != null) {
return varAddrInteger.intValue();
}
String regExp =
@ -704,9 +752,9 @@ public class ContikiMoteType implements MoteType {
String retString = getFirstMatchGroup(mapFileData, regExp, 1);
if (retString != null) {
varAddresses.setProperty(varName, Integer.toString(Integer.parseInt(
retString.trim(), 16)));
return Integer.parseInt(retString.trim(), 16);
varAddrInteger = Integer.parseInt(retString.trim(), 16);
varAddresses.put(varName, varAddrInteger);
return varAddrInteger.intValue();
} else {
return -1;
}
@ -760,7 +808,7 @@ public class ContikiMoteType implements MoteType {
return varNames.toArray(new String[0]);
}
public static String[] getAllVariableNames(String[] lines,
private static String[] getAllVariableNames(String[] lines,
int startAddress, int endAddress) {
ArrayList<String> varNames = new ArrayList<String>();
@ -914,6 +962,21 @@ public class ContikiMoteType implements MoteType {
}
return end - start;
}
private static int parseCommandReadonlySectionAddr(String[] output) {
return parseFirstHexInt("^([0-9A-Fa-f]*)[ \t]t[ \t].text$", output);
}
private static int parseCommandReadonlySectionSize(String[] output) {
int start = parseCommandReadonlySectionAddr(output);
if (start < 0) {
return -1;
}
/* Extract the last specified address, assuming that the interval covers all the memory */
String last = output[output.length-1];
int lastAddress = Integer.parseInt(last.split("[ \t]")[0],16);
return lastAddress - start;
}
private static int getRelVarAddr(String mapFileData[], String varName) {
String regExp =

View file

@ -495,6 +495,7 @@ public class CompileContiki {
env.add(new String[] { "COOJA_SOURCEDIRS", "" });
env.add(new String[] { "COOJA_SOURCEFILES", "" });
env.add(new String[] { "CC", GUI.getExternalToolsSetting("PATH_C_COMPILER") });
env.add(new String[] { "OBJCOPY", GUI.getExternalToolsSetting("PATH_OBJCOPY") });
env.add(new String[] { "EXTRA_CC_ARGS", ccFlags });
env.add(new String[] { "LD", GUI.getExternalToolsSetting("PATH_LINKER") });
env.add(new String[] { "LINK_COMMAND_1", link1 });

View file

@ -50,7 +50,7 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.util.Properties;
import java.util.HashMap;
import javax.swing.Box;
import javax.swing.BoxLayout;
@ -66,11 +66,12 @@ import javax.swing.JScrollPane;
import se.sics.cooja.CoreComm;
import se.sics.cooja.GUI;
import se.sics.cooja.SectionMoteMemory;
import se.sics.cooja.MoteType.MoteTypeCreationException;
import se.sics.cooja.SectionMoteMemory;
import se.sics.cooja.contikimote.ContikiMoteType;
/* TODO Test common section */
/* TODO Test readonly section */
public class ConfigurationWizard extends JDialog {
private static final long serialVersionUID = 1L;
@ -141,7 +142,7 @@ public class ConfigurationWizard extends JDialog {
private static File cLibraryFile;
private static String javaLibraryName;
private static CoreComm javaLibrary;
private static Properties addresses;
private static HashMap<String, Integer> addresses;
private static int relDataSectionAddr;
private static int dataSectionSize;
private static int relBssSectionAddr;
@ -195,7 +196,7 @@ public class ConfigurationWizard extends JDialog {
"Changes made in this wizard are reflected in menu Settings, External tools paths.\n" +
"\n" +
"NOTE: You do not need to complete this wizard for emulating motes, such as Sky motes.\n",
"Configuration Wizard",
"Contiki mote configuration wizard",
JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE,
null, options, options[0]);
@ -756,7 +757,7 @@ public class ConfigurationWizard extends JDialog {
}
testOutput.addMessage("### Parsing map file data for addresses");
addresses = new Properties();
addresses = new HashMap<String, Integer>();
boolean parseOK = ContikiMoteType.parseMapFileData(mapData, addresses);
if (!parseOK) {
testOutput.addMessage("### Error: Failed parsing map file data", MessageList.ERROR);
@ -836,7 +837,7 @@ public class ConfigurationWizard extends JDialog {
}
testOutput.addMessage("### Parsing command output for addresses");
addresses = new Properties();
addresses = new HashMap<String, Integer>();
boolean parseOK = ContikiMoteType.parseCommandData(commandData, addresses);
if (!parseOK) {
testOutput.addMessage("### Error: Failed parsing command output", MessageList.ERROR);
@ -930,11 +931,11 @@ public class ConfigurationWizard extends JDialog {
testOutput.addMessage("### Testing Contiki library memory replacement");
testOutput.addMessage("### Configuring Contiki using parsed reference address");
int relRefAddress = (Integer) addresses.get("ref_var");
if (!addresses.containsKey("ref_var")) {
testOutput.addMessage("Could not find address of ref_var", MessageList.ERROR);
if (!addresses.containsKey("referenceVar")) {
testOutput.addMessage("Could not find address of referenceVar", MessageList.ERROR);
return false;
}
int relRefAddress = (Integer) addresses.get("referenceVar");
javaLibrary.setReferenceAddress(relRefAddress);
testOutput.addMessage("### Creating data and BSS memory sections");
@ -942,7 +943,7 @@ public class ConfigurationWizard extends JDialog {
byte[] initialBssSection = new byte[bssSectionSize];
javaLibrary.getMemory(relDataSectionAddr, dataSectionSize, initialDataSection);
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, initialBssSection);
SectionMoteMemory memory = new SectionMoteMemory(addresses);
SectionMoteMemory memory = new SectionMoteMemory(addresses, 0);
memory.setMemorySegment(relDataSectionAddr, initialDataSection);
memory.setMemorySegment(relBssSectionAddr, initialBssSection);

View file

@ -48,8 +48,7 @@ import se.sics.cooja.ClassDescription;
import se.sics.cooja.GUI;
import se.sics.cooja.Mote;
import se.sics.cooja.MoteInterface;
import se.sics.cooja.SimEventCentral.LogOutputEvent;
import se.sics.cooja.SimEventCentral.LogOutputListener;
import se.sics.cooja.SimEventCentral.MoteCountListener;
/**
* Mote2Mote Relations is used to show mote relations in simulated
@ -83,13 +82,32 @@ public class Mote2MoteRelations extends MoteInterface {
private ArrayList<Mote> relations = new ArrayList<Mote>();
private GUI gui;
private LogOutputListener logListener;
private Observer logObserver = new Observer() {
public void update(Observable o, Object arg) {
String msg = ((Log) o).getLastLogMessage();
handleNewLog(msg);
};
};
private MoteCountListener moteCountListener;
public Mote2MoteRelations(Mote mote) {
this.mote = mote;
this.gui = mote.getSimulation().getGUI();
}
mote.getSimulation().getEventCentral().addLogOutputListener(logListener = new LogOutputListener() {
public void added() {
super.added();
/* Observe log interfaces */
for (MoteInterface mi: mote.getInterfaces().getInterfaces()) {
if (mi instanceof Log) {
((Log)mi).addObserver(logObserver);
}
}
/* Observe other motes: if removed, remove our relations to them too */
mote.getSimulation().getEventCentral().addMoteCountListener(moteCountListener = new MoteCountListener() {
public void moteWasAdded(Mote mote) {
/* Ignored */
}
@ -106,28 +124,28 @@ public class Mote2MoteRelations extends MoteInterface {
relations.remove(mote);
gui.removeMoteRelation(Mote2MoteRelations.this.mote, mote);
}
public void newLogOutput(LogOutputEvent ev) {
if (ev.getMote() != Mote2MoteRelations.this.mote) {
return;
}
handleNewLog(ev.msg);
}
public void removedLogOutput(LogOutputEvent ev) {
/* Ignored */
}
});
}
public void removed() {
super.removed();
/* Stop observing log interfaces */
for (MoteInterface mi: mote.getInterfaces().getInterfaces()) {
if (mi instanceof Log) {
((Log)mi).deleteObserver(logObserver);
}
}
logObserver = null;
/* Remove all relations to other motes */
Mote[] relationsArr = relations.toArray(new Mote[0]);
for (Mote m: relationsArr) {
gui.removeMoteRelation(Mote2MoteRelations.this.mote, m);
}
relations.clear();
mote.getSimulation().getEventCentral().removeLogOutputListener(logListener);
mote.getSimulation().getEventCentral().removeMoteCountListener(moteCountListener);
}
private void handleNewLog(String msg) {

View file

@ -46,8 +46,6 @@ import org.jdom.Element;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
import se.sics.cooja.MoteInterface;
import se.sics.cooja.SimEventCentral.LogOutputEvent;
import se.sics.cooja.SimEventCentral.LogOutputListener;
import se.sics.cooja.plugins.skins.AttributeVisualizerSkin;
/**
@ -86,33 +84,38 @@ public class MoteAttributes extends MoteInterface {
private HashMap<String, Object> attributes = new HashMap<String, Object>();
private LogOutputListener logListener;
private Observer logObserver = new Observer() {
public void update(Observable o, Object arg) {
String msg = ((Log) o).getLastLogMessage();
handleNewLog(msg);
};
};
public MoteAttributes(Mote mote) {
this.mote = mote;
mote.getSimulation().getEventCentral().addLogOutputListener(logListener = new LogOutputListener() {
public void moteWasAdded(Mote mote) {
/* Ignored */
}
public void moteWasRemoved(Mote mote) {
/* Ignored */
}
public void newLogOutput(LogOutputEvent ev) {
if (ev.getMote() != MoteAttributes.this.mote) {
return;
}
handleNewLog(ev.msg);
}
public void removedLogOutput(LogOutputEvent ev) {
/* Ignored */
}
});
}
public void added() {
super.added();
/* Observe log interfaces */
for (MoteInterface mi: mote.getInterfaces().getInterfaces()) {
if (mi instanceof Log) {
((Log)mi).addObserver(logObserver);
}
}
}
public void removed() {
super.removed();
mote.getSimulation().getEventCentral().removeLogOutputListener(logListener);
/* Stop observing log interfaces */
for (MoteInterface mi: mote.getInterfaces().getInterfaces()) {
if (mi instanceof Log) {
((Log)mi).deleteObserver(logObserver);
}
}
logObserver = null;
}
private void handleNewLog(String msg) {

View file

@ -41,13 +41,12 @@ import javax.swing.JPanel;
import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.AddressMemory;
import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote;
import se.sics.cooja.MoteInterface;
import se.sics.cooja.MoteTimeEvent;
import se.sics.cooja.Simulation;
import se.sics.cooja.TimeEvent;
import se.sics.cooja.MoteMemory;
import se.sics.cooja.MoteMemory.MemoryEventType;
import se.sics.cooja.MoteMemory.MemoryMonitor;
/**
* Read-only interface to Rime address read from Contiki variable: rimeaddr_node_addr.
@ -59,37 +58,27 @@ import se.sics.cooja.TimeEvent;
@ClassDescription("Rime address")
public class RimeAddress extends MoteInterface {
private static Logger logger = Logger.getLogger(RimeAddress.class);
private AddressMemory moteMem;
private MoteMemory moteMem;
public static final int RIME_ADDR_LENGTH = 2;
private MemoryMonitor memMonitor = null;
public RimeAddress(final Mote mote) {
moteMem = (AddressMemory) mote.getMemory();
/* Detect startup address (only zeroes) */
TimeEvent updateWhenAddressReady = new MoteTimeEvent(mote, 0) {
public void execute(long t) {
if (!hasRimeAddress()) {
return;
}
String addrString = getAddressString();
addrString = addrString.replace(".", "");
addrString = addrString.replace("0", "");
if (!addrString.isEmpty()) {
moteMem = mote.getMemory();
if (hasRimeAddress()) {
memMonitor = new MemoryMonitor() {
public void memoryChanged(MoteMemory memory, MemoryEventType type, int address) {
if (type != MemoryEventType.WRITE) {
return;
}
setChanged();
notifyObservers();
return;
}
/* Postpone until address has been set */
mote.getSimulation().scheduleEvent(
this,
mote.getSimulation().getSimulationTime() + Simulation.MILLISECOND);
return;
}
};
updateWhenAddressReady.execute(0);
};
/* TODO XXX Timeout? */
moteMem.addMemoryMonitor(moteMem.getVariableAddress("rimeaddr_node_addr"), RIME_ADDR_LENGTH, memMonitor);
}
}
public boolean hasRimeAddress() {
@ -140,6 +129,13 @@ public class RimeAddress extends MoteInterface {
this.deleteObserver(observer);
}
public void removed() {
super.removed();
if (memMonitor != null) {
moteMem.removeMemoryMonitor(moteMem.getVariableAddress("rimeaddr_node_addr"), RIME_ADDR_LENGTH, memMonitor);
}
}
public Collection<Element> getConfigXML() {
return null;
}

Some files were not shown because too many files have changed in this diff Show more