]> begriffs open source - cmsis-freertos/blob - Demo/ARM7_AT91FR40008_GCC/ParTest/ParTest.c
Set error state if no delay or already expired
[cmsis-freertos] / Demo / ARM7_AT91FR40008_GCC / ParTest / ParTest.c
1 /*
2  * FreeRTOS Kernel V10.1.1
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /* Scheduler includes. */
29 #include "FreeRTOS.h"
30 #include "portable.h"
31
32 /* Demo app includes. */
33 #include "partest.h"
34
35 /* Hardware specific definitions. */
36 #include "AT91R40008.h"
37 #include "pio.h"
38 #include "aic.h"
39
40 #define partstNUM_LEDS                  ( 8 )
41 #define partstALL_OUTPUTS_OFF   ( ( unsigned long ) ~(0xFFFFFFFF << partstNUM_LEDS) )
42
43 static unsigned long ulLEDReg;
44
45 /*-----------------------------------------------------------
46  * Simple parallel port IO routines.
47  *-----------------------------------------------------------*/
48
49 static void SetLeds (unsigned int leds)
50 {
51 unsigned long ulPIOSetReg, ulPIOClearReg;
52
53         /* LEDs are grouped in different port bits: P3-P6 and P16-P19.
54         A port bit set to '0' turns an LED on, '1' turns it off. */
55
56         ulPIOSetReg = ( (leds & 0xF) << 16 ) | ( (leds & 0xF0) >> 1 );
57         ulPIOClearReg = (~ulPIOSetReg) & 0x000F0078;
58
59         AT91C_BASE_PIO->PIO_SODR = ulPIOSetReg;
60         AT91C_BASE_PIO->PIO_CODR = ulPIOClearReg;
61 }
62 /*-----------------------------------------------------------*/
63
64 void vParTestInitialise( void )
65 {
66         /* This is performed from main() as the io bits are shared with other setup
67         functions.  Ensure the outputs are off to start. */
68         ulLEDReg = partstALL_OUTPUTS_OFF;  
69
70         /* Enable clock to PIO... */
71         AT91C_BASE_PS->PS_PCER = AT91C_PS_PIO;
72
73         /* Enable all 8 LEDs and the four switches to be controlled by PIO... */
74         AT91C_BASE_PIO->PIO_PER = P3 | P4 | P5 | P6 | P16 | P17 | P18 | P19 | P1 | P2 | P9 | P12;
75
76         /* Configure all LED PIO lines for output... */
77         AT91C_BASE_PIO->PIO_OER = P3 | P4 | P5 | P6 | P16 | P17 | P18 | P19;
78
79         /* Configure all switch PIO lines for input... */
80         AT91C_BASE_PIO->PIO_ODR = P1 | P2 | P9 | P12;
81
82         /* Set initial state of LEDs. */
83         SetLeds( ulLEDReg );
84 }
85 /*-----------------------------------------------------------*/
86
87 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
88 {
89         /* Switch an LED on or off as requested. */
90         if (uxLED < partstNUM_LEDS)
91         {
92                 if( xValue )
93                 {
94                         ulLEDReg &= ~(1 << uxLED);
95                 }
96                 else
97                 {
98                         ulLEDReg |= (1 << uxLED);
99                 }
100
101                 SetLeds( ulLEDReg );
102         }
103 }
104 /*-----------------------------------------------------------*/
105
106 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
107 {
108         /* Toggle the state of the requested LED. */
109         if (uxLED < partstNUM_LEDS)
110         {
111                 ulLEDReg ^= ( 1 << uxLED );
112                 SetLeds( ulLEDReg );
113         }
114 }
115