aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Drivers/Peripheral_GPIO/GPIO.c
blob: 38f333d1f51dd72ece4b5b1d110633166ce55037 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#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] =
{
#ifdef EVALUATION_BOARD
	{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}, 	//
#endif
};

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;
		}
	}
}