初始提交

This commit is contained in:
2024-09-28 14:24:04 +08:00
commit c756587541
5564 changed files with 2413077 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
/****************************************************************************
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 IOT_ADDR_HASH_TABLE_H
#define IOT_ADDR_HASH_TABLE_H
/* export includes */
#include "iot_addr_hash_table_api.h"
/* common includes */
#include "iot_utils.h"
#ifdef __cplusplus
extern "C" {
#endif
/* exponent of max table size */
#define IOT_ADDR_HASH_TABLE_SIZE_MAX 10
/* iot mac address hash table */
typedef struct _iot_addr_hash_table {
/* number of entries supported */
uint16_t entry_cnt;
/* size of each entry */
uint16_t entry_size;
/* hash table size. The larger the table, the smaller the possibilty to
* hit hash key conflict.
*/
uint16_t table_size;
/* extern address entry flag */
uint8_t meter_flag;
/* entry point for each mac address hash index */
iot_addr_hash_entry_t **hash_ent;
/* entry pool */
iot_mem_pool_t *entry_p;
} iot_addr_hash_table_t;
#ifdef __cplusplus
}
#endif
#endif /* IOT_ADDR_HASH_TABLE_H */

36
inc/utils/iot_bitops.h Normal file
View File

@@ -0,0 +1,36 @@
/****************************************************************************
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 IOT_BITOPS_H
#define IOT_BITOPS_H
/* export includes */
#include "iot_bitops_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief iot_bitops_init() - init the bitops feature
*/
void iot_bitops_init();
#ifdef __cplusplus
}
#endif
#endif /* IOT_BITOPS_H */

30
inc/utils/iot_crc.h Normal file
View File

@@ -0,0 +1,30 @@
/****************************************************************************
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 IOT_CRC_H
#define IOT_CRC_H
#include "os_types.h"
#include "iot_crc_api.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif // !IOT_CRC_H

View File

@@ -0,0 +1,31 @@
/****************************************************************************
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 IOT_FRAME_PARSE_H
#define IOT_FRAME_PARSE_H
/* export includes */
#include "iot_frame_parse_api.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif // IOT_FRAME_PARSE_H

472
inc/utils/iot_img_hdr.h Normal file
View File

