aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.c
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.c')
-rw-r--r--Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.c b/Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.c
new file mode 100644
index 000000000..158dd2e14
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.c
@@ -0,0 +1,130 @@
+
+#include <stdbool.h>
+#include <ti/sysbios/BIOS.h>
+#include <driverlib/rom.h>
+#include <inc/hw_memmap.h>
+#include "Drivers/Peripheral_GPIO/GPIO.h"
+
+//#define MAX_NUM_OF_REGISTRED_CALLBACKS 9 // screw,6 dispensers , 2 sw - start manual/stop manual
+#define MAX_NUM_OF_REGISTRED_CALLBACKS 7 // screw,6 dispensers , 2 sw - start manual/stop manual
+
+typedef struct
+{
+ uint32_t m_port;
+ uint32_t m_pin;
+} GPIOIntPortMap;
+
+static GPIOIntPortMap portMap[NUM_OF_GPIO_INT] =
+{
+ {GPIO_PORTG_BASE, GPIO_INT_PIN_0}, // Dispenser LSW 1
+ {GPIO_PORTG_BASE, GPIO_INT_PIN_1}, // Dispenser LSW 2
+ {GPIO_PORTP_BASE, GPIO_INT_PIN_4}, // Dispenser LSW 3
+ {GPIO_PORTP_BASE, GPIO_INT_PIN_5}, // Dispenser LSW 4
+ {GPIO_PORTQ_BASE, GPIO_INT_PIN_7}, // Dispenser LSW 5
+ {GPIO_PORTS_BASE, GPIO_INT_PIN_0}, // Dispenser LSW 6
+ {GPIO_PORTS_BASE, GPIO_INT_PIN_3}, // Screw LSW
+ {GPIO_PORTD_BASE, GPIO_INT_PIN_1}, // Start Manual Btn
+ {GPIO_PORTJ_BASE, GPIO_INT_PIN_3}, // End Manual Btn
+ {GPIO_PORTE_BASE, GPIO_INT_PIN_4}, //
+ {GPIO_PORTH_BASE, GPIO_INT_PIN_5}, //
+ {GPIO_PORTP_BASE, GPIO_INT_PIN_0}, //
+ {GPIO_PORTQ_BASE, GPIO_INT_PIN_5}, //
+};
+
+typedef struct
+{
+ bool m_isEnabled;
+ GPIOInt_t m_param;
+ GPIOIntCallback m_callback;
+}PortConfig_t;
+
+static PortConfig_t gpio_configuration[MAX_NUM_OF_REGISTRED_CALLBACKS];
+
+bool PollGPIO (uint8_t index)
+{
+ unsigned long ulStatus = ROM_GPIOPinRead(portMap[index].m_port, portMap[index].m_pin);
+ if ( ulStatus)
+ {
+ return true;
+ }
+ return false;
+}
+//********************************************************************************************************************
+//genneral interrupt handler for all GPIO's
+//********************************************************************************************************************
+void IntGPIO(UArg arg0)
+{
+ uint32_t port = (uint32_t)arg0;
+ unsigned long ulStatus = ROM_GPIOIntStatus(port, true);
+
+
+ uint8_t index;
+ for (index = 0; index < MAX_NUM_OF_REGISTRED_CALLBACKS; ++index)
+ {
+ GPIOInt_t gpioInt = gpio_configuration[index].m_param;
+ if (gpio_configuration[index].m_isEnabled && (portMap[gpioInt].m_port == port) && (portMap[gpioInt].m_pin & ulStatus))
+ {
+ gpio_configuration[index].m_callback(gpio_configuration[index].m_param);
+ }
+ }
+ //
+ // Clear all the pin interrupts that are set
+ //
+ ROM_GPIOIntClear(port, ulStatus);
+}
+
+//********************************************************************************************************************
+void GPIOInit(void)
+{
+ uint8_t index;
+ for (index = 0; index < MAX_NUM_OF_REGISTRED_CALLBACKS; ++index)
+ {
+ gpio_configuration[index].m_isEnabled = false;
+ }
+}
+
+//********************************************************************************************************************
+void GPIOEnableInterrupt(GPIOInt_t gpioInt, GPIOIntCallback callBack, uint32_t type)
+{
+ uint8_t index;
+ for (index = 0; index < MAX_NUM_OF_REGISTRED_CALLBACKS; ++index)
+ {
+ if (!gpio_configuration[index].m_isEnabled)
+ {
+ gpio_configuration[index].m_isEnabled = true;
+ gpio_configuration[index].m_param = gpioInt;
+ gpio_configuration[index].m_callback = callBack;
+ ROM_GPIOIntTypeSet(portMap[gpioInt].m_port,portMap[gpioInt].m_pin, type);
+ ROM_GPIOIntClear(portMap[gpioInt].m_port,portMap[gpioInt].m_pin);
+ ROM_GPIOIntEnable(portMap[gpioInt].m_port,portMap[gpioInt].m_pin);
+ return;
+ }
+ else
+ {
+ if ((gpio_configuration[index].m_param == gpioInt) &&
+ (gpio_configuration[index].m_callback == callBack))
+ {
+ return;
+ }
+ }
+ }
+}
+
+//********************************************************************************************************************
+
+void GPIODisableInterrupt(GPIOInt_t gpioInt,GPIOIntCallback callBack)
+{
+ uint8_t index;
+ for (index = 0; index < MAX_NUM_OF_REGISTRED_CALLBACKS; ++index)
+ {
+ if (gpio_configuration[index].m_isEnabled &&
+ (gpio_configuration[index].m_param == gpioInt) &&
+ (gpio_configuration[index].m_callback == callBack))
+ {
+ ROM_GPIOIntDisable(portMap[gpioInt].m_port,portMap[gpioInt].m_pin);
+ ROM_GPIOIntClear(portMap[gpioInt].m_port,portMap[gpioInt].m_pin);
+ gpio_configuration[index].m_isEnabled = false;
+ return;
+ }
+ }
+}