@@ -124,14 +124,12 @@ extern page_t curr_page;
124124volatile dashboard_input_state_t input_state = {0 }; // Clear all input states
125125
126126/* Function Prototypes */
127- void preflightAnimation (void );
128- void heartBeatLED ();
129- void lcdTxUpdate ();
130- void enableInterrupts ();
131- void encoderISR ();
132- void handleDashboardInputs ();
133- void sendBrakeStatus ();
134- void sendVersion ();
127+ void preflight_animation (void );
128+ void heartbeat_led ();
129+ void lcd_tx_cmd ();
130+ void config_button_irqs ();
131+ void service_button_inputs ();
132+ void send_version ();
135133extern void HardFault_Handler ();
136134
137135// Communication queues
@@ -140,59 +138,21 @@ q_handle_t q_tx_usart;
140138void preflight_task ();
141139void can_worker_task ();
142140
143- // The preflight thread must not be interrupted, give highest priority
141+ // The preflight thread must not be interrupted, give highest priority (will self exit when finished)
144142defineThreadStack (preflight_task , 10 , osPriorityRealtime , 1024 );
145143
144+ // System critical threads
146145defineThreadStack (pedalsPeriodic , FILT_THROTTLE_BRAKE_PERIOD_MS , osPriorityHigh , 512 );
147146defineThreadStack (can_worker_task , 20 , osPriorityNormal , 512 );
148147
148+ // Auxilary threads
149149defineThreadStack (updateFaultDisplay , 500 , osPriorityLow , 256 );
150- defineThreadStack (heartBeatLED , 500 , osPriorityLow , 128 );
151- defineThreadStack (handleDashboardInputs , 50 , osPriorityLow , 1024 );
152- defineThreadStack (sendVersion , DASH_VERSION_PERIOD_MS , osPriorityLow , 256 );
150+ defineThreadStack (heartbeat_led , 500 , osPriorityLow , 128 );
151+ defineThreadStack (service_button_inputs , 50 , osPriorityLow , 1024 );
152+ defineThreadStack (send_version , DASH_VERSION_PERIOD_MS , osPriorityLow , 256 );
153153defineThreadStack (updateTelemetryPages , 200 , osPriorityLow , 1024 );
154154defineThreadStack (sendTVParameters , DASHBOARD_VCU_PARAMETERS_PERIOD_MS , osPriorityLow , 256 );
155155
156- void preflight_task () {
157- static uint8_t counter = 0 ;
158-
159- // run animation until for at least 1.5 seconds
160- if (counter >= 150 ) {
161- PHAL_writeGPIO (HEART_LED_GPIO_Port , HEART_LED_Pin , 0 );
162- PHAL_writeGPIO (CONN_LED_GPIO_Port , CONN_LED_Pin , 0 );
163- PHAL_writeGPIO (ERROR_LED_GPIO_Port , ERROR_LED_Pin , 0 );
164-
165- // spawn the other threads
166- createThread (pedalsPeriodic );
167- createThread (can_worker_task );
168-
169- createThread (updateFaultDisplay )
170- createThread (heartBeatLED )
171- createThread (handleDashboardInputs )
172- createThread (sendVersion )
173- createThread (updateTelemetryPages )
174- createThread (sendTVParameters )
175- osThreadExit (); // Self delete
176- return ;
177- }
178-
179- if (counter % 10 == 0 ) { // Run every 100ms
180- preflightAnimation ();
181- }
182-
183- counter ++ ;
184- }
185-
186- void can_worker_task () {
187- // Process all received CAN messages
188- CAN_rx_update ();
189-
190- // Drain all CAN transmit queues
191- CAN_tx_update ();
192-
193- lcdTxUpdate ();
194- }
195-
196156int main (void ) {
197157 // Hardware Initialization
198158 if (0 != PHAL_configureClockRates (& clock_config )) {
@@ -216,13 +176,13 @@ int main(void) {
216176 PHAL_startTxfer (& adc_dma_config );
217177 PHAL_startADC (& adc_config );
218178
219- // Begin Software Init tasks
179+ // Software Initialization
220180 osKernelInitialize ();
221181
222182 CAN_library_init ();
223183 initLCD ();
224184 NVIC_EnableIRQ (FDCAN2_IT0_IRQn );
225- enableInterrupts ();
185+ config_button_irqs ();
226186
227187 // show signs of life
228188 PHAL_writeGPIO (BMS_LED_GPIO_Port , BMS_LED_Pin , 1 );
@@ -242,7 +202,47 @@ int main(void) {
242202 return 0 ;
243203}
244204
245- void preflightAnimation (void ) {
205+ void preflight_task () {
206+ static uint8_t counter = 0 ;
207+
208+ // run animation until for at least 1.5 seconds
209+ if (counter >= 150 ) {
210+ PHAL_writeGPIO (HEART_LED_GPIO_Port , HEART_LED_Pin , 0 );
211+ PHAL_writeGPIO (CONN_LED_GPIO_Port , CONN_LED_Pin , 0 );
212+ PHAL_writeGPIO (ERROR_LED_GPIO_Port , ERROR_LED_Pin , 0 );
213+
214+ // spawn the other threads
215+ createThread (pedalsPeriodic );
216+ createThread (can_worker_task );
217+
218+ createThread (updateFaultDisplay )
219+ createThread (heartbeat_led )
220+ createThread (service_button_inputs )
221+ createThread (send_version )
222+ createThread (updateTelemetryPages )
223+ createThread (sendTVParameters )
224+ osThreadExit (); // Self delete
225+ return ;
226+ }
227+
228+ if (counter % 10 == 0 ) { // Run every 100ms
229+ preflight_animation ();
230+ }
231+
232+ counter ++ ;
233+ }
234+
235+ void can_worker_task () {
236+ // Process all received CAN messages
237+ CAN_rx_update ();
238+
239+ // Drain all CAN transmit queues
240+ CAN_tx_update ();
241+
242+ lcd_tx_cmd ();
243+ }
244+
245+ void preflight_animation (void ) {
246246 // Controls external LEDs since they are more visible when dash is in car
247247 static uint32_t external_index ;
248248 static uint32_t sweep_index ;
@@ -279,7 +279,7 @@ void preflightAnimation(void) {
279279 }
280280}
281281
282- void sendVersion () {
282+ void send_version () {
283283 CAN_SEND_dash_version (GIT_HASH );
284284}
285285
@@ -291,7 +291,7 @@ void sendVersion() {
291291 * Controls heartbeat, connection, precharge, IMD and BMS status LEDs.
292292 * Handles periodic CAN statistics transmission.
293293 */
294- void heartBeatLED () {
294+ void heartbeat_led () {
295295 static uint8_t imd_prev_latched ;
296296 static uint8_t bms_prev_latched ;
297297
@@ -371,7 +371,7 @@ void EXTI15_10_IRQHandler() {
371371 *
372372 * Meant to be called periodically.
373373 */
374- void handleDashboardInputs () {
374+ void service_button_inputs () {
375375 if (input_state .up_button ) {
376376 input_state .up_button = 0 ;
377377 moveUp ();
@@ -408,7 +408,7 @@ void handleDashboardInputs() {
408408 }
409409}
410410
411- void enableInterrupts () {
411+ void config_button_irqs () {
412412 // Enable the SYSCFG clock for interrupts
413413 RCC -> APB2ENR |= RCC_APB2ENR_SYSCFGEN ;
414414
@@ -441,7 +441,7 @@ void enableInterrupts() {
441441 * @note The queue holds a max of 10 commands. Design your LCD page updates with this in mind.
442442 */
443443char cmd [NXT_STR_SIZE ] = {'\0' }; // Buffer for Nextion LCD commands
444- void lcdTxUpdate () {
444+ void lcd_tx_cmd () {
445445 if ((false == PHAL_usartTxBusy (& lcd )) && (SUCCESS_G == qReceive (& q_tx_usart , cmd ))) {
446446 PHAL_usartTxDma (& lcd , (uint8_t * )cmd , strlen (cmd ));
447447 }
0 commit comments