75f0a3cee5ef690558dce3388148c85aafb0b27e
[cortex-from-scratch] / regf.c
1 #include <stdbool.h>
2 #include <stddef.h>
3 #include <stdint.h>
4 #include <stm32.h>
5 #include <mmap.h>
6
7 /* write value (uint8_t) to register */
8 void regw_u8(volatile uint32_t * reg, uint8_t val, short shift, short flag) {
9
10         switch(flag) {
11                 case OWRITE:
12                         *reg = (val << shift);
13                         break;
14                 case SETBIT:
15                         *reg = *reg | (val << shift);
16                         break;
17                 case CLRBIT:
18                         *reg = (val << shift);
19                         break;
20         }
21 }
22
23 /* write value (uint32_t) to register */
24 void regw_u32(volatile uint32_t * reg, uint32_t val, short shift, short flag) {
25
26         switch(flag) {
27                 case OWRITE:
28                         //*reg = (val << shift);
29                         *reg = (val << shift);
30                         break;
31                 case SETBIT:
32                         *reg = *reg | (val << shift);
33                         break;
34                 case CLRBIT:
35                         //
36                         break;
37         }
38 }
39
40