summaryrefslogtreecommitdiff
path: root/dio.c
diff options
context:
space:
mode:
authorOmar Magdy <omar.professional8777@gmail.com>2022-08-21 18:42:49 +0200
committerOmar Magdy <omar.professional8777@gmail.com>2022-08-21 18:42:49 +0200
commit063ac23917f608202b337b09fe355d9223493245 (patch)
tree8d45778269529e4d2a0bcbca8cc128c9a15cc0bd /dio.c
parentff6ccb57551afe8904254313fb7ed0204fe74d19 (diff)
downloadTraffic-light-063ac23917f608202b337b09fe355d9223493245.tar.xz
Traffic-light-063ac23917f608202b337b09fe355d9223493245.zip
Added intital project
Diffstat (limited to 'dio.c')
-rw-r--r--dio.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/dio.c b/dio.c
new file mode 100644
index 0000000..bcda92e
--- /dev/null
+++ b/dio.c
@@ -0,0 +1,43 @@
+#include "dio.h"
+
+void DIO_Init(char port, unsigned int dir, unsigned int pur) {
+ unsigned int off = port - 'A';
+ SYSCTL_RCGCGPIO_R |= 1 << off;
+ while(SYSCTL_RCGCGPIO_R && (1 << off) == 0) {};
+ unsigned int* address = (unsigned int*)(0x40004000 + (off * 0x1000));
+ if (off >= 4) {
+ address = (unsigned int*)(0x40024000 + ((off - 4) * 0x1000));
+ }
+ *(address + LOCKOFF) = 0x4C4F434B; // LOCK
+ *(address + COMMITOFF) = 0x1F;
+ *(address + PUROFF) = pur;
+ *(address + DENOFF) = 0x1F;
+ *(address + DIROFF) = dir;
+}
+
+void DIO_WritePin(volatile uint32_t* port, unsigned int pin, unsigned int value) {
+ if(value) {
+ SET(port, pin);
+ } else {
+ RESET(port, pin);
+ }
+}
+
+void DIO_WritePort(volatile uint32_t* port, unsigned int value) {
+ *port = value;
+}
+
+
+int DIO_ReadPin(volatile uint32_t* port, unsigned int pin) {
+ int x = GET_BIT(port, pin);
+ return x;
+}
+
+uint32_t DIO_ReadPort(volatile uint32_t port) {
+ return port;
+}
+
+void delay(int value) {
+ while(value--) {}
+}
+