]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/RL78_RL78G13_Promo_Board_IAR/main.c
Minor updates to demo projects to ensure correct building with V8 rc1.
[freertos] / FreeRTOS / Demo / RL78_RL78G13_Promo_Board_IAR / main.c
index 499676718d4c09e82a77bc669a00d1abad05d86e..91d45f46c05821707b8f82921db31d0c934db677 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
-    FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+    FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+    All rights reserved\r
 \r
     FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME.  PLEASE VISIT\r
     http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
@@ -152,7 +153,7 @@ its own executions. */
 #define mainDEMO_TIMER_PERIOD_MS                       ( mainCHECK_TIMER_PERIOD_MS / mainDEMO_TIMER_INCREMENTS_PER_CHECK_TIMER_TIMEOUT )\r
 \r
 /* The LED toggled by the check timer. */\r
-#define mainLED_0                                              P1_bit.no0\r
+#define mainLED_0                                              P7_bit.no7\r
 \r
 /* A block time of zero simple means "don't block". */\r
 #define mainDONT_BLOCK                                         ( 0U )\r
@@ -184,9 +185,10 @@ extern void vRegTest2( void *pvParameters );
 \r
 /*-----------------------------------------------------------*/\r
 \r
-/* Variables that are incremented on each cycle of the two reg tests to allow\r
-the check timer to know that they are still executing. */\r
-unsigned short usRegTest1LoopCounter = 0, usRegTest2LoopCounter;\r
+/* If an error is discovered by one of the RegTest tasks then this flag is set\r
+to pdFAIL.  The 'check' timer then inspects this flag to detect errors within\r
+the RegTest tasks. */\r
+static short sRegTestStatus = pdPASS;\r
 \r
 /* The check timer.  This uses prvCheckTimerCallback() as its callback\r
 function. */\r
@@ -198,17 +200,17 @@ static xTimerHandle xDemoTimer = NULL;
 /* This variable is incremented each time the demo timer expires. */\r
 static volatile unsigned long ulDemoSoftwareTimerCounter = 0UL;\r
 \r
-/* RL78/G13 Option Byte Definition. Watchdog disabled, LVI enabled, OCD interface\r
+/* RL78 Option Byte Definition. Watchdog disabled, LVI enabled, OCD interface\r
 enabled. */\r
 __root __far const unsigned char OptionByte[] @ 0x00C0 =\r
 {\r
-       0x00U, 0xFFU, 0xF8U, 0x81U\r
+       0x6eU, 0xffU, 0xe8U, 0x85U\r
 };\r
 \r
 /* Security byte definition */\r
-__root __far const unsigned char ucSecurityCode[]  @ 0x00C4 =\r
+__root __far const unsigned char SecuIDCode[]  @ 0x00C4 =\r
 {\r
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
+       0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x54\r
 };\r
 \r
 /*-----------------------------------------------------------*/\r
@@ -226,31 +228,31 @@ short main( void )
 \r
        /* Create the RegTest tasks as described at the top of this file. */\r
        xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, 0, NULL );\r
-       xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );      \r
+       xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );\r
 \r
        /* Create the software timer that performs the 'check' functionality,\r
        as described at the top of this file. */\r
