Hi,
I am new to freeRTOS and am debugging some examples of freeRTOS-wsn430 using simulators WSim and WSNet.
When I was testing 05_network_device and 06_coordinator, I can successfully ready ds2411_id and treat it as MAC address
of device. But then, The program steps into preSetupTimerInterrupt() and never goes out.
int main( void )
{
/* Setup the hardware. */
prvSetupHardware();
printf(”hardware ready!n”);
/* Create the SPI mutex */
xSPIMutex = xSemaphoreCreateMutex();
/* Create the task of the application */
vCreateMacTask(xSPIMutex, configMAX_PRIORITIES-2);
/* Add the local task */
printf(”donen”);
xTaskCreate( vSendingTask, “sender”, configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL );
/* Start the scheduler. */
vTaskStartScheduler();
/* As the scheduler has been started we should never get here! */
return 0;
}
void vCreateMacTask(xSemaphoreHandle xSPIMutex, uint16_t usPriority) {
/* Stores the mutex handle */
xSPIM = xSPIMutex;
/* Create an Event Queue */
xEventQ = xQueueCreate(5, sizeof(uint8_t));
/* Create a Semaphore for waiting end of TX */
vSemaphoreCreateBinary( xSendingS );
/* Make sure the semaphore is taken */
xSemaphoreTake( xSendingS, 0 );
/* Create the task */
xTaskCreate( vMacTask, “MAC”, configMINIMAL_STACK_SIZE, NULL, usPriority, NULL );
// printf(”create MAC Task!”);
}
static void vMacTask(void* pvParameters) {
uint8_t event;
macState = STATE_ATTACHING;
vInitMac();
/* Network Attachment Procedure */
while (1) {
printf(”sending attach requestrn”);
LED_RED_TOGGLE();
vSendAttachFrame();
vStartRx();
uint16_t RXTimeout = 1000;
uint16_t time;
while (1) {
time = xTaskGetTickCount();
if (xQueueReceive(xEventQ, &event, RXTimeout)) {
if (event == EVENT_FRAME_RECEIVED) {
LED_GREEN_OFF();
if (xParseAttachFrame()) {
printf(”received attach replyrn”);
break;
}
}
}
LED_GREEN_ON();
time = xTaskGetTickCount() – time;
if (time < RXTimeout) {
RXTimeout -= time;
} else {
break;
}
}
}
LEDS_OFF();
/* Packet Sending/Receiving */
for (;;) {
vStartRx();
macState = STATE_RX;
while (xQueueReceive(xEventQ, &event, portMAX_DELAY)) {
if (event == EVENT_FRAME_RECEIVED) {
LED_RED_ON();
vParseFrame();
LED_RED_OFF();
} else if (event == EVENT_FRAME_TO_SEND) {
LED_GREEN_ON();
macState = STATE_TX;
vSendFrame();
LED_GREEN_OFF();
}
vStartRx();
macState = STATE_RX;
}
}
}
static void vInitMac(void) {
/* Initialize the unique electronic signature and read it */
ds2411_init();
printf(”MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02xn”,
ds2411_id.raw, ds2411_id.raw, ds2411_id.raw, ds2411_id.raw,
ds2411_id.raw, ds2411_id.raw, ds2411_id.raw, ds2411_id.raw);
// printf(”nds2411 ready!n “);
/* XXX hack: Fix it so that the 802.15.4 MAC address is compatible
with an Ethernet MAC address – byte 0 (byte 2 in the DS ID)
cannot be odd. */
// ds2411_id.raw &= 0xfe;
//
// uint16_t i;
// for (i=0;i<6;i++)
// {
// nodeAddr_ = ds2411_id.raw;
// }
memcpy(nodeAddr, ds2411_id.raw+sizeof(uint8_t), 6);
printf(”nodeAddr: %02x:%02x:%02x:%02x:%02x:%02xn”,
nodeAddr,nodeAddr,nodeAddr,nodeAddr,nodeAddr,nodeAddr);
printf(”coordAddr: %02x:%02x:%02x:%02x:%02x:%02xn”,
coordAddr,coordAddr,coordAddr,coordAddr,coordAddr,coordAddr);
wsn430_set_rime_addr();
/* Seed the random number generator */
uint16_t seed;
seed = (((uint16_t) ds2411_id.serial0) << 8) + (uint16_t) ds2411_id.serial1;
srand(seed);
/* Leds */
LEDS_INIT();
LEDS_ON();
xSemaphoreTake(xSPIM, portMAX_DELAY);
/* Initialize the radio driver */
/***********************************************************/
cc1100_init();
// printf(”cc1100 ready!n”);
cc1100_cmd_idle();
cc1100_cfg_append_status(CC1100_APPEND_STATUS_DISABLE);
cc1100_cfg_crc_autoflush(CC1100_CRC_AUTOFLUSH_DISABLE);
cc1100_cfg_white_data(CC1100_DATA_WHITENING_ENABLE);
cc1100_cfg_crc_en(CC1100_CRC_CALCULATION_ENABLE);
cc1100_cfg_freq_if(0x0C);
cc1100_cfg_fs_autocal(CC1100_AUTOCAL_NEVER);//CC1100_AUTOCAL_4TH_TX_RX_TO_IDLE
// cc1100_cfg_fs_autocal(CC1100_AUTOCAL_4TH_TX_RX_TO_IDLE);
//bpsk
cc1100_cfg_mod_format(CC1100_MODULATION_MSK);
cc1100_cfg_sync_mode(CC1100_SYNCMODE_30_32);
cc1100_cfg_manchester_en(CC1100_MANCHESTER_DISABLE);
cc1100_cfg_txoff_mode(CC1100_TXOFF_MODE_IDLE);
cc1100_cfg_rxoff_mode(CC1100_RXOFF_MODE_IDLE);
// set channel bandwidth (560 kHz)
cc1100_cfg_chanbw_e(0);
cc1100_cfg_chanbw_m(2);
// set data rate (0xD/0x2F is 250kbps)
cc1100_cfg_drate_e(0x0D);
cc1100_cfg_drate_m(0x2F);
uint8_t table;
table = 0x67; // -10dBm 0x67 //-5dBm
cc1100_cfg_patable(table, 1);
cc1100_cfg_pa_power(0);
cc1100_cmd_calibrate();
xSemaphoreGive(xSPIM);
}
Can anybody help me please!_
freeRTOS + wsn430
freeRTOS + wsn430
I have not idea what this platform is, but I will try and help based on some knowledge of common problems.
1 Most support requests that come from people using simulators end up being bugs in the simulator.
2 I notice you are using printf() in a task. Are you sure the task stack is big enough? Are any other tasks also using IO functions without any sort of guards against re-entrancy or mutual exclusion problems (although prvSetupTimerInterrupt() is called before any tasks run, so I would guess the task code is not relevant to the problem, yet).
3 Does preSetupTimerInterrupt() poll any hardware registers that are not updated by the simulator? Where in prvSetupTimerInterrupt() does the code crash? Can you post the code for that?
freeRTOS + wsn430
hi edwards, thank you very much for your reply.
I also suspect that there are bugs in simulators.. But I do not have devices on my hand now, so…..
I tried to comment all the printf(), but the problem is still there.. code went into there there functions and never went out
vTaskIncrementTick();
vTaskSwitchContext();
/* Restore the context of the new task. */
portRESTORE_CONTEXT(); Sorry I am really new to freeRTOS, how to check hardware registers that preSetupInterrupt() poll
I also suspect that there are bugs in simulators.. But I do not have devices on my hand now, so…..
I tried to comment all the printf(), but the problem is still there.. code went into there there functions and never went out
vTaskIncrementTick();
vTaskSwitchContext();
/* Restore the context of the new task. */
portRESTORE_CONTEXT(); Sorry I am really new to freeRTOS, how to check hardware registers that preSetupInterrupt() poll