Ash#

Use the Asynchronous Serial Host (ASH) Framework interfaces on a host microcontroller when it communicates with an Ember chip via EZSP-UART.

See ash-protocol.h for source code.

See ash-common.h for source code.

Variables#

bool

set false to start decoding a new frame

uint16_t

rec'd ack timer (msecs)

uint16_t

rec'd ack timer period (msecs)

uint8_t

not ready timer (16 msec units)

Functions#

uint8_t
ashEncodeByte(uint8_t len, uint8_t byte, uint8_t *offset)

Builds an ASH frame.

sl_zigbee_ezsp_status_t
ashDecodeByte(uint8_t byte, uint8_t *out, uint8_t *outLen)

Decodes and validates an ASH frame.

uint8_t
ashRandomizeArray(uint8_t seed, uint8_t *buf, uint8_t len)

Randomizes array contents by XORing with an 8-bit pseudo random sequence.

void

Sets ashAckTimer to the specified period and starts it running.

bool

Indicates whether or not ashAckTimer has expired.

void
ashAdjustAckPeriod(bool expired)

Adapts the acknowledgement timer period to the observed ACK delay.

void

Starts the Not Ready timer.

bool

Tests whether the Not Ready timer has expired or has stopped.

Macros#

#define
ashStopAckTimer (void)

Stops and clears ashAckTimer.

#define
ashAckTimerIsRunning ()

Indicates whether or not ashAckTimer is currently running.

#define
ashAckTimerIsNotRunning ()

Indicates whether or not ashAckTimer is currently running.

#define
ashSetAckPeriod (msec)

Sets the acknowledgement timer period (in msec) and stops the timer.

#define
ashGetAckPeriod ()

Returns the acknowledgement timer period (in msec).

#define
ashSetAndStartAckTimer (msec)

Sets the acknowledgement timer period (in msec), and starts the timer running.

#define
ASH_NR_TIMER_BIT 4

log2 of msecs per NR timer unit

#define
ashStopNrTimer ()

Stops the Not Ready timer.

#define
ashNrTimerIsNotRunning ()

Indicates whether or not ashNrTimer is currently running.

#define
ASH_VERSION 2

protocol version

#define
ASH_FLAG 0x7E

frame delimiter

#define
ASH_ESC 0x7D

byte stuffing escape byte

#define
ASH_XON 0x11

flow control byte - means resume transmission

#define
ASH_XOFF 0x13

flow control byte - means suspend transmission

#define
ASH_SUB 0x18

replaces bytes w framing, overrun or overflow errors

#define
ASH_CAN 0x1A

frame cancel byte

#define
ASH_WAKE 0xFF

wake signal byte (also means NCP data pending)

#define
ASH_FLIP 0x20

XOR mask used in byte stuffing.

#define
ASH_MIN_DATA_FIELD_LEN EZSP_MIN_FRAME_LENGTH

ash min data field len

#define
ASH_MAX_DATA_FIELD_LEN EZSP_MAX_FRAME_LENGTH

ash max data field len

#define
ASH_MIN_DATA_FRAME_LEN (ASH_MIN_DATA_FIELD_LEN + 1)

with control

#define
ASH_MIN_FRAME_LEN 1

control plus data field, but not CRC

#define
ASH_MAX_FRAME_LEN (ASH_MAX_DATA_FIELD_LEN + 1)

ash max frame len

#define
ASH_CRC_LEN 2

ash crc len

#define
ASH_MIN_FRAME_WITH_CRC_LEN (ASH_MIN_FRAME_LEN + ASH_CRC_LEN)

ash min frame with crc len

#define
ASH_MAX_FRAME_WITH_CRC_LEN (ASH_MAX_FRAME_LEN + ASH_CRC_LEN)

ash max frame with crc len

#define
ASH_NCP_SHFRAME_RX_LEN 2

longest non-data frame received

#define
ASH_NCP_SHFRAME_TX_LEN 3

longest non-data frame sent

#define
ASH_HOST_SHFRAME_RX_LEN 3

longest non-data frame received

#define
ASH_HOST_SHFRAME_TX_LEN 2

longest non-data frame sent

#define
ASH_DFRAME_MASK 0x80

ash dframe mask

#define
ASH_CONTROL_DATA 0x00

ash control data

#define
ASH_SHFRAME_MASK 0xE0

ash shframe mask

#define
ASH_CONTROL_ACK 0x80

ash control ack

#define
ASH_CONTROL_NAK 0xA0

ash control nak

#define
ASH_CONTROL_RST 0xC0

ash control rst

#define
ASH_CONTROL_RSTACK 0xC1

ash control rstack

#define
ASH_CONTROL_ERROR 0xC2

ash control error

#define
ASH_ACKNUM_MASK 0x07

acknowledge frame number

#define
ASH_ACKNUM_BIT 0

ash acknum bit

#define
ASH_RFLAG_MASK 0x08

retransmitted frame flag

#define
ASH_RFLAG_BIT 3

ash rflag bit

#define
ASH_NFLAG_MASK 0x08

receiver not ready flag

#define
ASH_NFLAG_BIT 3

ash nflag bit

#define
ASH_PFLAG_MASK 0x10

flag reserved for future use

#define
ASH_PFLAG_BIT 4

ash pflag bit

#define
ASH_FRMNUM_MASK 0x70

DATA frame number.

#define
ASH_FRMNUM_BIT 4

ash frmnum bit

#define
ASH_GET_RFLAG (ctl)

ash get rflag(ctl)

#define
ASH_GET_NFLAG (ctl)

ash get nflag(ctl)

#define
ASH_GET_FRMNUM (ctl)

ash get frmnum(ctl)

#define
ASH_GET_ACKNUM (ctl)

ash get acknum(ctl)

