Zigbee Module Examples

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions | Variables
hal_ek-lm4f120XL.c File Reference

Hardware Abstraction Layer (HAL) for the Stellaris LaunchPad EK-LM4F120XL. Based on hal_gw1.c. More...

`#include "hal.h"`
`#include "hal_version.h"`
`#include "../HAL/hal_ek-lm4f120XL_rgb.h"`
`#include "inc/hw_types.h"`
`#include "inc/hw_memmap.h"`
`#include "inc/hw_ints.h"`
`#include "inc/hw_gpio.h"`
`#include "driverlib/gpio.h"`
`#include "driverlib/ssi.h"`
`#include "driverlib/i2c.h"`
`#include "driverlib/interrupt.h"`
`#include "driverlib/uart.h"`
`#include "driverlib/fpu.h"`
`#include "driverlib/rom.h"`
`#include "driverlib/timer.h"`
`#include "inc/hw_ssi.h"`
`#include "utils/uartstdio.h"`
`#include <stdint.h>`
`#include "driverlib/adc.h"`

## Macros
#define | PERIPHERAL_ENABLE_DELAY() SysCtlDelay(10)
#define | LEFT_BUTTON GPIO_PIN_4
#define | RIGHT_BUTTON GPIO_PIN_0
#define | ALL_BUTTONS (LEFT_BUTTON | RIGHT_BUTTON)
#define | NUM_LEDS 4
#define | REFERENCE_VOLTAGE_MV (3300l)
#define | NUMBER_OF_STEPS_12_BIT_RESOLUTION (4096l)
#define | TIMER_MAX_SECONDS (0xFFFFFFFF / SysCtlClockGet())

## Functions
void | oscInit ()
void | portInit ()
void | halUartInit ()
void | doNothing (int8_t a)
void | displayVersion ()
void | halInit ()
void | IntGPIOe (void)
void | IntGPIOf (void)
uint8_t | buttonIsPressed (uint8_t button)
uint8_t | halUartBusy ()
void | UARTIntHandler (void)
int16_t | toggleLed (uint8_t led)
int16_t | setLed (uint8_t led)
int16_t | clearLed (uint8_t led)
void | clearLeds ()
void | halSpiInitModule ()
void | spiWrite (unsigned char *bytes, unsigned char numBytes)
void | delayMs (uint16_t ms)
void | halRgbLedPwmInit ()
void | halRgbSetLeds (uint8_t red, uint8_t blue, uint8_t green)
int16_t | calibrateVlo ()
uint16_t | getCurrentSensor ()
void | Timer2IntHandler (void)
int16_t | initTimer (uint8_t seconds)
void | halSetWakeupFlags (uint16_t wakeupFlagsToSet)

## Variables
void(* | debugConsoleIsr )(int8_t)
void(* | buttonIsr )(int8_t)
void(* | timerIsr )(void)

## Detailed Description

Hardware Abstraction Layer (HAL) for the Stellaris LaunchPad EK-LM4F120XL. Based on hal_gw1.c.

Tools to interact with the onboard peripherals for Module interface. The EK-LM4F120XL is a development board utilizing a LM4F120XL processor and a few peripherals.

This file must be modified if changing hardware platforms.

The Zigbee Module library & examples require several methods to be defined. See hal_helper documentation. Also see hal_launchpad.h for macros that must be defined.

See also:
  hal_helper.c for utilities to assist when changing hardware platforms

Rev:
  1568

Author:
  dsmith

Date:
  2012-09-24 17:16:29 -0700 (Mon, 24 Sep 2012)

# Support

Please refer to the wiki at http://teslacontrols.com/mw/ for more information. Additional support is available via email at the following addresses:

- Questions on how to use the product: AIR@a.nosp@m.nare.nosp@m.n.com
- Feature requests, comments, and improvements: featu.nosp@m.rere.nosp@m.quest.nosp@m.s@te.nosp@m.slaco.nosp@m.ntro.nosp@m.ls.co.nosp@m.m
- Consulting engagements: sales.nosp@m.@tes.nosp@m.lacon.nosp@m.trol.nosp@m.s.com

