Changed the way the ARM7/9 GCC ports enter interrupts that can cause a context switch.

This commit is contained in:
Richard Barry 2007-10-28 13:55:35 +00:00
parent c54ec1c639
commit ada7fa862d
24 changed files with 322 additions and 275 deletions

View file

@ -96,6 +96,8 @@
#define mainLED_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
#define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
#define mainLIST_BUFFER_SIZE 2048
#define mainNO_DELAY ( 0 )
#define mainSHORT_DELAY ( 150 / portTICK_RATE_MS )
/* Task priorities. */
#define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
@ -178,7 +180,7 @@ int main( void )
/* Start the scheduler. */
vTaskStartScheduler();
/* The scheduler should now running, so we will only ever reach here if we
/* The scheduler should now be running, so we will only ever reach here if we
ran out of heap space. */
return 0;
@ -290,7 +292,7 @@ static void vButtonHandlerTask( void *pvParameters )
static portCHAR cListBuffer[ mainLIST_BUFFER_SIZE ];
const portCHAR *pcList = &( cListBuffer[ 0 ] );
const portCHAR * const pcHeader = "\nTask State Priority Stack #\n************************************************";
extern void (vButtonISR) ( void );
extern void (vButtonISRWrapper) ( void );
/* Configure the interrupt. */
portENTER_CRITICAL();
@ -303,15 +305,19 @@ extern void (vButtonISR) ( void );
/* Setup the VIC for EINT 1. */
VICIntSelect &= ~mainEINT_1_VIC_CHANNEL_BIT;
VICIntEnable |= mainEINT_1_VIC_CHANNEL_BIT;
VICVectAddr1 = ( portLONG ) vButtonISR;
VICVectAddr1 = ( portLONG ) vButtonISRWrapper;
VICVectCntl1 = mainEINT_1_ENABLE_BIT | mainEINT_1_CHANNEL;
}
portEXIT_CRITICAL();
for( ;; )
{
/* For debouncing, wait a while then clear the semaphore. */
vTaskDelay( mainSHORT_DELAY );
xSemaphoreTake( xButtonSemaphore, mainNO_DELAY );
/* Wait for an interrupt. */
while( xSemaphoreTake( xButtonSemaphore, portMAX_DELAY ) != pdPASS );
xSemaphoreTake( xButtonSemaphore, portMAX_DELAY );
/* Send the column headers to the print task for display. */
xQueueSend( xPrintQueue, &pcHeader, portMAX_DELAY );

View file

@ -39,18 +39,43 @@
/*
* Interrupt routine that simply wakes vButtonHandlerTask on each interrupt
* generated by a push of the built in button.
* generated by a push of the built in button. The wrapper takes care of
* the ISR entry. This then calls the actual handler function to perform
* the work. This work should not be done in the wrapper itself unless
* you are absolutely sure that no stack space is used.
*/
void vButtonISR( void ) __attribute__ ((naked));
void vButtonISRWrapper( void ) __attribute__ ((naked));
void vButtonHandler( void );
void vButtonHandler( void )
{
extern xSemaphoreHandle xButtonSemaphore;
void vButtonISR( void )
if( xSemaphoreGiveFromISR( xButtonSemaphore, pdFALSE ) )
{
/* We have woken a task. Calling "yield from ISR" here will ensure
the interrupt returns to the woken task if it has a priority higher
than the interrupted task. */
portYIELD_FROM_ISR();
}
EXTINT = isrCLEAR_EINT_1;
VICVectAddr = 0;
}
/*-----------------------------------------------------------*/
void vButtonISRWrapper( void )
{
portENTER_SWITCHING_ISR();
xSemaphoreGiveFromISR( xButtonSemaphore, pdFALSE );
EXTINT = isrCLEAR_EINT_1;
VICVectAddr = 0;
portEXIT_SWITCHING_ISR( pdTRUE );
/* Save the context of the interrupted task. */
portSAVE_CONTEXT();
/* Call the handler to do the work. This must be a separate function to
the wrapper to ensure the correct stack frame is set up. */
vButtonHandler();
/* Restore the context of whichever task is going to run once the interrupt
completes. */
portRESTORE_CONTEXT();
}