Files
kunlun/app/grapp/iot_flashinfo.h
2024-09-28 14:24:04 +08:00

242 lines
7.7 KiB
C
Executable File

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef _GE_AT_FLASHINFO_H_
#define _GE_AT_FLASHINFO_H_
#include "iot_plctxrx.h"
#include "iot_pib_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ****************************************** */
/* The custom flash control from addr:0x0 */
/* ****************************************** */
#define APP_FLASH_START_ADDR 0x0
/* ****************************************** */
/* The custom flash block size is 4k */
/* ****************************************** */
#define PRODUCT_CFG_FLASH_BLOCK_SIZE 0x1000
#define IOT_PROTO_CUST_FLASHINFO_MAGIC1 0xAA55AA55
#define IOT_PROTO_CUST_FLASHINFO_MAGIC2 0x55AA55AA
#if PLC_SUPPORT_CCO_ROLE
#define IOT_APP_PUBLIC_SIZE (IOT_PIB_CCO_APP_WRITE_SECTION_SIZE - \
278)
#else
#define IOT_APP_PUBLIC_SIZE (IOT_PIB_STA_APP_WRITE_SECTION_SIZE - \
278) /* bytes */
#endif
#define IOT_APP_AT_PRIVATE_SIZE (20) /* bytes */
#define IOT_APP_PROTO_PRIVATE_SIZE (250) /* bytes */
#define IOT_PROTO_CUST_APP_FLASH_SIZE (240)
#define IOT_MAGIC_SIZE (4)
#define IOT_DEV_TEST_FLASH_START_OFFSET (APP_FLASH_START_ADDR + \
PRODUCT_CFG_FLASH_BLOCK_SIZE)
/*
* CCO app pib flash layout shows like below, total 7416bytes
* |-------------------|
* | magic1 | 4 bytes
* |-------------------|
* | public | 7318 + 8192bytes
* |-------------------|
* | AT private | 20 bytes
* |-------------------|
* | PROTO private | 250 bytes
* |-------------------|
* | magic2 | 4 bytes
* |-------------------|
*
*-----------------------------------------------------------------------------
* STA app pib flash layout shows like below total 312bytes
* |-------------------|
* | magic1 | 4 bytes
* |-------------------|
* | public | 34 bytes
* |-------------------|
* | AT private | 20 bytes
* |-------------------|
* | PROTO private | 250 bytes
* |-------------------|
* | magic2 | 4 bytes
* |-------------------|
*/
typedef struct _proto_dev_t {
/* IP of this device. */
uint8_t ip;
/* Role of this device as indoor
* outdoor or linectrl and so on
*/
uint8_t dev_role;
/* Mac address of this device. */
uint8_t mac[IOT_MAC_ADDR_LEN];
} proto_dev_t;
typedef struct _at_transparent_t
{
/* transparent mode flag */
bool_t transpmode;
/* transparent address */
uint8_t trans_addr[IOT_MAC_ADDR_LEN];
}at_transparent_t;
#pragma pack(push) // save the pack status
#pragma pack(1) // 1 byte align
/* define informations need saved into flash (customer flash) */
/* usage: 1. when bootup, load flash and read into protocontext. remeber do
magic check.
2. when mcu or monitor tool change dev_tbl or pair_tbl, once change
done(indicated by done bit), save it to flash. also, need broadcast
by plc data path as indication.
3. when generated by start_net_group or start pair, once end_net_group
or end pair, save it to flash also.
4. when bootup, dev should send mac and passd apply to mcu. when mcu
response, proto should compare mac to detec, whether plc moudle
plug into different mcu board.
*/
typedef struct _custom_flash_info_t {
/* 0xAA55AA55, the head of this struct */
uint8_t magic1[IOT_MAGIC_SIZE];
/* self mac addr */
uint8_t local_mac[IOT_MAC_ADDR_LEN];
/* self dev role */
uint8_t local_type;
/* network cco mac */
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
/* network magic id */
uint8_t local_passd[GREE_PASSWD_LENGTH];
/* wl tbl num */
uint8_t dev_cnt;
/* pair tbl num */
uint8_t pair_cnt;
/* uart baud index */
uint8_t baudidx;
/* whitelist state */
uint8_t wl_state;
/* wl tbl */
proto_dev_t dev_tbl[STA_DEV_MAX];
/* transparent info */
at_transparent_t transp;
/* 0x55AA55AA, the tail of this struct */
uint8_t magic2[IOT_MAGIC_SIZE];
} custom_flash_info_t;
/* GE app layer CCO role writable section layout in PIB */
typedef struct _iot_proto_ge_cco_app_pib_rw {
uint8_t drv[IOT_PIB_CCO_APP_WRITE_SECTION_SIZE];
} iot_proto_ge_cco_app_pib_rw_t;
/* GE app layer STA role writable section layout in PIB */
typedef struct _iot_proto_ge_sta_app_pib_rw {
/* driver specific persistent storage */
uint8_t drv[IOT_PIB_STA_APP_WRITE_SECTION_SIZE];
} iot_proto_ge_sta_app_pib_rw_t;
#if PLC_SUPPORT_CCO_ROLE
typedef iot_proto_ge_cco_app_pib_rw_t app_pib_rw_t;
#else
typedef iot_proto_ge_sta_app_pib_rw_t app_pib_rw_t;
#endif
typedef struct _public_use_t {
/* self mac addr */
uint8_t local_mac[IOT_MAC_ADDR_LEN];
/* self dev role */
uint8_t local_type;
/* network cco mac */
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
/* uart baud index */
uint8_t baudidx;
/* whitelist state */
uint8_t wl_state;
#if PLC_SUPPORT_CCO_ROLE
/* wl tbl num */
uint16_t dev_cnt;
/* wl tbl */
proto_dev_t dev_tbl[STA_DEV_MAX];
#endif
/**
* bitmap defined as follow:
* bit0 == 1: support band 0
* bit1 == 1: support band 1
* ...
* bit15 == 1: support band 15
*/
uint16_t fb_bitmap;
/* to record trial run pass flag */
uint8_t trial_run_pass;
/* uart parity bit value */
uint8_t parity;
/* uart data bit value */
uint8_t data;
/* uart stop bit value */
uint8_t stop;
/* delay time for starting polling */
uint16_t edge_start_tm;
} public_use_t;
/* at private save pib information */
typedef struct _at_private_use_t {
/* transparent info */
at_transparent_t transp;
} at_private_use_t;
/* proto private save pib information */
typedef struct _proto_private_use_t {
/* custom app save pib info */
uint8_t custom_pib_info[IOT_PROTO_CUST_APP_FLASH_SIZE];
} proto_private_use_t;
typedef struct _ge_app_pib_info_t {
/* 0xAA55AA55, the head of this struct */
uint8_t magic1[IOT_MAGIC_SIZE];
/* public save pib flash information */
union {
public_use_t pub;
uint8_t resv[IOT_APP_PUBLIC_SIZE];
} public;
/* at private save pib flash information */
union {
at_private_use_t at;
uint8_t resv[IOT_APP_AT_PRIVATE_SIZE];
} at_prv;
/* proto private save pib flash information */
union {
proto_private_use_t proto;
uint8_t resv[IOT_APP_PROTO_PRIVATE_SIZE];
} proto_prv;
/* 0x55AA55AA, the tail of this struct */
uint8_t magic2[IOT_MAGIC_SIZE];
} ge_app_pib_info_t;
#pragma pack(pop)
#ifdef __cplusplus
}
#endif
#endif