2013-10-13

Fong EKG v0.1 development notes


























Fong EKG v0.1 development notes

// ***********************************************************************
// Program  - Fong EKG v5.0
// Function - Olimex EKG Board Evaluation
// Author   - TL Fong
// Build    - 2013.10.13.01
// Date     - 2013oct13hkt1021
// Hardware - Olimex/CooCox/MagicBlue/WHUT/Somy LPC1114/C14/301
// Software - GCC ARM 4.7, CoIDE 1.7.4,  CoLinkEx 1.1, Flash Magic v7.51
// ***********************************************************************

#include "test050.h" // main tests

// ***********************************************************************
// Main Function
// ***********************************************************************

int main()
{
blinkLedP09();

return 0;
}

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



// ***********************************************************************
// test050.h 2013oct13hkt1026
// ***********************************************************************

#include "led050.h"
// #include "key050.h"

void blinkLedP09()
{
blinkOneLed050(PortPinArrayP09, ON_ONE_FIFTH_SECOND, OFF_ONE_SECOND, \
     REPEAT_6_TIMES);
}

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



// ***********************************************************************
// config050.h - 2013oct13hk1036
// ***********************************************************************

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

#ifndef CONFIG_HEADER_SEEN
#define CONFIG_HEADER_SEEN

// *** Logic level ***

#define LOW 0
#define HIGH 1

#define LOW_LEVEL 0
#define HIGH_LEVEL 1

#define LOGIC_LOW_LEVEL 0
#define LOGIC_HIGH_LEVEL 1

typedef int logicLevelValue;

logicLevelValue LogicLevelLow = 0;
logicLevelValue LogicLevelHigh = 1;

// *** GPIO direction ***

#define INPUT_DIRECTION 0
#define OUTPUT_DIRECTION 1

typedef int directionValue;

directionValue InputDirection = 0;
directionValue OutputDirection = 1;

// *** GPIO port number, pin number, port/pin number ***

#define PORT0 0
#define PORT1 1
#define PORT2 2
#define PORT3 3

#define PIN0 0
#define PIN1 1
#define PIN2 2
#define PIN3 3
#define PIN4 4
#define PIN5 5
#define PIN6 6
#define PIN7 7
#define PIN8 8
#define PIN9 9
#define PIN10 10
#define PIN11 11

typedef int portNumber;
portNumber Port0 = 0;
portNumber Port1 = 1;
portNumber Port2 = 2;
portNumber Port3 = 3;

typedef int pinNumber;
pinNumber Pin0  =  0;
pinNumber Pin1  =  1;
pinNumber Pin2  =  2;
pinNumber Pin3  =  3;
pinNumber Pin4  =  4;
pinNumber Pin5  =  5;
pinNumber Pin6  =  6;
pinNumber Pin7  =  7;
pinNumber Pin8  =  8;
pinNumber Pin9  =  9;
pinNumber Pin10 = 10;
pinNumber Pin11 = 11;

typedef const int portPinNumber;

portPinNumber Pio05  = 5;
portPinNumber Pio08  = 8;
portPinNumber Pio09  = 9;

portPinNumber Rpio11 = 11;
portPinNumber Rpio12 = 12;
portPinNumber Pio19  = 19;
portPinNumber Rpio18 = 18;
portPinNumber Pio110  = 110;

// *** LED, key, 7-segment LED digit number ***

typedef const int deviceNumber;

#define LED1 1
#define LED2 2
#define LED3 3
#define LED4 4
#define LED5 5

#define LED_1 1
#define LED_2 2
#define LED_3 3
#define LED_4 4
#define LED_5 5

#define KEY_1 1
#define KEY_2 2
#define KEY_3 3
#define KEY_4 4
#define KEY_5 5

#define MAX_DEVICE_NUMBER 5
#define MAX_LED_NUMBER    5
#define MAX_KEY_NUMBER    5
#define MAX_PWM_NUMBER    5

#define DIGIT_0 0
#define DIGIT_1 1
#define DIGIT_2 2
#define DIGIT_3 3
#define DIGIT_4 4
#define DIGIT_5 5
#define DIGIT_6 6
#define DIGIT_7 7
#define DIGIT_8 8
#define DIGIT_9 9

