]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/main.c
e73f29f469cbed46d6065f16c9100a9846e0392f
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / main.c
1 /*\r
2  * FreeRTOS Kernel V10.1.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /******************************************************************************\r
29  * This project provides two demo applications.  A simple blinky style project,\r
30  * and a more comprehensive test and demo application.  The\r
31  * configCREATE_SIMPLE_TICKLESS_DEMO setting (defined in FreeRTOSConfig.h) is\r
32  * used to select between the two.  The simply blinky demo is implemented and\r
33  * described in main_blinky.c.  The more comprehensive test and demo application\r
34  * is implemented and described in main_full.c.\r
35  *\r
36  * The comprehensive demo uses FreeRTOS+CLI to create a simple command line\r
37  * interface through a UART.\r
38  *\r
39  * The blinky demo uses FreeRTOS's tickless idle mode to reduce power\r
40  * consumption.  See the notes on the web page below regarding the difference\r
41  * in power saving that can be achieved between using the generic tickless\r
42  * implementation (as used by the blinky demo) and a tickless implementation\r
43  * that is tailored specifically to the MSP432.\r
44  *\r
45  * This file implements the code that is not demo specific.\r
46  *\r
47  * See http://www.FreeRTOS.org/TI_MSP432_Free_RTOS_Demo.html for instructions.\r
48  *\r
49  */\r
50 \r
51 /* Standard includes. */\r
52 #include <stdio.h>\r
53 \r
54 /* Kernel includes. */\r
55 #include "FreeRTOS.h"\r
56 #include "task.h"\r
57 \r
58 /*-----------------------------------------------------------*/\r
59 \r
60 /* NOTE: If an IAR build results in an undefined "reference to __write" linker\r
61 error then set the printf formatter project option to "tiny" and the scanf\r
62 formatter project option to "small". */\r
63 \r
64 /*\r
65  * Set up the hardware ready to run this demo.\r
66  */\r
67 static void prvSetupHardware( void );\r
68 \r
69 /*\r
70  * main_blinky() is used when configCREATE_SIMPLE_TICKLESS_DEMO is set to 1.\r
71  * main_full() is used when configCREATE_SIMPLE_TICKLESS_DEMO is set to 0.\r
72  */\r
73 extern void main_blinky( void );\r
74 extern void main_full( void );\r
75 \r
76 /*-----------------------------------------------------------*/\r
77 \r
78 int main( void )\r
79 {\r
80         /* See http://www.FreeRTOS.org/TI_MSP432_Free_RTOS_Demo.html for instructions. */\r
81 \r
82         /* Prepare the hardware to run this demo. */\r
83         prvSetupHardware();\r
84 \r
85         /* The configCREATE_SIMPLE_TICKLESS_DEMO setting is described at the top\r
86         of this file. */\r
87         #if( configCREATE_SIMPLE_TICKLESS_DEMO == 1 )\r
88         {\r
89                 main_blinky();\r
90         }\r
91         #else\r
92         {\r
93                 main_full();\r
94         }\r
95         #endif\r
96 \r
97         return 0;\r
98 }\r
99 /*-----------------------------------------------------------*/\r
100 \r
101 static void prvSetupHardware( void )\r
102 {\r
103 extern void FPU_enableModule( void );\r
104 \r
105         /* The clocks are not configured here, but inside main_full() and\r
106         main_blinky() as the full demo uses a fast clock and the blinky demo uses\r
107         a slow clock. */\r
108 \r
109         /* Stop the watchdog timer. */\r
110         MAP_WDT_A_holdTimer();\r
111 \r
112         /* Ensure the FPU is enabled. */\r
113         FPU_enableModule();\r
114 \r
115         /* Selecting P1.2 and P1.3 in UART mode and P1.0 as output (LED) */\r
116         MAP_GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P1, GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION );\r
117         MAP_GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 );\r
118         MAP_GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 );\r
119 }\r
120 /*-----------------------------------------------------------*/\r
121 \r
122 void vApplicationMallocFailedHook( void )\r
123 {\r
124         /* vApplicationMallocFailedHook() will only be called if\r
125         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
126         function that will get called if a call to pvPortMalloc() fails.\r
127         pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
128         timer or semaphore is created.  It is also called by various parts of the\r
129         demo application.  If heap_1.c or heap_2.c are used, then the size of the\r
130         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in\r
131         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
132         to query the size of free heap space that remains (although it does not\r
133         provide information on how the remaining heap might be fragmented). */\r
134         taskDISABLE_INTERRUPTS();\r
135         for( ;; );\r
136 }\r
137 /*-----------------------------------------------------------*/\r
138 \r
139 void vApplicationIdleHook( void )\r
140 {\r
141         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set\r
142         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle\r
143         task.  It is essential that code added to this hook function never attempts\r
144         to block in any way (for example, call xQueueReceive() with a block time\r
145         specified, or call vTaskDelay()).  If the application makes use of the\r
146         vTaskDelete() API function (as this demo application does) then it is also\r
147         important that vApplicationIdleHook() is permitted to return to its calling\r
148         function, because it is the responsibility of the idle task to clean up\r
149         memory allocated by the kernel to any task that has since been deleted. */\r
150 }\r
151 /*-----------------------------------------------------------*/\r
152 \r
153 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
154 {\r
155         ( void ) pcTaskName;\r
156         ( void ) pxTask;\r
157 \r
158         /* Run time stack overflow checking is performed if\r
159         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
160         function is called if a stack overflow is detected. */\r
161         taskDISABLE_INTERRUPTS();\r
162         for( ;; );\r
163 }\r
164 /*-----------------------------------------------------------*/\r
165 \r
166 void *malloc( size_t xSize )\r
167 {\r
168         /* There should not be a heap defined, so trap any attempts to call\r
169         malloc. */\r
170         Interrupt_disableMaster();\r
171         for( ;; );\r
172 }\r
173 /*-----------------------------------------------------------*/\r
174 \r
175 \r