diff options
| author | Omar Magdy <omar.professional8777@gmail.com> | 2022-08-21 18:42:49 +0200 |
|---|---|---|
| committer | Omar Magdy <omar.professional8777@gmail.com> | 2022-08-21 18:42:49 +0200 |
| commit | 063ac23917f608202b337b09fe355d9223493245 (patch) | |
| tree | 8d45778269529e4d2a0bcbca8cc128c9a15cc0bd /dio.c | |
| parent | ff6ccb57551afe8904254313fb7ed0204fe74d19 (diff) | |
| download | Traffic-light-063ac23917f608202b337b09fe355d9223493245.tar.xz Traffic-light-063ac23917f608202b337b09fe355d9223493245.zip | |
Added intital project
Diffstat (limited to 'dio.c')
| -rw-r--r-- | dio.c | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -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--) {}
+}
+
|
