Digi XBee(R) ANSI C Host Library
bl_gen3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Digi International Inc.,
3  * All rights not expressly granted are reserved.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
7  * You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * Digi International Inc., 9350 Excelsior Blvd., Suite 700, Hopkins, MN 55343
10  * ===========================================================================
11  */
12 
22 #ifndef XBEE_BL_GEN3_H
23 #define XBEE_BL_GEN3_H
24 
25 #include "xbee/device.h"
26 #include "wpan/types.h"
27 
29 
30 typedef enum xbee_gen3_state {
31  XBEE_GEN3_STATE_INIT, // hold TX in break
32  XBEE_GEN3_STATE_ENTER_BOOTLOADER, // wait for bootloader (drops CTS)
33  XBEE_GEN3_STATE_GET_BL_VERSION, // wait until bootloader ready, send 'B'
34  XBEE_GEN3_STATE_BL_VERSION, // parse 'B' response, send 'L'
35  XBEE_GEN3_STATE_BL_PROTOCOL, // parse 'L' response, send 'R'/'X'
36  XBEE_GEN3_STATE_BAUD_RATE, // parse 'R'/'X', change baud, send 'V'
37  XBEE_GEN3_STATE_EXT_VERSION, // parse 'V' response, send 'I'
38  XBEE_GEN3_STATE_START_TRANSFER, // parse 'I' response, start transfer
39  XBEE_GEN3_STATE_SEND_PAGE, // send the current page
40  XBEE_GEN3_STATE_LOAD_PAGE, // on success, load next page or verify
41  XBEE_GEN3_STATE_VERIFY, // wait for response to 'C'
42 
43  XBEE_GEN3_STATE_SUCCESS,
44  XBEE_GEN3_STATE_FAILURE
45 } xbee_gen3_state_t;
46 
47 #define XBEE_GEN3_UPLOAD_PAGE_SIZE 512
48 
49 // Response to a XBEE_GEN3_CMD_EXTENDED_VER command.
50 typedef XBEE_PACKED(xbee_gen3_extended_ver_t, {
51  uint16_t hw_version_le; // ATHV
52  uint16_t hw_revision_le; // AT%R
53  uint8_t hw_compatibility; // AT%C
54  uint8_t unused;
55  uint16_t hw_series_le; // ATHS
56  addr64 mac_address_be;
57  uint8_t end_of_response; // always 'U'
59 
60 void xbee_gen3_dump_extended_ver(const xbee_gen3_extended_ver_t *ver);
61 
62 typedef struct xbee_gen3_update_t {
63  uint32_t timer;
64  xbee_gen3_state_t state;
65  xbee_gen3_state_t next_state;
66  uint16_t flags;
67 #define XBEE_GEN3_BL_FLAG_RETRY_MASK (0xFF)
68 #define XBEE_GEN3_BL_FLAG_QUERY_ONLY (1<<8)
69 #define XBEE_GEN3_BL_FLAG_PROTO1 (1<<9)
70 #define XBEE_GEN3_BL_FLAG_EOF (1<<10)
71 
74 
78 
80 
81  xbee_dev_t *xbee;
82 
84  char buffer[XBEE_GEN3_UPLOAD_PAGE_SIZE];
85 
89  int (*read)(void *context, void *buffer, int16_t bytes);
90 
92  void *context;
94 
95 #define XBEE_GEN3_FW_LOAD_TIMEOUT_MS 10000
96 
127 
140 
164 
166 #define XBEE_GEN3_STATUS_BUF_SIZE 60
167 
183 
185 
186 #endif // XBEE_BL_GEN3_H
187 
unsigned long uint32_t
32-bit unsigned integer
Definition: platform_config.h:43
Definition: bl_gen3.h:62
WPAN datatypes and support functions, valid for ZigBee and DigiMesh.
const char * xbee_bl_gen3_install_status(xbee_gen3_update_t *source, char buffer[XBEE_GEN3_STATUS_BUF_SIZE])
Return a string describing the current state of the firmware update.
Definition: xbee_bl_gen3.c:493
#define XBEE_BEGIN_DECLS
Macro defined to.
Definition: platform.h:41
uint16_t xbee_bl_gen3_install_state(xbee_gen3_update_t *source)
Return a unique value identifying the install state.
Definition: xbee_bl_gen3.c:112
uint16_t bl_version
parsed response from &#39;B&#39; cmd
Definition: bl_gen3.h:72
int16_t page_offset
Current offset into buffer (0 - <n-1>); -1 if sending page header; <n> if sending checksum/CRC16 (whe...
Definition: bl_gen3.h:77
int xbee_bl_gen3_install_init(xbee_dev_t *xbee, xbee_gen3_update_t *source)
Prepare to install new firmware on an attached XBee module.
Definition: xbee_bl_gen3.c:96
uint16_t page_num
page we&#39;re sending to BL
Definition: bl_gen3.h:73
unsigned short uint16_t
16-bit unsigned integer
Definition: platform_config.h:41
xbee_gen3_extended_ver_t ext_ver
parsed response from &#39;V&#39; cmd
Definition: bl_gen3.h:79
unsigned char uint8_t
8-bit unsigned integer
Definition: platform_config.h:39
int xbee_bl_gen3_install_tick(xbee_gen3_update_t *source)
Install the firmware image stored in source.
Definition: xbee_bl_gen3.c:225
int(* read)(void *context, void *buffer, int16_t bytes)
Function to read firmware image contents.
Definition: bl_gen3.h:89
char buffer[XBEE_GEN3_UPLOAD_PAGE_SIZE]
buffer for upload page, must persist for duration of update
Definition: bl_gen3.h:84
short int16_t
16-bit signed integer
Definition: platform_config.h:40
Typedef used to hold a 64-bit IEEE address, represented as 8 bytes, 4 16-bit values or 2 32-bit value...
Definition: types.h:34
Definition: device.h:361
#define XBEE_END_DECLS
Macro defined to.
Definition: platform.h:42
Definition: bl_gen3.h:58
void * context
context passed to .read() function
Definition: bl_gen3.h:92
#define XBEE_GEN3_STATUS_BUF_SIZE
Minimum size of buffer passed to xbee_bl_gen3_install_status()
Definition: bl_gen3.h:166