diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-03-06 12:09:02 +0200 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-03-06 12:09:02 +0200 |
| commit | fb2d080fbbcea3a91e598b4ea8837a230de6a319 (patch) | |
| tree | 6b3ce09a252d2ebab8189a92b3326ffbba6dbe4b /Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO | |
| parent | d734bb5cf08ba2433b74fc86a8858d2437d1a237 (diff) | |
| download | Tango-fb2d080fbbcea3a91e598b4ea8837a230de6a319.tar.gz Tango-fb2d080fbbcea3a91e598b4ea8837a230de6a319.zip | |
A new forlder for embedded software in our common structure
Diffstat (limited to 'Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO')
| -rw-r--r-- | Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.c | 130 | ||||
| -rw-r--r-- | Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.h | 37 |
2 files changed, 167 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; + } + } +} diff --git a/Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.h b/Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.h new file mode 100644 index 000000000..8a0c54df4 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.h @@ -0,0 +1,37 @@ + +#ifndef DRIVERS_GPIO_H_ +#define DRIVERS_GPIO_H_ + +#include <stdint.h> +#include <stdbool.h> +#include <driverlib/gpio.h> + +typedef enum +{ + DISPENSER_1_LMS, + DISPENSER_2_LMS, + DISPENSER_3_LMS, + DISPENSER_4_LMS, + DISPENSER_5_LMS, + DISPENSER_6_LMS, + SCREW_LMS, + START_MANUAL_BTN, + END_MANUAL_BTN, + MANUAL_1_BTN, + MANUAL_2_BTN, + MANUAL_3_BTN, + MANUAL_4_BTN, + NUM_OF_GPIO_INT +}GPIOInt_t; + +typedef void (*GPIOIntCallback)(GPIOInt_t arg); + +void GPIOInit(void); + +bool PollGPIO (uint8_t index); + +void GPIOEnableInterrupt(GPIOInt_t gpioInt, GPIOIntCallback callBack, uint32_t type); + +void GPIODisableInterrupt(GPIOInt_t gpioInt,GPIOIntCallback callBack); + +#endif /* DRIVERS_GPIO_H_ */ |
