Skip to content

Commit

Permalink
enable unusedFunction per build - Bootstub
Browse files Browse the repository at this point in the history
  • Loading branch information
dzid26 committed Jun 4, 2024
1 parent d6c6ab8 commit 31ff4a0
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 11 deletions.
2 changes: 2 additions & 0 deletions board/drivers/clock_source.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#define CLOCK_SOURCE_PERIOD_MS 50U
#define CLOCK_SOURCE_PULSE_LEN_MS 2U

#ifndef BOOTSTUB
void clock_source_set_period(uint8_t period) {
register_set(&(TIM1->ARR), ((period*10U) - 1U), 0xFFFFU);
}
#endif

void clock_source_init(void) {
// Setup timer
Expand Down
2 changes: 2 additions & 0 deletions board/drivers/harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ uint8_t harness_detect_orientation(void) {
return ret;
}

#ifndef BOOTSTUB
void harness_tick(void) {
harness.status = harness_detect_orientation();
}
#endif

void harness_init(void) {
// try to detect orientation
Expand Down
5 changes: 3 additions & 2 deletions board/drivers/registers.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void register_clear_bits(volatile uint32_t *addr, uint32_t val) {
register_set(addr, (~val), val);
}

// To be called periodically
void check_registers(void){
#ifndef BOOTSTUB
void check_registers_tick(void){
for(uint16_t i=0U; i<REGISTER_MAP_SIZE; i++){
if((uint32_t) register_map[i].address != 0U){
ENTER_CRITICAL()
Expand All @@ -72,6 +72,7 @@ void check_registers(void){
}
}
}
#endif

void init_registers(void) {
for(uint16_t i=0U; i<REGISTER_MAP_SIZE; i++){
Expand Down
12 changes: 7 additions & 5 deletions board/drivers/timers.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
#ifndef BOOTSTUB
void timer_init(TIM_TypeDef *TIM, int psc) {
register_set(&(TIM->PSC), (psc-1), 0xFFFFU);
register_set(&(TIM->DIER), TIM_DIER_UIE, 0x5F5FU);
register_set(&(TIM->CR1), TIM_CR1_CEN, 0x3FU);
TIM->SR = 0;
}

void tick_timer_init(void) {
timer_init(TICK_TIMER, (uint16_t)((15.25*APB2_TIMER_FREQ)/8U));
NVIC_EnableIRQ(TICK_TIMER_IRQ);
}

void microsecond_timer_init(void) {
MICROSECOND_TIMER->PSC = (APB1_TIMER_FREQ - 1U);
MICROSECOND_TIMER->CR1 = TIM_CR1_CEN;
MICROSECOND_TIMER->EGR = TIM_EGR_UG;
}
#endif

uint32_t microsecond_timer_get(void) {
return MICROSECOND_TIMER->CNT;
Expand All @@ -24,8 +31,3 @@ void interrupt_timer_init(void) {
INTERRUPT_TIMER->SR = 0;
NVIC_EnableIRQ(INTERRUPT_TIMER_IRQ);
}

void tick_timer_init(void) {
timer_init(TICK_TIMER, (uint16_t)((15.25*APB2_TIMER_FREQ)/8U));
NVIC_EnableIRQ(TICK_TIMER_IRQ);
}
4 changes: 4 additions & 0 deletions board/drivers/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,13 @@ char to_hex_char(uint8_t a) {
return ret;
}

#ifndef BOOTSTUB
void usb_tick(void) {
uint16_t current_frame_num = (USBx_DEVICE->DSTS & USB_OTG_DSTS_FNSOF_Msk) >> USB_OTG_DSTS_FNSOF_Pos;
usb_enumerated = (current_frame_num != usb_last_frame_num);
usb_last_frame_num = current_frame_num;
}
#endif

void usb_setup(void) {
int resp_len;
Expand Down Expand Up @@ -906,6 +908,7 @@ void usb_irqhandler(void) {
//USBx->GINTMSK = 0xFFFFFFFF & ~(USB_OTG_GINTMSK_NPTXFEM | USB_OTG_GINTMSK_PTXFEM | USB_OTG_GINTSTS_SOF | USB_OTG_GINTSTS_EOPF);
}

#ifndef BOOTSTUB
void can_tx_comms_resume_usb(void) {
ENTER_CRITICAL();
if (!outep3_processing && (USBx_OUTEP(3U)->DOEPCTL & USB_OTG_DOEPCTL_NAKSTS) != 0U) {
Expand All @@ -914,3 +917,4 @@ void can_tx_comms_resume_usb(void) {
}
EXIT_CRITICAL();
}
#endif
2 changes: 2 additions & 0 deletions board/faults.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ void fault_occurred(uint32_t fault) {
faults |= fault;
}

#ifndef BOOTSTUB
void fault_recovered(uint32_t fault) {
if ((PERMANENT_FAULTS & fault) == 0U) {
faults &= ~fault;
} else {
print("Cannot recover from a permanent fault!\n");
}
}
#endif
2 changes: 1 addition & 1 deletion board/jungle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void tick_handler(void) {
current_board->board_tick();

// check registers
check_registers();
check_registers_tick();

// turn off the blue LED, turned on by CAN
current_board->set_led(LED_BLUE, false);
Expand Down
2 changes: 1 addition & 1 deletion board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void tick_handler(void) {
}

// check registers
check_registers();
check_registers_tick();

// set ignition_can to false after 2s of no CAN seen
if (ignition_can_cnt > 2U) {
Expand Down
3 changes: 3 additions & 0 deletions board/stm32f4/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
// ///// Board definition and detection ///// //
#include "stm32f4/lladc.h"
#include "drivers/harness.h"

#ifndef BOOTSTUB
#include "drivers/fan.h"
#include "stm32f4/llfan.h"
#endif
#include "drivers/clock_source.h"
#include "boards/white.h"
#include "boards/grey.h"
Expand Down
2 changes: 2 additions & 0 deletions board/stm32f4/lladc.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

void register_set(volatile uint32_t *addr, uint32_t val, uint32_t mask);

#ifndef BOOTSTUB
void adc_init(void) {
register_set(&(ADC->CCR), ADC_CCR_TSVREFE | ADC_CCR_VBATE, 0xC30000U);
register_set(&(ADC1->CR2), ADC_CR2_ADON, 0xFF7F0F03U);
register_set(&(ADC1->SMPR1), ADC_SMPR1_SMP12 | ADC_SMPR1_SMP13, 0x7FFFFFFU);
}
#endif

uint16_t adc_get_raw(uint8_t channel) {
// Select channel
Expand Down
2 changes: 1 addition & 1 deletion board/stm32f4/stm32f4_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#include "stm32f4/llspi.h"
#endif

#if !defined(BOOTSTUB)
#ifndef BOOTSTUB
#include "drivers/uart.h"
#include "stm32f4/lluart.h"
#endif
Expand Down
2 changes: 2 additions & 0 deletions board/stm32h7/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
// ///// Board definition and detection ///// //
#include "stm32h7/lladc.h"
#include "drivers/harness.h"
#ifndef BOOTSTUB
#include "drivers/fan.h"
#include "stm32h7/llfan.h"
#endif
#include "drivers/fake_siren.h"
#include "drivers/clock_source.h"
#include "boards/red.h"
Expand Down
2 changes: 2 additions & 0 deletions board/stm32h7/lladc.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#ifndef BOOTSTUB
void adc_init(void) {
ADC1->CR &= ~(ADC_CR_DEEPPWD); //Reset deep-power-down mode
ADC1->CR |= ADC_CR_ADVREGEN; // Enable ADC regulator
Expand All @@ -13,6 +14,7 @@ void adc_init(void) {
ADC1->CR |= ADC_CR_ADEN;
while(!(ADC1->ISR & ADC_ISR_ADRDY));
}
#endif

uint16_t adc_get_raw(uint8_t channel) {
uint16_t res = 0U;
Expand Down
Loading

0 comments on commit 31ff4a0

Please sign in to comment.