From 562ed7a05286efb4eb6c442ff434fd0793cd6e50 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Wed, 5 Jan 2011 14:10:14 +0000 Subject: [PATCH] Minor formatting changes to the GCC PSoC demo. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1225 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../FreeRTOS_Demo.cydsn/IntQueueTimer.c | 8 +- .../FreeRTOS_Demo.cydsn/ParTest.c | 9 +- .../FreeRTOS_Demo.cydsn/Serial.c | 66 ++++++----- .../FreeRTOS_Demo.cydsn/main.c | 104 ++++++++---------- 4 files changed, 92 insertions(+), 95 deletions(-) diff --git a/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/IntQueueTimer.c b/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/IntQueueTimer.c index 94787b3d4..0005bf2a4 100644 --- a/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/IntQueueTimer.c +++ b/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/IntQueueTimer.c @@ -60,8 +60,8 @@ extern portBASE_TYPE xFirstTimerHandler( void ); extern portBASE_TYPE xSecondTimerHandler( void ); /*---------------------------------------------------------------------------*/ -CY_ISR_PROTO(vHighFrequencyFirstISR); -CY_ISR_PROTO(vHighFrequencySecondISR); +CY_ISR_PROTO( vHighFrequencyFirstISR ); +CY_ISR_PROTO( vHighFrequencySecondISR ); /*---------------------------------------------------------------------------*/ /** @@ -73,11 +73,11 @@ void vInitialiseTimerForIntQueueTest( void ) { /* Initialise and start the First Timer ISR. */ isr_High_Frequency_2000Hz_ClearPending(); - isr_High_Frequency_2000Hz_StartEx((cyisraddress)vHighFrequencyFirstISR); + isr_High_Frequency_2000Hz_StartEx( ( cyisraddress ) vHighFrequencyFirstISR ); /* Initialise and start the Second Timer ISR. */ isr_High_Frequency_2001Hz_ClearPending(); - isr_High_Frequency_2001Hz_StartEx((cyisraddress)vHighFrequencySecondISR); + isr_High_Frequency_2001Hz_StartEx( ( cyisraddress ) vHighFrequencySecondISR ); } taskEXIT_CRITICAL(); } diff --git a/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/ParTest.c b/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/ParTest.c index e98e673de..56f305303 100644 --- a/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/ParTest.c +++ b/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/ParTest.c @@ -67,7 +67,8 @@ static volatile char cLedOutput[ partstMAX_LED ]; void vParTestInitialise( void ) { long lIndex; - for ( lIndex = 0; lIndex < partstMAX_LED; lIndex++ ) + + for( lIndex = 0; lIndex < partstMAX_LED; lIndex++ ) { cLedOutput[ lIndex ] = 0; } @@ -78,7 +79,7 @@ void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue ) { taskENTER_CRITICAL(); { - switch ( uxLED ) + switch( uxLED ) { case 0: Pin_LED_0_Write( xValue & 0x1 ); @@ -100,7 +101,7 @@ void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue ) taskEXIT_CRITICAL(); /* Record the output for the sake of toggling. */ - if ( uxLED < partstMAX_LED ) + if( uxLED < partstMAX_LED ) { cLedOutput[ uxLED ] = ( xValue & 0x1 ); } @@ -109,7 +110,7 @@ void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue ) void vParTestToggleLED( unsigned portBASE_TYPE uxLED ) { - if ( uxLED < partstMAX_LED ) + if( uxLED < partstMAX_LED ) { vParTestSetLED( uxLED, !cLedOutput[ uxLED ] ); } diff --git a/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/Serial.c b/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/Serial.c index a82d0c00a..e81352fed 100644 --- a/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/Serial.c +++ b/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/Serial.c @@ -61,8 +61,8 @@ #define serialSTRING_DELAY_TICKS ( portMAX_DELAY ) /*---------------------------------------------------------------------------*/ -CY_ISR_PROTO(vUartRxISR); -CY_ISR_PROTO(vUartTxISR); +CY_ISR_PROTO( vUartRxISR ); +CY_ISR_PROTO( vUartTxISR ); /*---------------------------------------------------------------------------*/ static xQueueHandle xSerialTxQueue = NULL; @@ -85,23 +85,24 @@ xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned port UART_1_SetTxInterruptMode( 0 ); /* Both configured successfully. */ - return (xComPortHandle)( xSerialTxQueue && xSerialRxQueue ); + return ( xComPortHandle )( xSerialTxQueue && xSerialRxQueue ); } /*---------------------------------------------------------------------------*/ void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength ) { unsigned short usIndex = 0; - for ( usIndex = 0; usIndex < usStringLength; usIndex++ ) + + for( usIndex = 0; usIndex < usStringLength; usIndex++ ) { /* Check for pre-mature end of line. */ - if ( '\0' == pcString[ usIndex ] ) + if( '\0' == pcString[ usIndex ] ) { break; } /* Send out, one character at a time. */ - if ( pdTRUE != xSerialPutChar( NULL, pcString[ usIndex ], serialSTRING_DELAY_TICKS ) ) + if( pdTRUE != xSerialPutChar( NULL, pcString[ usIndex ], serialSTRING_DELAY_TICKS ) ) { /* Failed to send, this will be picked up in the receive comtest task. */ } @@ -112,7 +113,8 @@ unsigned short usIndex = 0; signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, portTickType xBlockTime ) { portBASE_TYPE xReturn = pdFALSE; - if ( pdTRUE == xQueueReceive( xSerialRxQueue, pcRxedChar, xBlockTime ) ) + + if( pdTRUE == xQueueReceive( xSerialRxQueue, pcRxedChar, xBlockTime ) ) { /* Picked up a character. */ xReturn = pdTRUE; @@ -126,7 +128,7 @@ signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar portBASE_TYPE xReturn = pdFALSE; /* The ISR is processing characters is so just add to the end of the queue. */ - if ( pdTRUE == xQueueSend( xSerialTxQueue, &cOutChar, xBlockTime ) ) + if( pdTRUE == xQueueSend( xSerialTxQueue, &cOutChar, xBlockTime ) ) { xReturn = pdTRUE; } @@ -137,9 +139,8 @@ portBASE_TYPE xReturn = pdFALSE; } /* Make sure that the interrupt will fire in the case where: - * Currently sending so the Tx Complete will fire. - * Not sending so the Empty will fire. - */ + Currently sending so the Tx Complete will fire. + Not sending so the Empty will fire. */ taskENTER_CRITICAL(); UART_1_SetTxInterruptMode( UART_1_TX_STS_COMPLETE | UART_1_TX_STS_FIFO_EMPTY ); taskEXIT_CRITICAL(); @@ -150,7 +151,7 @@ portBASE_TYPE xReturn = pdFALSE; CY_ISR(vUartRxISR) { -portBASE_TYPE xTaskWoken = pdFALSE; +portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; volatile unsigned char ucStatus = 0; signed char cInChar = 0; unsigned long ulMask = 0; @@ -159,7 +160,7 @@ unsigned long ulMask = 0; ucStatus = UART_1_ReadRxStatus(); /* Only interested in a character being received. */ - if ( 0 != ( ucStatus & UART_1_RX_STS_FIFO_NOTEMPTY ) ) + if( 0 != ( ucStatus & UART_1_RX_STS_FIFO_NOTEMPTY ) ) { /* Get the character. */ cInChar = UART_1_GetChar(); @@ -168,7 +169,7 @@ unsigned long ulMask = 0; ulMask = portSET_INTERRUPT_MASK_FROM_ISR(); { /* Try to deliver the character. */ - if ( pdTRUE != xQueueSendFromISR( xSerialRxQueue, &cInChar, &xTaskWoken ) ) + if( pdTRUE != xQueueSendFromISR( xSerialRxQueue, &cInChar, &xHigherPriorityTaskWoken ) ) { /* Run out of space. */ } @@ -176,14 +177,20 @@ unsigned long ulMask = 0; portCLEAR_INTERRUPT_MASK_FROM_ISR( ulMask ); } - /* If we delivered the character then a context switch might be required. */ - portEND_SWITCHING_ISR( xTaskWoken ); + /* If we delivered the character then a context switch might be required. + xHigherPriorityTaskWoken was set to pdFALSE on interrupt entry. If calling + xQueueSendFromISR() caused a task to unblock, and the unblocked task has + a priority equal to or higher than the currently running task (the task this + ISR interrupted), then xHigherPriorityTaskWoken will have been set to pdTRUE and + portEND_SWITCHING_ISR() will request a context switch to the newly unblocked + task. */ + portEND_SWITCHING_ISR( xHigherPriorityTaskWoken ); } /*---------------------------------------------------------------------------*/ CY_ISR(vUartTxISR) { -portBASE_TYPE xTaskWoken = pdFALSE; +portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE; volatile unsigned char ucStatus = 0; signed char cOutChar = 0; unsigned long ulMask = 0; @@ -192,35 +199,38 @@ unsigned long ulMask = 0; ucStatus = UART_1_ReadTxStatus(); /* Check to see whether this is a genuine interrupt. */ - if ( ( 0 != ( ucStatus & UART_1_TX_STS_COMPLETE ) ) - || ( 0 != ( ucStatus & UART_1_TX_STS_FIFO_EMPTY ) ) ) + if( ( 0 != ( ucStatus & UART_1_TX_STS_COMPLETE ) ) || ( 0 != ( ucStatus & UART_1_TX_STS_FIFO_EMPTY ) ) ) { /* Mask off the other RTOS interrupts to interact with the queue. */ ulMask = portSET_INTERRUPT_MASK_FROM_ISR(); { - if ( pdTRUE == xQueueReceiveFromISR( xSerialTxQueue, &cOutChar, &xTaskWoken ) ) + if( pdTRUE == xQueueReceiveFromISR( xSerialTxQueue, &cOutChar, &xHigherPriorityTaskWoken ) ) { /* Send the next character. */ UART_1_PutChar( cOutChar ); /* If we are firing, then the only interrupt we are interested in - * is the Complete. The application code will add the Empty interrupt - * when there is something else to be done. - */ + is the Complete. The application code will add the Empty interrupt + when there is something else to be done. */ UART_1_SetTxInterruptMode( UART_1_TX_STS_COMPLETE ); } else { - /* There is no work left so disable the interrupt - * until the application puts more into the queue. - */ + /* There is no work left so disable the interrupt until the application + puts more into the queue. */ UART_1_SetTxInterruptMode( 0 ); } } portCLEAR_INTERRUPT_MASK_FROM_ISR( ulMask ); } - /* If we delivered the character then a context switch might be required. */ - portEND_SWITCHING_ISR( xTaskWoken ); + /* If we delivered the character then a context switch might be required. + xHigherPriorityTaskWoken was set to pdFALSE on interrupt entry. If calling + xQueueSendFromISR() caused a task to unblock, and the unblocked task has + a priority equal to or higher than the currently running task (the task this + ISR interrupted), then xHigherPriorityTaskWoken will have been set to pdTRUE and + portEND_SWITCHING_ISR() will request a context switch to the newly unblocked + task. */ + portEND_SWITCHING_ISR( xHigherPriorityTaskWoken ); } /*---------------------------------------------------------------------------*/ diff --git a/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/main.c b/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/main.c index 3aa26e31c..fe8b6ff3f 100644 --- a/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/main.c +++ b/Demo/CORTEX_CY8C5588_PSoC_Creator_GCC/FreeRTOS_Demo.cydsn/main.c @@ -107,7 +107,7 @@ tick hook. */ extern void vSetupTimerTest( void ); /*---------------------------------------------------------------------------*/ -/** +/* * The Check task periodical interrogates each of the running tests to * ensure that they are still executing correctly. * If all the tests pass, then the LCD is updated with Pass, the number of @@ -117,7 +117,7 @@ extern void vSetupTimerTest( void ); */ void vCheckTask( void *pvParameters ); -/** +/* * Installs the RTOS interrupt handlers and starts the peripherals. */ static void prvHardwareSetup( void ); @@ -131,25 +131,6 @@ unsigned long ulIteration = 0; /* Place your initialization/startup code here (e.g. MyInst_Start()) */ prvHardwareSetup(); - /* Poll the switch connected to P1[7] - * to prevent the Soak test from (re)starting. - */ - while ( 0 != Startup_Release_Switch_Read() ) - { - if ( 100000 <= ulIteration++ ) - { - vParTestToggleLED( ulLed++ ); - ulLed = ulLed % 4; - ulIteration = 0; - } - } - - /* Reset the LEDS. */ - for ( ulLed = 0; ulLed < 4; ulLed++ ) - { - vParTestSetLED( ulLed, pdFALSE ); - } - /* Start the standard demo tasks. These are just here to exercise the kernel port and provide examples of how the FreeRTOS API can be used. */ vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY ); @@ -167,7 +148,7 @@ unsigned long ulIteration = 0; vStartInterruptQueueTasks(); /* Start the error checking task. */ - (void)xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); + ( void ) xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); /* Configure the timers used by the fast interrupt timer test. */ vSetupTimerTest(); @@ -181,8 +162,11 @@ unsigned long ulIteration = 0; task. The idle task is created within vTaskStartScheduler(). */ vTaskStartScheduler(); - /* Should never reach here. */ - for (;;); + /* Should never reach here as the kernel will now be running. If + vTaskStartScheduler() does return then it is very likely that there was + insufficient (FreeRTOS) heap space available to create all the tasks, + including the idle task that is created within vTaskStartScheduler() itself. */ + for( ;; ); } /*---------------------------------------------------------------------------*/ @@ -195,18 +179,18 @@ extern void vPortSVCHandler( void ); extern cyisraddress CyRamVectors[]; /* Install the OS Interrupt Handlers. */ - CyRamVectors[11] = (cyisraddress)vPortSVCHandler; - CyRamVectors[14] = (cyisraddress)xPortPendSVHandler; - CyRamVectors[15] = (cyisraddress)xPortSysTickHandler; + CyRamVectors[ 11 ] = ( cyisraddress ) vPortSVCHandler; + CyRamVectors[ 14 ] = ( cyisraddress ) xPortPendSVHandler; + CyRamVectors[ 15 ] = ( cyisraddress ) xPortSysTickHandler; /* Start-up the peripherals. */ /* Enable and clear the LCD Display. */ LCD_Character_Display_Start(); LCD_Character_Display_ClearDisplay(); - LCD_Character_Display_Position(0,0); - LCD_Character_Display_PrintString("www.FreeRTOS.org "); - LCD_Character_Display_Position(1,0); + LCD_Character_Display_Position( 0, 0 ); + LCD_Character_Display_PrintString( "www.FreeRTOS.org " ); + LCD_Character_Display_Position( 1, 0 ); LCD_Character_Display_PrintString("CY8C5588AX-060 "); /* Start the UART. */ @@ -236,97 +220,97 @@ extern unsigned portSHORT usMaxJitter; /* Intialise the sleeper. */ xDelay = xTaskGetTickCount(); - for ( ;; ) + for( ;; ) { /* Perform this check every mainCHECK_DELAY milliseconds. */ vTaskDelayUntil( &xDelay, mainCHECK_DELAY ); /* Check that all of the Demo tasks are still running. */ - if ( pdTRUE != xAreBlockingQueuesStillRunning() ) + if( pdTRUE != xAreBlockingQueuesStillRunning() ) { usErrorCode |= 0x1; } - if ( pdTRUE != xAreBlockTimeTestTasksStillRunning() ) + if( pdTRUE != xAreBlockTimeTestTasksStillRunning() ) { usErrorCode |= 0x2; } - if ( pdTRUE != xAreCountingSemaphoreTasksStillRunning() ) + if( pdTRUE != xAreCountingSemaphoreTasksStillRunning() ) { usErrorCode |= 0x4; } - if ( pdTRUE != xIsCreateTaskStillRunning() ) + if( pdTRUE != xIsCreateTaskStillRunning() ) { usErrorCode |= 0x8; } - if ( pdTRUE != xAreDynamicPriorityTasksStillRunning() ) + if( pdTRUE != xAreDynamicPriorityTasksStillRunning() ) { usErrorCode |= 0x10; } - if ( pdTRUE != xAreMathsTaskStillRunning() ) + if( pdTRUE != xAreMathsTaskStillRunning() ) { usErrorCode |= 0x20; } - if ( pdTRUE != xAreGenericQueueTasksStillRunning() ) + if( pdTRUE != xAreGenericQueueTasksStillRunning() ) { usErrorCode |= 0x40; } - if ( pdTRUE != xAreIntegerMathsTaskStillRunning() ) + if( pdTRUE != xAreIntegerMathsTaskStillRunning() ) { usErrorCode |= 0x80; } - if ( pdTRUE != xArePollingQueuesStillRunning() ) + if( pdTRUE != xArePollingQueuesStillRunning() ) { usErrorCode |= 0x100; } - if ( pdTRUE != xAreQueuePeekTasksStillRunning() ) + if( pdTRUE != xAreQueuePeekTasksStillRunning() ) { usErrorCode |= 0x200; } - if ( pdTRUE != xAreSemaphoreTasksStillRunning() ) + if( pdTRUE != xAreSemaphoreTasksStillRunning() ) { usErrorCode |= 0x400; } - if ( pdTRUE != xAreComTestTasksStillRunning() ) + if( pdTRUE != xAreComTestTasksStillRunning() ) { usErrorCode |= 0x800; } - if ( pdTRUE != xAreIntQueueTasksStillRunning() ) + if( pdTRUE != xAreIntQueueTasksStillRunning() ) { usErrorCode |= 0x1000; } /* Clear the display. */ LCD_Character_Display_ClearDisplay(); - if ( 0 == usErrorCode ) + if( 0 == usErrorCode ) { - LCD_Character_Display_Position( (ulRow) & 0x1, 0); - LCD_Character_Display_PrintString("Pass: "); - LCD_Character_Display_PrintNumber(ulIteration++); - LCD_Character_Display_Position( (++ulRow) & 0x1, 0); - LCD_Character_Display_PrintString("Jitter(ns):"); - LCD_Character_Display_PrintNumber((usMaxJitter * mainNS_PER_CLOCK)); + LCD_Character_Display_Position( ( ulRow ) & 0x1, 0); + LCD_Character_Display_PrintString( "Pass: " ); + LCD_Character_Display_PrintNumber( ulIteration++ ); + LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 ); + LCD_Character_Display_PrintString( "Jitter(ns):" ); + LCD_Character_Display_PrintNumber( ( usMaxJitter * mainNS_PER_CLOCK ) ); } else { /* Do something to indicate the failure. */ - LCD_Character_Display_Position( (ulRow) & 0x1, 0); - LCD_Character_Display_PrintString("Fail at: "); - LCD_Character_Display_PrintNumber(ulIteration); - LCD_Character_Display_Position( (++ulRow) & 0x1, 0); - LCD_Character_Display_PrintString("Error: 0x"); - LCD_Character_Display_PrintHexUint16(usErrorCode); + LCD_Character_Display_Position( ( ulRow ) & 0x1, 0 ); + LCD_Character_Display_PrintString( "Fail at: " ); + LCD_Character_Display_PrintNumber( ulIteration ); + LCD_Character_Display_Position( ( ++ulRow ) & 0x1, 0 ); + LCD_Character_Display_PrintString( "Error: 0x" ); + LCD_Character_Display_PrintHexUint16( usErrorCode ); } } } @@ -335,13 +319,15 @@ extern unsigned portSHORT usMaxJitter; void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName ) { /* The stack space has been execeeded for a task, considering allocating more. */ - for (;;); + taskDISABLE_INTERRUPTS(); + for( ;; ); } /*---------------------------------------------------------------------------*/ void vApplicationMallocFailedHook( void ) { /* The heap space has been execeeded. */ - for (;;); + taskDISABLE_INTERRUPTS(); + for( ;; ); } /*---------------------------------------------------------------------------*/ -- 2.39.5