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

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 data types
10 #include <stdbool.h> // include standard boolean data types
11
12 #include "main.h" // include main header
13 #include "config/apps.h"
14
15 /*******************************************************************************
16 * @fn int main(void)
17 * @ingroup firmware-flow
18 * @brief Application main function executed after device comes out of RESET
19 * @return Signed Integer (0=failure, 1=success)
20 * @details
21 * This function is the starting point of the firmware. It is called after the
22 * device is coming out of RESET, starting to execute code. The startup sequence
23 * is as follows:
24 *
25 * 1) Boot():
26 *
27 * Configures fundamental system components
28 *
29 * Fundamental components are peripherals which are essential for the CPU to run,
30 * such as
31 *
32 * - system oscillator
33 * - auxiliary oscillator
34 * - general purpose input/output configuration
35 * - digital signal processor configuration
36 *
37 * 2) sysUserPeriperhals_Initialize()
38 *
39 * User-defined, static peripheral configurations (optional)
40 *
41 * Specific peripheral modules required to support circuit functions
42 * of the hardware, which are not covered by any task library, such as
43 *
44 * - Digital-To-Analog Converter (DAC):
45 * This peripheral instance is used to provide an analog debugging signal which
46 * can be used to output internal high-speed signals/values on an oscilloscope.
47 *
48 * - Operational Amplifier (OPA)
49 * The analog debugging signal generated by the DAC is buffered by one of the
50 * internal operational amplifiers to stabilize the signal when probed.
51 *
52 * 3) rtos_Execute()
53 *
54 * This application executes five tasks simultaneously:
55 *
56 * - High Priority Tasks
57 * - Power Supply State Machine & Control
58 * - System Fault Monitor & Diagnostics
59 *
60 * - Low Priority Tasks
61 * - LCD Display Control & Update
62 * - On-Board Push-Button HMI Control
63 * - On-Board Debugging LED Control
64 *
65 * The operating system supports four individual task queues:
66 *
67 * - Queue Initialize
68 * - Queue Startup Sequence
69 * - Queue Execute Sequence
70 * - Queue Stop Sequence
71 *
72 * Each 'Task' is an independent process which is called at integer multiples of
73 * the execution frequency. The default frequency (OS base clock) set in this code
74 * version is 100 us (= 10 kHz).
75 *
76 * At device startup the OS will execute all tasks listed in Queue Initialize
77 * where all initialization functions of all listed user tasks will be executed
78 * in one sequence without timing control. Each of the listed tasks must make
79 * sure all required device resources are configured within its individual
80 * initialization routine.
81 *
82 * After all initialization functions have been executed, the OS executes all
83 * tasks of Queue Startup Sequence. This intermediary step allows the alignment
84 * and deterministic startup behavior of all listed user tasks.
85 *
86 * After startup the OS is continuously executing Queue Execute. In each
87 * execution cycle the task execution timing settings Period and Offset are
88 * applied.
89 *
90 * The individual, effective task execution rate is set within each user-task
91 * configuration. The operating system is managing the internal counters of each
92 * task and raises execution triggers at integer multiples of the OS base clock.
93 * Timing settings Priority and Offset can be modified during runtime allowing
94 * readjustments to the application code execution profile. When called, the
95 * OS collects statistical data about the individual task execution and attaches
96 * the results to the individual task object data structure to be observed by
97 * other software processes and allows the detection of task execution quantum
98 * violations.
99 *
100 * High- and low-priority task execution is achieved by setting the high-priority
101 * parameter when Queue Execute gets called from the high priority OS interrupt.
102 * when Queue Execute gets called from the low-priority OS routine, only low-
103 * priority tasks will get called. This allows tasks to be dynamically lifted
104 * or dropped in priority during runtime while their individual task execution
105 * range is kept unchanged during priority transitions.
106 *
107 *********************************************************************************/
108
109 int main(void) {
110
111 volatile uint16_t retval = 1;
112
113 // Initialize basic system configuration
114 retval &= Boot();
115
116 // Initialize special, application-specific peripherals
117 retval &= sysUserPeriperhals_Initialize();
118
119 // Main program execution
120 retval &= rtos_Execute();
121
122 // if the firmware ever ends up here, reset the CPU
123 CPU_RESET();
124
125 // Main program execution
126 retval &= rtos_Execute();
127
128 // When the OS is exited, a CPU RESET will be triggered
129 // This section of the code should never be reached.
130
131 return (0);
132 }
133
134 // ______________________________________
135 // end of file