Part Number: CC3220SF-LAUNCHXL
Hello,
I'm analyzing the out_of_box project aobut the CC3220SF and I need some clarifications about POSIX threads:
1) In the main() a posix thread is configurated and created by pthread_attr_init(), pthread_attr_setdetachstate(),pthread_attr_setschedparam() and pthread_create() functions. In this way, the thread is a detached thread, after all these functions, BIOS_start() is called, so: is the thread always started by the pthread_create() or by the BIOS_start()? (I think the first one)
2) Why the others threads (inside the out_of_the_box.c file) are inizialized and started into a main thread and not in the main() function?
3) The others threads (inside the out_of_the_box.c file) are not set to detached mode, so for default they are joinable. I check that a joinable thread is a blocking thread, and all threads inside the inside the out_of_the_box.c file are launched sequentially, how can they work at the same time?
4) the threads inside the out_of_the_box.c file keep running also when the mainthread exit ?
4) the threads inside the out_of_the_box.c are dependent from the the mainthread stack size ?
I attach the code.
Thanks !!!
int main(void)
{
pthread_t thread;
pthread_attr_t pAttrs;
struct sched_param priParam;
int retc;
int detachState;
/* Call board init functions */
Board_initGeneral();
/* Set priority and stack size attributes */
pthread_attr_init(&pAttrs);
priParam.sched_priority = 1;
detachState = PTHREAD_CREATE_DETACHED;
retc = pthread_attr_setdetachstate(&pAttrs, detachState);
if(retc != 0)
{
/* pthread_attr_setdetachstate() failed */
while(1)
{
;
}
}
pthread_attr_setschedparam(&pAttrs, &priParam);
retc |= pthread_attr_setstacksize(&pAttrs, THREADSTACKSIZE);
if(retc != 0)
{
/* pthread_attr_setstacksize() failed */
while(1)
{
;
}
}
retc = pthread_create(&thread, &pAttrs, mainThread, NULL);
if(retc != 0)
{
/* pthread_create() failed */
while(1)
{
;
}
}
BIOS_start();
return (0);
}
void * mainThread(void *arg)
{
int32_t RetVal;
pthread_attr_t pAttrs;
pthread_attr_t pAttrs_spawn;
struct sched_param priParam;
struct timespec ts = {0};
GPIO_init();
SPI_init();
I2C_init();
/* init Terminal, and print App name */
InitTerm();
/* initialize the realtime clock */
clock_settime(CLOCK_REALTIME, &ts);
InitializeAppVariables();
/* Switch off all LEDs on boards */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_OFF);
/* initializes signals for all tasks */
sem_init(&Provisioning_ControlBlock.connectionAsyncEvent, 0, 0);
sem_init(&Provisioning_ControlBlock.provisioningDoneSignal, 0, 0);
sem_init(&Provisioning_ControlBlock.provisioningConnDoneToOtaServerSignal,
0,
0);
sem_init(&LinkLocal_ControlBlock.otaReportServerStartSignal, 0, 0);
sem_init(&LinkLocal_ControlBlock.otaReportServerStopSignal, 0, 0);
/* create the sl_Task */
pthread_attr_init(&pAttrs_spawn);
priParam.sched_priority = SPAWN_TASK_PRIORITY;
RetVal = pthread_attr_setschedparam(&pAttrs_spawn, &priParam);
RetVal |= pthread_attr_setstacksize(&pAttrs_spawn, TASK_STACK_SIZE);
RetVal = pthread_create(&gSpawnThread, &pAttrs_spawn, sl_Task, NULL);
if(RetVal)
{
/* Handle Error */
UART_PRINT("Unable to create sl_Task thread \n");
while(1)
{
;
}
}
RetVal = sl_Start(0, 0, 0);
if(RetVal >= 0)
{
DisplayBanner(APPLICATION_NAME, APPLICATION_VERSION);
RetVal = sl_Stop(SL_STOP_TIMEOUT);
if(RetVal < 0)
{
/* Handle Error */
UART_PRINT("\n sl_Stop failed\n");
while(1)
{
;
}
}
}
else if((RetVal < 0) && (RetVal != SL_ERROR_RESTORE_IMAGE_COMPLETE))
{
/* Handle Error */
UART_PRINT("\n sl_Start failed\n");
UART_PRINT("\n %s Example Ver. %s\n",APPLICATION_NAME,
APPLICATION_VERSION);
while(1)
{
;
}
}
pthread_attr_init(&pAttrs);
priParam.sched_priority = 1;
RetVal = pthread_attr_setschedparam(&pAttrs, &priParam);
RetVal |= pthread_attr_setstacksize(&pAttrs, TASK_STACK_SIZE);
if(RetVal)
{
/* Handle Error */
UART_PRINT("Unable to configure provisioningTask thread parameters \n");
while(1)
{
;
}
}
RetVal = pthread_create(&gProvisioningThread, &pAttrs, provisioningTask,
NULL);
if(RetVal)
{
/* Handle Error */
UART_PRINT("Unable to create provisioningTask thread \n");
while(1)
{
;
}
}
pthread_attr_init(&pAttrs);
priParam.sched_priority = 1;
RetVal = pthread_attr_setschedparam(&pAttrs, &priParam);
RetVal |= pthread_attr_setstacksize(&pAttrs, LINKLOCAL_STACK_SIZE);
if(RetVal)
{
/* Handle Error */
UART_PRINT("Unable to configure linkLocalTask thread parameters \n");
while(1)
{
;
}
}
RetVal = pthread_create(&gLinklocalThread, &pAttrs, linkLocalTask, NULL);
if(RetVal)
{
/* Handle Error */
UART_PRINT("Unable to create linkLocalTask thread \n");
while(1)
{
;
}
}
pthread_attr_init(&pAttrs);
priParam.sched_priority = 1;
RetVal = pthread_attr_setschedparam(&pAttrs, &priParam);
RetVal |= pthread_attr_setstacksize(&pAttrs, CONTROL_STACK_SIZE);
if(RetVal)
{
/* Handle Error */
UART_PRINT("Unable to configure controlTask thread parameters \n");
while(1)
{
;
}
}
RetVal = pthread_create(&gControlThread, &pAttrs, controlTask, NULL);
if(RetVal)
{
/* Handle Error */
UART_PRINT("Unable to create controlTask thread \n");
while(1)
{
;
}
}
pthread_attr_init(&pAttrs);
priParam.sched_priority = 5;
RetVal = pthread_attr_setschedparam(&pAttrs, &priParam);
RetVal |= pthread_attr_setstacksize(&pAttrs, TASK_STACK_SIZE);
if(RetVal)
{
/* Handle Error */
UART_PRINT("Unable to configure otaTask thread parameters \n");
while(1)
{
;
}
}
RetVal = pthread_create(&gOtaThread, &pAttrs, otaTask, NULL);
if(RetVal)
{
/* Handle Error */
UART_PRINT("Unable to create otaTask thread \n");
while(1)
{
;
}
}
return(0);
}