Other Parts Discussed in Thread: SYSBIOS
Tool/software: Code Composer Studio
Hi TI,
Recently, I'm making a 2-threaded code for CC2640R2
However, the CC2640R2 MCU crushes after executing the code between "for(;;){}" about 1500-1600 times.
To add an additional task thread, I'm using the code below:
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/knl/Queue.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Swi.h>
/*******
//These 4 lines below are my custom codes. Never mind these.
#include "adc_task.h"
#include "util.h"
#include "gpioCustom.h"
#include "main.h"
*/
#include "st_util.h"
// Task configuration
#define ADC_TASK_PRIORITY 1
#ifndef ADC_TASK_STACK_SIZE
#define ADC_TASK_STACK_SIZE 256
#endif
// Task configuration
Task_Struct adcTask;
Char adcTaskStack[ADC_TASK_STACK_SIZE];
Event_Handle eventADCHandle;
// Event globally used to post local events and pend on system and
// local events.
void adc_perodicTask(void);
void adc_startClock(void);
void adc_stopClock(void);
// Internal Events for RTOS application
#define ADC_PERIODIC_EVT Event_Id_00
#define ADC_START_EVT Event_Id_01
#define ADC_STOP_EVT Event_Id_02
#define ADC_ISOLATE_RUN 0
static void adc_taskFunction(UArg a0, UArg a1)
{
uint32_t events;
uint32_t timeOutInTicks = BIOS_WAIT_FOREVER;
if(ADC_ISOLATE_RUN){
timeOutInTicks = 200 * (1000 / Clock_tickPeriod);
}
Event_Params eventParams;
Event_Struct structEvent;
Event_Params_init(&eventParams);
Event_construct(&structEvent, &eventParams);
eventADCHandle = Event_handle(&structEvent);
if(eventADCHandle == NULL){
while (1);
}
// Application main loop
for (;;)
{
events = Event_pend(eventADCHandle,
Event_Id_NONE,
ADC_START_EVT | ADC_STOP_EVT,
timeOutInTicks);
adc_perodicTask();
if(ADC_ISOLATE_RUN){
timeOutInTicks = 200 * (1000 / Clock_tickPeriod);
}else{
if(events & ADC_STOP_EVT){
timeOutInTicks = BIOS_WAIT_FOREVER;
}
if(events & ADC_START_EVT){
timeOutInTicks = 200 * (1000 / Clock_tickPeriod);
}
}
}
}
void adc_createTask(void)
{
Task_Params taskParams;
// Configure task
Task_Params_init(&taskParams);
taskParams.stack = adcTaskStack;
taskParams.stackSize = ADC_TASK_STACK_SIZE;
taskParams.priority = ADC_TASK_PRIORITY;
Task_construct(&adcTask, adc_taskFunction, &taskParams, NULL);
}
uint8_t adcPointer = 0;
void adc_perodicTask(void){
if(adcPointer == 0){
adcPointer = 1;
PIN_OnlyGLight(); // This controls GREEN LED light
}else{
adcPointer = 0;
PIN_GDark(); // This controls GREEN LED dark
}
}
//Start Or Stop Clock(For outside code to control task running or stopping)
void adc_startClock(void){
Event_post(eventADCHandle, ADC_START_EVT);
}
void adc_stopClock(void){
Event_post(eventADCHandle, ADC_STOP_EVT);
}
I wonder where is the bug, or where is the incorrect handling.
P.S. The original main task thread is the example named "Simple_Peripheral.c".
Thanks.