# License

Copyright (c) 2012 Tesla Controls. All rights reserved. This Software may only be used with an Anaren A2530E24AZ1, A2530E24CZ1, A2530R24AZ1, or A2530R24CZ1 module. Redistribution and use in source and binary forms, with or without modification, are subject to the Software License Agreement in the file "anaren_eula.txt"

YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL ANAREN MICROWAVE OR TESLA CONTROLS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSE INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.

## Function Documentation

int16_t calibrateVlo | ( |  | ) |

Required for compatibility with MSP430 libraries

int16_t clearLed | ( | uint8_t | led | ) |

Turns OFF the specified LED.

Parameters:

  led | the LED to turn off

Postcondition:
  The specified LED is turned on.

Returns:
  0 if success, -1 if invalid LED specified

void clearLeds | ( |  | ) |

Turns OFF LEDs.

Postcondition:
  LEDs are turned off.

void delayMs | ( | uint16_t | ms | ) |

A fairly accurate Blocking Delay in Milliseconds - delays by at least the specified number of milliseconds (mSec)

Precondition:
  SysCtlClockSet() has been called to set the processor clock rate

Parameters:

  ms | number of milliseconds to delay

Note:
  change if you are using an RTOS.

void displayVersion | ( |  | ) |

Display information about this driver firmware

void doNothing | ( | int8_t | a | ) |

Simple placeholder function to point the function pointers to so that they don't cause mischief

uint16_t getCurrentSensor | ( |  | ) |

Reads the current sense amplifier output using the Analog to Digital Converter (ADC). Current sense resistor is 0.2 ohms, amplifier multiplies voltage drop by 50. Therefore, every mA of current translates into 10mV measured by the microcontroller

Note:
  Current sense input is on PE5 on Stellaris LaunchPad

Precondition:
  Current sense shunt is installed on the BoosterPack

Returns:
  Current in mA multiplied by 10 (e.g. return value of 713 = 71.3mA)

See also:
  StellarisWare/examples/peripherals/adc/single_ended.c

void halInit | ( |  | ) |

Configures hardware for the particular hardware platform:

- Ports: sets direction, interrupts, pullup/pulldown resistors etc.
- Holds radio in reset (active-low)

void halRgbLedPwmInit | ( |  | ) |

Initializes the PWM engine used for the RGB LED. This allows the RGB LED to display many colors.

Postcondition:
  RGB LED may be used, with halRgbSetLeds().

void halRgbSetLeds | ( | uint8_t | red,
|  | uint8_t | blue,
|  | uint8_t | green
| ) |  |

Sets RGB LED color to the selected values.

Precondition:
  halRgbLedPwmInit() has been called to initialize the PWM engine.

Postcondition:
  RGB LED displays the selected colors.

Note:
  you must include hal_ek-lm4f120XL_rgb.h in this file and ensure that the .c file is included in the build path

void halSetWakeupFlags | ( | uint16_t | wakeupFlagsToSet | ) |

Required for compatibility with MSP430 library

void halSpiInitModule | ( |  | ) |

Initializes the Serial Peripheral Interface (SPI) interface to the Zigbee Module (ZM).

Note:
  Maximum module SPI clock speed is 4MHz. SPI port configured for clock polarity of 0, clock phase of 0, and MSB first.
  The Stellaris LaunchPad uses SSI2 to communicate with module

Precondition:
  SPI pins configured correctly:
  - Clock, MOSI, MISO configured as SPI function
  - Chip Select configured as an output
  - SRDY configured as an input.

Postcondition:
  SPI port is configured for communications with the module.

uint8_t halUartBusy | ( |  | ) |

The UART has a 16 byte FIFO buffer, so our printf() methods return even though the processor is still outputting bytes on the UART.

Returns:
  1 if the Debug UART is busy sending data or 0 if not. Useful to postpone sleeping until the UART has sent all data.

void halUartInit | ( |  | ) |

Initialize UART0 to use for stdio

Precondition:
  UART0 pins were configured

int16_t initTimer | ( | uint8_t | seconds | ) |

Configures timer.

