| Digital Power Starter Kit 3 Firmware dsPIC33C Boost Converter Voltage Mode Control Example |

app_led.c
1 /*
2 * File: lcd.c
3 * Author: M91406
4 *
5 * Created on March 12, 2020, 12:10 PM
6 */
7
8
9 #include "config/apps.h"
10 #include "config/hal.h"
11
12 // PRIVATE VARIABLE DELARATIONS
13 static volatile uint16_t tgl_cnt = 0; // local counter of LED toggle loops
14 #define TGL_INTERVAL 4 // LED toggle interval of 5 x 100 ms = 500 ms
15 #define TGL_INTERVAL_ERR 0 // LED toggle interval of 1 x 100 ms = 100 ms
16
17 volatile DEBUGGING_LED_t debug_led;
18
19 /*********************************************************************************
20 * @ingroup app-layer-debug-led-functions-public
21 * @fn volatile uint16_t appLED_Initialize(void)
22 * @brief Initializes the LED driving GPIO
23 * @param void
24 * @return unsigned int (0=failure, 1=success)
25 * @details
26 * This routine configures the driving GPIO as output and sets the initial
27 * toggle interval of the debugging LED.
28 **********************************************************************************/
29
30 volatile uint16_t appLED_Initialize(void)
31 {
32 volatile uint16_t retval = 1;
33
34 if(debug_led.period == 0)
35 debug_led.period = TGL_INTERVAL;
36
37 DBGLED_Init();
38
39 return(retval);
40 }
41
42 /*********************************************************************************
43 * @ingroup app-layer-debug-led-functions-public
44 * @fn volatile uint16_t appLED_Execute(void)
45 * @brief Executes the debugging LED driver
46 * @param void
47 * @return unsigned int (0=failure, 1=success)
48 * @details
49 * This routine executes the debugging LED driver controlling the toggling
50 * interval of the debugging LED.
51 **********************************************************************************/
52
53 volatile uint16_t appLED_Execute(void)
54 {
55 volatile uint16_t retval = 1;
56
57 DBGPIN1_Set();
58
59 // Exit early if debugging LED is disabled
60 if (!debug_led.status.bits.enabled)
61 return(1);
62
63 // Change LED toggle frequency when power supply is in fault state
64 if (boost.status.bits.fault_active)
65 debug_led.period = TGL_INTERVAL_ERR;
66 else
67 debug_led.period = TGL_INTERVAL;
68
69 // Toggle LED, refresh LCD and reset toggle counter
70 if (++tgl_cnt > debug_led.period) { // Count n loops until LED toggle interval is exceeded
71 DBGLED_Toggle();
72 debug_led.status.bits.on = (bool)(DBGLED_Get() == DBGLED_ON);
73 tgl_cnt = 0;
74 }
75
76 DBGPIN1_Clear();
77
78 return(retval);
79 }
80
81 /*********************************************************************************
82 * @ingroup app-layer-debug-led-functions-public
83 * @fn volatile uint16_t appLED_Start(void)
84 * @brief Enables the periodic refresh of the debugging LED status
85 * @param void
86 * @return unsigned int (0=failure, 1=success)
87 * @details
88 * This routine is used to allow function 'appLED_Execute' to periodically
89 * refresh the debugging LED status.
90 **********************************************************************************/
91
92 volatile uint16_t appLED_Start(void)
93 {
94 volatile uint16_t retval = 1;
95
96 debug_led.status.bits.enabled = true;
97 retval &= (uint16_t)(debug_led.status.bits.enabled);
98
99 return(retval);
100 }
101
102 /*********************************************************************************
103 * @ingroup app-layer-debug-led-functions-public
104 * @fn volatile uint16_t appLED_Dispose(void)
105 * @brief Frees the resources of the debugging LED driver
106 * @param void
107 * @return unsigned int (0=failure, 1=success)
108 * @details
109 * This routine is used to end the debugging LED driver task and frees
110 * its resources.
111 **********************************************************************************/
112
113 volatile uint16_t appLED_Dispose(void)
114 {
115 volatile uint16_t retval = 1;
116
117 debug_led.period = 0;
118 DBGLED_Dispose();
119
120 return(retval);
121 }
122
123 // end of file
BOOST_CONVERTER_STATUS_s::fault_active
volatile bool fault_active
Bit #5: Flag bit indicating system is in enforced shut down mode (usually due to a fault condition)
Definition: dev_boost_typedef.h:214
DEBUGGING_LED_s::period
volatile uint16_t period
Definition: app_led.h:85
DEBUGGING_LED_STATUS_s::on
unsigned on
Definition: app_led.h:59
DEBUGGING_LED_s
Definition: app_led.h:83
DEBUGGING_LED_s::status
volatile struct DEBUGGING_LED_STATUS_s status
Status word of the Debugging LED driver.
Definition: app_led.h:84
DEBUGGING_LED_STATUS_s::enabled
unsigned enabled
Definition: app_led.h:75
BOOST_CONVERTER_s::status
volatile struct BOOST_CONVERTER_STATUS_s status
BOOST operation status bits.
Definition: dev_boost_typedef.h:529