This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-CC2640R2: what is meaning of this code?

Part Number: LAUNCHXL-CC2640R2
//Stack size in bytes
#define THREADSTACKSIZE 1024
// PIN_init() should be called as early as possible in boot
void main() {
pthread_t thread;
pthread_attr_t attrs;
struct sched_param priParam;
int retc;
int detachState;
//Board_initGeneral() will call PIN_init(BoardGpioInitTable)
Board_initGeneral();
// Set priority and stack size attributes
pthread_attr_init(&attrs);
priParam.sched_priority = 1;
detachState = PTHREAD_CREATE_DETACHED;
retc = pthread_attr_setdetachstate(&attrs, detachState);
if (retc != 0) {
// pthread_attr_setdetachstate() failed
while (1);
}
pthread_attr_setschedparam(&attrs, &priParam);
retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
if (retc != 0) {
// pthread_attr_setstacksize() failed
while (1);
}
retc = pthread_create(&thread, &attrs, mainThread, NULL);
if (retc != 0) {
// pthread_create() failed
while (1);
}
// Start kernel
Add_Kernel_Start_Call();
return (0);
}
// Human user interface PIN state/handle
PIN_State hStateHui;
#define HUI_LED_A PIN_ID(11)
#define HUI_LED_B PIN_ID(10)
#define HUI_LED_C PIN_ID(9)
#define HUI_BUTTON_A PIN_ID(23)
#define HUI_BUTTON_B PIN_ID(24)
static void taskStartFxn(UArg a0, UArg a1) {
// Define pins used by Human user interface and initial configuration
const PIN_Config pinListHui[] = {
HUI_LED_A | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
HUI_LED_B | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
HUI_BUTTON_A | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,
HUI_BUTTON_B | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS,
PIN_TERMINATE
};
// Get handle to this collection of pins
if (!PIN_open(&hStateHui, pinListHui)) {
// Handle allocation error
}
// ...
// We can also add (and remove) pins to a set at run time
PIN_Status status = PIN_add(
&hStateHui,
HUI_LED_C | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
);
if (status != PIN_SUCCESS) {
// Handling allocation error is especially important with PIN_add()
}
// ...
huiDoSomething();
// Before ending task, make sure to deallocate pins. They will return
// to the default configurations provided in PIN_init()
PIN_close(&hStateHui);
}
WhAT IS THE USE OF THIS THREAD FUNCTION ?
HOW IT IS GOING TO USEFUL IN CODE?