2014-01-17

SPI test - gpio050.h


// ***********************************************************************
// gpio050.h 2013nov29hkt1008
// ***********************************************************************

#ifndef GPIO050_HEADER_SEEN
#define GPIO050_HEADER_SEEN

#include "lpc11xx_syscon.h"
#include "lpc11xx_gpio.h"
#include "lpc11xx_iocon.h"
#include "config050.h"
#include "timer050.h"

// ***************************************************************************
// End
// ***************************************************************************

// *** GPIO struct pointer ***

typedef GPIO_TypeDef *gpioStructPointerArray[4];
gpioStructPointerArray CmsisGpioStructPointerArray = {LPC_GPIO0, LPC_GPIO1, LPC_GPIO2, LPC_GPIO3};

GPIO_TypeDef *getGpioStructPointer(int portNumber)
{
 GPIO_TypeDef *gpioStructPointer;
 gpioStructPointer =  CmsisGpioStructPointerArray[portNumber];
 return gpioStructPointer;
}

typedef struct
{
 GPIO_TypeDef *GpioStructPointer;
 int PinNumber;
} gpioPortStructPinStruct;

gpioPortStructPinStruct *getGpioPortStructPinStructPointer(portNumber portNumber, \
pinNumber pinNumber) // *** To be tested ***
  {
 gpioPortStructPinStruct *gpioPortStructPinStruct;
 gpioPortStructPinStruct->GpioStructPointer = getGpioStructPointer(portNumber);
 gpioPortStructPinStruct->PinNumber = pinNumber;
 return gpioPortStructPinStruct;
  }

// *** GPIO functions ***

void initializeOutputPin01HighV093(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setGpioDataPinOutput(gpioStructPointer, pinNumber);
setGpioDataPinHigh(gpioStructPointer, pinNumber);

// printf("Port Pin = %2d,%2d\n", portNumber, pinNumber);
}

void setGpioDataPinInput(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DIR  &= ~(1 << pinNumber);
}

void setGpioDataPinOutput(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DIR |= (1 << pinNumber);
}

void setGpioDataPinLow(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DATA &= ~(1 << pinNumber);
}

void setGpioDataPinHigh(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DATA |= (1 << pinNumber);
}

void setGpioPinDirection(GPIO_TypeDef *gpio_struct_ptr, int pinNumber, directionValue directionValue)
{
 if (directionValue == INPUT_DIRECTION)
  setGpioDataPinInput(gpio_struct_ptr, pinNumber);
 else
  setGpioDataPinOutput(gpio_struct_ptr, pinNumber);
}

void setGpioDataPin(GPIO_TypeDef *gpio_struct_ptr, int pinNumber, logicLevelValue logicLevelValue)
{
 if (logicLevelValue == LOGIC_LOW_LEVEL)
  setGpioDataPinLow(gpio_struct_ptr, pinNumber);
 else
  setGpioDataPinHigh(gpio_struct_ptr, pinNumber);
}

logicLevelValue getGpioDataPinValue01(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 logicLevelValue logicLevelValue;

  int GpioDataPinMask = (1 << pinNumber);

  if ((gpio_struct_ptr->DATA  &= GpioDataPinMask) == GpioDataPinMask)
  logicLevelValue = HIGH;
 else
  logicLevelValue = LOW;

  return logicLevelValue;
}

logicLevelValue getGpioDataPinValue(portPinArrayPointerArray inputPortPinArrayPointerArray, int pinNumber)
{
 int portNumber;
 GPIO_TypeDef *gpioStructPointer;
 logicLevelValue logicLevelValue;

  portNumber = getPortNumber01(inputPortPinArrayPointerArray, pinNumber);
 gpioStructPointer = getGpioStructPointer(portNumber);
 pinNumber = getPinNumber01(inputPortPinArrayPointerArray, pinNumber);

  logicLevelValue = getGpioDataPinValue01(gpioStructPointer, pinNumber);

  return logicLevelValue;
}

portNumber getPortNumber(portPinArray portPinArray)
{
 int portNumber;
 portNumber = portPinArray[PORT_INDEX];
 return portNumber;
}

portNumber getPortNumber01(portPinArrayPointerArray portPinArrayPointerArray, deviceNumber deviceNumber)
{
 int portNumber;
 portNumber = getPortNumber(*portPinArrayPointerArray[deviceNumber - 1]);
 return portNumber;
}

