]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/partest/partest.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / PPC440_DP_FPU_Xilinx_Virtex5_GCC / RTOSDemo / partest / partest.c
1 /*\r
2  * FreeRTOS Kernel V10.0.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. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 \r
30 /* Scheduler includes. */\r
31 #include "FreeRTOS.h"\r
32 \r
33 /* Demo application includes. */\r
34 #include "partest.h"\r
35 \r
36 /* Library includes. */\r
37 #include "xparameters.h"\r
38 #include "xgpio_l.h"\r
39 \r
40 /* Misc hardware specific definitions. */\r
41 #define partstALL_AS_OUTPUT     0x00\r
42 #define partstCHANNEL_1         0x01\r
43 #define partstMAX_8BIT_LED      0x07\r
44 \r
45 /* The outputs are split into two IO sections, these variables maintain the \r
46 current value of either section. */\r
47 static unsigned portBASE_TYPE uxCurrentOutput8Bit, uxCurrentOutput5Bit;\r
48 \r
49 /*-----------------------------------------------------------*/\r
50 /*\r
51  * Setup the IO for the LED outputs.\r
52  */\r
53 void vParTestInitialise( void )\r
54 {\r
55         /* Set both sets of LED's on the demo board to outputs. */\r
56         XGpio_mSetDataDirection( XPAR_LEDS_8BIT_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );\r
57         XGpio_mSetDataDirection( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );\r
58 \r
59         /* Start with all outputs off. */\r
60         uxCurrentOutput8Bit = 0;\r
61         XGpio_mSetDataReg( XPAR_LEDS_8BIT_BASEADDR, partstCHANNEL_1, 0x00 );\r
62         uxCurrentOutput5Bit = 0;\r
63         XGpio_mSetDataReg( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, 0x00 );\r
64 }\r
65 /*-----------------------------------------------------------*/\r
66 \r
67 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )\r
68 {\r
69 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;\r
70 \r
71         portENTER_CRITICAL();\r
72         {\r
73                 /* Which IO section does the LED being set/cleared belong to?  The\r
74                 4 bit or 5 bit outputs? */\r
75                 if( uxLED <= partstMAX_8BIT_LED )\r
76                 {\r
77                         uxBaseAddress = XPAR_LEDS_8BIT_BASEADDR;\r
78                         puxCurrentValue = &uxCurrentOutput5Bit;\r
79                 }       \r
80                 else\r
81                 {\r
82                         uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;\r
83                         puxCurrentValue = &uxCurrentOutput8Bit;\r
84                         uxLED -= partstMAX_8BIT_LED;\r
85                 }\r
86 \r
87                 /* Setup the bit mask accordingly. */\r
88                 uxLED = 0x01 << uxLED;\r
89 \r
90                 /* Maintain the current output value. */\r
91                 if( xValue )\r
92                 {\r
93                         *puxCurrentValue |= uxLED;\r
94                 }\r
95                 else\r
96                 {\r
97                         *puxCurrentValue &= ~uxLED;\r
98                 }\r
99 \r
100                 /* Write the value to the port. */\r
101                 XGpio_mSetDataReg( uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );\r
102         }\r
103         portEXIT_CRITICAL();\r
104 }\r
105 /*-----------------------------------------------------------*/\r
106 \r
107 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
108 {\r
109 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;\r
110 \r
111         portENTER_CRITICAL();\r
112         {\r
113                 /* Which IO section does the LED being toggled belong to?  The\r
114                 4 bit or 5 bit outputs? */\r
115                 if( uxLED <= partstMAX_8BIT_LED )\r
116                 {\r
117 \r
118                         uxBaseAddress = XPAR_LEDS_8BIT_BASEADDR;\r
119                         puxCurrentValue = &uxCurrentOutput5Bit;\r
120                 }       \r
121                 else\r
122                 {\r
123                         uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;\r
124                         puxCurrentValue = &uxCurrentOutput8Bit;\r
125                         uxLED -= partstMAX_8BIT_LED;\r
126                 }\r
127 \r
128                 /* Setup the bit mask accordingly. */\r
129                 uxLED = 0x01 << uxLED;\r
130 \r
131                 /* Maintain the current output value. */\r
132                 if( *puxCurrentValue & uxLED )\r
133                 {\r
134                         *puxCurrentValue &= ~uxLED;\r
135                 }\r
136                 else\r
137                 {\r
138                         *puxCurrentValue |= uxLED;\r
139                 }\r
140 \r
141                 /* Write the value to the port. */\r
142                 XGpio_mSetDataReg(uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );\r
143         }\r
144         portEXIT_CRITICAL();\r
145 }\r
146 \r
147 \r