-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathbsp.c
114 lines (88 loc) · 2.86 KB
/
bsp.c
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
/* Board Support Package (BSP) for the NUCLEO-C031C6 board */
#include <stdint.h> /* Standard integers. WG14/N843 C99 Standard */
#include "bsp.h"
#include "miros.h"
#include "stm32c0xx.h" /* CMSIS-compliant header file for the MCU used */
/* add other drivers if necessary... */
// LED marked "LD4" (PA.5) on the NUCLEO-C031C6 board
#define LD4_PIN 5U
// external LED to be inserted between GND (short leg) and
// D12 (longer leg) on the CN9 connector
#define LD5_PIN 6U
// Button B1 (PC.13) on the NUCLEO-C031C6 board
#define B1_PIN 13U
static uint32_t volatile l_tickCtr;
void SysTick_Handler(void) {
++l_tickCtr;
__disable_irq();
OS_sched();
__enable_irq();
}
void BSP_init(void) {
// enable GPIOA clock port for the LEDs
RCC->IOPENR |= (1U << 0U);
// NUCLEO-C031C6 board has LED LD4 on GPIOA pin LD4_PIN
// and external LED LD5 on GPIO LD5_PIN
// set the LED pins as push-pull output, no pull-up, pull-down
GPIOA->MODER &= ~((3U << 2U*LD4_PIN) | (3U << 2U*LD5_PIN));
GPIOA->MODER |= ((1U << 2U*LD4_PIN) | (1U << 2U*LD5_PIN));
GPIOA->OTYPER &= ~((1U << LD4_PIN) | (1U << LD5_PIN));
GPIOA->OSPEEDR &= ~((3U << 2U*LD4_PIN) | (3U << 2U*LD5_PIN));
GPIOA->OSPEEDR |= ((1U << 2U*LD4_PIN) | (1U << 2U*LD5_PIN));
GPIOA->PUPDR &= ~((3U << 2U*LD4_PIN) | (3U << 2U*LD5_PIN));
// configure Button B1 (PC.13) pins as input, no pull-up, pull-down
GPIOC->MODER &= ~(3U << 2*B1_PIN);
GPIOC->OSPEEDR &= ~(3U << 2*B1_PIN);
GPIOC->OSPEEDR |= (1U << 2*B1_PIN);
GPIOC->PUPDR &= ~(3U << 2*B1_PIN);
}
uint32_t BSP_tickCtr(void) {
uint32_t tickCtr;
__disable_irq();
tickCtr = l_tickCtr;
__enable_irq();
return tickCtr;
}
void BSP_delay(uint32_t ticks) {
uint32_t start = BSP_tickCtr();
while ((BSP_tickCtr() - start) < ticks) {
}
}
void BSP_ledRedOn(void) {
/* no red LED on board */
}
void BSP_ledRedOff(void) {
/* no red LED on board */
}
void BSP_ledBlueOn(void) {
/* no blue LED on board */
}
void BSP_ledBlueOff(void) {
/* no blue LED on board */
}
void BSP_ledGreenOn(void) {
GPIOA->BSRR = (1U << LD4_PIN); /* turn LED on */
}
void BSP_ledGreenOff(void) {
GPIOA->BSRR = (1U << (LD4_PIN + 16U)); /* turn LED off */
}
void OS_onStartup(void) {
SystemCoreClockUpdate();
SysTick_Config(SystemCoreClock / BSP_TICKS_PER_SEC);
/* set the SysTick interrupt priority (highest) */
NVIC_SetPriority(SysTick_IRQn, 0U);
}
void OS_onIdle(void) {
#ifdef NDBEBUG
__WFI(); /* stop the CPU and Wait for Interrupt */
#endif
}
void Q_onAssert(char const *module, int id) {
/* TBD: damage control */
(void)module; /* avoid the "unused parameter" compiler warning */
(void)id; /* avoid the "unused parameter" compiler warning */
NVIC_SystemReset();
}
void assert_failed(char const *module, int id) {
Q_onAssert(module, id);
}