Context Switch in Arduino Due

asked 2015-03-18 05:42:07 -0700

bling gravatar image

updated 2015-03-18 08:54:06 -0700

  The FW in ArduinoDue platform starts from AJ_PrintFWVersion() ->AJ_Network_Up() to AJ_WSL_DriverStart(). At this function, the main task creates another task,AJ_WSL_MBoxListenAndProcessTask. There should be somewhere doing context-switch and the FW will switch to AJ_WSL_MBoxListenAndProcess Task.If not, the main task should stuck in the while loop to wait the variable which should be set by AJ_WSL_MBoxListenAndProcessTask after creating the task. Because the two task has the same priority ,the FW won't do context-switch after creating the AJ_WSL_MBoxListenAndProcessTask. But I can't find out Where the part doing context switch is ?<br>     In my platform, I implement a timer and make the context-switch function in that timer so that the task will do context switch every time the timer times up. But I find this behavior may cause something wrong in the later part of AllJoyn. So,it may be wrong to use a timer to implement the context-switch. Could you help me to know how the Due platform implement the context-switch so that I may fix my bug. Thank you!!
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-03-18 09:01:44 -0700

jprestwo gravatar image

The Arduino DUE uses FreeRTOS which handles task switching (context switching). The two tasks have the same priority meaning they share a time slice. This means that FreeRTOS will automatically context switch every "tick" which is set to 1ms. You should be seeing the two tasks flip flop between one another once the MBoxListenAndProcessTask task is created. By your question I assume the main task is stuck in the while loop waiting for the driver to start? There is some difference in GT-202 shield pin-outs between hardware revisions. One thing you could try is changing pin 28 to pin 22 by editing line 82 in bsp/due/aj_target_platform.h to read:

#define AJ_WSL_SPI_CHIP_POWER_PIN PIO_PC22_IDX /* pin D3 on the Arduino Due */

Recompile with that and see if that fixes the problem your seeing.

edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-03-18 05:42:07 -0700

Seen: 119 times

Last updated: Mar 18 '15