pinNumber getPinNumber(portPinArray portPinArray)
{
 int pinNumber;
 pinNumber = portPinArray[PIN_INDEX];
 return pinNumber;
}

pinNumber getPinNumber01(portPinArrayPointerArray portPinArrayPointerArray, deviceNumber deviceNumber)
{
 int pinNumber;
 pinNumber = getPinNumber(*portPinArrayPointerArray[deviceNumber - 1]);
 return pinNumber;
}

// *** set up output pin ***

void initializeOutputPin01(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setGpioDataPinOutput(gpioStructPointer, pinNumber);
setGpioDataPinLow (gpioStructPointer, pinNumber);
  }

void initializeOutputPin01Low(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setGpioDataPinOutput(gpioStructPointer, pinNumber);
setGpioDataPinLow(gpioStructPointer, pinNumber);
  }

void initializeOneOutputPin(portPinArrayPointerArray outputPortPinArrayPointerArray, deviceNumber deviceNumber)
{
int portNumber;
int pinNumber;
portPinArray portPinArray = {0, 0};

portNumber = getPortNumber01(outputPortPinArrayPointerArray, deviceNumber);
pinNumber = getPinNumber01(outputPortPinArrayPointerArray, deviceNumber);

portPinArray[PORT_INDEX] = portNumber;
portPinArray[PIN_INDEX] = pinNumber;
initializeOutputPin01(portPinArray);

}

void initializeOneOutputPinHigh(portPinArrayPointerArray outputPortPinArrayPointerArray, deviceNumber deviceNumber)
{
int portNumber;
int pinNumber;
portPinArray portPinArray = {0, 0};

portNumber = getPortNumber01(outputPortPinArrayPointerArray, deviceNumber);
pinNumber = getPinNumber01(outputPortPinArrayPointerArray, deviceNumber);

portPinArray[PORT_INDEX] = portNumber;
portPinArray[PIN_INDEX] = pinNumber;
initializeOutputPin01High(portPinArray);
}

void initializeAllOutputPins(portPinArrayPointerArray outputPortPinArrayPointerArray, int maxPinNumber)
{
  int pinNumber;

  for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
  {
   initializeOneOutputPin(outputPortPinArrayPointerArray, pinNumber);
  }
}

void initializeAllOutputPinsHigh(portPinArrayPointerArray outputPortPinArrayPointerArray, int maxPinNumber)
{
  int pinNumber;

  for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
  {
   initializeOneOutputPinHigh(outputPortPinArrayPointerArray, pinNumber);
  }
}

// *** setup input pin ***

void initializeInputPin01(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setGpioDataPinInput(gpioStructPointer, pinNumber);
}

void initializeOneInputPin(portPinArrayPointerArray outputPortPinArrayPointerArray, \
  deviceNumber deviceNumber)
{
 int portNumber;
 int pinNumber;
 GPIO_TypeDef *gpioStructPointer;

 portNumber = getPortNumber01(outputPortPinArrayPointerArray, deviceNumber);
 gpioStructPointer = getGpioStructPointer(portNumber);
 pinNumber = getPinNumber01(outputPortPinArrayPointerArray, deviceNumber);

  setGpioDataPinInput(gpioStructPointer, pinNumber);
  }

void initializeAllInputPins(portPinArrayPointerArray inputPortPinArrayPointerArray, int maxPinNumber)
{
  int pinNumber;

  for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
  {
   initializeOneInputPin(inputPortPinArrayPointerArray, pinNumber);
  }
}

void initializeAllInputPins40(portPinArrayPointerArray inputPortPinArrayPointerArray)
{
int pinNumber;
int maxPinNumber;

maxPinNumber = sizeof(inputPortPinArrayPointerArray) / sizeof(*inputPortPinArrayPointerArray);

for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
{
initializeOneInputPin(inputPortPinArrayPointerArray, pinNumber);
}
}

// *** Set GPIO output pin data value ***

void setGpioDataPinHigh01(portPinArray *portPinArrayPointer)
{
pinNumber pinNumber;
portNumber portNumber;
GPIO_TypeDef *gpioStructPointer;

pinNumber = getPinNumber(portPinArrayPointer);
portNumber = getPortNumber(portPinArrayPointer);
gpioStructPointer = getGpioStructPointer(portNumber);
setGpioDataPinHigh(gpioStructPointer, pinNumber);
}