@@ -0,0 +1,472 @@
/****************************************************************************
*
* Copyright(c) 2019 by Aerospace C.Power-tech Technologies. 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 IOT_IMG_HDR_H
#define IOT_IMG_HDR_H
#ifdef __cplusplus
extern "C" {
#endif
/* pack for the structures in the whole file */
#pragma pack(push) /* save the pack status */
#pragma pack(1) /* 1 byte align */
typedef enum
{
devKunlun = 0xDC01, /* KL1/KL2 */
devKunlun2 = 0xDC02, /* KL2 */
devKunlun3 = 0xDC03, /* KL3 */
devMAX = 0xFFFF
}dvcType;
typedef enum
{
imgROM = 0x0000, /* Maybe,ROM doesn't need a imgType */
imgSP = 0xFC00, /* sp */
imgSBL = 0xFC01, /* sbl */
imgFRW = 0xFC02, /* kl1: 1MB fw, uncompressed for sta, run in flash; compressed for cco, run in psram */
imgCFG = 0xFC03, /* The first pib file. */
imgEFUSE = 0xFC04, /* efuse */
imgOEM = 0xFC05, /* oem */
imgFRW2 = 0xFC06, /* The second fw, maybe the backup one. not used. */
imgCFG2 = 0xFC07, /* The second pib file. */
imgCFRW1 = 0xFC08, /* kl1: 2MB fw, compressed for sta or cco, run in flash; kl2: 4M flash fw */
imgCFRW2 = 0xFC09, /* The second fw, maybe the backup one. not used. */
imgCFRW = 0xFC0A, /* kl1: 2MB fw, compressed for sta or cco, run in psram; kl2: 4M psram fw */
imgREF = 0xFC0B, /* ref */
imgCUS = 0xFC0C, /* cus */
imgCFRW4F = 0xFC0D, /* kl1: 4MB fw, compressed for sta or cco, run in flash */
imgCFRW4P = 0xFC0E, /* kl1: 4MB fw, compressed for sta or cco, run in psram */
imgMAX = 0xFFFF, /* invalid */
}imgType;
typedef enum
{
devV1Kunlun = 0x01, /* KL1/KL2 */
devV1Kunlun2= 0x02, /* KL2 */
devV1Kunlun3= 0x03, /* KL3 */
devV1MAX = 0xFF
}dvcTypeV1;
typedef enum
{
imgV1ROM = 0x00, /* Maybe,ROM doesn't need a imgType */
imgV1SBL = 0x01, /* sbl */
imgV1FRWPLC = 0x02, /* FW-PLC */
imgV1CFG = 0x03, /* The first pib file. */
imgV1OEM = 0x05, /* oem */
imgV1FRWCUS = 0x06, /* FW-CUS */
imgV1MAX = 0xFF /* invalid */
}imgTypeV1;
typedef enum
{
encType_none = 0x00,
encType_aa = 0xAA,
encType_99 = 0x99,
}encType;
typedef enum
{
zipType_none = 0x00, /* Uncompressed file. */
zipType_defult = 0x01, /* Compressed with lzma, level-0. */
zipType_max = 0xFF
}zipType;
typedef enum
{
sizeType_0MB = 0x00,
sizeType_1MB = 0x01,
sizeType_2MB = 0x02,
sizeType_4MB = 0x04,
sizeType_8MB = 0x08,
sizeType_max = 0xFF
}sizeType;
typedef enum
{
hdrVer_00 = 0x00, /* V0.0, first edition */
hdrVer_01 = 0x01, /* V0.1, be from v0.0, enable 4m flash module, kl1 kl2 used it */
hdrVer_02 = 0x02, /* V0.2, be from V0.1, offset->layout index + resv[3], kl1 kl2 */
hdrVer_10 = 0x10, /* V1.0, enable kl3, kl3 used it */
hdrVer_max = 0xFF
}hdrVersion;
#define IOT_MAGIC_NO 0x5566
#define IOT_XOR_VALUE 0xAA
#define IOT_XOR_VALUE_FLX 0x99
#define IOT_XOR_VALUE_QJ 0x66
#define IOT_XOR_VALUE_SPE 0xCC
#define IOT_XOR_VALUE_GX 0x33
#define IOT_XOR_VALUE_DT 0xDD
#define IOT_XOR_VALUE_YP 0xA9
#define IOT_FILE_MODE_PLAIN 0x00
#define IOT_FILE_MODE_ADD 0x01
#define IOT_FILE_MODE_SUB 0x02
#define IOT_FILE_MODE_XOR 0x03
#define IOT_FILE_MODE_UNKNOWN 0xFF
#define IOT_IMG_FLAG_MASK 0xf
#define IOT_IMG_FLAG_OFFSET 0x0
#define IOT_IMG_SIZE_MASK 0xf
#define IOT_IMG_SIZE_OFFSET 0x4
/* image global flag: bit0-3 */
#define IOT_IMG_FLAG_LZMA_EN 0x4
#define IOT_IMG_FLAG_FW2_EXT 0x8
/* image size: bit4-7 */
#define IOT_IMG_FLAG_SIZE_1M 0x1
#define IOT_IMG_FLAG_SIZE_2M 0x2
#define IOT_PKG_HDR_LEN 96
typedef struct iot_pkg_hdr {
/* 0 - plain, 1 - add enc_patern, 2 - dec enc_patern */
uint8_t enctype;
/* encrypt pattern */
uint8_t pattern;
/* 0 for CCo, 1 for STA. other value is reserved. */
uint16_t dev_type;
/* CRC of the whole upgrade file */
uint32_t file_crc;
/* length of the upgrade file */
uint32_t file_len;
/* magic number */
uint32_t magic_no;
/* version info */
uint32_t version;
/* start index of sp section */
uint32_t sp_start;
/* length of sp section */
uint32_t sp_len;
/* start index of sbl section */
uint32_t sbl_start;
/* length of sbl section */
uint32_t sbl_len;
/* start of oem section */
uint32_t oem_start;
/* length of oem section */
uint32_t oem_len;
/* start index of pib section */
uint32_t pib_start;
/* length of pib section */
uint32_t pib_len;
/* start index of fw section */
uint32_t fw_start;
/* length of fw section */
uint32_t fw_len;
/* start index of efuse section */
uint32_t efuse_start;
/* length of efuse section */
uint32_t efuse_len;
/* start index of fw2 section */
uint32_t fw2_start;
/* length of fw2 section */
uint32_t fw2_len;
/* start index of reference section */
uint32_t ref_start;
/* length of reference section */
uint32_t ref_len;
/* start index of custom section */
uint32_t cus_start;
/* length of custom section */
uint32_t cus_len;
/* vendor id*/
uint16_t vendor_id;
/* image type */
uint8_t img_type;
/* image flags */
uint8_t img_flag;
}iot_pkg_hdr_t;
/*
Format of image:
0 31
____________________________
|__________________________| --> image header size 64Bytes
| |
| |
| PAYLOAD |
| |
| _________________|
| |XXXXXXXXXXXXXXXXX| --> X is FIXED pad for 32Byte-aligning, suggested keeping '0'.
----------------------------
0 31
Description for image header V0 :
0 64
______________________________________________________________________________________________________________
| _dvcType | _imgType | _imgSize | _imgVer | _bltTimeS | _bltTimeB | _imgCRC | _guard | rev[8] | sha256[32]|
--------------------------------------------------------------------------------------------------------------
| 2Byte | 2Byte | 4Byte | 2Byte | 2Byte | 4Byte | 4Byte | 4Byte | 8Byte| 32Byte |
--------------------------------------------------------------------------------------------------------------
When written into file, PLS use big-endian . eg :
_________________________________________________________
image-header: | _dvcType=0xDEAD | _imgType=0xBEEF |
------------------------------------------------------ .......
bytes-stream: | byte0=0xDE | byte1=0xAD | byte2=0xBE | byte3=0xEF |
---------------------------------------------------------
*/
#define HEADER_REV_SIZE 0
#define SHA256_SIZE 32
/* 64Bytes-len */
typedef struct
{
/* Refrence to enum dvcType. */
uint16_t devType;
/* Refrence to enum imgType. _dvcType + _imgType -> MagicNum. */
uint16_t imgType;
/* Size of Payload only.NOT include imgHdr or data for aligning */
uint32_t imgSize;
/* Version. 0xA1C8 stands for V 10.1.200 (0x F.F.FF).V 15.15.255 is maximum. */
uint16_t imgVer;
/* Psram size, 0, 1, 2, 4, unit is MB. */
uint8_t psramSize;
/* Header version. reference for hdrVersion. */
uint8_t hdrVer;
/* firmware size, non-compressed */
uint32_t fwSize;
/* CRC32 for 'payload + pad for aligning' */
uint32_t imgCRC;
/* fixed, 0xa4e49a17 */
uint32_t guard;
/* flash layout index */
uint8_t layoutIdx;
/* reserved */
uint8_t resv[3];
/* reserved */
uint32_t fwCRC;
/* sha256 for payload */
uint8_t sha256[SHA256_SIZE];
} imgHdrV0;
/* 64 bytes */
typedef struct
{
/* Refrence to enum dvcType. */
uint8_t devType;
/* Refrence to enum imgType. _dvcType + _imgType -> MagicNum. */
uint8_t imgType;
/* Refrence to enum encType. */
uint8_t encType;
/*
* bit0 : Only for ROM while loading SBL.
* 1b-Quad read enable if supported, 0b-Single byte read mode.
*/
uint8_t cfg;
/* Size of Payload only.NOT include imgHdr or data for aligning */
uint32_t imgSize;
/* Compress type, reference for zipType. */
uint8_t zipType;
/* Flash size, reference for sizeType. */
uint8_t flashSize;
/* Psram/DDR size, reference for sizeType. */
uint8_t psramSize;
/* Header version. reference for hdrVersion. */
uint8_t hdrVer;
uint32_t imgVer;
/* CRC32 for 'payload + pad for aligning' */
uint32_t imgCRC;
/* fixed, 0xa4e49a17 */
uint32_t guard;
/* flash layout index */
uint8_t layoutIdx;
/* reserved */
uint8_t resv[3];
/* Run address. */
uint32_t runAddr;
/* sha256 for payload */
uint8_t sha256[SHA256_SIZE];
} imgHdrV1;
#define HEADER_TOLTAL_SIZE 64
#define IMAGE_ALIGNED_SIZE 32
#define IMAGE_LEN_FOR_CRC(l) ((((l)&(IMAGE_ALIGNED_SIZE-1)) ?\
(IMAGE_ALIGNED_SIZE-((l)&(IMAGE_ALIGNED_SIZE-1))) :0) + (l))
#define IMAGE_GUARD 0xa4e49a17
#define UINT8_GET(buf, n) (buf[n]&0xFF)
#define UINT16_GET(buf, n) (((buf[n]<<8)&0xFF00) | (buf[(n)+1]&0x00FF))
#define UINT32_GET(buf, n) (((buf[n]<<24)&0xFF000000) | ((buf[n+1]<<16)&0x00FF0000)\
|((buf[n+2]<<8)&0x0000FF00) | (buf[n+3]&0x000000FF))
#define IMGHDR_GET_DEVTYPE(p) UINT16_GET(p, 0)
#define IMGHDR_GET_IMGTYPE(p) UINT16_GET(p, 2)
#define IMGHDR_GET_IMGSIZE(p) UINT32_GET(p, 4)
#define IMGHDR_GET_IMGVER(p) UINT16_GET(p, 8)
#define IMGHDR_GET_PSRAMSIZE(p) UINT8_GET(p, 10)
#define IMGHDR_GET_HDRVER(p) UINT8_GET(p, 11)
#define IMGHDR_GET_FWSIZE(p) UINT32_GET(p, 12)
#define IMGHDR_GET_CRC(p) UINT32_GET(p, 16)
#define IMGHDR_GET_GUARD(p) UINT32_GET(p, 20)
#define IMGHDR_GET_LAYOUTIDX(p) UINT8_GET(p, 24)
#define IMGHDR_GET_FWCRC(p) UINT32_GET(p, 28)
#define IMGHDR_V1_GET_DEVTYPE(p) UINT8_GET(p, 0)
#define IMGHDR_V1_GET_IMGTYPE(p) UINT8_GET(p, 1)
#define IMGHDR_V1_GET_ENCVAL(p) UINT8_GET(p, 2)
#define IMGHDR_V1_GET_CONFIG(p) UINT8_GET(p, 3)
#define IMGHDR_V1_GET_IMGSIZE(p) UINT32_GET(p, 4)
#define IMGHDR_V1_GET_ZIPTYPE(p) UINT8_GET(p, 8)
#define IMGHDR_V1_GET_FLASHSIZE(p) UINT8_GET(p, 9)
#define IMGHDR_V1_GET_PSRAMSIZE(p) UINT8_GET(p, 10)
#define IMGHDR_V1_GET_HDRVER(p) UINT8_GET(p, 11)
#define IMGHDR_V1_GET_IMGVER(p) UINT32_GET(p, 12)
#define IMGHDR_V1_GET_IMGCRC(p) UINT32_GET(p, 16)
#define IMGHDR_V1_GET_GUARD(p) UINT32_GET(p, 20)
#define IMGHDR_V1_GET_LAYOUTIDX(p) UINT8_GET(p, 24)
#define IMGHDR_V1_GET_RUNADDR(p) UINT32_GET(p, 28)
#pragma pack(pop) /* restore the pack status */
#ifndef BUILD_BUG_ON
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - (2 * (!(condition)))]))
#endif
typedef union
{
imgHdrV0 v0;
imgHdrV1 v1;
}imgHdr;
void static inline img_header_construct(imgHdr *pHr, char *pStr)
{
uint8_t hdrVersion = IMGHDR_GET_HDRVER(pStr);
uint32_t ui32 = IMGHDR_GET_GUARD(pStr);
BUILD_BUG_ON (sizeof(imgHdrV0) == sizeof(imgHdrV1));
if (ui32 != IMAGE_GUARD)
{
pHr->v0.hdrVer = hdrVer_max;
pHr->v0.guard = 0;
return;
}
if (hdrVersion == hdrVer_10) {
pHr->v1.devType = IMGHDR_V1_GET_DEVTYPE(pStr);
pHr->v1.imgType = IMGHDR_V1_GET_IMGTYPE(pStr);
pHr->v1.encType = IMGHDR_V1_GET_ENCVAL(pStr);
pHr->v1.cfg = IMGHDR_V1_GET_CONFIG(pStr);
pHr->v1.imgSize = IMGHDR_V1_GET_IMGSIZE(pStr);
pHr->v1.zipType = IMGHDR_V1_GET_ZIPTYPE(pStr);
pHr->v1.flashSize = IMGHDR_V1_GET_FLASHSIZE(pStr);
pHr->v1.psramSize = IMGHDR_V1_GET_PSRAMSIZE(pStr);
pHr->v1.hdrVer = hdrVersion;
pHr->v1.imgVer = IMGHDR_V1_GET_IMGVER(pStr);
pHr->v1.imgCRC = IMGHDR_V1_GET_IMGCRC(pStr);
pHr->v1.guard = IMAGE_GUARD;
pHr->v1.layoutIdx = IMGHDR_V1_GET_LAYOUTIDX(pStr);
pHr->v1.runAddr = IMGHDR_V1_GET_RUNADDR(pStr);
for(ui32 = 0; ui32 < SHA256_SIZE; ui32++)
{
pHr->v1.sha256[ui32] = (uint8_t)pStr[32 + ui32];
}
} else {
pHr->v0.devType = IMGHDR_GET_DEVTYPE(pStr);
pHr->v0.imgType = IMGHDR_GET_IMGTYPE(pStr);
pHr->v0.imgSize = IMGHDR_GET_IMGSIZE(pStr);
pHr->v0.hdrVer = hdrVersion;
pHr->v0.psramSize = IMGHDR_GET_PSRAMSIZE(pStr);
pHr->v0.imgVer = IMGHDR_GET_IMGVER(pStr);
pHr->v0.fwSize = IMGHDR_GET_FWSIZE(pStr);
pHr->v0.imgCRC = IMGHDR_GET_CRC(pStr);
pHr->v0.guard = IMAGE_GUARD;
pHr->v0.layoutIdx = IMGHDR_GET_LAYOUTIDX(pStr);
pHr->v0.fwCRC = IMGHDR_GET_FWCRC(pStr);
for(ui32 = 0; ui32 < SHA256_SIZE; ui32++)
{
pHr->v0.sha256[ui32] = (uint8_t)pStr[32 + ui32];
}
}
return;
}
#define IMGHDR_GET_COMMON_ITERM(pHdr, item) \
(((pHdr)->v0.guard != IMAGE_GUARD) ? \
(uint32_t)(0) : ((pHdr)->v1.hdrVer == hdrVer_10 ? \
(uint32_t)(pHdr)->v1.item : (uint32_t)(pHdr)->v0.item))
#define iot_imghdr_get_hdrVer(pHdr) IMGHDR_GET_COMMON_ITERM(pHdr, hdrVer)
#define iot_imghdr_get_devType(pHdr) IMGHDR_GET_COMMON_ITERM(pHdr, devType)
#define iot_imghdr_get_imgType(pHdr) IMGHDR_GET_COMMON_ITERM(pHdr, imgType)
#define iot_imghdr_get_imgSize(pHdr) IMGHDR_GET_COMMON_ITERM(pHdr, imgSize)
#define iot_imghdr_get_psramSize(pHdr) IMGHDR_GET_COMMON_ITERM(pHdr, psramSize)
#define iot_imghdr_get_imgVer(pHdr) IMGHDR_GET_COMMON_ITERM(pHdr, imgVer)
#define iot_imghdr_get_imgCRC(pHdr) IMGHDR_GET_COMMON_ITERM(pHdr, imgCRC)
#define iot_imghdr_get_guard(pHdr) IMGHDR_GET_COMMON_ITERM(pHdr, guard)
#define iot_imghdr_get_layout_idx(pHdr) IMGHDR_GET_COMMON_ITERM(pHdr, layoutIdx)
#define iot_imghdr_get_sha256(pHdr) IMGHDR_GET_COMMON_ITERM(pHdr, sha256)
#define iot_imghdr_get_fwSize(pHdr) \
(((pHdr)->v0.guard != IMAGE_GUARD) || (pHdr)->v1.hdrVer == hdrVer_10 ? \
(uint32_t)(0) : (uint32_t)(pHdr)->v0.fwSize)
#define iot_imghdr_get_fwCRC(pHdr) \
(((pHdr)->v0.guard != IMAGE_GUARD) || (pHdr)->v1.hdrVer == hdrVer_10 ? \
(uint32_t)(0) : (uint32_t)(pHdr)->v0.fwCRC)
#define iot_imghdr_get_encType(pHdr) \
(((pHdr)->v1.guard != IMAGE_GUARD) || (pHdr)->v1.hdrVer != hdrVer_10 ? \
(uint32_t)(0) : (uint32_t)(pHdr)->v1.encType)
#define iot_imghdr_get_zipType(pHdr) \
(((pHdr)->v1.guard != IMAGE_GUARD) || (pHdr)->v1.hdrVer != hdrVer_10 ? \
(uint32_t)(0) : (uint32_t)(pHdr)->v1.zipType)
#define iot_imghdr_get_flashSize(pHdr) \
(((pHdr)->v1.guard != IMAGE_GUARD) || (pHdr)->v1.hdrVer != hdrVer_10 ? \
(uint32_t)(0) : (uint32_t)(pHdr)->v1.flashSize)
#define iot_imghdr_get_runAddr(pHdr) \
(((pHdr)->v1.guard != IMAGE_GUARD) || (pHdr)->v1.hdrVer != hdrVer_10 ? \
(uint32_t)(0) : (uint32_t)(pHdr)->v1.runAddr)
#define iot_imghdr_get_quad_rd(pHdr) \
(((pHdr)->v1.guard != IMAGE_GUARD) || (pHdr)->v1.hdrVer != hdrVer_10 ? \
(uint32_t)(0) : (uint32_t)(((pHdr)->v1.cfg) & 0x1))
#ifdef __cplusplus
}
#endif
#endif //IOT_IMG_HDR_H