See also:
  timers example in EK-LM4F120XL StellarisWare package

Note:
  On the LM4F120XL, there are 16/32 bit timers or "wide" timers featuring 32/64bit. We use a standard timer.

Parameters:

  seconds | period of the timer. Maximum is 0xFFFFFFFF / SysCtlClockGet(); or about 171 sec if using 25MHz main clock

Returns:
  0 if success; -1 if illegal parameter

void IntGPIOe | ( | void |  | ) |

    Port E interrupt service routine

Note:
  Must be configured in startup_ccs.c or else will not be called.

void IntGPIOf | ( | void |  | ) |

    Port F interrupt service routine

Note:
  Must be configured in startup_ccs.c or else will not be called.

void oscInit | ( |  | ) |

Initializes Oscillator: configures MCLK to 25MHz using internal PLL (SYSCTL_USE_PLL) calibrated to 8MHz external crystal (SYSCTL_XTAL_8MHZ).

Note:
  PLL native frequency = 200MHz, so divide by 8 (SYSCTL_SYSDIV_8) to get 25MHz
  ADC requires either the PLL or a 16MHz clock source

void portInit | ( |  | ) |

Initializes Ports/Pins: sets direction, interrupts, pullup/pulldown resistors etc.

int16_t setLed | ( | uint8_t | led | ) |

Turns ON the specified LED.

Parameters:

  led | the LED to turn on

Postcondition:
  The specified LED is turned on.

Returns:
  0 if success, -1 if invalid LED specified

void spiWrite | ( | unsigned char * | bytes,
|  | unsigned char | numBytes
| ) |  |

Sends a message over SPI to the Module. SPI uses a "write-to-read" approach to read data out, you must write data in. This is a private method that gets wrapped by other methods, e.g. spiSreq(), spiPoll(), etc. To Write, set *bytes, numBytes. To Read, set *bytes only. Don't need to set numBytes because Module will stop when no more bytes read.

Parameters:

  bytes | the data to be sent or received.
  numBytes | the number of bytes to be sent. This same buffer will be overwritten with the received data.

Note:
  Modify this method for other hardware implementations.

Precondition:
  SPI port configured for writing
  Module has been initialized

Postcondition:
  bytes contains received data, if any

See also:
  Stellaris Application Note spma002.pdf, "Adding 32kB of Serial SRAM to a Stellaris Microcontroller"

void Timer2IntHandler | ( | void |  | ) |

ISR for Timer 2

Precondition:
  timer configured with initTimer
  global interrupts enabled with HAL_ENABLE_INTERRUPTS()

int16_t toggleLed | ( | uint8_t | led | ) |

Toggles the specified LED.

Parameters:

  led | the LED to toggle

Postcondition:
  The specified LED is toggled.

Returns:
  0 if success, -1 if invalid LED specified

void UARTIntHandler | ( | void |  | ) |

Debug console interrupt service routine, called when a byte is received on UART.

Precondition:
  In startup_ccs.c, UARTIntHandler is set as the ISR for the UART0 Rx and Tx interrupt
  In startup_ccs.c, this function is declared, e.g:

       extern void UARTIntHandler(void);

  Interrupts have been enabled, e.g:

       IntMasterEnable();
       IntEnable(INT_UART0);
       UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

  UART has been configured

Postcondition:
  a byte received on the UART will result in debugConsoleIsr() function pointer called

## Variable Documentation

void(* buttonIsr)(int8_t)

    Function pointer for the ISR called when the button is pressed.

Parameter is which button was pressed.

void(* debugConsoleIsr)(int8_t)

    This is a function pointer for the Interrupt Service Routine called when a debug console

character is received. To use it, declare it with `extern void (*debugConsoleIsr)(int8_t);` and then point it to a function you created, e.g. `debugConsoleIsr =` and your function handleDebugConsoleInterrupt() will be called when a byte is received on the debug serial port. Obviously your handleDebugConsoleInterrupt must have the same method signature as the function pointer. In other words, your function should be declared as: void handleDebugConsoleInterrupt(int8_t);

void(* timerIsr)(void)

Function pointer for the ISR called when a timer generates an interrupt