--- /dev/null
+/*\r
+ FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS tutorial books are available in pdf and paperback. *\r
+ * Complete, revised, and edited pdf reference manuals are also *\r
+ * available. *\r
+ * *\r
+ * Purchasing FreeRTOS documentation will not only help you, by *\r
+ * ensuring you get running as quickly as possible and with an *\r
+ * in-depth knowledge of how to use FreeRTOS, it will also help *\r
+ * the FreeRTOS project to continue with its mission of providing *\r
+ * professional grade, cross platform, de facto standard solutions *\r
+ * for microcontrollers - completely free of charge! *\r
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\r
+ * *\r
+ ***************************************************************************\r
+\r
+\r
+ This file is part of the FreeRTOS distribution.\r
+\r
+ FreeRTOS is free software; you can redistribute it and/or modify it under\r
+ the terms of the GNU General Public License (version 2) as published by the\r
+ Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+ >>>NOTE<<< The modification to the GPL is included to allow you to\r
+ distribute a combined work that includes FreeRTOS without being obliged to\r
+ provide the source code for proprietary components outside of the FreeRTOS\r
+ kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ more details. You should have received a copy of the GNU General Public\r
+ License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+ can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+ by writing to Richard Barry, contact details for whom are available on the\r
+ FreeRTOS WEB site.\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+/* Standard includes. */\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+/* Scheduler includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "semphr.h"\r
+\r
+/* Demo application includes. */\r
+#include "InterruptNestTest.h"\r
+\r
+/* TriCore specific includes. */\r
+#include <tc1782.h>\r
+#include <machine/intrinsics.h>\r
+#include <machine/cint.h>\r
+#include <machine/wdtcon.h>\r
+\r
+/* This constant is specific to this test application. It allows the high\r
+frequency (interrupt nesting test) timer to know how often to trigger, and the\r
+check task to know how many iterations to expect at any given time. */\r
+#define tmrtestHIGH_FREQUENCY_TIMER_TEST_HZ ( 1931UL )\r
+\r
+static void prvPortHighFrequencyTimerHandler( int iArg ) __attribute__((longcall));\r
+static void prvHighFrequencyTimerTask( void *pvParameters );\r
+\r
+static const unsigned long ulCompareMatchValue = configPERIPHERAL_CLOCK_HZ / tmrtestHIGH_FREQUENCY_TIMER_TEST_HZ;\r
+static const unsigned long ulInterruptsPer10ms = tmrtestHIGH_FREQUENCY_TIMER_TEST_HZ / 100UL;\r
+static const unsigned long ulSemaphoreGiveRate_ms = 10UL;\r
+\r
+static xSemaphoreHandle xHighFrequencyTimerSemaphore = NULL;\r
+static unsigned long ulHighFrequencyCounterIterations = 0UL;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void vSetupInterruptNestingTest( void )\r
+{\r
+unsigned long ulCompareMatchBits;\r
+\r
+ /* Create the semaphore used to communicate between the high frequency\r
+ interrupt and the task. */\r
+ vSemaphoreCreateBinary( xHighFrequencyTimerSemaphore );\r
+ configASSERT( xHighFrequencyTimerSemaphore );\r
+ \r
+ /* Create the task that pends on the semaphore that is given by the\r
+ high frequency interrupt. */\r
+ xTaskCreate( prvHighFrequencyTimerTask, ( signed char * ) "HFTmr", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );\r
+ \r
+ /* Setup the interrupt itself. The STM module clock divider is setup when \r
+ the tick interrupt is configured - which is when the scheduler is started - \r
+ so there is no need to do it here. */\r
+\r
+ unlock_wdtcon();\r
+ {\r
+ /* Wait until access to Endint protected register is enabled. */\r
+ while( 0 != ( WDT_CON0.reg & 0x1UL ) );\r
+\r
+ /* RMC == 1 so STM Clock == FPI */\r
+ STM_CLC.reg = ( 1UL << 8 );\r
+ }\r
+ lock_wdtcon();\r
+\r
+ /* The tick interrupt uses compare match 0, so this test uses compare match\r
+ 1, which means shifting up the values by 16 before writing them to the\r
+ register. */\r
+ ulCompareMatchBits = ( 0x1fUL - __CLZ( ulCompareMatchValue ) );\r
+ ulCompareMatchBits <<= 16UL;\r
+ \r
+ /* Write the values to the relevant SMT registers, without changing other\r
+ bits. */\r
+ taskENTER_CRITICAL();\r
+ {\r
+ STM_CMCON.reg &= ~( 0x1fUL << 16UL );\r
+ STM_CMCON.reg |= ulCompareMatchBits;\r
+ STM_CMP1.reg = ulCompareMatchValue;\r
+\r
+ if( 0 != _install_int_handler( configMAX_SYSCALL_INTERRUPT_PRIORITY - 5, prvPortHighFrequencyTimerHandler, 0 ) )\r
+ {\r
+ /* Set-up the interrupt. */\r
+ STM_SRC1.reg = ( ( configMAX_SYSCALL_INTERRUPT_PRIORITY - 5 ) | 0x00005000UL );\r
+ \r
+ /* Enable the Interrupt. */\r
+ STM_ISRR.reg &= ~( 0x03UL << 2UL );\r
+ STM_ISRR.reg |= ( 0x1UL << 2UL );\r
+ STM_ICR.reg &= ~( 0x07UL << 4UL );\r
+ STM_ICR.reg |= ( 0x5UL << 4UL );\r
+ }\r
+ else\r
+ {\r
+ /* Failed to install the interrupt. */\r
+ configASSERT( ( ( volatile void * ) NULL ) );\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+unsigned long ulInterruptNestingTestGetIterationCount( unsigned long *pulExpectedIncFrequency_ms )\r
+{\r
+ *pulExpectedIncFrequency_ms = ulSemaphoreGiveRate_ms;\r
+ return ulHighFrequencyCounterIterations;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvHighFrequencyTimerTask( void *pvParameters )\r
+{\r
+ /* Just to remove compiler warnings about the unused parameter. */\r
+ ( void ) pvParameters;\r
+\r
+ for( ;; )\r
+ {\r
+ /* Wait for the next trigger from the high frequency timer interrupt. */\r
+ xSemaphoreTake( xHighFrequencyTimerSemaphore, portMAX_DELAY );\r
+ \r
+ /* Just count how many times the task has been unblocked before\r
+ returning to wait for the semaphore again. */\r
+ ulHighFrequencyCounterIterations++;\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvPortHighFrequencyTimerHandler( int iArg )\r
+{\r
+static volatile unsigned long ulExecutionCounter = 0UL;\r
+unsigned long ulHigherPriorityTaskWoken = pdFALSE;\r
+\r
+ /* Just to avoid compiler warnings about unused parameters. */\r
+ ( void ) iArg;\r
+\r
+ /* Clear the interrupt source. */\r
+ STM_ISRR.reg = 1UL << 2UL;\r
+\r
+ /* Reload the Compare Match register for X ticks into the future.*/\r
+ STM_CMP1.reg += ulCompareMatchValue;\r
+\r
+ ulExecutionCounter++;\r
+ \r
+ if( ulExecutionCounter >= ulInterruptsPer10ms )\r
+ {\r
+ ulExecutionCounter = xSemaphoreGiveFromISR( xHighFrequencyTimerSemaphore, &ulHigherPriorityTaskWoken );\r
+ \r
+ /* If the semaphore was given ulExeuctionCounter will now be pdTRUE. */\r
+ configASSERT( ulExecutionCounter == pdTRUE );\r
+ \r
+ /* Start counting again. */\r
+ ulExecutionCounter = 0UL;\r
+ }\r
+ \r
+ portYIELD_FROM_ISR( ulHigherPriorityTaskWoken );\r
+}\r
--- /dev/null
+/*\r
+ FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS tutorial books are available in pdf and paperback. *\r
+ * Complete, revised, and edited pdf reference manuals are also *\r
+ * available. *\r
+ * *\r
+ * Purchasing FreeRTOS documentation will not only help you, by *\r
+ * ensuring you get running as quickly as possible and with an *\r
+ * in-depth knowledge of how to use FreeRTOS, it will also help *\r
+ * the FreeRTOS project to continue with its mission of providing *\r
+ * professional grade, cross platform, de facto standard solutions *\r
+ * for microcontrollers - completely free of charge! *\r
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\r
+ * *\r
+ ***************************************************************************\r
+\r
+\r
+ This file is part of the FreeRTOS distribution.\r
+\r
+ FreeRTOS is free software; you can redistribute it and/or modify it under\r
+ the terms of the GNU General Public License (version 2) as published by the\r
+ Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+ >>>NOTE<<< The modification to the GPL is included to allow you to\r
+ distribute a combined work that includes FreeRTOS without being obliged to\r
+ provide the source code for proprietary components outside of the FreeRTOS\r
+ kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ more details. You should have received a copy of the GNU General Public\r
+ License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+ can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+ by writing to Richard Barry, contact details for whom are available on the\r
+ FreeRTOS WEB site.\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+#ifndef INTERRUPT_NEST_TEST_H\r
+#define INTERRUPT_NEST_TEST_H\r
+\r
+void vSetupInterruptNestingTest( void );\r
+unsigned long ulInterruptNestingTestGetIterationCount( unsigned long *pulExpectedIncFrequency_ms );\r
+\r
+#endif /* INTERRUPT_NEST_TEST_H */\r
+\r
#include "serial.h"\r
#include "death.h"\r
#include "TimerDemo.h"\r
+#include "InterruptNestTest.h"\r
\r
/*-----------------------------------------------------------*/\r
\r
\r
/* The rate at which the on board LED will toggle when there is/is not an\r
error. */\r
-#define mainNO_ERROR_FLASH_PERIOD ( ( portTickType ) 5000 / portTICK_RATE_MS )\r
-#define mainERROR_FLASH_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )\r
-#define mainON_BOARD_LED_BIT ( ( unsigned long ) 7 )\r
+#define mainNO_ERROR_FLASH_PERIOD_MS ( ( portTickType ) 5000 / portTICK_RATE_MS )\r
+#define mainERROR_FLASH_PERIOD_MS ( ( portTickType ) 500 / portTICK_RATE_MS )\r
+#define mainON_BOARD_LED_BIT ( ( unsigned long ) 7 )\r
\r
/* Constant used by the standard timer test functions. */\r
#define mainTIMER_TEST_PERIOD ( 50 )\r
\r
static void prvCheckTask( void *pvParameters )\r
{\r
-portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;\r
+portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD_MS;\r
portTickType xLastExecutionTime;\r
\r
/* Just to stop compiler warnings. */\r
\r
/* Cycle for ever, delaying then checking all the other tasks are still\r
operating without error. If an error is detected then the delay period\r
- is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so\r
+ is decreased from mainNO_ERROR_FLASH_PERIOD_MS to mainERROR_FLASH_PERIOD_MS so\r
the on board LED flash rate will increase. NOTE: This task could easily\r
be replaced by a software timer callback to remove the overhead of having\r
an extra task. */\r
at a higher frequency to give visible feedback that something has\r
gone wrong (it might just be that the loop back connector required\r
by the comtest tasks has not been fitted). */\r
- xDelayPeriod = mainERROR_FLASH_PERIOD;\r
+ xDelayPeriod = mainERROR_FLASH_PERIOD_MS;\r
}\r
\r
/* The toggle rate of the LED depends on how long this task delays for.\r
static long prvCheckOtherTasksAreStillRunning( void )\r
{\r
long lReturn = pdPASS;\r
+unsigned long ulHighFrequencyTimerTaskIterations, ulExpectedIncFrequency_ms;\r
\r
/* Check all the demo tasks (other than the flash tasks) to ensure\r
that they are all still running, and that none have detected an error. */\r
lReturn = pdFAIL;\r
}\r
\r
+ /* Obtain the number of times the task associated with the high frequency\r
+ (interrupt nesting) timer test has increment since the check task last\r
+ executed, and the frequency at which it is expected to execute in ms. */\r
+ ulHighFrequencyTimerTaskIterations = ulInterruptNestingTestGetIterationCount( &ulExpectedIncFrequency_ms );\r
+ if( ulHighFrequencyTimerTaskIterations < ( ( mainNO_ERROR_FLASH_PERIOD_MS / ulExpectedIncFrequency_ms ) - 1 ) )\r
+ {\r
+ /* Would have expected the high frequency timer task to have\r
+ incremented its execution count more times that reported. */\r
+ lReturn = pdFAIL;\r
+ }\r
+\r
+\r
#if configUSE_TIMERS == 1\r
{\r
/* For space constraint reasons, do not include the timer demo in\r
builds that execute from RAM. */\r
- if( xAreTimerDemoTasksStillRunning( mainNO_ERROR_FLASH_PERIOD ) != pdTRUE )\r
+ if( xAreTimerDemoTasksStillRunning( mainNO_ERROR_FLASH_PERIOD_MS ) != pdTRUE )\r
{\r
lReturn = pdFAIL;\r
}\r
vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
vStartRecursiveMutexTasks();\r
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
+ vSetupInterruptNestingTest();\r
\r
#if configUSE_TIMERS == 1\r
{\r