SRTOS
Loading...
Searching...
No Matches
config.c
Go to the documentation of this file.
1
9
10#include "config.h"
11
17
18static void
19configureClock ()
20{
21 /* Clock Configuration - SYSCLK sourced from HSE - 8 Mhz */
22 RCC_CR |= (1 << 16); /* HSEON -> 1 */
23 while (!(RCC_CR & (1 << 17)))
24 ;
25 RCC_CFGR &= ~(1U << 0);
26 RCC_CFGR &= ~(1U << 1);
27 RCC_CFGR |= (1 << 0);
28 while ((RCC_CFGR & (0x3 << 2)) != (0x1 << 2))
29 ;
30}
31
37static void
38configureBlueLED ()
39{
40 /* Enable the RCC Peripheral Clock for GPIOD */
41 RCC_AHB1ENR |= (1 << 3);
42 /* Set the PD15 GPIO Pin (Blue LED) to Output */
43 GPIOD_MODER &= ~(1U << 31);
44 GPIOD_MODER &= ~(1U << 30);
45 GPIOD_MODER |= (1 << 30);
46}
47
53static void
54configureGreenLED ()
55{
56 /* Clock already enabled, since blue LED is also on GPIOD */
57 /* Green LED: PD12 */
58 GPIOD_MODER &= ~(1U << 24);
59 GPIOD_MODER &= ~(1U << 25);
60 GPIOD_MODER |= (1 << 24);
61}
62
68static void
69configureOrangeLED ()
70{
71 /* Orange LED: PD13 */
72 GPIOD_MODER &= ~(1U << 26);
73 GPIOD_MODER &= ~(1U << 27);
74 GPIOD_MODER |= (1 << 26);
75}
76
82static void
83configureSystickInterrupts ()
84{
85 SYSTICK_CSR &= ~(1U << 0); /* Disable timer */
86 SYSTICK_CSR |= (1 << 2); /* Use SYSCLK */
87 SYSTICK_CSR |= (1 << 1); /* Enable interrupt requests */
88 SYSTICK_RELOAD = 7999; /* 1 ms per interval */
89 SYSTICK_CURRENT = 0x00000000; /* Reset current count */
90 SYSTICK_CSR |= (1 << 0); /* Enable Timer */
91}
92
98static void
99configureInterruptPriorities ()
100{
101 /* PendSV to the lowest priority (240 because only top 4 bits are used) */
102 SHPR3 &= ~(0xFFU << PENDSV_PRIORITY_START_BIT);
103 SHPR3 |= (0xF0U << PENDSV_PRIORITY_START_BIT);
104
105 /* SysTick to right above PendSV (224 because only top 4 bits are used) */
106 SHPR3 &= ~(0xFFU << SYSTICK_PRIORITY_START_BIT);
107 SHPR3 |= (0xE0U << SYSTICK_PRIORITY_START_BIT);
108}
109
110void
112{
113 configureClock ();
114 configureSystickInterrupts ();
115 configureBlueLED ();
116 configureGreenLED ();
117 configureOrangeLED ();
118 configureInterruptPriorities ();
119}
void configureAll()
This function will be called in the main() function of the user's code before the scheulder is starte...
Definition config.c:111
System configuration for SRTOS.
#define GPIOD_MODER
Definition mcu_macros.h:15
#define SYSTICK_PRIORITY_START_BIT
Definition mcu_macros.h:25
#define RCC_AHB1ENR
Definition mcu_macros.h:14
#define PENDSV_PRIORITY_START_BIT
Definition mcu_macros.h:24
#define RCC_CR
Definition mcu_macros.h:17
#define SYSTICK_RELOAD
Definition mcu_macros.h:20
#define SHPR3
Definition mcu_macros.h:23
#define RCC_CFGR
Definition mcu_macros.h:18
#define SYSTICK_CURRENT
Definition mcu_macros.h:21
#define SYSTICK_CSR
Definition mcu_macros.h:19