From 063ac23917f608202b337b09fe355d9223493245 Mon Sep 17 00:00:00 2001 From: Omar Magdy Date: Sun, 21 Aug 2022 18:42:49 +0200 Subject: Added intital project --- dio.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 dio.c (limited to 'dio.c') 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--) {} +} + -- cgit v1.2.3