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_mdb2.c File Reference

Hardware Abstraction Layer (HAL) for the MDB2. More...

`#include "hal_mdb2.h"`
`#include <stdint.h>`

## Macros
#define | TIMER_MAX_SECONDS 4

## Functions
__interrupt void | USCIAB0RX_ISR (void)
__interrupt void | PORT1_ISR (void)
__interrupt void | PORT2_ISR (void)
void | doNothing (int8_t a)
void | oscInit ()
void | halInit ()
int16_t | halConfigureSrdyInterrrupt (uint8_t flags)
int16_t | putchar (int16_t c)
void | halSpiInitModule ()
void | spiWrite (uint8_t *bytes, uint8_t numBytes)
void | delayMs (uint16_t delay)
int16_t | setLed (uint8_t led)
void | clearLeds ()
int16_t | toggleLed (uint8_t led)
uint16_t | getVcc3 ()
void | halSetAllPinsToInputs (void)
int16_t | initTimer (uint8_t seconds)
void | stopTimer ()
__interrupt void | Timer_A (void)
int16_t | calibrateVlo ()

## Variables
void(* | debugConsoleIsr )(int8_t)
void(* | buttonIsr )(int8_t)
void(* | timerIsr )(void)
void(* | srdyIsr )(void)
uint16_t | wakeupFlags = 0
uint16_t | vloFrequency = 0

## Detailed Description

Hardware Abstraction Layer (HAL) for the MDB2.

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_mdb2.h for macros that must be defined.

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

Rev:
  1642

Author:
  dsmith

Date:
  2012-10-31 11:17:04 -0700 (Wed, 31 Oct 2012)

# Support

Please refer to the wiki at www.anaren.com/air-wiki-zigbee 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 | ( |  | ) |

    Calibrate VLO. Once this is done, the VLO can be used semi-accurately for timers etc.

Once calibrated, VLO is within ~2% of actual when using a 1% calibrated DCO frequency and temperature and supply voltage remain unchanged.

Returns:
  VLO frequency (number of VLO counts in 1sec), or -1 if out of range

Precondition:
  SMCLK is 4MHz
  MCLK is 8MHz
  ACLK sourced by VLO (BCSCTL3 = LFXT1S_2; in MSP430F2xxx)

Note:
  Calibration is only as good as MCLK source. Obviously, if using the internal DCO (+/- 1%) then this value will only be as good as +/- 1%. YMMV.
  On MSP430F248 or MSP430F22x2 or MSP430F22x4, must use TACCR2. On MSP430F20x2, must use TACCR0. Check device-specific datasheet to see which module block has ACLK as a compare input. For example, see page 23 of the MSP430F24x datasheet or page 17 of the MSP430F20x2 datasheet, or page 18 of the MSP430F22x4 datasheet.
  If application will require accuracy over change in temperature or supply voltage, recommend calibrating VLO more often.

Postcondition:
  Timer A settings changed
  ACLK divide by 8 bit cleared

void clearLeds | ( |  | ) |

    Turns OFF LEDs.

Postcondition:
  LEDs are turned off.

void delayMs | ( | uint16_t | delay | ) |

    A fairly accurate blocking delay for waits in the millisecond range. Good for 1mSec to 1000mSec.

At 1MHz, error of zero for 100mSec or 1000mSec. For 10mSec, error of 100uSec. At 1mSec, error is 20uSec. At 8MHz, error of zero for 1000mSec. Note that accuracy will depend on the clock source. MSP430F2xx internal DCO is typically +/-1%. For better timing accuracy, use a timer, or a crystal.

Precondition:
  TICKS_PER_MS is defined correctly

Parameters:

  delay | number of milliseconds to delay

void doNothing | ( | int8_t | a | ) |

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

uint16_t getVcc3 | ( |  | ) |

    Reads the MSP430 supply voltage using the Analog to Digital Converter (ADC).

On MDB2, this is approx. 3600mV

Returns:
  Vcc supply voltage, in millivolts

int16_t halConfigureSrdyInterrrupt | ( | uint8_t | flags | ) |

    Configures SRDY interrupt. Does NOT enable the interrupt.

SRDY is P2.6

Parameters:

  flags | the options for the SRDY interrupt: SRDY_INTERRUPT_FALLING_EDGE or SRDY_INTERRUPT_RISING_EDGE NO_WAKEUP or WAKEUP_AFTER_SRDY

Returns:
  0 if success, -1 if bad flag

void halInit | ( |  | ) |

Configures hardware for the particular hardware platform:

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

void halSetAllPinsToInputs | ( | void |  | ) |

    Configures all module interface signals as inputs to allow the module to be programmed.

Toggles LED0 quickly to indicate application is running.

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.
  On the MDB2 the MSP430 uses USCIB0 SPI port to communicate with the 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.

int16_t initTimer | ( | uint8_t | seconds | ) |

    Configures timer.

Precondition:
  ACLK sourced from VLO
  VLO has been calibrated; number of VLO counts in one second is in vloFrequency.

Parameters:

  seconds | period of the timer. Maximum is 0xFFFF / vloFrequency; or about 4 since VLO varies between 9kHz - 15kHz. Use a prescaler on timer (e.g. set IDx bits in TACTL register) for longer times. Maximum prescaling of Timer A is divide by 8. Even longer times can be obtained by prescaling ACLK if this doesn't affect other system peripherals.

Returns:
  0 if success; -1 if illegal parameter or -2 if VLO not calibrated

void oscInit | ( |  | ) |

Initializes Oscillator: turns off WDT, configures MCLK = 8MHz using internal DCO & sets SMCLK = 4MHz

__interrupt void PORT1_ISR | ( | void |  | ) |

Port 1 interrupt service routine, called when an interrupt-enabled pin on port 1 changes state.

__interrupt void PORT2_ISR | ( | void |  | ) |

Port 2 interrupt service routine, called when an interrupt-enabled pin on port 2 changes state.

int16_t putchar | ( | int16_t | c | ) |

Send one byte via hardware UART. Required for printf() etc. in stdio.h

int16_t setLed | ( | uint8_t | led | ) |

    Turns ON the specified LED.

Parameters:

  led | the LED to turn on, must be 0 or 1.

Postcondition:
  The specified LED is turned on.

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

void spiWrite | ( | uint8_t * | bytes,
|  | uint8_t | numBytes
| ) |  |

Sends a message over SPI to the Module. The Module 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(), spiAreq, etc. To Write, set *bytes and numBytes. To Read, set *bytes only. Don't need to set numBytes because the Module will stop when no more bytes are received.

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.

Precondition:
  SPI port configured for the Module and Module has been initialized properly

Postcondition:
  bytes contains received data, if any

int16_t toggleLed | ( | uint8_t | led | ) |

    Toggles the specified LED.

Parameters:

  led | the LED to toggle, must be 0 or 1.

Postcondition:
  The specified LED is toggled.

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

__interrupt void USCIAB0RX_ISR | ( | void |  | ) |

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

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

void(* srdyIsr)(void)

Function pointer for the ISR called when a SRDY interrupt occurs

void(* timerIsr)(void)

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

uint16_t vloFrequency = 0

    The post-calibrated frequency of the Very Low Oscillator (VLO). This MUST be

calibrated by calibrateVlo() prior to use. Set with calibrateVlo() and read by initTimer().

uint16_t wakeupFlags = 0

    Flags to indicate when to wake up the processor. These are read in the various ISRs.

If the flag is set then the processor will be woken up with HAL_WAKEUP() at the end of the ISR. This is required because HAL_WAKEUP() cannot be called anywhere except in an ISR.