basic terminal
[cortex-from-scratch] / regf.c
diff --git a/regf.c b/regf.c
index 257a417..75f0a3c 100644 (file)
--- a/regf.c
+++ b/regf.c
@@ -2,24 +2,20 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <stm32.h>
-
-#define O_WRITE 0x01
-#define SET 0x02
-#define CLEAR 0x03
+#include <mmap.h>
 
 /* write value (uint8_t) to register */
 void regw_u8(volatile uint32_t * reg, uint8_t val, short shift, short flag) {
 
        switch(flag) {
-               case O_WRITE:
-                       (*(volatile uint32_t *) (reg)) = (val << shift);
+               case OWRITE:
+                       *reg = (val << shift);
                        break;
-               case SET:
-                       (*(volatile uint32_t *) (reg)) = 
-                       ((*(volatile uint32_t *) (reg)) | (val << shift));
+               case SETBIT:
+                       *reg = *reg | (val << shift);
                        break;
-               case CLEAR:
-                       (*(volatile uint32_t *) (reg)) = (val << shift);
+               case CLRBIT:
+                       *reg = (val << shift);
                        break;
        }
 }
@@ -28,13 +24,14 @@ void regw_u8(volatile uint32_t * reg, uint8_t val, short shift, short flag) {
 void regw_u32(volatile uint32_t * reg, uint32_t val, short shift, short flag) {
 
        switch(flag) {
-               case O_WRITE:
-                       (*(volatile uint32_t *) (reg)) = (val << shift);
+               case OWRITE:
+                       //*reg = (val << shift);
+                       *reg = (val << shift);
+                       break;
+               case SETBIT:
+                       *reg = *reg | (val << shift);
                        break;
-               case SET:
-                       (*(volatile uint32_t *) (reg)) = 
-                       ((*(volatile uint32_t *) (reg)) | (val << shift));
-               case CLEAR:
+               case CLRBIT:
                        //
                        break;
        }