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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Numb
#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;
		}
	}
}