45
inc/utils/iot_mem_pool.h Executable file
View File

@@ -0,0 +1,45 @@
/****************************************************************************
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.
****************************************************************************/
/* This is file is modified for embeded use, as the memory is limited, the
* macro define version inlined would take IRAM for every instance, so we
* change it to the function version
*/
#ifndef IOT_MEM_POOL_H
#define IOT_MEM_POOL_H
/* export includes */
#include "iot_mem_pool_api.h"
#ifdef __cplusplus
extern "C" {
#endif
#define IOT_MEM_POOL_POISON (0x5a5adead)
/**
* @brief iot_mem_pool_get_align_size() - return the align size of the mem pool
* @param pool_ptr: mem pool pointer
*
* @return the alignment size. unit is 1 byte
*/
uint32_t iot_mem_pool_get_align_size(iot_mem_pool_t *pool_ptr);
#ifdef __cplusplus
}
#endif
#endif /* IOT_MEM_POOL_H */

30
inc/utils/iot_ntoh.h Normal file
View File

@@ -0,0 +1,30 @@
/****************************************************************************
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 IOT_NTOH_H
#define IOT_NTOH_H
#include "iot_ntoh_api.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /*IOT_NTOH_H*/

31
inc/utils/iot_queue.h Normal file
View File

@@ -0,0 +1,31 @@
/****************************************************************************
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 IOT_QUEUE_H
#define IOT_QUEUE_H
/* export includes */
#include "iot_queue_api.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* IOT_QUEUE_H */

