ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
zigbee.h File Reference

Zigbee EZSP / ASH framing codec (PROTOCORE_ENABLE_ZIGBEE) - Silicon Labs NCP. More...

#include "protocore_config.h"

Go to the source code of this file.

Classes

struct  ZigbeeNs
 Dispatch table. Addressed by offset, so the layout is asserted below. More...
 

Macros

#define ASH_FLAG   0x7E
 ASH markers / reset control bytes.
 
#define ASH_ESCAPE   0x7D
 byte-stuffing escape
 
#define ASH_RST   0xC0
 reset control byte
 
#define ASH_RSTACK   0xC1
 reset acknowledge
 
#define ASH_ERROR   0xC2
 error
 

Functions

 PROTOCORE_NS_LAYOUT (ZigbeeNs, ash_crc16, ash_frame_encode, ash_frame_decode)
 
uint16_t protocore_zigbee_ash_crc16 (uint8_t *work, const uint8_t *buf, uint16_t len)
 CRC-16/CCITT (polynomial 0x1021, MSB-first, init 0xFFFF) over buf.
 
uint16_t protocore_zigbee_ash_frame_encode (uint8_t *work, uint8_t control, const uint8_t *payload, uint16_t len, uint8_t *out, uint16_t cap)
 Encode an ASH frame: [control | payload] + CRC-16, byte-stuffed, .
 
int protocore_zigbee_ash_frame_decode (uint8_t *work, const uint8_t *raw, uint16_t len, uint8_t *control, uint8_t *payload, uint16_t pay_cap, uint16_t *pay_len)
 Decode one ASH frame from the front of raw: find the flag, remove .
 

Variables

PROTOCORE_NS ZigbeeNs Zigbee PROTOCORE_UNUSED
 Module namespace.
 

Detailed Description

Zigbee EZSP / ASH framing codec (PROTOCORE_ENABLE_ZIGBEE) - Silicon Labs NCP.

The ASH (Asynchronous Serial Host, UG101) data-link layer that carries EZSP frames to a Silicon Labs EmberZNet network co-processor over UART - a Zigbee network bridged to the web. Each ASH frame is a control byte + payload + a CRC-16/CCITT, byte-stuffed so the reserved control bytes never appear in the body, and terminated by a Flag byte (0x7E):

[control | payload | CRC16(hi,lo)] –byte-stuffed--> ... | 0x7E

The reserved bytes that get stuffed (as 0x7D followed by byte XOR 0x20) are the Flag 0x7E, the Escape 0x7D, XON 0x11, XOFF 0x13, Substitute 0x18, and Cancel 0x1A.

protocore_ash_frame_encode() wraps a control byte + payload into a stuffed, CRC'd, flag-terminated frame; protocore_ash_frame_decode() finds the flag, removes the stuffing, and verifies the CRC. protocore_ash_crc16() is the shared CRC. The EZSP command the payload carries (version query, an incoming APS message, a network-init) is the application's. Pure - you carry the bytes over your UART - so it is fully host-testable.

work is bytes the CALLER holds. This module reads none of them: it carries nothing between calls, so there is no state to keep and nothing to wipe. The parameter is there so a caller drives every namespace the same way.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file zigbee.h.

Macro Definition Documentation

◆ ASH_FLAG

#define ASH_FLAG   0x7E

ASH markers / reset control bytes.

frame delimiter

Definition at line 44 of file zigbee.h.

◆ ASH_ESCAPE

#define ASH_ESCAPE   0x7D

byte-stuffing escape

Definition at line 45 of file zigbee.h.

◆ ASH_RST

#define ASH_RST   0xC0

reset control byte

Definition at line 46 of file zigbee.h.

◆ ASH_RSTACK

#define ASH_RSTACK   0xC1

reset acknowledge

Definition at line 47 of file zigbee.h.

◆ ASH_ERROR

#define ASH_ERROR   0xC2

error

Definition at line 48 of file zigbee.h.

Function Documentation

◆ PROTOCORE_NS_LAYOUT()

PROTOCORE_NS_LAYOUT ( ZigbeeNs  ,
ash_crc16  ,
ash_frame_encode  ,
ash_frame_decode   
)

◆ protocore_zigbee_ash_crc16()

uint16_t protocore_zigbee_ash_crc16 ( uint8_t *  work,
const uint8_t *  buf,
uint16_t  len 
)

CRC-16/CCITT (polynomial 0x1021, MSB-first, init 0xFFFF) over buf.

Parameters
workPROTOCORE_ZIGBEE_BORROW bytes the caller took. Not held past the call.
bufBuf
lenLen
Returns
The uint16_t.

◆ protocore_zigbee_ash_frame_encode()

uint16_t protocore_zigbee_ash_frame_encode ( uint8_t *  work,
uint8_t  control,
const uint8_t *  payload,
uint16_t  len,
uint8_t *  out,
uint16_t  cap 
)

Encode an ASH frame: [control | payload] + CRC-16, byte-stuffed, .

Parameters
workPROTOCORE_ZIGBEE_BORROW bytes the caller took. Not held past the call.
controlControl
payloadPayload
lenLen
outOut
capCap
Returns
The uint16_t.

◆ protocore_zigbee_ash_frame_decode()

int protocore_zigbee_ash_frame_decode ( uint8_t *  work,
const uint8_t *  raw,
uint16_t  len,
uint8_t *  control,
uint8_t *  payload,
uint16_t  pay_cap,
uint16_t *  pay_len 
)

Decode one ASH frame from the front of raw: find the flag, remove .

Parameters
workPROTOCORE_ZIGBEE_BORROW bytes the caller took. Not held past the call.
rawRaw
lenLen
controlControl
payloadPayload
pay_capPay cap
pay_lenPay len
Returns
The int.

Variable Documentation

◆ PROTOCORE_UNUSED

PROTOCORE_NS ZigbeeNs Zigbee PROTOCORE_UNUSED
Initial value:
.ash_frame_encode = protocore_zigbee_ash_frame_encode,
.ash_frame_decode = protocore_zigbee_ash_frame_decode}
uint16_t protocore_zigbee_ash_crc16(uint8_t *work, const uint8_t *buf, uint16_t len)
CRC-16/CCITT (polynomial 0x1021, MSB-first, init 0xFFFF) over buf.
uint16_t protocore_zigbee_ash_frame_encode(uint8_t *work, uint8_t control, const uint8_t *payload, uint16_t len, uint8_t *out, uint16_t cap)
Encode an ASH frame: [control | payload] + CRC-16, byte-stuffed, .
int protocore_zigbee_ash_frame_decode(uint8_t *work, const uint8_t *raw, uint16_t len, uint8_t *control, uint8_t *payload, uint16_t pay_cap, uint16_t *pay_len)
Decode one ASH frame from the front of raw: find the flag, remove .

Module namespace.

Definition at line 94 of file zigbee.h.