// *** Port pin array and port pin array pinters ***

#define PORT_INDEX 0
#define PIN_INDEX 1

typedef int portPinArray[2];

typedef portPinArray *portPinArrayPointerArray[MAX_DEVICE_NUMBER];

// *** Generic port pin array ***

portPinArray PortPinArrayP04 = {PORT0, PIN4};
portPinArray PortPinArrayP05 = {PORT0, PIN5};
portPinArray PortPinArrayP09 = {PORT0, PIN9};
portPinArray PortPinArrayP24 = {PORT2, PIN4};
portPinArray PortPinArrayP25 = {PORT2, PIN5}; // USB D- do NOT use
portPinArray PortPinArrayP26 = {PORT2, PIN6}; // USB D+ do NOT use
portPinArray PortPinArrayP27 = {PORT2, PIN7};
portPinArray PortPinArrayP34 = {PORT3, PIN4}; // replacing P24
portPinArray PortPinArrayP35 = {PORT3, PIN5}; // replacing P25

// *** Olimex LED port pin array ***

#define MAX_OLIMEX_LED_PIN_NUMBER 8 // 2013oct11

portPinArray OlimexBoardLedPortPinArray1 = {PORT3, PIN0}; // LED 0 2013oct11
portPinArray OlimexBoardLedPortPinArray2 = {PORT3, PIN1}; // LED 1 2013oct11
portPinArray OlimexBoardLedPortPinArray3 = {PORT3, PIN2}; // LED 2 2013oct11
portPinArray OlimexBoardLedPortPinArray4 = {PORT3, PIN3}; // LED 3 2013oct11
portPinArray OlimexBoardLedPortPinArray5 = {PORT3, PIN4}; // LED 4 2013oct11
portPinArray OlimexBoardLedPortPinArray6 = {PORT3, PIN5}; // LED 5 2013oct11
portPinArray OlimexBoardLedPortPinArray7 = {PORT2, PIN6}; // LED 6 2013oct11
portPinArray OlimexBoardLedPortPinArray8 = {PORT2, PIN7}; // LED 7 2013oct11

portPinArrayPointerArray OlimexBoardLedPortPinArrayPointerArray[MAX_OLIMEX_LED_PIN_NUMBER] = \
  {&OlimexBoardLedPortPinArray1, &OlimexBoardLedPortPinArray2, \
  &OlimexBoardLedPortPinArray3, &OlimexBoardLedPortPinArray4, \
  &OlimexBoardLedPortPinArray5, &OlimexBoardLedPortPinArray6, \
  &OlimexBoardLedPortPinArray7, &OlimexBoardLedPortPinArray8};

// *** Olimex Key port pin array ***

#define MAX_OLIMEX_KEY_PIN_NUMBER 2

portPinArray OlimexBoardKeyPortPinArray1 = {PORT2, PIN9};
portPinArray OlimexBoardKeyPortPinArray2 = {PORT1, PIN4};

portPinArrayPointerArray OlimexBoardKeyPortPinArrayPointerArray[MAX_OLIMEX_KEY_PIN_NUMBER] = \
    {&OlimexBoardKeyPortPinArray1, &OlimexBoardKeyPortPinArray2};

// *** 7-segment LED declaration ***

#define SCLK_INDEX 0
#define DIN_INDEX 1
#define LATCH_INDEX 2

// *** WHUT Seven segment LED data and control signals ***

portPinArray WhutBoardSevenSegmentLedPortPinArraySclk = {PORT2, PIN1}; // Serial Clock
portPinArray WhutBoardSevenSegmentLedPortPinArrayDin = {PORT2, PIN3}; // Data in
portPinArray WhutBoardSevenSegmentLedPortPinArrayLatch = {PORT2, PIN0}; // Latch

portPinArray WhutBoardKeyPortPinArray1 = {PORT2, PIN7};  // LCD D4 <<<<< 2013aug28
portPinArray WhutBoardKeyPortPinArray2 = {PORT2, PIN8};  // LCD D5 <<<<< 2013aug28
portPinArray WhutBoardKeyPortPinArray3 = {PORT2, PIN9};  // LCD D6 <<<<< 2013aug28
portPinArray WhutBoardKeyPortPinArray4 = {PORT2, PIN10}; // LCD D7 <<<<< 2013aug28
portPinArray WhutBoardKeyPortPinArray5 = {PORT1, PIN4};  // WakeUp <<<<< 2013aug30