#define
ASH_FRAME_LEN_DATA_MIN (ASH_MIN_DATA_FIELD_LEN + 1)

ash frame len data min

#define
ASH_FRAME_LEN_ACK 1

control

#define
ASH_FRAME_LEN_NAK 1

control

#define
ASH_FRAME_LEN_RST 1

control

#define
ASH_FRAME_LEN_RSTACK 3

control, version, reset reason

#define
ASH_FRAME_LEN_ERROR 3

control, version, error

#define
MOD8 (n)

mask to frame number modulus

#define
INC8 (n)

increment in frame number modulus

#define
WITHIN_RANGE (lo, n, hi)

within range lo and hi

Variable Documentation#

ashDecodeInProgress#

bool ashDecodeInProgress

set false to start decoding a new frame


ashAckTimer#

uint16_t ashAckTimer

rec'd ack timer (msecs)


ashAckPeriod#

uint16_t ashAckPeriod

rec'd ack timer period (msecs)


ashNrTimer#

uint8_t ashNrTimer

not ready timer (16 msec units)


Function Documentation#

ashEncodeByte#

uint8_t ashEncodeByte (uint8_t len, uint8_t byte, uint8_t * offset)

Builds an ASH frame.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Alen

new frame flag / length of the frame to be encoded. A non-zero value begins a new frame, so all subsequent calls must use zero. The length includes control byte and data field, but not the flag or crc. This function does not validate the length.

uint8_tN/Abyte

the next byte of data to add to the frame. Note that in general the same byte of data may have to be passed more than once as escape bytes, the CRC and the end flag byte are output.

uint8_t *N/Aoffset

pointer to the offset of the next input byte. (If the frame data is the array data[], the next byte would be data[offset].) Is set to 0 when starting a new frame (ie, len is non-zero). Is set to 0xFF when the last byte of the frame is returned.

Byte stuffs the control and data fields as required, computes and appends the CRC and adds the ending flag byte. Called with the next byte to encode, this function may return several output bytes before it's ready for the next byte.

Returns

  • next encoded output byte in frame.


ashDecodeByte#

sl_zigbee_ezsp_status_t ashDecodeByte (uint8_t byte, uint8_t * out, uint8_t * outLen)

Decodes and validates an ASH frame.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Abyte

the next byte of data to add to the frame

uint8_t *N/Aout

pointer to where to write an output byte

uint8_t *N/AoutLen

number of bytes output so far

Data is passed to it one byte at a time. Decodes byte stuffing, checks crc, finds the end flag and (if enabled) terminates the frame early on CAN or SUB bytes. The number of bytes output will not exceed the max valid frame length, which does not include the flag or the crc.

Returns

  • status of frame decoding

    • ::SL_ZIGBEE_EZSP_SUCCESS

    • ::SL_ZIGBEE_EZSP_ASH_IN_PROGRESS

    • ::SL_ZIGBEE_EZSP_ASH_CANCELLED

    • ::SL_ZIGBEE_EZSP_ASH_BAD_CRC

    • ::SL_ZIGBEE_EZSP_ASH_COMM_ERROR

    • ::SL_ZIGBEE_EZSP_ASH_TOO_SHORT

    • ::SL_ZIGBEE_EZSP_ASH_TOO_LONG


ashRandomizeArray#

uint8_t ashRandomizeArray (uint8_t seed, uint8_t * buf, uint8_t len)

Randomizes array contents by XORing with an 8-bit pseudo random sequence.

Parameters
TypeDirectionArgument NameDescription
uint8_tN/Aseed

zero initializes the random sequence a non-zero value continues from a previous invocation

uint8_t *N/Abuf

pointer to the array whose contents will be randomized

uint8_tN/Alen

number of bytes in the array to modify

This reduces the likelihood that byte-stuffing will greatly increase the size of the payload. (This could happen if a DATA frame contained repeated instances of the same reserved byte value.)

Returns

  • last value of the sequence. If a buffer is processed in two or more chunks, as with linked buffers, this value should be passed back as the value of the seed argument


ashStartAckTimer#

void ashStartAckTimer (void )

Sets ashAckTimer to the specified period and starts it running.

Parameters
TypeDirectionArgument NameDescription
voidN/A

ashAckTimerHasExpired#

bool ashAckTimerHasExpired (void )

Indicates whether or not ashAckTimer has expired.

Parameters
TypeDirectionArgument NameDescription
voidN/A

If the timer is stopped then it is not expired.

Returns

  • bool


ashAdjustAckPeriod#

void ashAdjustAckPeriod (bool expired)

Adapts the acknowledgement timer period to the observed ACK delay.

Parameters
TypeDirectionArgument NameDescription
boolN/Aexpired

true if timer has expired

If the timer is not running, it does nothing. If the timer has expired, the timeourt period is doubled. If the timer has not expired, the elapsed time is fed into simple IIR filter: T[n+1] = (7*T[n] + elapsedTime) / 8 The timeout period, ashAckPeriod, is limited such that: ASH_xxx_TIME_DATA_MIN <= ashAckPeriod <= ASH_xxx_TIME_DATA_MAX, where xxx is either HOST or NCP.

The acknowledgement timer is always stopped by this function.


ashStartNrTimer#

void ashStartNrTimer (void )

Starts the Not Ready timer.

Parameters
TypeDirectionArgument NameDescription
voidN/A

On the host, this times nFlag refreshing when the host doesn't have room for callbacks for a prolonged period.

On the NCP, if this times out the NCP resumes sending callbacks.


ashNrTimerHasExpired#

bool ashNrTimerHasExpired (void )

Tests whether the Not Ready timer has expired or has stopped.

Parameters
TypeDirectionArgument NameDescription
voidN/A

If expired, it is stopped.

Returns

  • true if the Not Ready timer has expired or stopped