30
inc/utils/iot_ringbuf.h Normal file
View File

@@ -0,0 +1,30 @@
/****************************************************************************
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 IOT_RINGBUF_H
#define IOT_RINGBUF_H
/* export includes */
#include "iot_ringbuf_api.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* IOT_RINGBUF_H */

194
inc/utils/iot_share_task.h Normal file
View File

@@ -0,0 +1,194 @@
/****************************************************************************
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 IOT_SHARE_TASK_H
#define IOT_SHARE_TASK_H
/* os shim includes */
#include "os_types.h"
#include "os_task.h"
/* common includes */
#include "iot_queue.h"
#include "iot_task.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \defgroup SHARE_TASK_APIs Share Task APIs
* @brief Share Task APIs
*
*
*
*/
/** @addtogroup SHARE_TASK_APIs
* @{
*/
/* define priorities for message to be handle */
#define IOT_SHARE_TASK_QUEUE_HP 0
#define IOT_SHARE_TASK_QUEUE_LP 1
#define IOT_SHARE_TASK_QUEUE_MAX_PRIO 2
/* define message type for posting msg to share task */
#define IOT_SHARE_TASK_MT_INVALID 0
#define IOT_SHARE_TASK_MT_PIB 1
#define IOT_SHARE_TASK_MT_PLC_LED 2
#define IOT_SHARE_TASK_MT_CLI 3
#define IOT_SHARE_TASK_MT_UPGRADE 4
#define IOT_SHARE_TASK_MT_BH_INIT 5
#define IOT_SHARE_TASK_MT_CCO_PK_HDL 6
#define IOT_SHARE_TASK_MT_PLC_PM 7
#define IOT_SHARE_TASK_MT_DRIVER_I2S 8
#define IOT_SHARE_TASK_MT_HW_TSFM 9
#define IOT_SHARE_TASK_MT_EM_EXT 10
#define IOT_SHARE_TASK_MT_CRYPTO 11
#define IOT_SHARE_TASK_MT_SPI 12
/* maximum supported message types, should always keep this number accurate */
#define IOT_SHARE_TASK_MT_MAX 12
/* Event ID NOT the Message ID */
typedef enum
{
IOT_SHARE_EVENT_START = 1,
IOT_SHARE_EVENT_GPIO_INT = 1,
IOT_SHARE_EVENT_LED_PLC_TX_PHASE_A = 2,
IOT_SHARE_EVENT_LED_PLC_TX_PHASE_B = 3,
IOT_SHARE_EVENT_LED_PLC_TX_PHASE_C = 4,
IOT_SHARE_EVENT_LED_PLC_RX = 5,
IOT_SHARE_EVENT_LED_PLC_485_TX = 6,
IOT_SHARE_EVENT_LED_PLC_485_RX = 7,
IOT_SHARE_EVENT_ETH0_INT = 8,
IOT_SHARE_EVENT_GP_TIMER_INT = 9,
IOT_SHARE_EVENT_PM_TIMER = 10,
IOT_SHARE_EVENT_I2S_DMA_INT = 11,
IOT_SHARE_EVENT_I2S_DMA_OUT_T_EOF = 12,
IOT_SHARE_EVENT_I2S_TX_POOL = 13,
IOT_SHARE_EVENT_LED_PLC_APP_TX = 14,
IOT_SHARE_EVENT_LED_PLC_APP_RX = 15,
IOT_SHARE_EVENT_SADC0_DMA_INT = 16,
IOT_SHARE_EVENT_SADC1_DMA_INT = 17,
IOT_SHARE_EVENT_UART_DMA_INT = 18,
IOT_SHARE_EVENT_EM_EXT = 19,
IOT_SHARE_EVENT_LED_PLC_SM_FOUND = 20,
IOT_SHARE_EVENT_HW_TSFM = 21,
IOT_SHARE_EVENT_DBG_MSG_TIMER = 22,
IOT_SHARE_EVENT_CRYPTO = 23,
IOT_SHARE_EVENT_SPI0_DMA_SEND_OVER = 24,
IOT_SHARE_EVENT_SPI2_DMA_SEND_OVER = 25,
IOT_SHARE_EVENT_LED_RF_APP_TX = 26,
IOT_SHARE_EVENT_END = 32
}iot_share_event_type;
#define IOT_SHARE_TASK_MSG_ID_ALL IOT_TASK_MSG_ID_ALL
typedef void (*iot_share_msg_func_t)(iot_msg_entry_t *entry);
typedef void (*iot_share_msg_cancel_func_t)(iot_msg_entry_t *entry);
typedef void (*iot_share_event_func)(int);
typedef struct _iot_share_task_msg {
iot_task_msg_t msg;
/* data1 */
uint32_t data1;
/* data2*/
void* data2;
}iot_share_task_msg_t;
/* @brief iot_share_task_init - create the background
* iot_task shared by all tasks
* @return return 0 for success case. other for failed case.
*/
uint32_t iot_share_task_init();
/* @brief iot_share_task_deinit - delete the background share task.
*/
void iot_share_task_deinit();
/* @brief iot_share_task_post_msg - post msg to share task with high priority
* @param prio: priority to handle this message
* @param msg_type: message type
* @param msg_id: id of the message
* @param data1: data1 field of the message
* @param data2: a pointer field of the message
*
* @return ERR_FAIL -- Operation failed.
* @return ERR_OK -- Operation Successful.
*/
uint32_t iot_share_task_post_msg
(uint32_t prio, uint16_t msg_type, uint16_t msg_id, uint32_t data1,
void *data2);
/* @brief iot_share_task_clean_msg - clean msg with specified type and id
* @param msg_type: type of the message to be removed from share task queue
* @param msg_id: if of the message to be removed.
*/
void iot_share_task_clean_msg
(uint16_t msg_type, uint16_t msg_id);
/* @brief iot_share_task_event_register - bind a event with a callback function.
* @param type: The event type.
* @param func: The callback function.
* @param arg: Argument for the callback function.
* @return ERR_FAIL -- Operation failed.
* @return ERR_OK -- Operation Successful.
*/
uint32_t iot_share_task_event_register
(iot_share_event_type type, iot_share_event_func func, int arg);
/* @brief iot_share_task_msg_register - bind a message type with handling
* callback function. note that this function can only be invoked in
* initialization stage as there is no lock protection for this function.
* @param msg_type: the message type. see IOT_SHARE_TASK_MT_XXX.
* @param exe_func: the callback function for message excuting
* @param cancel_func: the callback function for message canceling
*
* @return ERR_FAIL -- Operation failed.
* @return ERR_OK -- Operation Successful.
*/
uint32_t iot_share_task_msg_register(uint16_t msg_type,
iot_share_msg_func_t exe_func, iot_share_msg_cancel_func_t cancel_func);
/* @brief iot_share_task_post_event_from_isr - post event to share task,
* caller is an ISR
* @param prio: priority to handle this message
* @param type: event type
* @return ERR_FAIL -- Operation failed.
* @return ERR_OK -- Operation Successful.
*/
uint32_t iot_share_task_post_event_from_isr
(uint32_t prio, iot_share_event_type type);
/* @brief iot_share_task_post_event_from_isr - post event to share task,
* caller is a TASK
* @param prio: priority to handle this message
* @param type: event type
* @return ERR_FAIL -- Operation failed.
* @return ERR_OK -- Operation Successful.
*/
uint32_t iot_share_task_post_event_from_task
(uint32_t prio, iot_share_event_type type);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* IOT_SHARE_TASK_H */

