Skip to content

Commit 630e2ce

Browse files
author
Marti Bolivar
committed
wirish: allow boards to override more init() subroutines
Signed-off-by: Marti Bolivar <[email protected]>
1 parent ab36a38 commit 630e2ce

File tree

2 files changed

+57
-51
lines changed

2 files changed

+57
-51
lines changed

wirish/boards.cpp

+47-49
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* Copyright (c) 2010 Perry Hung.
55
* Copyright (c) 2011, 2012 LeafLabs, LLC.
6+
* Copyright 2014 Google, Inc.
67
*
78
* Permission is hereby granted, free of charge, to any person
89
* obtaining a copy of this software and associated documentation
@@ -52,24 +53,16 @@
5253
#include <libmaple/systick.h>
5354
#include "boards_private.h"
5455

55-
static void setup_flash(void);
56-
static void setup_clocks(void);
5756
static void setup_nvic(void);
58-
static void setup_adcs(void);
59-
static void setup_timers(void);
60-
61-
/*
62-
* Exported functions
63-
*/
6457

6558
void init(void) {
66-
setup_flash();
67-
setup_clocks();
59+
wirish::priv::board_setup_flash();
60+
wirish::priv::board_setup_clocks();
6861
setup_nvic();
6962
systick_init(SYSTICK_RELOAD_VAL);
7063
wirish::priv::board_setup_gpio();
71-
setup_adcs();
72-
setup_timers();
64+
wirish::priv::board_setup_adcs();
65+
wirish::priv::board_setup_timers();
7366
wirish::priv::board_setup_usb();
7467
wirish::priv::series_init();
7568
boardInit();
@@ -91,20 +84,52 @@ bool boardUsesPin(uint8 pin) {
9184
}
9285

9386
/*
94-
* Auxiliary routines
87+
* These addresses are where usercode starts when a bootloader is
88+
* present. If no bootloader is present, the user NVIC usually starts
89+
* at the Flash base address, 0x08000000.
90+
*/
91+
#if defined(BOOTLOADER_maple)
92+
#define USER_ADDR_ROM 0x08005000
93+
#elif defined(BOOTLOADER_robotis)
94+
#define USER_ADDR_ROM 0x08003000
95+
#endif
96+
#define USER_ADDR_RAM 0x20000C00
97+
extern char __text_start__;
98+
99+
static void setup_nvic(void) {
100+
#ifdef VECT_TAB_FLASH
101+
nvic_init(USER_ADDR_ROM, 0);
102+
#elif defined VECT_TAB_RAM
103+
nvic_init(USER_ADDR_RAM, 0);
104+
#elif defined VECT_TAB_BASE
105+
nvic_init((uint32)0x08000000, 0);
106+
#elif defined VECT_TAB_ADDR
107+
// A numerically supplied value
108+
nvic_init((uint32)VECT_TAB_ADDR, 0);
109+
#else
110+
// Use the __text_start__ value from the linker script; this
111+
// should be the start of the vector table.
112+
nvic_init((uint32)&__text_start__, 0);
113+
#endif
114+
}
115+
116+
/*
117+
* Default implementations for some board-specific routines.
95118
*/
96119

97-
static void setup_flash(void) {
120+
namespace wirish {
121+
namespace priv {
122+
123+
__weak void board_setup_flash(void) {
98124
// Turn on as many Flash "go faster" features as
99125
// possible. flash_enable_features() just ignores any flags it
100126
// can't support.
101127
flash_enable_features(FLASH_PREFETCH | FLASH_ICACHE | FLASH_DCACHE);
102-
// Configure the wait states, assuming we're operating at "close
103-
// enough" to 3.3V.
128+
// FLASH_SAFE_WAIT_STATES is a hack that needs to go away.
104129
flash_set_latency(FLASH_SAFE_WAIT_STATES);
105130
}
106131

107-
static void setup_clocks(void) {
132+
__weak void board_setup_clocks(void) {
108133
// Turn on HSI. We'll switch to and run off of this while we're
109134
// setting up the main PLL.
110135
rcc_turn_on_clk(RCC_CLK_HSI);
@@ -139,42 +164,12 @@ static void setup_clocks(void) {
139164
rcc_switch_sysclk(RCC_CLKSRC_PLL);
140165
}
141166

142-
/*
143-
* These addresses are where usercode starts when a bootloader is
144-
* present. If no bootloader is present, the user NVIC usually starts
145-
* at the Flash base address, 0x08000000.
146-
*/
147-
#if defined(BOOTLOADER_maple)
148-
#define USER_ADDR_ROM 0x08005000
149-
#elif defined(BOOTLOADER_robotis)
150-
#define USER_ADDR_ROM 0x08003000
151-
#endif
152-
#define USER_ADDR_RAM 0x20000C00
153-
extern char __text_start__;
154-
155-
static void setup_nvic(void) {
156-
#ifdef VECT_TAB_FLASH
157-
nvic_init(USER_ADDR_ROM, 0);
158-
#elif defined VECT_TAB_RAM
159-
nvic_init(USER_ADDR_RAM, 0);
160-
#elif defined VECT_TAB_BASE
161-
nvic_init((uint32)0x08000000, 0);
162-
#elif defined VECT_TAB_ADDR
163-
// A numerically supplied value
164-
nvic_init((uint32)VECT_TAB_ADDR, 0);
165-
#else
166-
// Use the __text_start__ value from the linker script; this
167-
// should be the start of the vector table.
168-
nvic_init((uint32)&__text_start__, 0);
169-
#endif
170-
}
171-
172167
static void adc_default_config(const adc_dev *dev) {
173168
adc_enable_single_swstart(dev);
174169
adc_set_sample_rate(dev, wirish::priv::w_adc_smp);
175170
}
176171

177-
static void setup_adcs(void) {
172+
__weak void board_setup_adcs(void) {
178173
adc_set_prescaler(wirish::priv::w_adc_pre);
179174
adc_foreach(adc_default_config);
180175
}
@@ -214,6 +209,9 @@ static void timer_default_config(timer_dev *dev) {
214209
timer_resume(dev);
215210
}
216211

217-
static void setup_timers(void) {
212+
__weak void board_setup_timers(void) {
218213
timer_foreach(timer_default_config);
219214
}
215+
216+
}
217+
}

wirish/boards_private.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,29 @@ namespace wirish {
4848
namespace priv {
4949

5050
/*
51-
* Chip-specific initialization data
51+
* Chip- and board-specific initialization data
5252
*/
5353

5454
extern rcc_pll_cfg w_board_pll_cfg;
5555
extern adc_prescaler w_adc_pre;
5656
extern adc_smp_rate w_adc_smp;
5757

5858
/*
59-
* Chip-specific initialization routines and helper functions.
59+
* Chip- and board-specific initialization routines and helper
60+
* functions.
61+
*
62+
* Some of these have default (weak) implementations in
63+
* boards.cpp; define them in your board file to override.
6064
*/
6165

6266
void board_reset_pll(void);
6367
void board_setup_clock_prescalers(void);
6468
void board_setup_gpio(void);
6569
void board_setup_usb(void);
70+
void board_setup_flash(void);
71+
void board_setup_adcs(void);
72+
void board_setup_timers(void);
73+
void board_setup_clocks(void);
6674
void series_init(void);
6775

6876
}

0 commit comments

Comments
 (0)