|
|
@ -10,8 +10,7 @@ hw_timer_t * _uclockTimer = NULL; |
|
|
|
|
|
|
|
|
|
|
|
// FreeRTOS main clock task size in bytes
|
|
|
|
// FreeRTOS main clock task size in bytes
|
|
|
|
#define CLOCK_STACK_SIZE 2048 |
|
|
|
#define CLOCK_STACK_SIZE 2048 |
|
|
|
// semaphore to signal the task from the ISR
|
|
|
|
TaskHandle_t taskHandle; |
|
|
|
SemaphoreHandle_t _semaphore; |
|
|
|
|
|
|
|
// mutex to protect the shared resource
|
|
|
|
// mutex to protect the shared resource
|
|
|
|
SemaphoreHandle_t _mutex; |
|
|
|
SemaphoreHandle_t _mutex; |
|
|
|
// mutex control for task
|
|
|
|
// mutex control for task
|
|
|
@ -28,21 +27,20 @@ void uClockHandler(); |
|
|
|
// ISR handler
|
|
|
|
// ISR handler
|
|
|
|
void ARDUINO_ISR_ATTR handlerISR(void) |
|
|
|
void ARDUINO_ISR_ATTR handlerISR(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// notify the clockTask using the semaphore
|
|
|
|
|
|
|
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE; |
|
|
|
BaseType_t xHigherPriorityTaskWoken = pdFALSE; |
|
|
|
xSemaphoreGiveFromISR(_semaphore, &xHigherPriorityTaskWoken); |
|
|
|
// Send a notification to task1
|
|
|
|
|
|
|
|
vTaskNotifyGiveFromISR(taskHandle, &xHigherPriorityTaskWoken); |
|
|
|
// context switch is required? request it
|
|
|
|
|
|
|
|
if (xHigherPriorityTaskWoken == pdTRUE) |
|
|
|
|
|
|
|
portYIELD_FROM_ISR(xHigherPriorityTaskWoken); |
|
|
|
portYIELD_FROM_ISR(xHigherPriorityTaskWoken); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// task for user clock process
|
|
|
|
// task for user clock process
|
|
|
|
void clockTask(void *pvParameters) |
|
|
|
void clockTask(void *pvParameters) |
|
|
|
{ |
|
|
|
{ |
|
|
|
while (1) |
|
|
|
while (1) { |
|
|
|
if (xSemaphoreTake(_semaphore, portMAX_DELAY) == pdTRUE) |
|
|
|
// wait for a notification from ISR
|
|
|
|
|
|
|
|
ulTaskNotifyTake(pdTRUE, portMAX_DELAY); |
|
|
|
uClockHandler(); |
|
|
|
uClockHandler(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void initTimer(uint32_t init_clock) |
|
|
|
void initTimer(uint32_t init_clock) |
|
|
@ -58,14 +56,11 @@ void initTimer(uint32_t init_clock) |
|
|
|
// activate it!
|
|
|
|
// activate it!
|
|
|
|
timerAlarmEnable(_uclockTimer); |
|
|
|
timerAlarmEnable(_uclockTimer); |
|
|
|
|
|
|
|
|
|
|
|
// initialize the semaphore
|
|
|
|
|
|
|
|
_semaphore = xSemaphoreCreateBinary(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// initialize the mutex for shared resource access
|
|
|
|
// initialize the mutex for shared resource access
|
|
|
|
_mutex = xSemaphoreCreateMutex(); |
|
|
|
_mutex = xSemaphoreCreateMutex(); |
|
|
|
|
|
|
|
|
|
|
|
// create the clockTask
|
|
|
|
// create the clockTask
|
|
|
|
xTaskCreate(clockTask, "clockTask", CLOCK_STACK_SIZE, NULL, 1, NULL); |
|
|
|
xTaskCreate(clockTask, "clockTask", CLOCK_STACK_SIZE, NULL, 1, &taskHandle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void setTimer(uint32_t us_interval) |
|
|
|
void setTimer(uint32_t us_interval) |
|
|
|