void setGpioDataPinLow01(portPinArray *portPinArrayPointer)
{
pinNumber pinNumber;
portNumber portNumber;
GPIO_TypeDef *gpioStructPointer;

pinNumber = getPinNumber(portPinArrayPointer);
portNumber = getPortNumber(portPinArrayPointer);
gpioStructPointer = getGpioStructPointer(portNumber);
setGpioDataPinLow(gpioStructPointer, pinNumber);
}

// *** Functions 050 ***

void setupGpioPinOutputLow050(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setupGpioPinOutput051(gpioStructPointer, pinNumber);
setGpioOutputPinLow051(gpioStructPointer, pinNumber);
  }

void setupGpioPinOutputHigh050(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setupGpioPinOutput051(gpioStructPointer, pinNumber);
setGpioOutputPinHigh051(gpioStructPointer, pinNumber);
  }

void setupGpioPinOutput051(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DIR |= (1 << pinNumber);
}

void setGpioOutputPinHigh051(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DATA |= (1 << pinNumber);
}

void setGpioOutputPinLow051(GPIO_TypeDef *gpio_struct_ptr, int pinNumber)
{
 gpio_struct_ptr->DATA &= ~(1 << pinNumber);
}

void setupAllGpioPinsOutputLow050(portPinArrayPointerArray portPinArrayPointerArray, int maxPinNumber)
{
  int pinNumber;

  for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
  {
   setupPinOutputLow050(portPinArrayPointerArray, pinNumber);
  }
}

void setupPinOutputLow050(portPinArrayPointerArray outputPortPinArrayPointerArray, deviceNumber deviceNumber)
{
int portNumber;
int pinNumber;
portPinArray portPinArray = {0, 0};

portNumber = getPortNumber01(outputPortPinArrayPointerArray, deviceNumber);
pinNumber = getPinNumber01(outputPortPinArrayPointerArray, deviceNumber);

portPinArray[PORT_INDEX] = portNumber;
portPinArray[PIN_INDEX] = pinNumber;
initializeOutputPin01Low(portPinArray);
}

void setupGpioPinInput050(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setGpioDataPinInput(gpioStructPointer, pinNumber);
}

void setupAllGpioPinsInput050(portPinArrayPointerArray portPinArrayPointerArray, int maxPinNumber)
{
  int pinNumber;

  for (pinNumber = 1; pinNumber < (maxPinNumber + 1); pinNumber++)
  {
 setupGpioPinInput051(portPinArrayPointerArray, pinNumber);
  }
}

void setupGpioPinInput051(portPinArrayPointerArray outputPortPinArrayPointerArray, \
 deviceNumber deviceNumber)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber01(outputPortPinArrayPointerArray, deviceNumber);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber01(outputPortPinArrayPointerArray, deviceNumber);

setGpioDataPinInput(gpioStructPointer, pinNumber);
  }

void setupOlimexGpio050()
{
setupAllGpioPinsOutputLow050(OlimexBoardLedPortPinArrayPointerArray, MAX_OLIMEX_LED_PIN_NUMBER);
setupAllGpioPinsInput050(OlimexBoardKeyPortPinArrayPointerArray,  MAX_OLIMEX_KEY_PIN_NUMBER);
}

void setupWhutGpio050()
{
setupAllGpioPinsOutputLow050(WhutBoardLedPortPinArrayPointerArray, MAX_WHUT_LED_PIN_NUMBER);
setupAllGpioPinsInput050(WhutBoardKeyPortPinArrayPointerArray,  MAX_WHUT_KEY_PIN_NUMBER);
}

void initializeOutputPin01High(portPinArray portPinArray)
{
int portNumber;
int pinNumber;
GPIO_TypeDef *gpioStructPointer;

portNumber = getPortNumber(portPinArray);
gpioStructPointer = getGpioStructPointer(portNumber);
pinNumber = getPinNumber(portPinArray);

setGpioDataPinOutput(gpioStructPointer, pinNumber);
setGpioDataPinHigh(gpioStructPointer, pinNumber);

// printf("Port Pin = %2d,%2d\n", portNumber, pinNumber);
}

#endif /* GPIO050_HEADER_SEEN */

// ***********************************************************************
// End
// ***********************************************************************

.END



No comments:

Post a Comment