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
zm_phy_uart.h File Reference

public methods for zm_phy_uart.c More...

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

## Macros
#define | ZIGBEE_MODULE_BUFFER_SIZE 0xFF
#define | UART_START_OF_FRAME 0xFE
#define | MESSAGE_BUFFER_IN_USE 0x01
#define | MESSAGE_BUFFER_SIZE 0xFF
#define | UART_MESSAGE_LENGTH_FIELD 0
#define | MINIMUM_MESSAGE_SIZE 4
#define | MESSAGE_OVERHEAD 3
#define | SRSP_BUFFER_SIZE 20
#define | SRSP_HEADER_SIZE 3
#define | SRSP_OFFSET 0x40
#define | SRSP_PAYLOAD_START 3
#define | SRSP_LENGTH_FIELD 0
#define | SRSP_CMD_LSB_FIELD 2
#define | SRSP_CMD_MSB_FIELD 1

## Functions
moduleResult_t | sendMessage ()
moduleResult_t | receiveAreq (uint8_t intervalMs, int16_t timeoutMs)
moduleResult_t | getMessage ()
void | displayMessageBuffer ()
void | auxSerialPortHandler (char c)
void | zm_phy_init ()
uint8_t | moduleHasMessageWaiting ()

## Detailed Description

public methods for zm_phy_uart.c

Rev:
  1528

Author:
  dsmith

Date:
  2012-08-30 15:58:08 -0700 (Thu, 30 Aug 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.

## Macro Definition Documentation

#define ZIGBEE_MODULE_BUFFER_SIZE 0xFF

The size of the Zigbee Buffer. This is used for both send and receive

## Function Documentation

void auxSerialPortHandler | ( | char | c | ) |

Processes bytes received from the Module. Should be called in the serial port ISR for the module serial port. For example:

    #pragma vector=USCIAB1RX_VECTOR
    __interrupt void USCI1RX_ISR(void)
    {
      if (UC1IFG & UCA1RXIFG)
      {
        auxSerialPort(UCA1RXBUF);    //reading this register clears the interrupt flag
      }
    }

Message processing is handled according to a simple state machine. If a message has already started, then append bytes to messageBuffer. When a byte is received:

1. Assert RTS so that the module doesn't send another byte while we're processing this one
2. Set messageFlags.MESSAGE_BUFFER_IN_USE. This is a simple mutex to control access to messageBufferIndex, messageBuffer, and fcs to prevent concurrency issues
3. Process received byte based on the state of messageBufferState
4. Clear messageFlags.MESSAGE_BUFFER_IN_USE mutex
5. Deassert RTS to allow more bytes to be received
   Parameters:

     c | the byte that was received in the ISR.

void displayMessageBuffer | ( |  | ) |

Displays the contents of the messageBuffer. Locks the messageBuffer while reading to prevent a concurrency problem.

Note:
  If you have sufficient memory and the printf is slow then it would be better to copy messageBuffer to a new buffer and then printf that. Or use a circular buffer on the debug UART.

moduleResult_t getMessage | ( |  | ) |

Polls the Module for data. This is used to receive data from the Module, for example when a message has arrived. This will be initiated by detecting SRDY going low.

Precondition:
  Module has been initialized.
  SRDY has gone low

Postcondition:
  received data is written to zmBuf

Note:
  this method not required to be implemented when using UART interface.

Get a message that is in messageBuffer and copy to zmBuf for further processing.

Precondition:
  moduleHasMessageWaiting() is true

Postcondition:
  zmBuf holds the message that was in messageBuffer

uint8_t moduleHasMessageWaiting | ( |  | ) |

Whether the module has a message waiting to be retrieved.

Returns:
  true (1) if there is a complete message ready for processing, or 0 otherwise.

Indicates whether the module has a message ready to be processed.

Returns:
  true (1) if there is a complete message in messageBuffer ready for processing, or 0 otherwise.

moduleResult_t receiveAreq | ( | uint8_t | intervalMs,
|  | int16_t | timeoutMs
| ) |  |

    Wait to receive an asynchronous message. Similar to spiPoll() but with wait.

Parameters:

  intervalMs | how often to check that we received the message.
  timeoutMs | how long to wait, total, for the message

Returns:
  MODULE_SUCCESS if message received before timeoutMs or else ZM_PHY_SRSP_TIMEOUT if no message was received before timeout.

Postcondition:
  received data is written to zmBuf and messageBuffer is reset

moduleResult_t sendMessage | ( |  | ) |

    Public method to send messages to the Module. This will send one message and then receive the

Synchronous Response (SRSP) message from the Module to indicate the command was received.

Precondition:
  zmBuf contains a properly formatted message
  Module has been initialized

Postcondition:
  buffer zmBuf contains the response (if any) from the Module.

Public method to send messages to the Module. This will send one message and then receive the Synchronous Response (SRSP) message from the Module to indicate the command was received.

Precondition:
  zmBuf contains a properly formatted message
  Module has been initialized

Postcondition:
  buffer zmBuf contains the response (if any) from the Module.