#define MAX_7_SEG_LED_PIN_NUMBER 3

portPinArrayPointerArray WhutBoardSevenSegmentLedPortPinArrayPointerArray[MAX_7_SEG_LED_PIN_NUMBER] = \
  {&WhutBoardSevenSegmentLedPortPinArraySclk, &WhutBoardSevenSegmentLedPortPinArrayDin, \
       &WhutBoardSevenSegmentLedPortPinArrayLatch};

// *** Mcu board struct ***

typedef struct
 {
portPinArrayPointerArray *LedPortPinArrayPointerArray;
portPinArrayPointerArray *KeyPortPinArrayPointerArray;
 } mcuBoardStruct;

 mcuBoardStruct OlimexLpc1114DevBoardStruct = {OlimexBoardLedPortPinArrayPointerArray, \
OlimexBoardKeyPortPinArrayPointerArray};

#endif /* CONFIG_HEADER_SEEN */

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


// ***********************************************************************
// gpio033.h
// 2013oct11hkt1623
// ***********************************************************************

#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"

// *** 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 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 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);
  }

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

#endif /* GPIO050_HEADER_SEEN */

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



// ***********************************************************************
// timer050.h 2013oct13hkt1108
// ***********************************************************************

#ifndef DELAY_HEADER_SEEN
#define DELAY_HEADER_SEEN

// *** Delay constants ***

#define ONE_FIFTH_SECOND  2
#define ONE_HALF_SECOND   5
#define ONE_SECOND       10
#define TWO_SECONDS      20

#define ON_ONE_FIFTH_SECOND   2
#define OFF_ONE_FIFTH_SECOND  2
#define ON_ONE_HALF_SECOND    5
#define OFF_ONE_HALF_SECOND   5
#define ON_ONE_SECOND        10
#define OFF_ONE_SECOND       10

// *** Repeat times ***

#define REPEAT_1_TIME 1
#define REPEAT_2_TIMES 2
#define REPEAT_3_TIMES 3
#define REPEAT_4_TIMES 4
#define REPEAT_5_TIMES 5
#define REPEAT_6_TIMES 6
#define REPEAT_8_TIMES 8
#define REPEAT_10_TIMES 10
#define REPEAT_20_TIMES 20

#define BLINK_0_TIME 0
#define BLINK_1_TIME 1
#define BLINK_2_TIMES 2
#define SEQUENCE_1_TIME 1
#define SEQUENCE_2_TIMES 2
#define SEQUENCE_4_TIMES 4

void delayTenthSecond(int count)
{
 int i, j, k;
 for (i = 0; i < count; i++)
 {
  for (j = 0; j < 0x4; j++)
     {
         for (k = 0; k < 0x000BB00; k++)
         {
         }
     }
 }
}

void delayTime(int count)
{
 delayTenthSecond(count);
}

// *** system timer number, match register number ***

typedef const int timerNumber;
timerNumber Ct16b0 = 0;
timerNumber Ct16b1 = 1;
timerNumber Ct32b0 = 2;
timerNumber Ct32b1 = 3;

typedef const int matchRegisterNumber;
matchRegisterNumber MatchRegister0 = 0;
matchRegisterNumber MatchRegister1 = 1;
matchRegisterNumber MatchRegister2 = 2;

#endif /* DELAY_HEADER_SEEN */

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




// ***********************************************************************
// led050.h 2013oct12hkt1105
// ***********************************************************************

#include "config050.h"
#include "gpio050.h"
#include "timer050.h"

void blinkOneLed050(portPinArray ledPortPinArrayPointer, \
                    int onTime, int offTime, int blinkCount)
{
initializeOutputPin01High(ledPortPinArrayPointer);
delayTime(ONE_SECOND);
int count;
for (count = 0; count < blinkCount; count++)
  {
   setGpioDataPinLow01(ledPortPinArrayPointer);
   delayTenthSecond(onTime);
   setGpioDataPinHigh01(ledPortPinArrayPointer);
   delayTenthSecond(offTime);
  }
}

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




.END

No comments:

Post a Comment