Other Parts Discussed in Thread: CC1350,
Tool/software: Code Composer Studio
I've been having a problem with the CC1350's timer peripherals. I'm using TI-RTOS in CCS, with a LAUNCHXL-CC1350 board. When I run the board in debug mode, I get what I expect based on the attached code. Every 15ms the callback gets called, and my LED gets toggled.
When I run in "flash" or "Run" mode, my callback gets triggered erratically based on the load in the other pthreads, and increasing the thread_sleep call seems to increase the delay. With the current version of the code it's at 100ms period.
So I have a few questions. One is whether the pthreads are running in new tasks, or all grouped into one lump that's getting delayed together. The documentation suggests it's supposed to be different threads. Two, is the callback a hardware interrupt (which I'd have expected from a timer) or just another task? And is that task part of the delayed thread group? I expected increasing the thread sleeps to give my callback MORE time to complete if were running as a thread and not a hardware interrupt.
Third, why is the debug behaviour different?
/*
* ======== spimaster.c ========
*/
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
/* POSIX Header files */
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/sysbios/hal/Timer.h>
#include <xdc/runtime/Types.h>
#include <ti/sysbios/hal/Hwi.h>
#include <xdc/std.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <xdc/cfg/global.h>
/* Example/Board Header files */
#include "Board.h"
/* Custom/Helper Header files */
#define THREADSTACKSIZE (1024)
Timer_Handle tHandle;
Timer_Params tParams;
void* timer_callback(void* arg0){
GPIO_toggle(Board_GPIO_LED0);
return(NULL);
// return NULL;
// int value;
// sem_getvalue(&sync_ready, &value);
// if(!value)
// sem_post(&sync_ready);
// return NULL;
}
/*
* Thread for controlling radio
*/
void* RFmasterThread(void* arg0){
Timer_Params_init(&tParams);
tParams.period = 15000;
tParams.runMode = Timer_RunMode_CONTINUOUS;
tParams.startMode = Timer_StartMode_USER;
tHandle = Timer_create(0, (Timer_FuncPtr)timer_callback, &tParams, NULL);
if(!tHandle){
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
while(1);
}
uint32_t key = Hwi_disable();
Timer_start(tHandle);
Hwi_restore(key);
while(1){
Task_sleep(1000);
}
return NULL;
}
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
pthread_t thread1;
pthread_attr_t attrs;
struct sched_param priParam;
int retc;
int detachState;
/* Call driver init functions. */
GPIO_init();
/* Configure the LED pins */
GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_setConfig(Board_GPIO_LED1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_OFF);
/* Create application threads */
pthread_attr_init(&attrs);
detachState = PTHREAD_CREATE_DETACHED;
/* Set priority and stack size attributes */
retc = pthread_attr_setdetachstate(&attrs, detachState);
if (retc != 0) {
/* pthread_attr_setdetachstate() failed */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
while (1);
}
retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
if (retc != 0) {
/* pthread_attr_setstacksize() failed */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
while (1);
}
/* Create SPI thread */
priParam.sched_priority = 1;
pthread_attr_setschedparam(&attrs, &priParam);
/* Create RF thread */
retc = pthread_create(&thread1, &attrs, RFmasterThread,NULL);
if (retc != 0) {
/* pthread_create() failed */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
while (1);
}
while(1){
Task_sleep(1000);
}
//FIXME
return (NULL);
}