31
inc/utils/iot_task.h Normal file
View File

@@ -0,0 +1,31 @@
/****************************************************************************
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 IOT_TASK_H
#define IOT_TASK_H
/* export includes includes */
#include "iot_task_api.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* IOT_TASK_H */

155
inc/utils/iot_utils.h Executable file
View File

@@ -0,0 +1,155 @@
/****************************************************************************
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 IOT_UTILS_H
#define IOT_UTILS_H
/* exports includes */
#include "iot_utils_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* iot_mac_addr_hash() - calculate hash value based upon mac address
* @add: pointer to mac address to be caculated
* @mask: mask to be applied to the calculated value
*
* return: calculated hash value
*/
static inline uint32_t iot_mac_addr_hash(uint8_t* addr, uint32_t mask)
{
uint32_t sum = 0, i = 0;
while (i < IOT_MAC_ADDR_LEN)
sum += addr[i++];
sum &= mask;
return sum;
}
/*
* iot_meter_addr_hash() - calculate hash value based upon meter address
* @add: pointer to meter address to be caculated
* @mask: mask to be applied to the calculated value
*
* return: calculated hash value
*/
static inline uint32_t iot_meter_addr_hash(uint8_t* addr, uint32_t mask)
{
uint32_t sum = 0, i = 0;
while (i < IOT_METER_ADDR_LEN)
sum += addr[i++];
sum &= mask;
return sum;
}
/*
* iot_calc_m_ratio() - calculate the multiplex ratio for r1 * r2
* @r1: ratio 1 value
* @r2: ratio 2 value
*
* return: calculated ratio value
*/
static inline uint8_t iot_calc_m_ratio(uint8_t r1, uint8_t r2)
{
uint8_t ret;
ret = (uint8_t)((((uint32_t)(r1)) * ((uint32_t)(r2))) / 100);
if (ret > 100)
ret = 100;
return ret;
}
/*
* iot_calc_gcd() - calculate the greatest common divisor of two values
* @a: value 1
* @b: value 2
*
* return: calculated greatest common divisor
*/
static inline uint32_t iot_calc_gcd(uint16_t a, uint16_t b)
{
if (a == 0 || b == 0)
return 0;
while (a != b) {
if (a > b)
a -= b;
else
b -= a;
}
return a;
}
/*
* iot_calc_lcm() - calculate the least common multiple of two values
* @a: value 1
* @b: value 2
*
* return: calculated least common multiple
*/
static inline uint32_t iot_calc_lcm(uint16_t a, uint16_t b)
{
uint32_t tmp1, tmp2;
if (a == 0 || b == 0)
return 0;
tmp1 = a * b;
tmp2 = iot_calc_gcd(a, b);
return (tmp1 / tmp2);
}
typedef int (*iot_timeout_func)(int);
/* wait time for fun process */
/**
* @brief wait_timeout_fun - wait wait_time_ms for fun
* @param func_pointer [wait function pointer]
* @param arg [obj_func(arg)]
* @param target_value [wait return flag]
* @param wait_time_ms [wait time (ms)]
* @return [ERR_OK or ERR_TIMEOVER]
*/
uint8_t iot_wait_timeout_fun(iot_timeout_func obj_func, \
int arg, int target_value, uint32_t wait_time_ms);
typedef int (*iot_timeout_func2)(void *);
/* wait time for fun process */
/**
* @brief iot_wait_timeout_fun2 - wait wait_time_ms for fun
* @param func_pointer [wait function pointer]
* @param arg [obj_func(arg)]
* @param target_value [wait return flag]
* @param wait_time_ms [wait time (ms)]
* @return [ERR_OK or ERR_TIMEOVER]
*/
uint8_t iot_wait_timeout_fun2(iot_timeout_func2 obj_func, \
void *arg, int target_value, uint32_t wait_time_ms);
#ifdef __cplusplus
}
#endif
#endif /* IOT_UTILS_H */