uart small ping pong receive, update of register functions
[cortex-from-scratch] / regf.c
1 #include <stdbool.h>
2 #include <stddef.h>
3 #include <stdint.h>
4 #include <stm32.h>
5
6 #define O_WRITE 0x01
7 #define SET 0x02
8 #define CLEAR 0x03
9
10 /* write value (uint8_t) to register */
11 void regw_u8(volatile uint32_t * reg, uint8_t val, short shift, short flag) {
12
13         switch(flag) {
14                 case O_WRITE:
15                         (*(volatile uint32_t *) (reg)) = (val << shift);
16                         break;
17                 case SET:
18                         (*(volatile uint32_t *) (reg)) = 
19                         ((*(volatile uint32_t *) (reg)) | (val << shift));
20                         break;
21                 case CLEAR:
22                         (*(volatile uint32_t *) (reg)) = (val << shift);
23                         break;
24         }
25 }
26
27 /* write value (uint32_t) to register */
28 void regw_u32(volatile uint32_t * reg, uint32_t val, short shift, short flag) {
29
30         switch(flag) {
31                 case O_WRITE:
32                         (*(volatile uint32_t *) (reg)) = (val << shift);
33                         break;
34                 case SET:
35                         (*(volatile uint32_t *) (reg)) = 
36                         ((*(volatile uint32_t *) (reg)) | (val << shift));
37                 case CLEAR:
38                         //
39                         break;
40         }
41 }
42
43