From 89ee198a04df6e0fee2f7bbad39a99798f9d7afa Mon Sep 17 00:00:00 2001 From: Roland Sahlsten Date: Tue, 24 May 2011 21:02:43 +0000 Subject: First version of MainProcessingUnit mpu. git-svn-id: https://svn.spreadspace.org/mur.sat@27 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/mpu/src/gpio/gpio.c | 378 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 378 insertions(+) create mode 100644 software/mpu/src/gpio/gpio.c (limited to 'software/mpu/src/gpio/gpio.c') diff --git a/software/mpu/src/gpio/gpio.c b/software/mpu/src/gpio/gpio.c new file mode 100644 index 0000000..84eee75 --- /dev/null +++ b/software/mpu/src/gpio/gpio.c @@ -0,0 +1,378 @@ +/***************************************************************************** + * gpio.c: GPIO C file for NXP LPC13xx Family Microprocessors + * + * Copyright(C) 2008, NXP Semiconductor + * All rights reserved. + * + * History + * 2008.07.20 ver 1.00 Preliminary version, first Release + * 2009.12.09 ver 1.05 Mod to use mask registers for GPIO writes + inlining (.h) + * +*****************************************************************************/ +#include "LPC13xx.h" /* LPC13xx Peripheral Registers */ +#include "gpio.h" + +/* =================== + * CodeRed - Modified file to extract out interrupt handler related code, + * which is really application project specific. + * Set TIMER16_GENERIC_INTS to 1 to reenable original code. + * =================== */ +//#define GPIO_GENERIC_INTS 1 + +#ifdef GPIO_GENERIC_INTS +volatile uint32_t gpio0_counter = 0; +volatile uint32_t gpio1_counter = 0; +volatile uint32_t gpio2_counter = 0; +volatile uint32_t gpio3_counter = 0; +volatile uint32_t p0_1_counter = 0; +volatile uint32_t p1_1_counter = 0; +volatile uint32_t p2_1_counter = 0; +volatile uint32_t p3_1_counter = 0; + +/***************************************************************************** +** Function name: PIOINT0_IRQHandler +** +** Descriptions: Use one GPIO pin(port0 pin1) as interrupt source +** +** parameters: None +** Returned value: None +** +*****************************************************************************/ +void PIOINT0_IRQHandler(void) +{ + uint32_t regVal; + + gpio0_counter++; + regVal = GPIOIntStatus( PORT0, 1 ); + if ( regVal ) + { + p0_1_counter++; + GPIOIntClear( PORT0, 1 ); + } + return; +} + +/***************************************************************************** +** Function name: PIOINT1_IRQHandler +** +** Descriptions: Use one GPIO pin(port1 pin1) as interrupt source +** +** parameters: None +** Returned value: None +** +*****************************************************************************/ +void PIOINT1_IRQHandler(void) +{ + uint32_t regVal; + + gpio1_counter++; + regVal = GPIOIntStatus( PORT1, 1 ); + if ( regVal ) + { + p1_1_counter++; + GPIOIntClear( PORT1, 1 ); + } + return; +} + +/***************************************************************************** +** Function name: PIOINT2_IRQHandler +** +** Descriptions: Use one GPIO pin(port2 pin1) as interrupt source +** +** parameters: None +** Returned value: None +** +*****************************************************************************/ +void PIOINT2_IRQHandler(void) +{ + uint32_t regVal; + + gpio2_counter++; + regVal = GPIOIntStatus( PORT2, 1 ); + if ( regVal ) + { + p2_1_counter++; + GPIOIntClear( PORT2, 1 ); + } + return; +} + +/***************************************************************************** +** Function name: PIOINT3_IRQHandler +** +** Descriptions: Use one GPIO pin(port3 pin1) as interrupt source +** +** parameters: None +** Returned value: None +** +*****************************************************************************/ +void PIOINT3_IRQHandler(void) +{ + uint32_t regVal; + + gpio3_counter++; + regVal = GPIOIntStatus( PORT3, 1 ); + if ( regVal ) + { + p3_1_counter++; + GPIOIntClear( PORT3, 1 ); + } + return; +} +#endif //GPIO_GENERIC_INTS + +/***************************************************************************** +** Function name: GPIOInit +** +** Descriptions: Initialize GPIO, install the +** GPIO interrupt handler +** +** parameters: None +** Returned value: true or false, return false if the VIC table +** is full and GPIO interrupt handler can be +** installed. +** +*****************************************************************************/ +void GPIOInit( void ) +{ + /* Enable AHB clock to the GPIO domain. */ + LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6); + +#ifdef __JTAG_DISABLED + LPC_IOCON->JTAG_TDO_PIO1_1 &= ~0x07; + LPC_IOCON->JTAG_TDO_PIO1_1 |= 0x01; +#endif + + /* Set up NVIC when I/O pins are configured as external interrupts. */ + NVIC_EnableIRQ(EINT0_IRQn); + NVIC_EnableIRQ(EINT1_IRQn); + NVIC_EnableIRQ(EINT2_IRQn); + NVIC_EnableIRQ(EINT3_IRQn); + return; +} + +/***************************************************************************** +** Function name: GPIOSetInterrupt +** +** Descriptions: Set interrupt sense, event, etc. +** edge or level, 0 is edge, 1 is level +** single or double edge, 0 is single, 1 is double +** active high or low, etc. +** +** parameters: port num, bit position, sense, single/doube, polarity +** Returned value: None +** +*****************************************************************************/ +void GPIOSetInterrupt( uint32_t portNum, uint32_t bitPosi, uint32_t sense, + uint32_t single, uint32_t event ) +{ + switch ( portNum ) + { + case PORT0: + if ( sense == 0 ) + { + LPC_GPIO0->IS &= ~(0x1<IBE &= ~(0x1<IBE |= (0x1<IS |= (0x1<IEV &= ~(0x1<IEV |= (0x1<IS &= ~(0x1<IBE &= ~(0x1<IBE |= (0x1<IS |= (0x1<IEV &= ~(0x1<IEV |= (0x1<IS &= ~(0x1<IBE &= ~(0x1<IBE |= (0x1<IS |= (0x1<IEV &= ~(0x1<IEV |= (0x1<IS &= ~(0x1<IBE &= ~(0x1<IBE |= (0x1<IS |= (0x1<IEV &= ~(0x1<IEV |= (0x1<IE |= (0x1<IE |= (0x1<IE |= (0x1<IE |= (0x1<IE &= ~(0x1<IE &= ~(0x1<IE &= ~(0x1<IE &= ~(0x1<MIS & (0x1<MIS & (0x1<MIS & (0x1<MIS & (0x1<IC |= (0x1<IC |= (0x1<IC |= (0x1<IC |= (0x1<