2 * FreeRTOS Kernel V10.1.1
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
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.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
28 /* Scheduler includes. */
32 /* Demo app includes. */
35 /* Hardware specific definitions. */
36 #include "AT91R40008.h"
40 #define partstNUM_LEDS ( 8 )
41 #define partstALL_OUTPUTS_OFF ( ( unsigned long ) ~(0xFFFFFFFF << partstNUM_LEDS) )
43 static unsigned long ulLEDReg;
45 /*-----------------------------------------------------------
46 * Simple parallel port IO routines.
47 *-----------------------------------------------------------*/
49 static void SetLeds (unsigned int leds)
51 unsigned long ulPIOSetReg, ulPIOClearReg;
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. */
56 ulPIOSetReg = ( (leds & 0xF) << 16 ) | ( (leds & 0xF0) >> 1 );
57 ulPIOClearReg = (~ulPIOSetReg) & 0x000F0078;
59 AT91C_BASE_PIO->PIO_SODR = ulPIOSetReg;
60 AT91C_BASE_PIO->PIO_CODR = ulPIOClearReg;
62 /*-----------------------------------------------------------*/
64 void vParTestInitialise( void )
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;
70 /* Enable clock to PIO... */
71 AT91C_BASE_PS->PS_PCER = AT91C_PS_PIO;
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;
76 /* Configure all LED PIO lines for output... */
77 AT91C_BASE_PIO->PIO_OER = P3 | P4 | P5 | P6 | P16 | P17 | P18 | P19;
79 /* Configure all switch PIO lines for input... */
80 AT91C_BASE_PIO->PIO_ODR = P1 | P2 | P9 | P12;
82 /* Set initial state of LEDs. */
85 /*-----------------------------------------------------------*/
87 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
89 /* Switch an LED on or off as requested. */
90 if (uxLED < partstNUM_LEDS)
94 ulLEDReg &= ~(1 << uxLED);
98 ulLEDReg |= (1 << uxLED);
104 /*-----------------------------------------------------------*/
106 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
108 /* Toggle the state of the requested LED. */
109 if (uxLED < partstNUM_LEDS)
111 ulLEDReg ^= ( 1 << uxLED );