]> git.sur5r.net Git - freertos/commitdiff
Added the digit counter timer to the FM3/IAR demo.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 6 May 2011 11:13:11 +0000 (11:13 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 6 May 2011 11:13:11 +0000 (11:13 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1414 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

Demo/CORTEX_MB9B500_IAR_Keil/main-full.c

index 29361610baebf8608cee2101559c0189a52a492c..159843d4deb35c4b3e45fe4d63a0a867869334c5 100644 (file)
@@ -172,12 +172,10 @@ the queue empty. */
 #define mainCHECK_LED                          0x07UL\r
 \r
 /* The LED toggle by the queue receive task. */\r
-#define mainTASK_CONTROLLED_LED                0x8000UL\r
+#define mainTASK_CONTROLLED_LED                0x04UL\r
 \r
-/* The LED turned on by the button interrupt, and turned off by the LED timer.\r
-Although it looks like this value is the same as that defined for\r
-mainTASK_CONTROLLED_LED, the two LEDs are on different ports. */\r
-#define mainTIMER_CONTROLLED_LED       0x8000UL\r
+/* The LED turned on by the button interrupt, and turned off by the LED timer. */\r
+#define mainTIMER_CONTROLLED_LED       0x05UL\r
 \r
 /* Constant used by the standard timer test functions. */\r
 #define mainTIMER_TEST_PERIOD          ( 50 )\r
@@ -200,6 +198,10 @@ have been reported by any of the standard demo tasks. */
 reported in one of the standard demo tasks. */\r
 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 500UL / portTICK_RATE_MS )\r
 \r
+/* The period at which the digit counter timer will expire, in ms, and converted\r
+to ticks using the portTICK_RATE_MS constant. */\r
+#define mainDIGIT_COUNTER_TIMER_PERIOD_MS ( 250UL / portTICK_RATE_MS )\r
+\r
 /* The LED will remain on until the button has not been pushed for a full\r
 5000ms. */\r
 #define mainLED_TIMER_PERIOD_MS                ( 5000UL / portTICK_RATE_MS )\r
@@ -230,6 +232,11 @@ static void prvLEDTimerCallback( xTimerHandle xTimer );
  */\r
 static void prvCheckTimerCallback( xTimerHandle xTimer );\r
 \r
+/*\r
+ * The digit counter callback function, as described at the top of this file.\r
+ */\r
+static void prvDigitCounterTimerCallback( xTimerHandle xTimer );\r
+\r
 /*\r
  * This is not a 'standard' partest function, so the prototype is not in\r
  * partest.h, and is instead included here.\r
@@ -245,6 +252,10 @@ static xQueueHandle xQueue = NULL;
 function. */\r
 static xTimerHandle xLEDTimer = NULL;\r
 \r
+/* The counter software timer.  This displays a counting digit on one of the\r
+seven segment displays. */\r
+static xTimerHandle xDigitCounterTimer = NULL;\r
+\r
 /* The check timer.  This uses prvCheckTimerCallback() as it's callback\r
 function. */\r
 static xTimerHandle xCheckTimer = NULL;\r
@@ -290,6 +301,15 @@ int main(void)
                                                                        prvCheckTimerCallback                           /* The callback function that inspects the status of all the other tasks. */\r
                                                                  );\r
 \r
+               /* Create the software timer that performs the 'digit counting'\r
+               functionality, as described at the top of this file. */\r
+               xDigitCounterTimer = xTimerCreate( ( const signed char * ) "DigitCounter",      /* A text name, purely to help debugging. */\r
+                                                                       ( mainDIGIT_COUNTER_TIMER_PERIOD_MS ),                  /* The timer period, in this case 3000ms (3s). */\r
+                                                                       pdTRUE,                                                                                 /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
+                                                                       ( void * ) 0,                                                                   /* The ID is not used, so can be set to anything. */\r
+                                                                       prvDigitCounterTimerCallback                                    /* The callback function that inspects the status of all the other tasks. */\r
+                                                                 );            \r
+               \r
                /* Create a lot of 'standard demo' tasks. */\r
                vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
                vCreateBlockTimeTasks();\r
@@ -385,14 +405,29 @@ static void prvCheckTimerCallback( xTimerHandle xTimer )
 static void prvLEDTimerCallback( xTimerHandle xTimer )\r
 {\r
        /* The timer has expired - so no button pushes have occurred in the last\r
-       five seconds - turn the LED off.  NOTE - accessing the LED port should use\r
-       a critical section because it is accessed from multiple tasks, and the\r
-       button interrupt - in this trivial case, for simplicity, the critical\r
-       section is omitted.\r
+       five seconds - turn the LED off. */\r
+       vParTestSetLED( mainTIMER_CONTROLLED_LED, pdFALSE );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvDigitCounterTimerCallback( xTimerHandle xTimer )\r
+{\r
+/* Define the bit patterns that display numbers on the seven segment display. */\r
+static const unsigned short usNumbersPatterns[] = { 0xC000U, 0xF900U, 0xA400U, 0xB000U, 0x9900U, 0x9200U, 0x8200U, 0xF800U, 0x8000U, 0x9000U };\r
+static long lCounter = 0L;\r
+const long lNumberOfDigits = 10L;\r
+\r
+       /* Display the next number, counting up. */\r
+       FM3_GPIO->PDOR1 = usNumbersPatterns[ lCounter ];\r
+\r
+       /* Move onto the next digit. */ \r
+       lCounter++;\r
        \r
-       A ParTest function is not used to set the LED as the LED is not on the seven\r
-       segment display that the ParTest functions control. */\r
-       FM3_GPIO->PDOR1 |= mainTIMER_CONTROLLED_LED;\r
+       /* Ensure the counter does not go off the end of the array. */\r
+       if( lCounter >= lNumberOfDigits )\r
+       {\r
+               lCounter = 0L;\r
+       }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -404,7 +439,7 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
        /* The button was pushed, so ensure the LED is on before resetting the\r
        LED timer.  The LED timer will turn the LED off if the button is not\r
        pushed within 5000ms. */\r
-       FM3_GPIO->PDOR1 &= ~mainTIMER_CONTROLLED_LED;\r
+       vParTestSetLEDFromISR( mainTIMER_CONTROLLED_LED, pdTRUE );\r
 \r
        /* This interrupt safe FreeRTOS function can be called from this interrupt\r
        because the interrupt priority is below the\r
@@ -431,11 +466,12 @@ const unsigned long ulValueToSend = 100UL;
 \r
        /* The timer command queue will have been filled when the timer test tasks\r
        were created in main() (this is part of the test they perform).  Therefore,\r
-       while the check and count timers can be created in main(), they cannot be\r
-       started from main().  Once the scheduler has started, the timer service\r
-       task will drain the command queue, and now the check and OLED timers can be\r
-       started successfully. */\r
+       while the check and digit counter timers can be created in main(), they\r
+       cannot be started from main().  Once the scheduler has started, the timer\r
+       service task will drain the command queue, and now the check and digit\r
+       counter timers can be started successfully. */\r
        xTimerStart( xCheckTimer, portMAX_DELAY );\r
+       xTimerStart( xDigitCounterTimer, portMAX_DELAY );\r
 \r
        /* Initialise xNextWakeTime - this only needs to be done once. */\r
        xNextWakeTime = xTaskGetTickCount();\r