]> begriffs open source - cmsis-freertos/blob - Demo/CORTEX_MB9B500_IAR_Keil/ParTest.c
Updated pack to FreeRTOS 10.3.1
[cmsis-freertos] / Demo / CORTEX_MB9B500_IAR_Keil / ParTest.c
1 /*
2  * FreeRTOS Kernel V10.3.1
3  * Copyright (C) 2020 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 /*-----------------------------------------------------------
29  * Simple parallel port IO routines.
30  *-----------------------------------------------------------*/
31
32 /* Kernel includes. */
33 #include "FreeRTOS.h"
34 #include "task.h"
35
36 /* Fujitsu drivers/libraries. */
37 #include "mb9bf506n.h"
38 #include "system_mb9bf50x.h"
39
40 /* Only the LEDs on one of the two seven segment displays are used. */
41 #define partstMAX_LEDS          8
42
43 /* The LEDs are controlled by bits 8 to 15 of the IO port. */
44 #define partstLED_0_OFFSET      8
45
46 /*-----------------------------------------------------------*/
47
48 void vParTestInitialise( void )
49 {
50 const unsigned short usGPIOState = 0xFF00U;
51
52         /* Analog inputs are not used on the LED outputs. */
53         FM3_GPIO->ADE  = 0x00FF;
54         
55         /* LED seg1 to GPIO output (P18->P1F). */
56         FM3_GPIO->DDR1 = 0xFF00;
57         FM3_GPIO->PFR1 = 0x0000;
58         
59         /* LED seg2 to GPIO output (P30->P3F). */
60         FM3_GPIO->DDR3 = 0xFF00;
61         FM3_GPIO->PFR3 = 0x0000;
62         
63         /* Start with all LEDs off. */
64         FM3_GPIO->PDOR3 = usGPIOState;
65         FM3_GPIO->PDOR1 = usGPIOState;
66 }
67 /*-----------------------------------------------------------*/
68
69 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
70 {
71         if( uxLED < partstMAX_LEDS )
72         {
73                 /* A critical section is used as the LEDs are also accessed from an
74                 interrupt. */
75                 taskENTER_CRITICAL();
76                 {
77                         if( xValue == pdTRUE )
78                         {
79                                 FM3_GPIO->PDOR3 &= ~( 1UL << ( uxLED + partstLED_0_OFFSET ) );
80                         }
81                         else
82                         {
83                                 FM3_GPIO->PDOR3 |= ( 1UL << ( uxLED + partstLED_0_OFFSET ) );
84                         }
85                 }
86                 taskEXIT_CRITICAL();
87         }
88 }
89 /*-----------------------------------------------------------*/
90
91 void vParTestSetLEDFromISR( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
92 {
93 unsigned portBASE_TYPE uxInterruptFlags;
94
95         uxInterruptFlags = portSET_INTERRUPT_MASK_FROM_ISR();
96         {
97                 if( uxLED < partstMAX_LEDS )
98                 {
99                         if( xValue == pdTRUE )
100                         {
101                                 FM3_GPIO->PDOR3 &= ~( 1UL << ( uxLED + partstLED_0_OFFSET ) );
102                         }
103                         else
104                         {
105                                 FM3_GPIO->PDOR3 |= ( 1UL << ( uxLED + partstLED_0_OFFSET ) );
106                         }
107                 }
108         }
109         portCLEAR_INTERRUPT_MASK_FROM_ISR( uxInterruptFlags );
110 }
111 /*-----------------------------------------------------------*/
112
113 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
114 {
115         if( uxLED < partstMAX_LEDS )
116         {
117                 /* A critical section is used as the LEDs are also accessed from an
118                 interrupt. */
119                 taskENTER_CRITICAL();
120                 {
121                         if( ( FM3_GPIO->PDOR3 & ( 1UL << ( uxLED + partstLED_0_OFFSET ) ) ) != 0UL )
122                         {
123                                 FM3_GPIO->PDOR3 &= ~( 1UL << ( uxLED + partstLED_0_OFFSET ) );
124                         }
125                         else
126                         {
127                                 FM3_GPIO->PDOR3 |= ( 1UL << ( uxLED + partstLED_0_OFFSET ) );
128                         }
129                 }
130                 taskEXIT_CRITICAL();
131         }
132 }
133 /*-----------------------------------------------------------*/
134
135 long lParTestGetLEDState( unsigned long ulLED )
136 {
137 long lReturn = pdFALSE;
138
139         if( ulLED < partstMAX_LEDS )
140         {
141                 taskENTER_CRITICAL();
142                 {
143                         if( ( FM3_GPIO->PDOR3 & ( 1UL << ( ulLED + partstLED_0_OFFSET ) ) ) == 0UL )
144                         {
145                                 lReturn = pdTRUE;
146                         }
147                 }
148                 taskEXIT_CRITICAL();
149         }
150
151         return lReturn;
152 }
153 /*-----------------------------------------------------------*/