contiki for CC2530的IAR移植

【引言】

移植的必要性

通过移植Contiki到IAR环境,可以很清晰的查看contiki操作系统的细节,同时IAR开发环境支持CC2530在线仿真,这对于WSN网络是十分有用的,有效地。这也是为什么喜欢2530的原因。 

概述

通过移植Contiki到IAR环境,可以很清晰的查看contiki操作系统的细节,同时IAR开发环境支持CC2530在线仿真,这对于WSN网络是十分有用的,有效地。这也是为什么喜欢2530的原因。 

你将学到

  •  如何移植contiki到IAR环境。
  •  关于移植的细节

【IAR文件路径】

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $TOOLKIT_DIR$\INC\DLIB\C\  
  2. $PROJ_DIR$\contiki-2.7\  
  3. $PROJ_DIR$\contiki-2.7\core\  
  4. $PROJ_DIR$\contiki-2.7\core\cfs\  
  5. $PROJ_DIR$\contiki-2.7\core\ctk\  
  6. $PROJ_DIR$\contiki-2.7\core\dev\  
  7. $PROJ_DIR$\contiki-2.7\core\lib\  
  8. $PROJ_DIR$\contiki-2.7\core\loader\  
  9. $PROJ_DIR$\contiki-2.7\core\net\  
  10. $PROJ_DIR$\contiki-2.7\core\net\mac\  
  11. $PROJ_DIR$\contiki-2.7\core\net\rime\  
  12. $PROJ_DIR$\contiki-2.7\core\net\routing\  
  13. $PROJ_DIR$\contiki-2.7\core\sys\  
  14. $PROJ_DIR$\contiki-2.7\cpu\  
  15. $PROJ_DIR$\contiki-2.7\cpu\cc253x\  
  16. $PROJ_DIR$\contiki-2.7\cpu\cc253x\dev\  
  17. $PROJ_DIR$\contiki-2.7\platform\  
  18. $PROJ_DIR$\contiki-2.7\platform\cc2530dk\  
  19. $PROJ_DIR$\contiki-2.7\platform\cc2530dk\dev\  
  20. $PROJ_DIR$\contiki-2.7\examples\  
  21. $PROJ_DIR$\contiki-2.7\examples\hello-world\  
【相关宏定义】
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. UIP_CONF_IPV6=1  
  2. VP_CONFIG_H="contiki-conf.h  
【GDCC到IAR的编译修改】

(1) __asm__未定义
GCC下关键字__asm__,等同于IAR的asm。不过,从文档《IAR C/C++ Compiler Reference Guide.pdf》来看,推荐使用关键字__asm(英文原文:the asm keyword is not available when the option --strict is used. The __asm keyword is always available)。在相应文件增加如下代码,即可解决:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #ifdef __IAR_SYSTEMS_ICC__  
  2. #define __asm__ __asm  
  3. #endif  
(2)变量
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. __xdata __at(0x0000) static unsigned long timer_value = 0;  
变成
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. static volatile unsigned long timer_value = 0;  
更恰当的修改

//static CC_AT_DATA struct timer debouncetimer;  

变成

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #ifdef SDCC  
  2. static__data structtimer debouncetimer;  
  3. #else  
  4. staticstruct timer debouncetimer;  
  5. #endif  
关于中断
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. void 2 port_0_isr(void) __interrupt(P0INT_VECTOR)   
修改成
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #ifdef SDCC  
  2. void  
  3. port_0_isr(void) __interrupt(P0INT_VECTOR)  
  4. #else  
  5. #pragma vector=P0INT_VECTOR  
  6. __near_func __interrupt void port_0_isr(void)  
  7. #endif  
1, 根据iocc2530.h修改了cc253x.h

为了找到cc2530的IEEE Addres,在cc253x.h(改编自iocc2530.h)中

 添加了#define X_IEEE_ADDR   PXREG(0x780C )  /* Start of unique IEEE Address */

2,中断服务函数 linux 下是SDCC  要改成IAR格式

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. void rtimer_isr(void) __interrupt(T1_VECTOR);  
改成
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #ifdef SDCC   
  2. void port_0_isr(void) __interrupt(P0INT_VECTOR)  
  3. #else  
  4. #pragma vector=P0INT_VECTOR  
  5. __near_func __interrupt void port_0_isr(void)  
  6. #endif  
此时还有90个错误

//__xdata __at(0x0000) static unsigned long timer_value = 0;

static volatile unsigned long timer_value = 0; 

修改了button-sensor.h 使之符合IAR格式

修改了button-sensor.c 清除了cc2531的情况

--这样做,不合算,仅是为了更快的修改而已,以后也要加上cc2531这种情况

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. Error[e46]: Undefined external"BUTTON_IRQ_CHECK::?relay"referredinbutton-sensor ( F:\Contiki OS\2530contiki2.7\Debug\Obj\  
  2. Error[e46]: Undefined external"BUTTON_IRQ_FLAG_OFF::?relay"referredinbutton-sensor ( F:\Contiki OS\2530contiki2.7\Debug\Obj\  
  3. Error[e27]: Entry"rime_sniffer_add::?relay"inmodule rime ( F:\Contiki OS\2530contiki2.7\Debug\Obj\rime.r51 ) redefinedinmodule   
相应的文件没有添加上 

Error[e46]: Undefined external "autostart_processes" referred in contiki-main ( F:\Contiki OS\2530contiki2.7\Debug\Obj\contiki-main.r51 ) 

相应的文件没有添加上

Error[e46]: Undefined external "rtimer_arch_init::?relay" referred in rtimer ( F:\Contiki OS\2530contiki2.7\Debug\Obj\rtimer.r51 ) 

相应的文件没有添加上 

Error[e46]: Undefined external "?DPL1" referred in cc2530-rf ( F:\Contiki OS\2530contiki2.7\Debug\Obj\cc2530-rf.r51 )

在8051def.h 屏蔽了部分宏(没用明确定义)

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. //#if !defined(__SDCC_mcs51) && !defined(SDCC_mcs51)  
  2. //#define __data  
  3. //#define __xdata  
  4. //#define __code  
  5. //#define __bit bool  
  6. //#define __sfr volatile unsigned char  
  7. //#define __sbit volatile bool  
  8. //#define __critical  
  9. //#define __at(x)  
  10. //#define __using(x)  
  11. //#define __interrupt(x)  
  12. //#define __naked  
  13. //#endif  
在cc253x.h文件中主要修改了关于读取芯片MAC的地址,如下
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. /* ------------------------------------------------------------------------------------------------  
  2.  *                                       Flash  
  3.  * ------------------------------------------------------------------------------------------------  
  4.  */  
  5.   
  6. #define X_INFOPAGE  PXREG( 0x7800 )  /* Pointer to Start of Flash Information Page          */  
  7. #define X_XBANK     PXREG( 0x8000 )  /* Pointer to Start of Selectable Flash Bank (XBANK)   */  
  8. //#define X_IEEE_ADDR   PXREG(0x780C )  /* Start of unique IEEE Address */  
  9. #define X_IEEE_ADDR (*(uint8_t*)(X_INFOPAGE + 0x0C))    /* Start of unique IEEE Address */  
  10. #define OVFIM T1OVFIM                              

主要是第8行,根据这个地址,程序可以读取芯片的MAC地址,由此作为网络IP或者节点IP等。

系统莫名其名重启---溢出问题和看门狗设置
1,修改看门狗启动--- WDCTL|=0x08

2,溢出--适当减少XDATA;


编译器的bug---更改一次烧写  linker  换成128_banked.xcl就好了,耗了我一天啊。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值