Other Parts Discussed in Thread: CC3200, SYSBIOS
Hi,
I am using a Timer to implement a "delayMicroSeconds" function, which does a semaphore_pend on a semaphore that will be posted by the timer.
I have also added a PWM control. When I init the PWM, the second delayMicroseconds() basically blocks on the semaphore_pend forever - which indicates the timer may not be getting fired.
I was wondering if the introduction of the PWM timer is conflicting with the one-shot timer. For the PWM I am using TIMERA0_BASE, TIMERA. For the one-shot timer, I use TIMER_ANY
I init the Timer_Handle so
Timer_Handle timerHandle;
void microSecondTimerFxn(UArg arg0) {
Semaphore_post(semMicroSecDelay);
}
void init()
{
Error_Block eb;
Timer_Params timerParams;
Task_Handle taskHandle;
Error_init(&eb);
Timer_Params_init(&timerParams);
timerParams.startMode = Timer_StartMode_USER;
timerParams.runMode = Timer_RunMode_ONESHOT;
timerHandle = Timer_create(Timer_ANY, microSecondTimerFxn, &timerParams, &eb);
if (timerHandle == NULL) {
System_abort("[pmSensor] Timer create failed");
}
...
}
void delayMicroseconds(int delayus)
{
// disable interrupts if an interrupt could lead to
// another call to Timer_start().
UInt key = Hwi_disable();
Timer_setPeriodMicroSecs(timerHandle, delayus);
Timer_start(timerHandle);
Hwi_restore(key);
System_printf("[delayMicroSeconds] semaphore pend\n");
Semaphore_pend(semMicroSecDelay, BIOS_WAIT_FOREVER);
}
void doStuff() {
...
delayMicroseconds(100);
....
delayMicroseconds(100); <----- hangs here on pend, consistently
....
delayMicroseconds(100);
....
}
Here is the PWM stuff
PWM_Handle fanPWMHandle = NULL;
uint16_t pwmPeriod = 3000; // Period and duty in microseconds
void FAN_init()
{
PWM_Params params;
PWM_Params_init(¶ms);
params.period = pwmPeriod;
fanPWMHandle = PWM_open(Board_PWMFAN, ¶ms);
if (fanPWMHandle == NULL) {
System_abort("Board_PWMFAN did not open\n");
} else {
System_printf("Board_PWNFAN has been initialized!\n");
}
}
void FAN_set(int fan, int speedPercent)
{
if (!fanPWMHandle) {
return;
}
System_printf("[FAN] set %d fan to speed %d\n", fan, speedPercent);
uint16_t duty = (speedPercent/100.0 * pwmPeriod);
PWM_setDuty(fanPWMHandle, duty);
}
Board.h
#define Board_PWMFAN CC3200_LAUNCHXL_PWM0
CC3200_LAUNCHXL.h
/*!
* @def CC3200_LAUNCHXL_PWMName
* @brief Enum of PWM names on the CC3200_LAUNCHXL dev board
*/
typedef enum CC3200_LAUNCHXL_PWMName {
CC3200_LAUNCHXL_PWM0 = 0,
CC3200_LAUNCHXL_PWMCOUNT
} CC3200_LAUNCHXL_PWMName;
CC3200_LAUNCHXL.c
/*
* =============================== PWM ===============================
*/
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(PWM_config, ".const:PWM_config")
#pragma DATA_SECTION(pwmTimerCC3200HWAttrs, ".const:pwmTimerCC3200HWAttrs")
#endif
#include <ti/drivers/PWM.h>
#include <ti/drivers/pwm/PWMTimerCC3200.h>
PWMTimerCC3200_Object pwmTimerCC3200Objects[CC3200_LAUNCHXL_PWMCOUNT];
const PWMTimerCC3200_HWAttrs pwmTimerCC3200HWAttrs[CC3200_LAUNCHXL_PWMCOUNT] = {
{ /* CC3200_LAUNCHXL_PWM0 */
/* TIMERA0A - From Redbear pins_energia.h */
.baseAddr = TIMERA0_BASE,
.timer = TIMER_A
}
// { /* CC3200_LAUNCHXL_PWM7 */
// .baseAddr = TIMERA3_BASE,
// .timer = TIMER_B
// }
};
const PWM_Config PWM_config[] = {
{
.fxnTablePtr = &PWMTimerCC3200_fxnTable,
.object = &pwmTimerCC3200Objects[0],
.hwAttrs = &pwmTimerCC3200HWAttrs[0]
},
// {
// .fxnTablePtr = &PWMTimerCC3200_fxnTable,
// .object = &pwmTimerCC3200Objects[1],
// .hwAttrs = &pwmTimerCC3200HWAttrs[1]
// },
{NULL, NULL, NULL}
};
/*
* ======== CC3200_LAUNCHXL_initPWM ========
*/
void CC3200_LAUNCHXL_initPWM(void)
{
PWM_init();
}
Thanks,
Sridhar