-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMB1_System.cpp
176 lines (141 loc) · 4.85 KB
/
MB1_System.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* @file MB1_System.cpp
* @author Pham Huu Dang Nhat <[email protected]>, HLib MBoard team.
* @version 1.2
* @date 9-4-2014
* @brief This file implement MB1_system_init function.
* MB1_System :
*
* (MB1_SPI1) (MB1_SPI2)
*
* (MB1_Led_green) (MB1_Led_red)
*
* (MB1_UsrBtn0) (MB1_UsrBtn1)
* btn_activeStates = 0,
* btn_samplingTimeCycle = 5 * miscTIM_period
* btn_longPressedTime = 200 * btn_samplingTimeCycle;
*
* (MB1_USART1)
* baud_rate (9600), retarget (config_interface)
*
* (MB1_USART2)
* baud_rate (9600), retarget (config_interface)
*
* (Misc functions)
* ledBeat_period, miscTIM_period (TIM6, 1msec).
*
* (MB1_ISRs)
* TIM6_ISRs other ISR
* | LedBeat_ISR | | subISR_ptr |
* | delay_ms_ISR | | subISR_ptr |
* | btn_ISR | | subISR_ptr |
* | ............ | | ............ |
* g_numOfSubISR_max (default = 4)
*
* (NVIC)
* 2 bit for preemption priority
* 2 bit for sub priority
*
* Other notes :
* - bugs_fix.
* - no NJTRST.
*/
#include "MB1_System.h"
/**<-------------- Global vars and objects in the system of MB1 ------------*/
/**< SPIs */
SPI MB1_SPI1 (1);
SPI MB1_SPI2 (2);
/**< LEDs */
Led MB1_Led_green (Led_ns::green);
Led MB1_Led_red (Led_ns::red);
/**< Buttons */
Button MB1_usrBtn0 (Btn_ns::usrBtn_0);
Button MB1_usrBtn1 (Btn_ns::usrBtn_1);
/**< USARTs */
/* serial_t MB1_USART1 (1); */
serial_t MB1_USART2 (2);
/**< CRC */
CRC_c MB1_crc;
/**< Misc, global functions ! */
/**< ISRs */
ISRMgr MB1_ISRs;
/**< NVIC */
const uint32_t MB1_NVIC_PriorityGroup = NVIC_PriorityGroup_2;
/**< Vector table relocation */
const uint32_t MB1_VectorTableRelocationOffset = 0x3000;
const bool MB1_VectorTableRelocation_isUsed = false;
/**<-------------- Global vars and objects in the system of MB1 ------------*/
/**< conf interface (compile-time) */
/**< for SysTick, miscTIM and led_beat */
TIM_TypeDef * MB1_conf_miscTIM_p = TIM6;
ISRMgr_ns::ISR_t MB1_conf_miscTIM_ISRType = ISRMgr_ns::ISRMgr_TIM6;
const uint16_t MB1_conf_miscTIMPrescaler = 1;
const uint16_t MB1_conf_miscTIMReloadVal = 36000; // for 1 msec with PCLK1 = 36MHz
const uint16_t MB1_conf_ledBeat_period = 500; //in msec
Led *MB1_conf_ledBeat_p = &MB1_Led_red;
/**< for SysTick and led_beat */
/**< for USART1 */
/*
const uint32_t MB1_conf_USART1_buadrate = 9600;
const bool MB1_conf_USART1_retarget_isUsed = false;
const uint8_t MB1_conf_USART1_retarget = USART_stdStream_stdout;
*/
/**< for USART1 */
/**< for USART2 */
const bool MB1_USART2_isUsed = true;
const uint32_t MB1_conf_USART2_buadrate = 9600;
const bool MB1_conf_USART2_retarget_isUsed = false;
const uint8_t MB1_conf_USART2_retarget = USART_stdStream_stdout;
/**< for USART1 */
/**< for ISRs */
const bool MB1_conf_LedBeat_isUsed = true;
const bool MB1_conf_delayms_isUsed = true;
const bool MB1_conf_btnProcessing_isUsed = true;
/**< for ISRs */
/**< others */
const bool MB1_conf_bugsFix_isUsed = false;
const bool MB1_conf_NJTRST_isntUsed = true;
/**< others */
/**< conf interface (compile-time) */
void MB1_system_init (void){
/**< others */
if (MB1_conf_bugsFix_isUsed)
bugs_fix ();
if (MB1_conf_NJTRST_isntUsed){
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig (GPIO_Remap_SWJ_NoJTRST , ENABLE);
}
/**< end others */
/**< SysTick and led beat */
miscTIM_run (MB1_conf_miscTIM_p, MB1_conf_miscTIMPrescaler, MB1_conf_miscTIMReloadVal);
LedBeat (MB1_conf_LedBeat_isUsed, MB1_conf_ledBeat_period, MB1_conf_ledBeat_p);
/**< end SysTick and led beat */
/**< USART1 */
/* Don't use UART1 with RIOT
MB1_USART1.Restart (MB1_conf_USART1_buadrate);
if (MB1_conf_USART1_retarget_isUsed)
MB1_USART1.Retarget (USART_stdStream_stdout);
*/
/**< end USART1 */
/**< USART2 */
if (MB1_USART2_isUsed){
MB1_USART2.Restart (MB1_conf_USART2_buadrate);
if (MB1_conf_USART2_retarget_isUsed)
MB1_USART2.Retarget (USART_stdStream_stdout);
}
/**< end USART2 */
/**< ISRs */
if (MB1_conf_LedBeat_isUsed)
MB1_ISRs.subISR_assign (MB1_conf_miscTIM_ISRType, LedBeat_miscTIMISR);
if (MB1_conf_delayms_isUsed)
MB1_ISRs.subISR_assign (MB1_conf_miscTIM_ISRType, delay_ms_miscTIMISR);
if (MB1_conf_btnProcessing_isUsed)
MB1_ISRs.subISR_assign (MB1_conf_miscTIM_ISRType, btnProcessing_miscTIMISR);
/**< end ISRs */
/**< NVIC priority group config */
NVIC_PriorityGroupConfig (MB1_NVIC_PriorityGroup);
/**< Vector table relocation */
if (MB1_VectorTableRelocation_isUsed){
NVIC_SetVectorTable(NVIC_VectTab_FLASH, MB1_VectorTableRelocationOffset);
}
}