Hi
I added a second task to the SimpleBLECentral example project. I use the smartRF06EB with a CC2650 BLE IC. My problem is that the additional task stops running as soon as the main task gets scheduled. Here the code for the additional task:
#define MAIN_CENTRAL_TASK_PRIORITY 3
#define AUXILIARY_TASK_PRIORITY 1
int main()
{
PIN_init(BoardGpioInitTable);
#ifndef POWER_SAVING
/* Set constraints for Standby, powerdown and idle mode */
Power_setConstraint(Power_SB_DISALLOW);
Power_setConstraint(Power_IDLE_PD_DISALLOW);
#endif //POWER_SAVING
/* Initialize ICall module */
ICall_init();
/* Start tasks of external images - Priority 5 */
ICall_createRemoteTasks();
/* Kick off profile - Priority 3 */
GAPCentralRole_createTask();
/* Kick off application - Priority 1 */
SimpleBLECentral_createMainCentralTask();
SimpleBLECentral_createAuxiliaryTask();
/* enable interrupts and start SYS/BIOS */
BIOS_start();
return 0;
}
void SimpleBLECentral_createAuxiliaryTask(void)
{
Task_Params taskParams;
// Configure task
Task_Params_init(&taskParams);
taskParams.stack = auxiliaryTaskStack;
taskParams.stackSize = AUXILIARY_TASK_STACK_SIZE;
taskParams.priority = AUXILIARY_TASK_PRIORITY;
PIN_setOutputValue(ledPinHandle, Board_LED2, 1);
PIN_setOutputValue(ledPinHandle, Board_LED2, 0);
Task_construct(&auxiliaryTask, SimpleBLECentral_auxiliaryTaskFxn, &taskParams, NULL);
PIN_setOutputValue(ledPinHandle, Board_LED2, 1);
PIN_setOutputValue(ledPinHandle, Board_LED2, 0);
}
static void SimpleBLECentral_auxiliaryTaskFxn(UArg a0, UArg a1)
{
PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
PIN_setOutputValue(ledPinHandle, Board_LED1, 0);
for (;;)
{
PIN_setOutputValue(ledPinHandle, Board_LED1, 1);
PIN_setOutputValue(ledPinHandle, Board_LED1, 0);
}
}
As you see, the auxiliary task has lower priority compared to the main task. So the main task is allowed to stop the auxiliary task. But as soon as the main task has no more work to do, the auxiliary task should continue running. The auxiliary task does not use a semaphore and it does not register with ICall. Is this an issue?
Here some code of the main task:
static void SimpleBLECentral_mainCentralTaskFxn(UArg a0, UArg a1)
{
// ******************************************************************
// N0 STACK API CALLS CAN OCCUR BEFORE THIS CALL TO ICall_registerApp
// ******************************************************************
// Register the current thread as an ICall dispatcher application
// so that the application can send and receive messages.
ICall_registerApp(&selfEntityMainCentral, &semMainCentralTask);
// Hard code the DB Address till CC2650 board gets its own IEEE address
//uint8 bdAddress[B_ADDR_LEN] = { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 };
//HCI_EXT_SetBDADDRCmd(bdAddress);
// Set device's Sleep Clock Accuracy
//HCI_EXT_SetSCACmd(40);
// Create an RTOS queue for message from profile to be sent to app.
appMsgQueueMainCentral = Util_constructQueue(&appMsgMainCentral);
// Initialize application
SimpleBLECentral_init();
// Application main loop
for (;;)
{
// Waits for a signal to the semaphore associated with the calling thread.
// Note that the semaphore associated with a thread is signaled when a
// message is queued to the message receive queue of the thread or when
// ICall_signal() function is called onto the semaphore.
PIN_setOutputValue(ledPinHandle, Board_LED3, 1);
ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER);
PIN_setOutputValue(ledPinHandle, Board_LED3, 0);
if (errno == ICALL_ERRNO_SUCCESS)
{
ICall_EntityID dest;
ICall_ServiceEnum src;
ICall_HciExtEvt *pMsg = NULL;
if (ICall_fetchServiceMsg(&src, &dest, (void**)&pMsg) == ICALL_ERRNO_SUCCESS)
{
if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntityMainCentral))
{
// Process inter-task message
SimpleBLECentral_processStackMsg((ICall_Hdr *)pMsg);
}
if (pMsg)
{
ICall_freeMsg(pMsg);
}
}
}
// If RTOS queue is not empty, process app message
while (!Queue_empty(appMsgQueueMainCentral))
{
...
I connected a logic analyzer to the evaluation board to display the LED status. I see that both tasks get created correctly. The auxiliary task enters the infinite loop (LED1 going high and low many times). But if LED3 goes low (the main task passes ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER); ), then the auxiliary tasks gets never scheduled again, even if LED3 goes high again (which is the case if the main task is waiting for work again). What am I doing wrong? I think a stack size of 512 bytes is enough. Here the logic analyzer output:
D0 is connected to LED1, D1 to LED2, D2 to LED3 and D3 to led4.
Predefined symbols:
ICALL_MAX_NUM_TASKS=4
ICALL_MAX_NUM_ENTITIES=7
Both numbers are increased by one as described here:
.
Is increasing these nubers really necessary, because my task is a pure RTOS task and has (as far as I know) nothing to do with ICall, right?
Remark: If i switch the task priorities, then the auxiliary task causes starvation of the main task: LED1 is going high and low in an infinite loop that is never left.
