Synchronizing task w/interrupt and semaphore
I’ve run into a problem that I can’t resolve: As long as I don’t call any FreeRTOS API’s from within an interrupt routine, everything worksfine. But when I try to use xSemaphoreGiveFromISR/xSemaphoreTake to synchronize a task using an interrupt, I begin to have problems.
FYI: I’m using the Luminary Micro LM3S811 evaluation board, their driver library version 1427, FreeRTOS V4.3.1, and the free evaluation version (V4.42A) of IAR’s Embedded Workbench.
I’ve simplified the application down to the minimal code that demonstrates the problem: The CPU is running at the default 6Mhz rate. A hardware timer is configured to interrupt 100 times per second. THe ISR merely clears the interrupt and calls xSemaphoreGiveFromISR. The task pends on the semaphore; when released, it increments an integer and sends it to the onboard display. Thus the application should display a continuously incrementing number on the onboard display. It does so for a while (up to 487) and then hangs. Where it hangs changes if I change the stack size or the interrupt rate, but it always hangs.
The code is attached. Any help would be most appreciated!
Dan
#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_types.h"
#include "timer.h"
#include "interrupt.h"
#include "sysctl.h"
#include "osram96x16x1.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
xSemaphoreHandle TimerSemaphore = NULL ;
void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT) ;
xSemaphoreGiveFromISR(TimerSemaphore, pdFALSE) ;
}
char *Convert(unsigned long int n, char *bfr)
{
if (n >= 10) bfr = Convert(n / 10, bfr) ;
*bfr++ = (n % 10) + ‘0’ ;
*bfr = ‘