|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
dev_led.c
Go to the documentation of this file.
1/*
2 * @ingroup version-information
3 * @file dev_led.c
4 * @details <b>Description</b><br>This file has all the logic for led blinkys.
5 * @author M70027
6 * @author M70027
7 * @version 1.0
8 * @date 2024
9 * @warning Improper use can crash your application.
10 * @copyright
11 */
12
13/*
14 (c) 2024 Microchip Technology Inc. and its subsidiaries. You may use this
15 software and any derivatives exclusively with Microchip products.
16
17 THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
18 EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
19 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
20 PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
21 WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
22
23 IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
24 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
25 WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
26 BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
27 FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
28 ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
29 THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
30
31 MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
32 TERMS.
33 */
34
35
41#include "xc.h"
42#include "dev_led.h"
43#include "system/pins.h"
44
45
51#define LED_STATE_OFF 0
52#define LED_STATE_ON 1
53#define LED_STATE_BLINK 2
54#define LED_STATE_BLINK_SLOW 3
55#define LED_STATE_BLINK_FAST 4
56#define LED_STATE_BLINK_COUNT 5
57
// end of dev-led-enums-private
59
60
63uint8_t ledStates[NUM_OF_LEDS];
64uint8_t ledTimer[NUM_OF_LEDS];
65
66
67uint8_t ledIterationsCounter[NUM_OF_LEDS];
68
78 void Dev_LED_Initialize(void)
79{
80 //Peripherals are initialized by MCC
81 Dev_LED_Blink(LED_PIM_RED);
82 Dev_LED_Blink(LED_BOARD_GREEN);
83 Dev_LED_Blink(LED_BOARD_RED);
84}
85
86
94 void Dev_LED_On(uint8_t led_id)
95{
96 if (led_id >= NUM_OF_LEDS)
97 return;
98 if (ledStates[led_id] == LED_STATE_ON)
99 return;
100 ledStates[led_id] = LED_STATE_ON;
101 switch(led_id)
102 {
103 case LED_PIM_RED: LED_DP_PIM_on(); break;
104 case LED_BOARD_RED: LED_Board_Red_On(); break;
105 case LED_BOARD_GREEN: LED_Board_Green_On(); break;
106 default: Nop(); break;
107 }
108}
109
110
118 void Dev_LED_Off(uint8_t led_id)
119{
120 if (led_id >= NUM_OF_LEDS)
121 return;
122 if (ledStates[led_id] == LED_STATE_OFF)
123 return;
124 ledStates[led_id] = LED_STATE_OFF;
125 switch(led_id)
126 {
127 case LED_PIM_RED: LED_DP_PIM_off(); break;
128 case LED_BOARD_RED: LED_Board_Red_Off(); break;
129 case LED_BOARD_GREEN: LED_Board_Green_Off(); break;
130 default: Nop(); break;
131 }
132}
133
134
142 void Dev_LED_Toggle(uint8_t led_id)
143{
144 switch(led_id)
145 {
146 case LED_PIM_RED: LED_DP_PIM_Toggle_State(); break;
147 case LED_BOARD_RED: LED_Board_Red_Toggle_State(); break;
148 case LED_BOARD_GREEN: LED_Board_Green_Toggle_State(); break;
149 default: Nop(); break;
150 }
151}
152
153
161 void Dev_LED_Blink(uint8_t led_id)
162{
163 if (led_id >= NUM_OF_LEDS)
164 return;
165 ledStates[led_id] = LED_STATE_BLINK;
166}
167
168
176 void Dev_LED_Blink_Iter(uint8_t led_id, uint8_t count)
177{
178 if (led_id >= NUM_OF_LEDS)
179 return;
180 ledStates[led_id] = LED_STATE_BLINK_COUNT;
181 ledIterationsCounter[led_id] = count;
182}
183
184
192 void Dev_LED_Blink_Slow(uint8_t led_id)
193{
194 if (led_id >= NUM_OF_LEDS)
195 return;
196 ledStates[led_id] = LED_STATE_BLINK_SLOW;
197}
198
199
207 void Dev_LED_Blink_Fast(uint8_t led_id)
208{
209 if (led_id >= NUM_OF_LEDS)
210 return;
211 ledStates[led_id] = LED_STATE_BLINK_FAST;
212}
213
214
224 void Dev_LED_Task_100ms()
225{
226 uint8_t led_index=0;
227 uint8_t timermax=0;
228
229 for (led_index = 0; led_index < NUM_OF_LEDS; led_index++)
230 {
231 if (ledStates[led_index] > LED_STATE_ON)
232 {
233 if (ledStates[led_index] == LED_STATE_BLINK_SLOW)
234 timermax = BLINK_SLOW_INTERVAL;
235 else if (ledStates[led_index] == LED_STATE_BLINK_FAST)
236 timermax = BLINK_FAST_INTERVAL;
237 else // normal speed
238 timermax = BLINK_INTERVAL;
239 if (++ledTimer[led_index] >= timermax)
240 {
241 ledTimer[led_index] = 0;
242 switch(led_index)
243 {
244 case LED_PIM_RED: LED_DP_PIM_Toggle_State(); break;
245 case LED_BOARD_RED: LED_Board_Red_Toggle_State(); break;
246 case LED_BOARD_GREEN: LED_Board_Green_Toggle_State(); break;
247 default: Nop(); break;
248 }
249 }
250 }
251 }
252}
ledTimer
uint8_t ledTimer[NUM_OF_LEDS]
array that stores led blink times
Definition dev_led.c:64
ledIterationsCounter
uint8_t ledIterationsCounter[NUM_OF_LEDS]
Definition dev_led.c:67
ledStates
uint8_t ledStates[NUM_OF_LEDS]
array that stores the led states
Definition dev_led.c:63
dev_led.h
led device driver
NUM_OF_LEDS
#define NUM_OF_LEDS
Definition dev_led.h:31
LED_BOARD_GREEN
#define LED_BOARD_GREEN
Definition dev_led.h:62
LED_PIM_RED
#define LED_PIM_RED
enumerating away
Definition dev_led.h:60
LED_DP_PIM_Toggle_State
#define LED_DP_PIM_Toggle_State
Definition dev_led.h:51
LED_Board_Red_On
#define LED_Board_Red_On
abstracting away led mcc function calls.
Definition dev_led.h:41
BLINK_SLOW_INTERVAL
#define BLINK_SLOW_INTERVAL
Definition dev_led.h:66
LED_DP_PIM_off
#define LED_DP_PIM_off
Definition dev_led.h:50
BLINK_FAST_INTERVAL
#define BLINK_FAST_INTERVAL
Definition dev_led.h:67
LED_Board_Green_On
#define LED_Board_Green_On
Definition dev_led.h:45
LED_DP_PIM_on
#define LED_DP_PIM_on
Definition dev_led.h:49
LED_Board_Green_Off
#define LED_Board_Green_Off
Definition dev_led.h:46
LED_Board_Green_Toggle_State
#define LED_Board_Green_Toggle_State
Definition dev_led.h:47
LED_Board_Red_Toggle_State
#define LED_Board_Red_Toggle_State
Definition dev_led.h:43
BLINK_INTERVAL
#define BLINK_INTERVAL
Definition dev_led.h:68
LED_BOARD_RED
#define LED_BOARD_RED
Definition dev_led.h:61
LED_Board_Red_Off
#define LED_Board_Red_Off
Definition dev_led.h:42
LED_STATE_ON
#define LED_STATE_ON
Definition dev_led.c:52
LED_STATE_BLINK_FAST
#define LED_STATE_BLINK_FAST
Definition dev_led.c:55
Dev_LED_Initialize
void Dev_LED_Initialize(void)
This function contains the LED initialization.
Definition dev_led.c:78
Dev_LED_Blink_Slow
void Dev_LED_Blink_Slow(uint8_t led_id)
Set the LED in SLOW blinking mode.
Definition dev_led.c:192
Dev_LED_Off
void Dev_LED_Off(uint8_t led_id)
Switch off the LED.
Definition dev_led.c:118
Dev_LED_On
void Dev_LED_On(uint8_t led_id)
Switch on the LED.
Definition dev_led.c:94
LED_STATE_OFF
#define LED_STATE_OFF
These are the macros indicating the status of the LED.
Definition dev_led.c:51
Dev_LED_Blink_Fast
void Dev_LED_Blink_Fast(uint8_t led_id)
Set the LED in FAST blinking mode.
Definition dev_led.c:207
LED_STATE_BLINK_COUNT
#define LED_STATE_BLINK_COUNT
Definition dev_led.c:56
Dev_LED_Blink_Iter
void Dev_LED_Blink_Iter(uint8_t led_id, uint8_t count)
Set the LED in blinking mode in number of LED iterations.
Definition dev_led.c:176
LED_STATE_BLINK_SLOW
#define LED_STATE_BLINK_SLOW
Definition dev_led.c:54
Dev_LED_Toggle
void Dev_LED_Toggle(uint8_t led_id)
Toggles the LED state.
Definition dev_led.c:142
Dev_LED_Task_100ms
void Dev_LED_Task_100ms()
This function needs to be called every 100ms and contains the code to update the status of the LEDs.
Definition dev_led.c:224
LED_STATE_BLINK
#define LED_STATE_BLINK
Definition dev_led.c:53
Dev_LED_Blink
void Dev_LED_Blink(uint8_t led_id)
Set the LED in blinking mode.
Definition dev_led.c:161