Hi
I’m working for the first time with FreeRTOS using a testboard from Atmel (ATSAM4S-XPRO) with the ARM processor SAM4SD32C (Atmel Studio 7.0, FreeRTOS 9.0) and port ARM_CM3.
http://www.microchip.com/DevelopmentTools/ProductDetails.aspx?PartNO=ATSAM4S-XPRO
I tried to implement an example using interrupts and binary semaphores:
~~~
//Declarations and definitions
SemaphoreHandle
t xInterruptSemaphore;
void pin
edgehandler(const uint32
t id, const uint32t index);
void vInterrupt_Task(void *pvParameters);
//****************************INTERRUPT TASKS************************//
//Interrupt function called when a button is pressed
void pin
edgehandler(const uint32
t id, const uint32t index)
{
if ((id == ID
PIOA) && (index == PIOPA2)){
print_str(“Interrupt detected”);
BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
if(xInterrupt_Semaphore != NULL){
xSemaphoreGiveFromISR( xInterrupt_Semaphore, &xHigherPriorityTaskWoken );
}
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
}
//Task released by the interrupt function
void vInterrupt
Task(void *pvParameters){
for(;;){
//Check Semaphore
if(xInterruptSemaphore != NULL){
BaseType
t semtaken = xSemaphoreTake( xInterrupt
Semaphore, pdMSTO_TICKS(10000) );
if(sem_taken == pdPASS){
print_str("Interrupt Task processed");
}
else{
print_str("No Interrupt in 10s");
}
}
}
}
//****************************END INTERRUPT TASKS************************//
//Part of main
int main (void)
{
…
//Create semaphore
xInterrupt_Semaphore = xSemaphoreCreateBinary();
if(xInterrupt_Semaphore != NULL){
//Create Task releasd by the interrupt function
xTaskCreate(vInterrupt_Task,"Interrupt Task",configMINIMAL_STACK_SIZE+1000,NULL,2, &vInterrupt_Task_id);
//Configure Interrupt on Pin PA2 (button) with interrupt function "pin_edge_handler"
pio_handler_set(PIOA, ID_PIOA, PIO_PA2, PIO_IT_FALL_EDGE, pin_edge_handler);
//Start Interrupt
pio_enable_interrupt(PIOA, PIO_PA2);
NVIC_EnableIRQ(PIOA_IRQn);
}
vTaskStartScheduler();
}
~~~
This does not work, the programm jumps to the following code in the portmacro.h when I press the interrupt button for the first time:
~~~
uint32_t ulNewBASEPRI;
__asm volatile
(
" mov %0, %1 n"
" msr basepri, %0 n"
" isb n"
" dsb n"
:"=r" (ulNewBASEPRI) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY )
);
}
~~~
Pressing the button further times has no effect, the debugger says that I didn’t return to the interrupt task.
As soon as I delete the “xSemaphoreGiveFromISR” line, it works and I can enter the interrupt task several times.
Any idea?
Thanks!
Sebastian