tag 标签: cc2630

相关博文
  • 热度 16
    2016-3-28 22:44
    1182 次阅读|
    0 个评论
    14. 那么如何完成数据发送呢,所有相关函数都在IEEE_MODE.C文件中,系统中采用函数实现。 static int send(const void *payload, unsigned short payload_len) {   prepare(payload, payload_len);   return transmit(payload_len); } prepare完成的是发送数据长度的判断,确保发送数据长度在180字节以内; transmit完成数据的发送...   15. 数据接收呢,如何判断数据的接收状态? 相关函数也在IEEE_MODE.C文件中 static int read_frame(void *buf, unsigned short buf_len);函数实现,函数返回接收数据长度. 函数中的RIMESTATS_ADD用于记录报接收异常状态记录,在内核void print_stats(void)函数中有调用,用于显示输出。
  • 热度 18
    2016-3-28 22:27
    1305 次阅读|
    0 个评论
    1. contiki-master\cpu\cc26xx-cc13xx\rf-core\ieee-mode.c文件为其相关的函数,改文件只有.C文件,没有.h文件 2. 跳过文件前面的内容,直接跳转到函数的最后有如下代码: /*---------------------------------------------------------------------------*/ const struct radio_driver ieee_mode_driver = {   init,   prepare,   transmit,   send,   read_frame,   channel_clear,   receiving_packet,   pending_packet,   on,   off,   get_value,   set_value,   get_object,   set_object, }; /*---------------------------------------------------------------------------*/ 这里初始化了一个数据结构,大括号里面的是对结构体的赋值,均属于函数调用。 结构体的定义在contiki-master\core\dev\radio.h中被定义,具体内容为: /**  * The structure of a device driver for a radio in Contiki.  */ struct radio_driver {     int (* init)(void);     /** Prepare the radio with a packet to be sent. */   int (* prepare)(const void *payload, unsigned short payload_len);     /** Send the packet that has previously been prepared. */   int (* transmit)(unsigned short transmit_len);     /** Prepare transmit a packet. */   int (* send)(const void *payload, unsigned short payload_len);     /** Read a received packet into a buffer. */   int (* read)(void *buf, unsigned short buf_len);     /** Perform a Clear-Channel Assessment (CCA) to find out if there is       a packet in the air or not. */   int (* channel_clear)(void);     /** Check if the radio driver is currently receiving a packet */   int (* receiving_packet)(void);     /** Check if the radio driver has just received a packet */   int (* pending_packet)(void);     /** Turn the radio on. */   int (* on)(void);     /** Turn the radio off. */   int (* off)(void);     /** Get a radio parameter value. */   radio_result_t (* get_value)(radio_param_t param, radio_value_t *value);     /** Set a radio parameter value. */   radio_result_t (* set_value)(radio_param_t param, radio_value_t value);     /**    * Get a radio parameter object. The argument 'dest' must point to a    * memory area of at least 'size' bytes, and this memory area will    * contain the parameter object if the function succeeds.    */   radio_result_t (* get_object)(radio_param_t param, void *dest, size_t size);     /**    * Set a radio parameter object. The memory area referred to by the    * argument 'src' will not be accessed after the function returns.    */   radio_result_t (* set_object)(radio_param_t param, const void *src,                                 size_t size); };   3. 然后在contiki-master\platform\srf06-cc26xx\contiki-conf.h文件中有如下定义; #define NETSTACK_CONF_RADIO        ieee_mode_driver 4. 然后在contiki-master\core\net\netstack.h文件中有如下定义: #ifndef NETSTACK_RADIO #ifdef NETSTACK_CONF_RADIO #define NETSTACK_RADIO NETSTACK_CONF_RADIO #else /* NETSTACK_CONF_RADIO */ #define NETSTACK_RADIO   nullradio_driver #endif /* NETSTACK_CONF_RADIO */ #endif /* NETSTACK_RADIO */ 5. 然后在 contiki-master\platform\srf06-cc26xx\contiki-conf.c文件文件中的 static void set_rf_params(void)函数中有对上面内容进行调用完成初始化配置,   NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID);   NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr);   NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, RF_CORE_CHANNEL);   NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);     NETSTACK_RADIO.get_value(RADIO_PARAM_CHANNEL, val); 6.  contiki-conf.c文件中有main函数,从main函数中可以看到网络相关的初始化函数为:   printf(" Net: ");   printf("%s\n", NETSTACK_NETWORK.name);   printf(" MAC: ");   printf("%s\n", NETSTACK_MAC.name);   printf(" RDC: ");   printf("%s", NETSTACK_RDC.name);     if(NETSTACK_RDC.channel_check_interval() != 0) {     printf(", Channel Check Interval: %u ticks",            NETSTACK_RDC.channel_check_interval());   }   printf("\n");     netstack_init();  set_rf_params(); 7. 在contiki-master\core\net\netstack.h文件中有如下定义和声明; struct network_driver {   char *name;     /** Initialize the network driver */   void (* init)(void);     /** Callback for getting notified of incoming packet. */   void (* input)(void); }; llsec_driver等在其他文件中被定义. extern const struct network_driver    NETSTACK_NETWORK;    extern const struct llsec_driver          NETSTACK_LLSEC;   extern const struct rdc_driver            NETSTACK_RDC; extern const struct mac_driver          NETSTACK_MAC; extern const struct radio_driver         NETSTACK_RADIO; extern const struct framer                  NETSTACK_FRAMER; 同样在该文件中还有: #ifndef NETSTACK_NETWORK #ifdef NETSTACK_CONF_NETWORK #define NETSTACK_NETWORK NETSTACK_CONF_NETWORK #else /* NETSTACK_CONF_NETWORK */ #define NETSTACK_NETWORK rime_driver #endif /* NETSTACK_CONF_NETWORK */ #endif /* NETSTACK_NETWORK */ 定义 8. 而在 contiki-master\platform\srf06-cc26xx\contiki-conf.h文件中有如下定义 #ifndef NETSTACK_CONF_NETWORK #if NETSTACK_CONF_WITH_IPV6 #define NETSTACK_CONF_NETWORK sicslowpan_driver #else #define NETSTACK_CONF_NETWORK rime_driver #endif /* NETSTACK_CONF_WITH_IPV6 */ #endif /* NETSTACK_CONF_NETWORK */   #ifndef NETSTACK_CONF_MAC #define NETSTACK_CONF_MAC     csma_driver #endif   #ifndef NETSTACK_CONF_RDC #define NETSTACK_CONF_RDC     contikimac_driver #endif 如果NETSTACK_CONF_WITH_IPV6被定义,则6中 NETSTACK_NETWORK.name为 sicslowpan;      
  • 热度 11
    2016-3-28 22:27
    1622 次阅读|
    0 个评论
    9. 回到6,跟踪  netstack_init();   set_rf_params();两个函数; 10. 在 netstack.c文件中只有一个函数: void  netstack_init(void) {   NETSTACK_RADIO.init();   NETSTACK_RDC.init();   NETSTACK_LLSEC.init();   NETSTACK_MAC.init();   NETSTACK_NETWORK.init(); } 其函数体的定义在8中被跟踪到,主要用于协议栈的初始化,位于不同协议层; 这里关注 NETSTACK_RADIO.init();对应2中 ieee_mode_driver的init,位于ieee-mode.c 11. ieee-mode.c中的 init函数如下: 其中完成了接收缓冲区的初始化,并将初始化缓冲区映射到内核的接收数据链表中 并调用了 init_rf_params();函数,在最后调用了process_start(rf_core_process, NULL);启动RF进程. static int  init(void) {   lpm_register_module(cc26xx_rf_lpm_module);     rf_core_set_modesel();     /* Initialise RX buffers */   memset(rx_buf_0, 0, RX_BUF_SIZE);   memset(rx_buf_1, 0, RX_BUF_SIZE);   memset(rx_buf_2, 0, RX_BUF_SIZE);   memset(rx_buf_3, 0, RX_BUF_SIZE);     /* Set of RF Core data queue. Circular buffer, no last entry */   rx_data_queue.pCurrEntry = rx_buf_0;     rx_data_queue.pLastEntry = NULL;     /* Initialize current read pointer to first element (used in ISR) */   rx_read_entry = rx_buf_0;     /* Populate the RF parameters data structure with default values */   init_rf_params();     if(on() != RF_CORE_CMD_OK) {     PRINTF("init: on() failed\n");     return RF_CORE_CMD_ERROR;   }     ENERGEST_ON(ENERGEST_TYPE_LISTEN);     rf_core_primary_mode_register(mode_ieee);     process_start(rf_core_process, NULL);   return 1; } 12.  init_rf_params();依然位于 ieee-mode.c文件中,函数体如下: 这里访问的是RF核也就是完成的是RF内核的初始化操作,因为之后就启动了RF进程。 static void  init_rf_params(void) {   rfc_CMD_IEEE_RX_t *cmd = (rfc_CMD_IEEE_RX_t *)cmd_ieee_rx_buf;     memset(cmd_ieee_rx_buf, 0x00, RF_CMD_BUFFER_SIZE);     cmd-commandNo = CMD_IEEE_RX;   cmd-status = RF_CORE_RADIO_OP_STATUS_IDLE;   cmd-pNextOp = NULL;   cmd-startTime = 0x00000000;   cmd-startTrigger.triggerType = TRIG_NOW;   cmd-condition.rule = COND_NEVER;   cmd-channel = RF_CORE_CHANNEL;     cmd-rxConfig.bAutoFlushCrc = 1;   cmd-rxConfig.bAutoFlushIgn = 0;   cmd-rxConfig.bIncludePhyHdr = 0;   cmd-rxConfig.bIncludeCrc = 1;   cmd-rxConfig.bAppendRssi = 1;   cmd-rxConfig.bAppendCorrCrc = 1;   cmd-rxConfig.bAppendSrcInd = 0;   cmd-rxConfig.bAppendTimestamp = 0;     cmd-pRxQ = rx_data_queue;   cmd-pOutput = (rfc_ieeeRxOutput_t *)rf_stats;   #if IEEE_MODE_PROMISCOUS   cmd-frameFiltOpt.frameFiltEn = 0; #else   cmd-frameFiltOpt.frameFiltEn = 1; #endif     cmd-frameFiltOpt.frameFiltStop = 1;   #if IEEE_MODE_AUTOACK   cmd-frameFiltOpt.autoAckEn = 1; #else   cmd-frameFiltOpt.autoAckEn = 0; #endif     cmd-frameFiltOpt.slottedAckEn = 0;   cmd-frameFiltOpt.autoPendEn = 0;   cmd-frameFiltOpt.defaultPend = 0;   cmd-frameFiltOpt.bPendDataReqOnly = 0;   cmd-frameFiltOpt.bPanCoord = 0;   cmd-frameFiltOpt.maxFrameVersion = 1;   cmd-frameFiltOpt.bStrictLenFilter = 0;     /* Receive all frame types */   cmd-frameTypes.bAcceptFt0Beacon = 1;   cmd-frameTypes.bAcceptFt1Data = 1;   cmd-frameTypes.bAcceptFt2Ack = 1;   cmd-frameTypes.bAcceptFt3MacCmd = 1;   cmd-frameTypes.bAcceptFt4Reserved = 1;   cmd-frameTypes.bAcceptFt5Reserved = 1;   cmd-frameTypes.bAcceptFt6Reserved = 1;   cmd-frameTypes.bAcceptFt7Reserved = 1;     /* Configure CCA settings */   cmd-ccaOpt.ccaEnEnergy = 1;   cmd-ccaOpt.ccaEnCorr = 1;   cmd-ccaOpt.ccaEnSync = 0;   cmd-ccaOpt.ccaCorrOp = 1;   cmd-ccaOpt.ccaSyncOp = 1;   cmd-ccaOpt.ccaCorrThr = 3;     cmd-ccaRssiThr = IEEE_MODE_RSSI_THRESHOLD;     cmd-numExtEntries = 0x00;   cmd-numShortEntries = 0x00;   cmd-pExtEntryList = 0;   cmd-pShortEntryList = 0;     cmd-endTrigger.triggerType = TRIG_NEVER;   cmd-endTime = 0x00000000; }   13. 只有在 contiki-conf.c文件中的 set_rf_params函数. 主要完成ID设置,通道设置, /*---------------------------------------------------------------------------*/ static void  set_rf_params(void) {   uint16_t short_addr;   uint8_t ext_addr ;   radio_value_t val = 0;     ieee_addr_cpy_to(ext_addr, 8);     short_addr = ext_addr ;   short_addr |= ext_addr 8;     /* Populate linkaddr_node_addr. Maintain endianness */   memcpy(linkaddr_node_addr, ext_addr , LINKADDR_SIZE);     NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID);   NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr);   NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, RF_CORE_CHANNEL);   NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8);     NETSTACK_RADIO.get_value(RADIO_PARAM_CHANNEL, val);   printf(" RF: Channel %d\n", val);   #if STARTUP_CONF_VERBOSE   {     int i;     printf(" Link layer addr: ");     for(i = 0; i LINKADDR_SIZE - 1; i++) {       printf("%02x:", linkaddr_node_addr.u8 );     }     printf("%02x\n", linkaddr_node_addr.u8 );   } #endif }