EPC9143 300 W 16th Brick DC/DC Module Reference Design
main.c
1 /*
2  * File: main.c
3  * Author: M91406
4  *
5  * Created on July 8, 2019, 1:52 PM
6  */
7 
8 #include <xc.h> // include processor files - each processor file is guarded.
9 #include <stdint.h> // include standard integer types header file
10 #include <stdbool.h> // include standard boolean types header file
11 
12 #include "main.h"
13 
14 volatile bool run_main = true; // Flag allowing to terminate the main loop and restart the CPU
15 
16 #define TMR1_TIMEOUT 30000 // Timeout protection for Timer1 interrupt flag bit
17 volatile bool LOW_PRIORITY_GO = false; // Flag allowing low priority tasks to be executed
18 
19 /* PRIVATE FUNCTION CALL PROTOTYPES */
20 volatile uint16_t sysLowPriorityTasks_Execute(void);
21 volatile uint16_t __attribute__((always_inline)) sysHighPriorityTasks_Execute(void);
22 
23 
72 int main(void) {
73 
74  volatile uint16_t retval=1;
75  volatile uint16_t timeout = 0;
76 
77  // Initialize basic system configuration
78  retval &= SYSTEM_Initialize();
79 
80  // Initialize special, application-specific peripherals
82 
83  // Initialize software modules
84  retval &= sysUserTasks_Initialize();
85 
86  // Enable OS Timer
87  retval &= sysOsTimer_Enable(true, 1);
88 
89  // Last line of defense:
90  // when configuration of any block failed...
91  if (!retval)
92  CPU_RESET(); // reset the CPU and try again
93 
94  // Main program execution
95  while (run_main) {
96 
97  // wait for Timer1 to overrun and the high-priority task interrupt to
98  // be executed
99  while ((!LOW_PRIORITY_GO) && (timeout++ < TMR1_TIMEOUT));
100  LOW_PRIORITY_GO = false;
101  timeout = 0; // Reset timeout counter
102 
103  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104  // Execute non-time critical, low-priority tasks
105 
106  retval &= sysLowPriorityTasks_Execute();
107 
108  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
109 
110  }
111 
112  CPU_RESET(); // if the firmware ever ends up here, reset the CPU
113 
114  return (0);
115 }
116 
117 
134 volatile uint16_t sysLowPriorityTasks_Execute(void)
135 {
136  volatile uint16_t retval=1;
137 
138  // (no low priority tasks)
139 
140  return(retval);
141 }
142 
143 
144 
162 volatile uint16_t sysHighPriorityTasks_Execute(void)
163 {
164  volatile uint16_t retval=1;
165 
166  // Execute high priority, time critical tasks
167  retval &= appPowerSupply_Execute(); // Execute power supply state machine
168  retval &= appFaultMonitor_Execute(); // Execute fault handler
169 
170  return(retval);
171 }
172 
173 
174 
184 void __attribute__((__interrupt__, context, no_auto_psv)) _OsTimerInterrupt(void)
185 {
186  volatile uint16_t retval=1;
187 
188  #ifdef DBGPIN2_Set
189  DBGPIN2_Set(); // Set the CPU debugging pin HIGH
190  #endif
191 
192  retval &= sysHighPriorityTasks_Execute(); // Execute list of high priority tasks
193 
194  LOW_PRIORITY_GO = true; // Set GO trigger for low priority tasks
195  _OSTIMER_IF = 0; // Reset the interrupt flag bit
196 
197  #ifdef DBGPIN2_Set
198  DBGPIN2_Clear(); // Clear the CPU debugging pin
199  #endif
200 
201  return;
202 }
203 
204 // ______________________________________
205 // end of file
206 
207 
208 
209 
DBGPIN2_Clear
#define DBGPIN2_Clear()
Macro instruction to set a pin state to logic LOW.
Definition: epc9143_r40_hwdescr.h:212
sysOsTimer_Enable
volatile uint16_t sysOsTimer_Enable(volatile bool interrupt_enable, volatile uint8_t interrupt_priority)
Definition: init_timer1.c:81
DBGPIN2_Set
#define DBGPIN2_Set()
Macro instruction to set a pin state to logic HIGH.
Definition: epc9143_r40_hwdescr.h:211
_OSTIMER_IF
#define _OSTIMER_IF
interrupt flag bit
Definition: epc9143_r40_hwdescr.h:180
appFaultMonitor_Execute
volatile uint16_t appFaultMonitor_Execute(void)
Application wide fault object monitoring routine.
Definition: app_fault_monitor.c:40
sysUserPeriperhals_Initialize
volatile uint16_t sysUserPeriperhals_Initialize(void)
Initializes the user-defined chip resources.
Definition: system.c:52
appPowerSupply_Execute
volatile uint16_t appPowerSupply_Execute(void)
This is the top-level function call triggering the most recent state machine of all associated power ...
Definition: app_power_control.c:71
_OsTimerInterrupt
#define _OsTimerInterrupt
Global state-machine peripheral assignments.
Definition: epc9143_r40_hwdescr.h:177
sysHighPriorityTasks_Execute
volatile uint16_t sysHighPriorityTasks_Execute(void)
High priority task sequence executed at a fixed repetition frequency.
Definition: main.c:162
sysLowPriorityTasks_Execute
volatile uint16_t sysLowPriorityTasks_Execute(void)
Low priority task sequence executed after the high priority task sequence execution is complete.
Definition: main.c:134
sysUserTasks_Initialize
volatile uint16_t sysUserTasks_Initialize(void)
Initializes the user-defined tasks.
Definition: system.c:95
SYSTEM_Initialize
volatile uint16_t SYSTEM_Initialize(void)
Initializes essential chip resources.
Definition: system.c:27