-       xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */\r
+       xCheckTimer = xTimerCreate( "CheckTimer",/* A text name, purely to help debugging. */\r
                                                                ( mainCHECK_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
                                                                prvCheckTimerCallback                           /* The callback function that inspects the status of all the other tasks. */\r
                                                          );\r
-                                                       \r
+\r
        /* Create the software timer that just increments a variable for demo\r
        purposes. */\r
-       xDemoTimer = xTimerCreate( ( const signed char * ) "DemoTimer",/* A text name, purely to help debugging. */\r
+       xDemoTimer = xTimerCreate( "DemoTimer",/* A text name, purely to help debugging. */\r
                                                                ( mainDEMO_TIMER_PERIOD_MS ),           /* The timer period, in this case it is always calculated relative to the check timer period (see the definition of mainDEMO_TIMER_PERIOD_MS). */\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
                                                                prvDemoTimerCallback                            /* The callback function that inspects the status of all the other tasks. */\r
                                                          );\r
-       \r
+\r
        /* Start both the check timer and the demo timer.  The timers won't actually\r
        start until the scheduler is started. */\r
        xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
        xTimerStart( xDemoTimer, mainDONT_BLOCK );\r
-       \r
+\r
        /* Finally start the scheduler running. */\r
        vTaskStartScheduler();\r
 \r
@@ -273,44 +275,29 @@ static void prvDemoTimerCallback( xTimerHandle xTimer )
 static void prvCheckTimerCallback( xTimerHandle xTimer )\r
 {\r
 static portBASE_TYPE xChangedTimerPeriodAlready = pdFALSE, xErrorStatus = pdPASS;\r
-static unsigned short usLastRegTest1Counter = 0, usLastRegTest2Counter = 0;\r
 \r
        /* Inspect the status of the standard demo tasks. */\r
        if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
        {\r
                xErrorStatus = pdFAIL;\r
        }\r
-       \r
+\r
        if( xArePollingQueuesStillRunning() != pdTRUE )\r
        {\r
                xErrorStatus = pdFAIL;\r
        }\r
-       \r
+\r
        if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
        {\r
                xErrorStatus = pdFAIL;\r
        }\r
 \r
-       /* Indicate an error if either of the reg test loop counters have not\r
-       incremented since the last time this function was called. */\r
-       if( usLastRegTest1Counter == usRegTest1LoopCounter )\r
+       /* Inspect the status of the reg test tasks. */\r
+       if( sRegTestStatus != pdPASS )\r
        {\r
                xErrorStatus = pdFAIL;\r
        }\r
-       else\r
-       {\r
-               usLastRegTest1Counter = usRegTest1LoopCounter;\r
-       }\r
 \r
-       if( usLastRegTest2Counter == usRegTest2LoopCounter )\r
-       {\r
-               xErrorStatus = pdFAIL;\r
-       }\r
-       else\r
-       {\r
-               usLastRegTest2Counter = usRegTest2LoopCounter;\r
-       }\r
-       \r
        /* Ensure that the demo software timer has expired\r
        mainDEMO_TIMER_INCREMENTS_PER_CHECK_TIMER_TIMEOUT times in between\r
        each call of this function.  A critical section is not required to access\r
@@ -327,7 +314,7 @@ static unsigned short usLastRegTest1Counter = 0, usLastRegTest2Counter = 0;
        {\r
                ulDemoSoftwareTimerCounter = 0UL;\r
        }\r
-       \r
+\r
        if( ( xErrorStatus == pdFAIL ) && ( xChangedTimerPeriodAlready == pdFALSE ) )\r
        {\r
                /* An error has occurred, but the timer's period has not yet been changed,\r
@@ -335,13 +322,13 @@ static unsigned short usLastRegTest1Counter = 0, usLastRegTest2Counter = 0;
                timer's period means the LED will toggle at a faster rate, giving a\r
                visible indication that something has gone wrong. */\r
                xChangedTimerPeriodAlready = pdTRUE;\r
-                       \r
+\r
                /* This call to xTimerChangePeriod() uses a zero block time.  Functions\r
                called from inside of a timer callback function must *never* attempt to\r
                block. */\r
                xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
        }\r
-       \r
+\r
        /* Toggle the LED.  The toggle rate will depend on whether or not an error\r
        has been found in any tasks. */\r
        mainLED_0 = !mainLED_0;\r
@@ -350,37 +337,73 @@ static unsigned short usLastRegTest1Counter = 0, usLastRegTest2Counter = 0;
 \r
 int __low_level_init(void)\r
 {\r
-unsigned portCHAR ucResetFlag = RESF;\r
+unsigned char ucResetFlag = RESF;\r
 \r
        portDISABLE_INTERRUPTS();\r
 \r
-       /* Set fMX */\r
-       CMC = 0x00;\r
-       MSTOP = 1U;\r
-       \r
-       /* Set fMAIN */\r
-       MCM0 = 0U;\r
-       \r
-       /* Set fSUB */\r
-       XTSTOP = 1U;\r
-       OSMC = 0x10;\r
-       \r
-       /* Set fCLK */\r
-       CSS = 0U;\r
-       \r
-       /* Set fIH */\r
-       HIOSTOP = 0U;\r
-       \r
+       /* Clock Configuration:\r
+       In this port, to use the internal high speed clock source of the\r
+       microcontroller, define the configCLOCK_SOURCE as 1 in FreeRTOSConfig.h.  To\r
+       use an external clock define configCLOCK_SOURCE as 0. */\r
+       #if configCLOCK_SOURCE == 1\r
+       {\r
+               /* Set fMX */\r
+               CMC = 0x00;\r
+               MSTOP = 1U;\r
+\r
+               /* Set fMAIN */\r
+               MCM0 = 0U;\r
+\r
+               /* Set fSUB */\r
+               XTSTOP = 1U;\r
+               OSMC = 0x10;\r
+\r
+               /* Set fCLK */\r
+               CSS = 0U;\r
+\r
+               /* Set fIH */\r
+               HIOSTOP = 0U;\r
+       }\r
+       #else\r
+       {\r
+               unsigned char ucTempStabset, ucTempStabWait;\r
+\r
+               /* Set fMX */\r
+               CMC = 0x41;\r
+               OSTS = 0x07;\r
+               MSTOP = 0U;\r
+               ucTempStabset = 0xFF;\r
+\r
+               do\r
+               {\r
+                       ucTempStabWait = OSTC;\r
+                       ucTempStabWait &= ucTempStabset;\r
+               }\r
+               while( ucTempStabWait != ucTempStabset );\r
+\r
+               /* Set fMAIN */\r
+               MCM0 = 1U;\r
+\r
+               /* Set fSUB */\r
+               XTSTOP = 1U;\r
+               OSMC = 0x10;\r
+\r
+               /* Set fCLK */\r
+               CSS = 0U;\r
+\r
+               /* Set fIH */\r
+               HIOSTOP = 0U;\r
+       }\r
+       #endif /* configCLOCK_SOURCE == 1 */\r
+\r
        /* LED port initialization - set port register. */\r
-//     P7 &= 0x7F;\r
-       P1 &= 0xFE;\r
-       \r
+       P7 &= 0x7F;\r
+\r
        /* Set port mode register. */\r
-//     PM7 &= 0x7F;\r
-       PM1 &= 0xFE;\r
-       \r
+       PM7 &= 0x7F;\r
+\r
        /* Switch pin initialization - enable pull-up resistor. */\r
-//     PU12_bit.no0  = 1;\r
+       PU12_bit.no0  = 1;\r
 \r
        return pdTRUE;\r
 }\r
@@ -388,9 +411,12 @@ unsigned portCHAR ucResetFlag = RESF;
 \r
 void vRegTestError( void )\r
 {\r
-       /* Called by both reg test tasks if an error is found.  There is no way out\r
-       of this function so the loop counter of the calling task will stop\r
-       incrementing, which will result in the check timer signialling an error. */\r
+       /* Called by the RegTest tasks if an error is found.  lRegTestStatus is\r
+       inspected by the check task. */\r
+       sRegTestStatus = pdFAIL;\r
+\r
+       /* Do not return from here as the reg test tasks clobber all registers so\r
+       function calls may not function correctly. */\r
        for( ;; );\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -407,7 +433,7 @@ void vApplicationMallocFailedHook( void )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )\r
+void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName )\r
 {\r
        ( void ) pcTaskName;\r
        ( void ) pxTask;\r
@@ -431,6 +457,6 @@ volatile size_t xFreeHeapSpace;
        management options.  If there is a lot of heap memory free then the\r
        configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
        RAM. */\r
-       xFreeHeapSpace = xPortGetFreeHeapSize();        \r
+       xFreeHeapSpace = xPortGetFreeHeapSize();\r
 }\r
 \r