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[8];
radio_value_t val = 0;
ieee_addr_cpy_to(ext_addr, 8);
short_addr = ext_addr[7];
short_addr |= ext_addr[6] << 8;
/* Populate linkaddr_node_addr. Maintain endianness */
memcpy(&linkaddr_node_addr, &ext_addr[8 - LINKADDR_SIZE], 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
}
文章评论(0条评论)
登录后参与讨论