更新硬件SDK

This commit is contained in:
kerwincui
2023-03-04 03:44:56 +08:00
parent dcdf6e1b7c
commit e39d3d2f03
1900 changed files with 663153 additions and 0 deletions

View File

@@ -0,0 +1,468 @@
/****************************************************************************
*
* Copy right: 2017-, Copyrigths of AirM2M Ltd.
* File name: apmu_external.h
* Description: EC618 platform power management header file
* History: 05/28/2018 Originated by bchang
* A77F40058A2024A1DB6C8CDCD7888A53
****************************************************************************/
#ifndef _EC_PM_EXT_H
#define _EC_PM_EXT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include "mem_map.h"
#include "commontypedef.h"
extern uint8_t apFlashMem[];
extern uint8_t psSleep2Mem[];
#define PS_PMUTIME_TEST (1)
#define PMU_ENABLE_MAGIC 0x504D5545 //"PMUE"
#define PMU_DISABLE_MAGIC 0x504D5544 //"PMUD"
/* HIBCNT maximum value is 745 hours */
#define HIBCNT_10MS_MAXIMUM 0x0FFFFFFF
#define DEEPSLP_TIMER_MAXRANGE 0x9EC96A00 // ticks in 740 hours
/******************************************************************************
* For CAT1bis:
* AP total AON RAM (Flash) 12 KB memory:
* AON MEM
* |<-------------------------- 4KB ------------------------------->|
* +---------+-----------------+---------+-------------+------------+
* |PLAT (1K)| MIDWARE |LWIP (1K)| CERRC BOOT | ERASECNT |
* +---------+-----------------+---------+-------------+------------+
* |<- 1KB ->|<-- 1792 Byte -->|<- 1KB ->|<- 252 Byte->|<- 4 Byte ->|
*
* |<-------------------------- 4KB ------------------------------->|
* +---------------------------------------------------+------------+
* | RRC Tiny Context | ERASECNT |
* +---------------------------------------------------+------------+
* | |<- 4 Byte ->|
*
* |<-------------------------- 4KB ------------------------------->|
* +---------------------------------------------------+------------+
* | CAM CCM NAS(CEPLMN/CEMM/CESM/SMS) UICC L2 | ERASECNT |
* +---------------------------------------------------+------------+
* |<- 4 Byte ->|
*
*=============================================================================
* Note:
* 1> All these 12 KB RAM, located in ASMB, and write back to flash before enter
* HIB state, if any context changed.
* 2> Only the first 4KB context need read to ASMB when wakeup from HIB to receive
* paging.
*
******************************************************************************/
/*****
* 4KB AON MEM 0
*****/
#define APMU_PLAT_AON_MEM_SIZE (1024) //1KB
#define APMU_MID_WARE_AON_MEM_SIZE (1792) //1024+768
#define APMU_TCPIP_AON_MEM_SIZE (1024)
#define APMU_CERRC_BOOT_AON_MEM_SIZE (252)
#define PLAT_AON_MEM_ADDR (apFlashMem)
#define MID_WARE_AON_MEM_ADDR (apFlashMem + APMU_PLAT_AON_MEM_SIZE)
#define TCPIP_AON_MEM_ADDR (MID_WARE_AON_MEM_ADDR + APMU_MID_WARE_AON_MEM_SIZE)
#define CERRC_BOOT_AON_MEM_ADDR (TCPIP_AON_MEM_ADDR + APMU_TCPIP_AON_MEM_SIZE)
/*****
* 4KB AON MEM 1
*****/
#define PS_AON_MEM_1_ADDR (apFlashMem + 4096)
/*****
* 4KB AON MEM 2
*****/
#define PS_AON_MEM_2_ADDR (apFlashMem + 8192)
/******************************************************************************
* SLEEP2 AP MEM
* 4KB memory which could remain during SLEEP2 PMU state
* Total
* +-----------------------------+
* | PS SLEEP2 MEM (4KB) |
* +-----------------------------+
* |<----------- 4K ------------>|
*
******************************************************************************/
#define PS_SLEEP2_MEM_ADDR psSleep2Mem
#define PS_SLEEP2_MEM_SIZE 4096 //4KB
#define HIB_SECONDS_TO_TICKS(S) (UINT32)(S)
#define HIB_MINUTES_TO_TICKS(M) (HIB_SECONDS_TO_TICKS(M)*60)
//list which module should vote before system enter sleep state
typedef enum PmuVoteSleepModule_enum
{
PMU_SLEEP_UICC_MOD,
PMU_SLEEP_SCT_MOD,
PMU_SLEEP_AT_UART_MOD,
PMU_SLEEP_NUM_OF_MOD
}PmuVoteSleepModule;
/*
* list which module should vote before system enter hib state
*/
typedef enum PmuVoteDeepSlpModule_enum
{
PMU_DEEPSLP_PS_CCM_MOD,
PMU_DEEPSLP_PS_CEMM_MOD,
PMU_DEEPSLP_PS_CERRC_MOD,
PMU_DEEPSLP_PS_UICC_MOD,
PMU_DEEPSLP_PS_LWIP_MOD,
PMU_DEEPSLP_CMS_MOD,
PMU_DEEPSLP_PS_CEUP_MOD, /* Note, CEUP MOD should be last,
* as the UP preSleep Callback need check whether other module tiny context changed
*/
//...
PMU_DEEPSLP_NUM_OF_MOD
}PmuVoteDeepSlpModule;
/*
* list which module should vote before system enter off state
*/
typedef enum PmuVoteOffModule_enum
{
PMU_OFF_MODEM_MOD, /* modem vote off state, call when cfun0 success */
PMU_OFF_USR_MOD, /* user vote off state, user call api to enable off state*/
PMU_OFF_NUM_OF_MOD
}PmuVoteOffModule;
/*
* |<-------------------------- 4KB ------------------------------->|
* +---------+-----------------+---------+-------------+------------+
* |PLAT (1K)| MIDWARE |LWIP (1K)| CERRC BOOT | ERASECNT |
* +---------+-----------------+---------+-------------+------------+
* |<- 1KB ->|<-- 1792 Byte -->|<- 1KB ->|<- 252 Byte->|<- 4 Byte ->|
*
* |<-------------------------- 4KB ------------------------------->|
* +---------------------------------------------------+------------+
* | RRC Tiny Context | ERASECNT |
* +---------------------------------------------------+------------+
* | |<- 4 Byte ->|
*
* |<-------------------------- 4KB ------------------------------->|
* +---------------------------------------------------+------------+
* | CAM CCM NAS(CEPLMN/CEMM/CESM/SMS) UICC L2 | ERASECNT |
* +---------------------------------------------------+------------+
* |<- 4 Byte ->|
*/
typedef enum
{
/* 4KB, flash sector 0 */
AP_FLASHREQ_HIBTIMER = 0,
AP_FLASHREQ_GLOBALCNT,
AP_FLASHREQ_MIDWARE_CFG,
AP_FLASHREQ_MIDWARE_AON,
AP_FLASHREQ_LWIP,
AP_FLASHREQ_CERRC_BOOT,
AP_FLASHREQ_SECTOR0_END = AP_FLASHREQ_CERRC_BOOT,
/* 4KB, flash sector 1 */
AP_FLASHREQ_RRC,
AP_FLASHREQ_SECTOR1_END = AP_FLASHREQ_RRC,
/* 4KB, flash sector 2 */
AP_FLASHREQ_CCM,
AP_FLASHREQ_NAS,
AP_FLASHREQ_UICC,
AP_FLASHREQ_L2,
AP_FLASHREQ_PDCP_PKG_STATIS,
AP_FLASHREQ_SECTOR2_END = AP_FLASHREQ_PDCP_PKG_STATIS,
/* 4KB, flash sector 3 */
AP_FLASHREQ_RSVD,
AP_FLASHREQ_SECTOR3_END = AP_FLASHREQ_RSVD,
}APFlashWrReq_e;
typedef enum _EPAT_APSleepState_TAG
{
AP_STATE_ACTIVE=0,
AP_STATE_IDLE,
AP_STATE_SLEEP1,
AP_STATE_SLEEP2,
AP_STATE_HIBERNATE,
AP_STATE_OFF,
NUM_AP_LP_MODE
} APSleepState;
typedef enum _EPAT_APBootFlag_e_TAG
{
AP_BOOT_FROM_POWER_ON = 0x0,
AP_BOOT_FROM_UNDEF = 0x1,
AP_BOOT_FROM_AS1 = 0x2,
AP_BOOT_FROM_AS2 = 0x3,
AP_BOOT_FROM_AH = 0x4,
AP_BOOT_FROM_AO = 0x5,
}APBootFlag_e;
typedef enum _pmuen_config_id
{
PLAT_DISABLE_CONFIG_ACTION = 0, /**< pmu disable item */
PLAT_ENABLE_CONFIG_ACTION, /**< pmu enable item */
PLAT_ENABLE_ITEM_TOTAL_NUMBER /**< total number of items */
} PmuEnCfgId;
//internal pmu vote for platform use
typedef enum PmuVotePlatInternal_enum
{
PMU_SLEEP_ATCMD_MOD, // vote to sleep when receive some at command
PMU_SLEEP_NUM_OF_Other_MOD
}PmuVotePlatInternal;
typedef enum
{
WAKEUP_PAD_0 = 0,
WAKEUP_PAD_1,
WAKEUP_PAD_2,
WAKEUP_PAD_3,
WAKEUP_PAD_4,
WAKEUP_PAD_5,
WAKEUP_LPUART,
WAKEUP_LPUSB,
WAKEUP_PWRKEY,
WAKEUP_CHARGE,
WAKEUP_PAD_MAX
}APmuWakeupPad_e;
typedef struct
{
bool posEdgeEn;
bool negEdgeEn;
bool pullUpEn;
bool pullDownEn;
}APmuWakeupPadSettings_t;
typedef void(* pmuPreDeepSlpCb_t)(void *pdata, APSleepState state);
typedef void(* pmuPostDeepSlpCb_t)(void *pdata, APSleepState state);
void apmuVoteToSleep1State(PmuVoteSleepModule pmuMod, BOOL bAllow);
void apmuVoteToSleep2State(PmuVoteDeepSlpModule pmuMod, BOOL bAllow);
void apmuVoteToHibState(PmuVoteDeepSlpModule pmuMod, BOOL bAllow);
void apmuVoteToOffState(PmuVoteOffModule pmuMod, BOOL bAllow);
BOOL apmuBVoteToSleep1State(PmuVoteSleepModule pmuMod);
BOOL apmuBVoteToSleep2State(PmuVoteDeepSlpModule pmuMod);
BOOL apmuBVoteToHibState(PmuVoteDeepSlpModule pmuMod);
BOOL apmuBVoteToSleep1State(PmuVoteSleepModule pmuMod);
void apmuGetSDKVoteDetail(uint32_t *sleepVoteFlag, uint32_t *sleep2VoteFlag, uint32_t *hibVoteFlag);
void apmuSetDeepestSleepMode(APSleepState state);
APSleepState apmuGetDeepestSleepMode(void);
BOOL apmuBWakeupFromHib(void);
BOOL apmuBWakeupFromSleep1(void);
BOOL apmuBWakeupFromSleep2(void);
BOOL pmuBPsVoteToDeepSAPSleepState(void);
uint32_t apmuBuildWaitSlpCfg(uint32_t value);
uint32_t apmuGetWaitSlpCfg(uint32_t value);
void apmuSdkFlashWrReq(APFlashWrReq_e reqID);
BOOL apmuSdkFlashBlockBeWr(APFlashWrReq_e reqID);
void apmuPreDeepSlpCbRegister(PmuVoteDeepSlpModule module, pmuPreDeepSlpCb_t cb, void *pdata);
void apmuPostDeepSlpCbRegister(PmuVoteDeepSlpModule module, pmuPostDeepSlpCb_t cb, void *pdata);
void apmuGetPMUSettings(APSleepState defaultState);
BOOL apmuBPsVoteToDeepSlpState(void);
bool apmuGetSleepedFlag(void);
void apmuPrintPostPagingSlowCnt(void);
uint16_t apmuGetLatchExternalInt(void);
void ApmuWakeupProc(uint8_t wakeupEvent, uint8_t branchFlag);
/**
* @brief apmuSetWakeupPadCfg
* @details set a specific pad as a wakeup pad and control the wakeup edge and pull settings
* @return
* @note
*/
void apmuSetWakeupPadCfg(APmuWakeupPad_e padNum, bool wakeupEn, APmuWakeupPadSettings_t *cfg);
/**
* @brief apmuGetWakeupPadCfg
* @details get wakeup pad config
* @return
* @note
*/
void apmuGetWakeupPadCfg(APmuWakeupPad_e padNum, bool *isWakeupEn, APmuWakeupPadSettings_t *cfg);
/**
* @brief apmuGetAPBootFlag
* @details get AP Boot Flag
* @return
* @note
*/
APBootFlag_e apmuGetAPBootFlag(void);
/**
* @brief apmuGetAPLLBootFlag
* @details get AP LLBoot Flag
* @return
* @note
*/
APBootFlag_e apmuGetAPLLBootFlag(void);
/**
* @brief apmuIntInit
* @details enable ap interrupt
* @return
* @note
*/
void apmuIntInit(void);
/**
* @brief apmuRestoreHibTimer
* @details retore hib timer
* @return
* @note
*/
void apmuRestoreHibTimer(void);
/**
* @brief apmuSetSwWakeupSlowCnt
* @details get a slowcnt as soon as the software wakeup, this api call in ram
* @note
*/
void apmuSetSwWakeupSlowCnt(void);
/**
* @brief apmuSetSwWakeupSlowCnt
* @details get a slowcnt as soon as the software wakeup, this api call in flash
* @note
*/
void apmuSetSwWakeupSlowCntFlash(void);
/**
* @brief apmuGetBT10MsCnt
* @details get BT counter in 10ms, for hibcnt
* @note
*/
uint32_t apmuGetBT10MsCnt(void);
/**
* @brief apmuGetBTMsCnt
* @details get BT counter in 1ms, for system time check
* @note
*/
uint32_t apmuGetBTMsCnt(void);
/**
* @brief apmuGetBTSampleCnt
* @details get accurate BT counter in 30.72M
[31:15]: in milisecond
[14: 0]: 30720 in 1 milisecond
* @note
*/
uint32_t apmuGetBTSampleCnt(void);
/**
* @brief apmuSetCPFastBoot
* @details set cp fast boot, but not power on cp
* @param force_on =true if cp code is not valid still config fast boot
force_on=false if cp code is not valid do not config fast boot
* @note
*/
void apmuSetCPFastBoot(bool force_on);
/**
* @brief apmuPsFullImageTransfer
* @details set toFullImage = true if ps want to go full image
* @param toFullImage =true if ps want to go full image
toFullImage=false continue to loop in ap paging
* @note
*/
void apmuPsFullImageTransfer(bool toFullImage);
/**
* @brief ApmuWtdgStop
* @details aon watchdog is start in closed source api when power on, but can close through calling this api
* @note
*/
void ApmuWtdgStop(void);
/**
* @brief ApmuWtdgStop
* @details feed aon watch dog
* @note
*/
void ApmuFeedWtdg(void);
/**
* @brief restore boot flag to RAM var
* @details called when paltform boot up to record golbal boot flag
* @note
*/
void apmuRestoreBootFlag(void);
/**
* @brief AonRegGetAPBootFlag
* @details get ap bootflag
* @note
*/
uint8_t AonRegGetAPBootFlag(void);
/**
* @brief AonRegSetSimLatchEnable
* @details for uicc use
* @note
*/
void AonRegSetSimLatchEnable(bool en);
/**
* @brief AonRegGetSimLatchState
* @details for uicc use
* @note
*/
bool AonRegGetSimLatchState(void);
/**
* @brief apmuGetImageType
* @details get current image type
* @note
*/
uint8_t apmuGetImageType(void);
/**
* @brief apmuSetBootTimeStamp
* @details set and store time stamp in boot flow
* @note
*/
void apmuSetBootTimeStamp(bool isPostPaging, uint8_t index);
/**
* @brief apmuPrintBootTimeStamp
* @details print time stamp in boot flow
* @note
*/
void apmuPrintBootTimeStamp(bool isPostPaging);
/**
* @brief apmuBTChangedFlag(int value)
* @details indicate bt has changed, param value is for debug, always set to 0
* @note
*/
void apmuBTChangedFlag(int value);
/**
* @brief void apmuInit(void)
* @details apmu init
* @note
*/
void apmuInit(void);
#define BOOT_TIMESTAMP_SET(type, index) apmuSetBootTimeStamp(type, index)
#define BOOT_TIMESTAMP_PRINT(type) apmuPrintBootTimeStamp(type)
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,568 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename: ccio_device.h
*
* Description:
*
* History: 2021/1/19 created by xuwang
*
* Notes: channel device of Channel Centre for Input/Output(CCIO) service
*
******************************************************************************/
#ifndef CCIO_DEVICE_H
#define CCIO_DEVICE_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#include "ccio_pub.h"
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
/* build device status flag begin & end Idx
1 1 1
6 3 2 0
|--ht--+-irq-+----------------code-------|
|======+=====+===========================|
| CCIO Device FLAG |
|======+=====+===========================|
--[NOTE]
ht : hw type
*/
#define CCIO_DSF_BASE_BUILD(ht) ((0x0D5F << 16) | ((ht) << 13))
#define CCIO_DSF_END_BUILD(ht) (CCIO_DSF_BASE_BUILD(ht) | CCIO_BITMASK(13, 0))
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
/* 'flags' definition of 'chdevExecFunc' */
typedef enum
{
CCIO_DEF_BEGIN = 0x0DEF0000,
CCIO_DEF_CHG_SERL_CONF = CCIO_DEF_BEGIN,
CCIO_DEF_GET_RECV_CONF,
CCIO_DEF_SET_RECV_CONF,
CCIO_DEF_SET_STATIC_CONF,
CCIO_DEF_SET_DATA_CONF,
CCIO_DEF_ULDP_RESET,
CCIO_DEF_ULDP_RESUME,
CCIO_DEF_ULDP_START_SW,
CCIO_DEF_ULDP_SET_SW_CONF,
CCIO_DEF_ULDP_CLR_NPT_STATE,
CCIO_DEF_SET_PPP_ACCM,
CCIO_DEF_SET_PPP_SPEC,
CCIO_DEF_ETH_MEDIA_STATUS,
CCIO_DEF_FLUSH_TX_FIFO,
CCIO_DEF_DIRECT_OUTPUT,
CCIO_DEF_UNBLOCK_SCT_EP,
CCIO_DEF_SERL_DCD_STATUS,
CCIO_DEF_SERL_RI_STATUS,
CCIO_DEF_GET_CTS_SIGNAL,
CCIO_DEF_CUST_RSVD_BEGIN = 0x0DEFC000,
/*
* rsvd for customers
* refer to 'CcioCustDevExecFlags_e'
*/
CCIO_DEF_CUST_RSVD_END = 0x0DEFFFFF,
CCIO_DEF_END = CCIO_DEF_CUST_RSVD_END,
CCIO_DEF_UNDEF = CCIO_DEF_END
}CcioDevExecFlags_e;
/* CCIO_DEF_CHG_SERL_CONF */
typedef struct
{
uint32_t baudRate;
uint32_t frameFmt;
struct CcioDevice *chdev;
}CcioDeaChgSerlConf_t;
/* CCIO_DEF_GET_RECV_CONF */
typedef struct
{
uint8_t llsn;
uint8_t isRxWinEn :1;
uint8_t isXferChk :1;
uint8_t rsvdBits :6;
uint16_t rxWinSize; /* recv window size */
uint16_t dummySti; /* dummy startIdx, valid @dummyCnt != 0 */
uint16_t dummyCnt; /* dummy cnt, for uart rbuf flush */
uint16_t xferCnt;
uint16_t writeIdx; /* in: last writeIdx, out: latest writeIdx */
}CcioDeaGetRecvConf_t;
/* CCIO_DEF_SET_RECV_CONF */
typedef struct
{
uint8_t llsn;
uint8_t isCctEn :1;
uint8_t forceTrigg :1;
uint8_t rsvdBits :6;
uint16_t readIdx;
uint16_t writeIdx;
}CcioDeaSetRecvConf_t;
/* CCIO_DEF_SET_STATIC_CONF */
typedef struct
{
uint8_t llsn;
uint8_t rsvd[3];
uint16_t ahcbSize :6; /* Additional-Header-Control-Block */
uint16_t alignVal :3;
uint16_t isThresEn :1;
uint16_t rsvdBits :6;
uint16_t cctSize;
uint16_t avlbThres;
uint16_t writeIdx;
uint16_t readIdx;
uint16_t bufLen;
uint8_t *buffer;
}CcioDeaSetStaticConf_t;
/* CCIO_DEF_SET_DATA_CONF */
typedef struct
{
uint8_t llsn;
uint8_t bmHwAcm;
uint16_t cctSize;
uint8_t alignVal;
uint8_t rsvd[2];
uint8_t dtype; /* CcioDevType_e */
union
{
CsioDevType_e stype;
CnioDevType_e ntype;
CuioDevType_e utype;
}subtype;
}CcioDeaSetDataConf_t;
/* CCIO_DEF_ULDP_RESET */
typedef struct
{
uint8_t rsvd[4];
}CcioDeaUldpReset_t;
/* CCIO_DEF_ULDP_RESUME */
typedef struct
{
uint8_t rsvd[4];
}CcioDeaUldpResume_t;
/* CCIO_DEF_ULDP_START_SW */
typedef struct
{
uint8_t rsvd[4];
}CcioDeaUldpStartSw_t;
/* CCIO_DEF_ULDP_SET_SW_CONF */
typedef struct
{
uint8_t *srcAddr;
uint16_t len;
uint8_t rsvd[2];
}CcioDeaUldpSetSwConf_t;
/* CCIO_DEF_ULDP_CLR_NPT_STATE */
typedef struct
{
uint8_t rsvd[4];
}CcioDeaUldpClrNptState_t;
/* CCIO_DEF_SET_PPP_ACCM */
typedef struct
{
uint8_t llsn;
uint8_t isOut; /* is accm for output or input? */
uint8_t rsvd[2];
uint32_t accm[8];
}CcioDeaSetPppAccm_t;
/* CCIO_DEF_SET_PPP_SPEC */
typedef struct
{
uint8_t data[3];
uint8_t rsvd;
}CcioDeaSetPppSpec_t;
/* CCIO_DEF_ETH_MEDIA_STATUS */
typedef struct
{
uint8_t lanType; /* refer to 'CcioLanMediaType_e' */
uint8_t isWanAvlb;
uint8_t rsvd[2];
}CcioDeaEthMediaStatus_t;
/* CCIO_DEF_FLUSH_TX_FIFO */
typedef struct
{
uint8_t llsn;
uint8_t rsvd[3];
void *extras;
}CcioDeaFlushTxFifo_t;
/* CCIO_DEF_DIRECT_OUTPUT */
typedef struct
{
uint8_t llsn;
uint8_t rsvd[3];
void *dlpdu;
}CcioDeaDirectOutput_t;
/* CCIO_DEF_UNBLOCK_SCT_EP */
typedef struct
{
uint8_t llsn;
uint8_t rsvd[3];
}CcioDeaUnblockSctEp_t;
/* CCIO_DEF_SERL_DCD_STATUS */
typedef struct
{
uint8_t llsn;
uint8_t state; /* CcioSerlDcdState_e */
uint8_t rsvd[2];
}CcioDeaSerlDcdStatus_t;
/* CCIO_DEF_SERL_RI_STATUS */
typedef struct
{
uint8_t llsn;
uint8_t rsvd[3];
uint16_t cycleCnt;
uint16_t dutyCyclePct;
uint32_t cycleTimeMs;
}CcioDeaSerlRiStatus_t;
/* CCIO_DEF_GET_CTS_SIGNAL */
typedef struct
{
uint8_t llsn;
uint8_t isAllowed;
uint8_t rsvd[2];
}CcioDeaGetCtsSignal_t;
/* 'flags' definition of 'chdevStatusCallback' */
typedef enum
{
CCIO_DSF_USB_BEGIN = CCIO_DSF_BASE_BUILD(CCIO_HT_USB),
CCIO_DSF_QUERY_PEER_MAC = CCIO_DSF_USB_BEGIN,
CCIO_DSF_QUERY_LOCAL_MAC,
CCIO_DSF_RNDIS_INIT,
CCIO_DSF_RNDIS_HALT,
CCIO_DSF_RNDIS_RESET,
CCIO_DSF_ECM_SET_FILTER,
CCIO_DSF_PPP_SPEC_PATTN,
CCIO_DSF_RBUF_EBNA,
CCIO_DSF_RNDIS_ESIZE,
CCIO_DSF_USB_ESTATUS,
CCIO_DSF_AHB_EADDR,
CCIO_DSF_SCT_TX_FDBACK,
CCIO_DSF_SCT_TX_DONE,
CCIO_DSF_SCT_USB_STATE,
CCIO_DSF_SCT_USB_TMEXPR,
CCIO_DSF_SCT_USB_UNBLKEP,
CCIO_DSF_USB_STATE,
CCIO_DSF_USB_END = CCIO_DSF_END_BUILD(CCIO_HT_USB),
CCIO_DSF_UART_BEGIN = CCIO_DSF_BASE_BUILD(CCIO_HT_UART),
CCIO_DSF_AUTO_BAUDRATE = CCIO_DSF_UART_BEGIN,
CCIO_DSF_WAIT_TX_DONE,
CCIO_DSF_SET_TX_DONE,
CCIO_DSF_IPR_FLUSH,
CCIO_DSF_UART_END = CCIO_DSF_END_BUILD(CCIO_HT_UART),
CCIO_DSF_RADIO_BEGIN = CCIO_DSF_BASE_BUILD(CCIO_HT_RADIO),
CCIO_DSF_ULPDU_FREE = CCIO_DSF_RADIO_BEGIN,
CCIO_DSF_DLPDU_FREE,
CCIO_DSF_WAN_MEDIA_NOTIF,
CCIO_DSF_RADIO_END = CCIO_DSF_END_BUILD(CCIO_HT_RADIO),
CCIO_DSF_HWIND_BEGIN = CCIO_DSF_BASE_BUILD(CCIO_HT_HWIND),
CCIO_DSF_DEV_ADD,
CCIO_DSF_DEV_DEL,
CCIO_DSF_CTS_CHG,
CCIO_DSF_DTR_CHG,
CCIO_DSF_RI_DONE,
CCIO_DSF_HWIND_END = CCIO_DSF_END_BUILD(CCIO_HT_HWIND),
CCIO_DSF_CUSTOM_BEGIN = CCIO_DSF_BASE_BUILD(CCIO_BITMASK(3, 0)),
/*
* rsvd for customers
* refer to 'CcioCustDevStatusFlags_e'
*/
CCIO_DSF_CUSTOM_END = CCIO_DSF_END_BUILD(CCIO_BITMASK(3, 0)),
CCIO_DSF_UNDEF = 0x0D5FFFFF
}CcioDevStatusFlags_e;
typedef struct
{
uint16_t xferCnt;
uint16_t startIdx;
uint32_t xferCos; /* refer to CCIO_CHAN_MSG_CF_COS0/1/2 */
uint32_t flags; /* for CcioDevStatusFlags_e */
struct CcioDevice *chdev;
}CcioDevInXfer_t;
typedef enum
{
CCIO_OXT_PDU_LIST_WITHOUT_TAIL, /* "DlPduBlock_t" one node/list need output, only pass the header, carried in: "CcioDevOutXfer_t->dlpdu" */
CCIO_OXT_PDU_LIST_WITH_TAIL, /* "DlPduBlock_t" list need output, pass the header and tail,
* header: "CcioDevOutXfer_t->dlpdu"
* tail : "CcioDevOutXfer_t->extra"
*/
CCIO_OXT_PDU_LIST_EVENT /* "DlPduBlock_t" is in a shared list, notify Tx task to get from the list when proc this type
* Only used for PS DL PDU (IP), sent from L2
*/
}CcioOutXferType_e;
typedef enum
{
CCIO_OXF_RAW_DATA,
CCIO_OXF_CMD_LINE,
CCIO_OXF_MAXNUM
}CcioOutXferFormat_e;
typedef struct
{
uint8_t outType; /* CcioOutXferType_e */
uint8_t outFmt; /* CcioOutXferFormat_e */
uint8_t xtag; /* some kind of private info */
uint8_t rsvd; /* used for 4 byte aligned */
void *head; /* DlPduBlock_t */
void *tail;
struct CcioDevice *chdev;
}CcioDevOutXfer_t;
typedef CcioDevInXfer_t CcioDsaRxStatus_t;
/* CCIO_DSF_QUERY_PEER_MAC */
typedef CcioMacAddr_t CcioDsaQueryPeerMac_t;
/* CCIO_DSF_QUERY_LOCAL_MAC */
typedef CcioMacAddr_t CcioDsaQueryLocalMac_t;
/* CCIO_DSF_RNDIS_INIT */
typedef struct
{
struct CcioDevice *chdev;
}CcioDsaRndisInit_t;
/* CCIO_DSF_RNDIS_HALT */
/* CCIO_DSF_RNDIS_RESET */
typedef struct
{
struct CcioDevice *chdev;
}CcioDsaRndisDeinit_t;
/* CCIO_DSF_ECM_SET_FILTER */
typedef struct
{
struct CcioDevice *chdev;
}CcioDsaEcmSetFilter_t;
/* CCIO_DSF_SCT_TX_FDBACK */
typedef struct
{
uint8_t isCmplt;
uint8_t rsvd[3];
struct CcioDevice *chdev;
}CcioDsaSctTxFdback_t;
/* CCIO_DSF_SCT_TX_DONE */
typedef struct
{
uint32_t txEvt;
struct CcioDevice *chdev;
}CcioDsaSctTxDone_t;
/* CCIO_DSF_SCT_USB_STATE */
typedef struct
{
uint32_t stateEvt;
struct CcioDevice *chdev;
}CcioDsaSctUsbState_t;
/* CCIO_DSF_SCT_USB_TMEXPR */
typedef struct
{
uint32_t timerId;
struct CcioDevice *chdev;
}CcioDsaSctUsbTmExpr_t;
/* CCIO_DSF_SCT_USB_UNBLKEP */
typedef struct
{
uint32_t epNum;
struct CcioDevice *chdev;
}CcioDsaSctUsbUnblkEp_t;
/* CCIO_DSF_USB_STATE */
typedef struct
{
uint16_t isEnable;
uint16_t devState;
struct CcioDevice *chdev;
}CcioDsaUsbState_t;
/* CCIO_DSF_AUTO_BAUDRATE */
typedef struct
{
uint32_t baudRate;
struct CcioDevice *chdev;
}CcioDsaAutoBaudRate_t;
/* CCIO_DSF_WAIT_TX_DONE */
typedef struct
{
struct CcioDevice *chdev;
}CcioDsaWaitTxDone_t;
/* CCIO_DSF_SET_TX_DONE */
typedef struct
{
struct CcioDevice *chdev;
}CcioDsaSetTxDone_t;
/* CCIO_DSF_ULPDU_FREE */
typedef struct
{
void *ulpdu; /* maybe a list */
void *extras;
}CcioDsaUlPduFree_t;
/* CCIO_DSF_DLPDU_FREE */
typedef struct
{
uint8_t isFast; /* If TRUE, "list" set to PNULL, and Tx task call: NetifLanDlPkgListGet() to get the DL PDu to free */
uint8_t xtag; /* some kind of private info */
uint8_t rsvd[2];
void *dlpdu; /* maybe a list */
void *chdev;
}CcioDsaDlPduFree_t;
/* CCIO_DSF_WAN_MEDIA_NOTIF */
typedef CcioDataPathCap_t CcioDsaWanMediaNotif_t;
/* CCIO_DSF_DEV_ADD */
typedef struct
{
struct CcioDevice *chdev;
}CcioDsaDevAdd_t;
/* CCIO_DSF_DEV_DEL */
typedef struct
{
struct CcioDevice *chdev;
}CcioDsaDevDel_t;
/* CCIO_DSF_CTS_CHG */
typedef struct
{
uint8_t isAllowed;
uint8_t epNum;
uint8_t rsvd[2];
struct CcioDevice *chdev;
}CcioDsaCtsChg_t;
/* CCIO_DSF_DTR_CHG */
typedef struct
{
struct CcioDevice *chdev;
}CcioDsaDtrChg_t;
/* CCIO_DSF_RI_DONE */
typedef struct
{
struct CcioDevice *chdev;
}CcioDsaRiDone_t;
typedef int32_t (*chdevPostHandleFunc)(CcioDevice_t *chdev, void *extras);
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
/**
* get rigestered device ctlr map in DeviceMan;
*/
uint32_t ccioGetDevRdcm(void);
/**
* Add an I/O device to the list of CCIO devices by driver
* And it is disabled by default if not referred by an entity,
* In which state drivers cannot input anything.
*/
CcioDevice_t* ccioAddDevice(CcioDevice_t *chdev);
/**
* Delete an I/O device from the list of CCIO devices by driver;
*/
int32_t ccioDelDevice(CcioDevice_t *chdev);
/**
* Find a device by searching for its device Id
*/
CcioDevice_t* ccioFindDevice(uint16_t devId);
/**
* Find a device by searching for its device type and subtype
*/
CcioDevice_t* ccioFindDeviceByTypes(CcioHwType_e hwtype, CcioDevType_e dtype, uint8_t subtype);
/**
* assign an unused device to channel entity via specific device types
*/
CcioDevice_t* ccioAssignDeviceByTypes(CcioDevType_e dtype, uint8_t subtype);
/**
* assign an unused device to channel entity via device type
*/
CcioDevice_t* ccioAssignDeviceByType(CcioDevType_e dtype);
/**
* traverse all devices by searching for its hw type
*/
int32_t ccioTraverseDeviceByHwType(CcioHwType_e hwtype, void *extras, chdevPostHandleFunc postHandleFn);
/**
* check if there are any free device in the list
*/
bool_t ccioHasFreeDevice(void);
/**
* release the device ever used by channel entity
*/
int32_t ccioReleaseDevice(CcioDevice_t* chdev);
/**
* set the device neccesary facility.
*/
void ccioSetDeviceEntity(CcioDevice_t *chdev, chdevInCallback chdevInCb, void *chent);
/**
* set the working state of device.
*/
void ccioSetDeviceState(CcioDevice_t *chdev, CcioDevWorkState_e state, uint8_t bmHwAcm);
uint8_t ccioAsgnDeviceTxCos(CcioHwType_e htype, uint8_t idx);
/**
* free the ulpdu list for a certain kind of device.
*/
void ccioFreeDeviceUlPdu(CcioDevice_t *chdev, void *ulpduList);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,209 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename: ccio_entity.h
*
* Description:
*
* History: 2021/1/19 created by xuwang
*
* Notes: Channel Centre for Input/Output(CCIO) service
*
******************************************************************************/
#ifndef CCIO_ENTITY_H
#define CCIO_ENTITY_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#include "ccio_base.h"
#include "ccio_pub.h"
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
#define CCIO_CHAN_OPEN(chent) (chent)->open = 1
#define CCIO_CHAN_CLOSE(chent) (chent)->open = 0
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
/* 'flags' definition of 'chentStatusCallback' */
typedef enum
{
CCIO_ESF_BEGIN = 0x0E5F0000,
CCIO_ESF_SET_WAN_ENTITY = CCIO_ESF_BEGIN,
CCIO_ESF_UNSET_WAN_ENTITY,
CCIO_ESF_SET_LAN_ENTITY,
CCIO_ESF_UNSET_LAN_ENTITY,
CCIO_ESF_SET_DIAG_ENTITY,
CCIO_ESF_UNSET_DIAG_ENTITY,
CCIO_ESF_CUST_RSVD_BEGIN = 0x0E5FC000,
/*
* rsvd for customers
* refer to 'CcioCustEntStatusFlags_e'
*/
CCIO_ESF_CUST_RSVD_END = 0x0E5FFFFF,
CCIO_ESF_END = CCIO_ESF_CUST_RSVD_END,
CCIO_ESF_UNDEF = CCIO_ESF_END
}CcioEntStatusFlags_e;
/* CCIO_ESF_SET_WAN_ENTITY */
typedef struct
{
uint8_t pdpCid;
uint8_t rsvd[3];
void *chent;
}CcioEsaSetWanEntity_t;
/* CCIO_ESF_UNSET_WAN_ENTITY */
typedef struct
{
uint8_t pdpCid;
uint8_t rsvd[3];
}CcioEsaUnsetWanEntity_t;
/* CCIO_ESF_SET_LAN_ENTITY */
typedef struct
{
uint8_t lanType; /* refer to 'CcioLanMediaType_e' */
uint8_t rsvd[3];
void *chent;
}CcioEsaSetLanEntity_t;
/* CCIO_ESF_UNSET_LAN_ENTITY */
typedef struct
{
uint8_t lanType; /* refer to 'CcioLanMediaType_e' */
uint8_t rsvd[3];
}CcioEsaUnsetLanEntity_t;
/* CCIO_ESF_SET_DIAG_ENTITY */
typedef struct
{
void *chent;
}CcioEsaSetDiagEntity_t;
/* CCIO_ESF_UNSET_DIAG_ENTITY */
typedef struct
{
void *chent;
}CcioEsaUnsetDiagEntity_t;
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
/**
* @brief ccioSetBaseEntity(CcioEntity_t *chent,
uint8_t hasRbuf,
uint8_t chanType,
uint8_t servType,
chentStatusCallback statusCb)
* @details base entity settings
*
* @param chent The base entity to be set
* @param chanType The channel type
* @param servType The service type
* @param status_cb The handler of entity status
* @return 0 succ; < 0 failure with errno.
*/
int32_t ccioSetBaseEntity(CcioEntity_t *chent,
uint8_t hasRbuf,
uint8_t chanType,
uint8_t servType,
chentStatusCallback statusCb);
/**
* @brief ccioResetBaseEntity(CcioEntity_t *chent)
* @details base entity clearing
*
* @param chent The base entity to be set
* @return 0 succ; < 0 failure with errno.
*/
int32_t ccioResetBaseEntity(CcioEntity_t *chent);
/**
* @brief ccioAddEntity(CcioEntity_t *chent)
* @details add the entity to the list
*
* @param chent The chan entity to be added
* @return !NULL the 1st entity in list; NULL failure.
*/
CcioEntity_t* ccioAddEntity(CcioEntity_t *chent);
/**
* @brief ccioDelEntity(void *chent)
* @details delete the entity from the list
*
* @param chent The entity to be deleted
* @return 0 succ; < 0 failure with errno.
*/
int32_t ccioDelEntity(CcioEntity_t *chent);
/**
* @brief ccioFindEntity(uint16_t chanId)
* @details find the channel entity in the list by chanId or chanNo
*
* @param chanId The channel ID/No
* @return NULL if not found; != NULL the found entity.
*/
CcioEntity_t* ccioFindEntity(uint16_t chanId);
/**
* @brief ccioFindEntityByTypes(uint8_t chanType, uint8_t servType)
* @details find the channel entity in the list by chanType & servType
*
* @param chanType The channel type
* @param servType The service type
* @return NULL if not found; != NULL the found entity.
*/
CcioEntity_t* ccioFindEntityByTypes(uint8_t chanType, uint8_t servType);
/**
* @brief ccioCheckNoDevEntity(uint8_t *nodevNum)
* @details check the entity which is not assigned with device in the list
*
* @param nodevNum output the count of entity that has no device
* @return NULL if not found; != NULL the found entity.
*/
CcioEntity_t* ccioCheckNoDevEntity(uint8_t *nodevNum);
/**
* @brief ccioGetEntityRbuf(uint16_t chanId)
* @details find the channel entity in the list by an ID
*
* @param chanId The channel ID
* @return NULL if not found; != NULL the found entity.
*/
void* ccioGetEntityRbuf(uint16_t chanId);
/**
* @brief ccioTryAssignDevice(CcioEntity_t *chent)
* @details assign an unused device to channel entity in the specific mode
*
* @param chent the entity to be assigned
* @return 0 succ; < 0 failure with errno.
*/
int32_t ccioTryAssignDevice(CcioEntity_t *chent);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,84 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename: ccio_tfc.h
*
* Description:
*
* History: 2021/1/19 created by xuwang
*
* Notes: flow controlling policy for Transmitting
*
******************************************************************************/
#ifndef CCIO_TFC_H
#define CCIO_TFC_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
#define CCIO_TFC_PID_UNDEF 0xFFFF
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
typedef uint16_t CcioTfcPid_t;
typedef enum
{
CCIO_TOI_SOCK = 0,
CCIO_TOI_HTTP,
CCIO_TOI_SSL,
CCIO_TOI_MQTT,
CCIO_TOI_RSVD_1,
CCIO_TOI_RSVD_2,
CCIO_TOI_MAXNUM
}CcioTfcObjId_e;
typedef struct
{
uint8_t mediaType; /* CcioLanMediaType_e */
uint8_t mediaCid; /* such as atCid/... */
uint8_t rsvd[2];
}CcioTfcObjKeys_t;
typedef struct
{
uint8_t objId; /* CcioTfcObjId_e */
uint8_t rsvd[3];
}CcioTfcObjAttr_t;
typedef struct
{
void *handle;
CcioDevice_t *chdev;
}CcioTfcPolicyEnable_t;
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
CcioTfcPid_t ccioCreateTfcPolicy(CcioTfcObjKeys_t *keys, CcioTfcObjAttr_t *attr);
int32_t ccioDeleteTfcPolicy(CcioTfcPid_t afcPid, CcioTfcObjAttr_t *attr);
int32_t ccioEnableTfcPolicy(CcioTfcPid_t afcPid);
uint8_t ccioIsTfcPolicyEnable(CcioTfcObjKeys_t *keys, CcioTfcObjAttr_t *attr);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,117 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename: ecm_entity.h
*
* Description:
*
* History: 2022/2/22 created by xuwang
*
* Notes:
*
******************************************************************************/
#ifndef ECM_ENTITY_H
#define ECM_ENTITY_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
#if 0
typedef struct
{
/* inherited field & MUST be placed on the top! */
CcioEntity_t base;
uint8_t lanState; /* refer to 'CcioLanMediaState_e', via monitor/user */
uint8_t pdp4Cid; /* ipv4 pdp context Id, via monitor */
uint8_t pdp6Cid; /* ipv6 pdp context Id, via monitor */
uint8_t rsvd;
void *extras; /* for user context. */
/* TODO: statistic, via monitor */
}EcmEntity_t;
#else
typedef EtherEntity_t EcmEntity_t;
#endif
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
/**
* @brief ceioInitEntity(SerialEntity_t *serlEnt, chentStatusCallback statusCb, void *extras)
* @details create a ecm entity
*
* @param rndisEnt The entity to be created
* @param status_cb The handler of entity status
* @param extras The user's extra info/useful context
* @return 0 succ; < 0 failure with errno.
*/
int32_t ceioInitEntity(EcmEntity_t *ecmEnt,
chentStatusCallback statusCb,
void *extras);
/**
* @brief ceioDeinitEntity(EcmEntity_t *ecmEnt)
* @details delete/reset a ecm entity
*
* @param rndisEnt The entity to be deleted
* @return 0 succ; < 0 failure with errno.
*/
int32_t ceioDeinitEntity(EcmEntity_t *ecmEnt);
/**
* @brief ceioSetUpChannel(EcmEntity_t *ecmEnt)
* @details establish a ecm channel
*
* @param rndisEnt The entity to be established the channel
* @return 0 succ; < 0 failure with errno.
*/
int32_t ceioSetUpChannel(EcmEntity_t *ecmEnt);
/**
* @brief ceioPullDownChannel(EcmEntity_t *ecmEnt)
* @details destroy a ecm channel
*
* @param rndisEnt The entity to be destroied the channel
* @return 0 succ; < 0 failure with errno.
*/
int32_t ceioPullDownChannel(EcmEntity_t *ecmEnt);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,106 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename: eutra_entity.h
*
* Description:
*
* History: 2021/1/19 created by xuwang
*
* Notes:
*
******************************************************************************/
#ifndef EUTRA_ENTITY_H
#define EUTRA_ENTITY_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#include "lwip/netif.h"
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
typedef struct
{
/* inherited field & MUST be placed on the top! */
CcioEntity_t base;
uint8_t isPrimary:1;
uint8_t rsvdBit:7;
uint8_t rsvd[3];
struct netif *eutraIf; /* lwip netif, via user/monitor */
void *extras; /* for user context. */
}EutraEntity_t;
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
/**
* @brief cuioInitEntity(EutraEntity_t *eutraEnt, struct netif *eutraIf, chentStatusCallback statusCb, void *extras)
* @details create a rndis entity
*
* @param eutraEnt The entity to be created
* @param eutraIf The eutra(ps) netif info
* @param status_cb The handler of entity status
* @param extras The user's extra info/useful context
* @return 0 succ; < 0 failure with errno.
*/
int32_t cuioInitEntity(EutraEntity_t *eutraEnt,
struct netif *eutraIf,
chentStatusCallback statusCb,
void *extras);
/**
* @brief cuioDeinitEntity(EutraEntity_t *eutraEnt)
* @details delete/reset a rndis entity
*
* @param eutraEnt The entity to be deleted
* @return 0 succ; < 0 failure with errno.
*/
int32_t cuioDeinitEntity(EutraEntity_t *eutraEnt);
/**
* @brief cuioSetUpChannel(EutraEntity_t *eutraEnt)
* @details establish a eutra channel
*
* @param eutraEnt The entity to be established the channel
* @return 0 succ; < 0 failure with errno.
*/
int32_t cuioSetUpChannel(EutraEntity_t *eutraEnt);
/**
* @brief cuioPullDownChannel(EutraEntity_t *eutraEnt)
* @details destroy a eutra channel
*
* @param eutraEnt The entity to be destroied the channel
* @return 0 succ; < 0 failure with errno.
*/
int32_t cuioPullDownChannel(EutraEntity_t *eutraEnt);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,133 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename:
*
* Description:
*
* History:
*
* Notes:
*
******************************************************************************/
#ifndef HAL_TRIM_H
#define HAL_TRIM_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
/**
\brief ADC EFUSE calibration code
*/
typedef struct
{
uint32_t code500 : 12;
uint32_t code900 : 12;
uint32_t reserved : 8;
} AdcEfuseCalCode_t;
/**
\brief ADC EFUSE thermal code
*/
typedef struct
{
uint32_t codet0 : 12;
uint32_t t0 : 10;
uint32_t reserved : 10;
} AdcEfuseT0Code_t;
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
/**
\fn trimEfuseNotAon( void )
\brief used to read trim value from efuse, then write into none Aon reg
\note called in bootloader when POR/SLEEP2/HIB, in ramboot when SLEEP1
*/
void trimEfuseNotAon( void );
/**
\fn trimEfuseAon( void )
\brief used to read trim value from efuse, then write into Aon reg
\note called in bootloader when POR
*/
void trimEfuseAon( void );
/**
\fn trimFromCalNv2Aon( void )
\brief used to read trim value from ap nv, then write into Aon reg
\note called in app img after ap nv init when POR
*/
void trimFromCalNv2Aon( void );
/**
\fn trimAdcSetGolbalVar( void )
\brief read the adc cali value in efuse and set to a golbal var for ADC use
\note this golbal var will be used in both paging and app img, and should be set when POR/SLEEP2/HIB case
no need for SLEEP1.
*/
void trimAdcSetGolbalVar( void );
/**
\fn trimAdcGetCalCode( void )
\brief used by ADC to get the Cali code
\return retrun the address of Cali code golbal var
\note
*/
AdcEfuseCalCode_t* trimAdcGetCalCode ( void );
/**
\fn trimAdcGetT0Code( void )
\brief used by ADC to get the T0 code
\return retrun the address of T0 code golbal var
\note
*/
AdcEfuseT0Code_t* trimAdcGetT0Code( void );
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,266 @@
/* This file has been prepared for Doxygen automatic documentation generation.*/
/*! \file ndis.h ***************************************************************
*
* \brief
* This file contains the possible external configuration of the USB.
*
* \addtogroup usbstick
*
*
******************************************************************************/
/**
\ingroup usbstick
\defgroup RNDIS RNDIS Support
@{
*/
/*
* ndis.h
*
* Modified by Colin O'Flynn <coflynn@newae.com>
* ntddndis.h modified by Benedikt Spranger <b.spranger@pengutronix.de>
*
* Thanks to the cygwin development team,
* espacially to Casper S. Hornstrup <chorns@users.sourceforge.net>
*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* This source code is offered for use in the public domain. You may
* use, modify or distribute it freely.
*
* This code is distributed in the hope that it will be useful but
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
* DISCLAIMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#ifndef _LINUX_NDIS_H
#define _LINUX_NDIS_H
#define NDIS_STATUS_MULTICAST_FULL 0xC0010009
#define NDIS_STATUS_MULTICAST_EXISTS 0xC001000A
#define NDIS_STATUS_MULTICAST_NOT_FOUND 0xC001000B
/* from drivers/net/sk98lin/h/skgepnmi.h */
#define OID_PNP_CAPABILITIES 0xFD010100
#define OID_PNP_SET_POWER 0xFD010101
#define OID_PNP_QUERY_POWER 0xFD010102
#define OID_PNP_ADD_WAKE_UP_PATTERN 0xFD010103
#define OID_PNP_REMOVE_WAKE_UP_PATTERN 0xFD010104
#define OID_PNP_ENABLE_WAKE_UP 0xFD010106
enum NDIS_DEVICE_POWER_STATE {
NdisDeviceStateUnspecified = 0,
NdisDeviceStateD0,
NdisDeviceStateD1,
NdisDeviceStateD2,
NdisDeviceStateD3,
NdisDeviceStateMaximum
};
struct NDIS_PM_WAKE_UP_CAPABILITIES {
enum NDIS_DEVICE_POWER_STATE MinMagicPacketWakeUp;
enum NDIS_DEVICE_POWER_STATE MinPatternWakeUp;
enum NDIS_DEVICE_POWER_STATE MinLinkChangeWakeUp;
};
/* NDIS_PNP_CAPABILITIES.Flags constants */
#define NDIS_DEVICE_WAKE_UP_ENABLE 0x00000001
#define NDIS_DEVICE_WAKE_ON_PATTERN_MATCH_ENABLE 0x00000002
#define NDIS_DEVICE_WAKE_ON_MAGIC_PACKET_ENABLE 0x00000004
/*
struct NDIS_PNP_CAPABILITIES {
__le32 Flags;
struct NDIS_PM_WAKE_UP_CAPABILITIES WakeUpCapabilities;
};
struct NDIS_PM_PACKET_PATTERN {
__le32 Priority;
__le32 Reserved;
__le32 MaskSize;
__le32 PatternOffset;
__le32 PatternSize;
__le32 PatternFlags;
};
*/
/* Required Object IDs (OIDs) */
#define OID_GEN_SUPPORTED_LIST 0x00010101
#define OID_GEN_HARDWARE_STATUS 0x00010102
#define OID_GEN_MEDIA_SUPPORTED 0x00010103
#define OID_GEN_MEDIA_IN_USE 0x00010104
#define OID_GEN_MAXIMUM_LOOKAHEAD 0x00010105
#define OID_GEN_MAXIMUM_FRAME_SIZE 0x00010106
#define OID_GEN_LINK_SPEED 0x00010107
#define OID_GEN_TRANSMIT_BUFFER_SPACE 0x00010108
#define OID_GEN_RECEIVE_BUFFER_SPACE 0x00010109
#define OID_GEN_TRANSMIT_BLOCK_SIZE 0x0001010A
#define OID_GEN_RECEIVE_BLOCK_SIZE 0x0001010B
#define OID_GEN_VENDOR_ID 0x0001010C
#define OID_GEN_VENDOR_DESCRIPTION 0x0001010D
#define OID_GEN_CURRENT_PACKET_FILTER 0x0001010E
#define OID_GEN_CURRENT_LOOKAHEAD 0x0001010F
#define OID_GEN_DRIVER_VERSION 0x00010110
#define OID_GEN_MAXIMUM_TOTAL_SIZE 0x00010111
#define OID_GEN_PROTOCOL_OPTIONS 0x00010112
#define OID_GEN_MAC_OPTIONS 0x00010113
#define OID_GEN_MEDIA_CONNECT_STATUS 0x00010114
#define OID_GEN_MAXIMUM_SEND_PACKETS 0x00010115
#define OID_GEN_VENDOR_DRIVER_VERSION 0x00010116
#define OID_GEN_SUPPORTED_GUIDS 0x00010117
#define OID_GEN_NETWORK_LAYER_ADDRESSES 0x00010118
#define OID_GEN_TRANSPORT_HEADER_OFFSET 0x00010119
#define OID_GEN_MACHINE_NAME 0x0001021A
#define OID_GEN_RNDIS_CONFIG_PARAMETER 0x0001021B
#define OID_GEN_VLAN_ID 0x0001021C
/* Optional OIDs */
#define OID_GEN_MEDIA_CAPABILITIES 0x00010201
#define OID_GEN_PHYSICAL_MEDIUM 0x00010202
/* Required statistics OIDs */
#define OID_GEN_XMIT_OK 0x00020101
#define OID_GEN_RCV_OK 0x00020102
#define OID_GEN_XMIT_ERROR 0x00020103
#define OID_GEN_RCV_ERROR 0x00020104
#define OID_GEN_RCV_NO_BUFFER 0x00020105
/* Optional statistics OIDs */
#define OID_GEN_DIRECTED_BYTES_XMIT 0x00020201
#define OID_GEN_DIRECTED_FRAMES_XMIT 0x00020202
#define OID_GEN_MULTICAST_BYTES_XMIT 0x00020203
#define OID_GEN_MULTICAST_FRAMES_XMIT 0x00020204
#define OID_GEN_BROADCAST_BYTES_XMIT 0x00020205
#define OID_GEN_BROADCAST_FRAMES_XMIT 0x00020206
#define OID_GEN_DIRECTED_BYTES_RCV 0x00020207
#define OID_GEN_DIRECTED_FRAMES_RCV 0x00020208
#define OID_GEN_MULTICAST_BYTES_RCV 0x00020209
#define OID_GEN_MULTICAST_FRAMES_RCV 0x0002020A
#define OID_GEN_BROADCAST_BYTES_RCV 0x0002020B
#define OID_GEN_BROADCAST_FRAMES_RCV 0x0002020C
#define OID_GEN_RCV_CRC_ERROR 0x0002020D
#define OID_GEN_TRANSMIT_QUEUE_LENGTH 0x0002020E
#define OID_GEN_GET_TIME_CAPS 0x0002020F
#define OID_GEN_GET_NETCARD_TIME 0x00020210
#define OID_GEN_NETCARD_LOAD 0x00020211
#define OID_GEN_DEVICE_PROFILE 0x00020212
#define OID_GEN_INIT_TIME_MS 0x00020213
#define OID_GEN_RESET_COUNTS 0x00020214
#define OID_GEN_MEDIA_SENSE_COUNTS 0x00020215
#define OID_GEN_FRIENDLY_NAME 0x00020216
#define OID_GEN_MINIPORT_INFO 0x00020217
#define OID_GEN_RESET_VERIFY_PARAMETERS 0x00020218
/* IEEE 802.3 (Ethernet) OIDs */
#define NDIS_802_3_MAC_OPTION_PRIORITY 0x00000001
#define OID_802_3_PERMANENT_ADDRESS 0x01010101
#define OID_802_3_CURRENT_ADDRESS 0x01010102
#define OID_802_3_MULTICAST_LIST 0x01010103
#define OID_802_3_MAXIMUM_LIST_SIZE 0x01010104
#define OID_802_3_MAC_OPTIONS 0x01010105
#define OID_802_3_RCV_ERROR_ALIGNMENT 0x01020101
#define OID_802_3_XMIT_ONE_COLLISION 0x01020102
#define OID_802_3_XMIT_MORE_COLLISIONS 0x01020103
#define OID_802_3_XMIT_DEFERRED 0x01020201
#define OID_802_3_XMIT_MAX_COLLISIONS 0x01020202
#define OID_802_3_RCV_OVERRUN 0x01020203
#define OID_802_3_XMIT_UNDERRUN 0x01020204
#define OID_802_3_XMIT_HEARTBEAT_FAILURE 0x01020205
#define OID_802_3_XMIT_TIMES_CRS_LOST 0x01020206
#define OID_802_3_XMIT_LATE_COLLISIONS 0x01020207
/* Wireless LAN OIDs */
/* Mandatory */
#define OID_802_11_BSSID 0x0D010101 /* Q S */
#define OID_802_11_SSID 0x0D010102 /* Q S */
#define OID_802_11_NETWORK_TYPE_IN_USE 0x0D010204 /* Q S */
#define OID_802_11_RSSI 0x0D010206 /* Q I */
#define OID_802_11_BSSID_LIST 0x0D010217 /* Q */
#define OID_802_11_BSSID_LIST_SCAN 0x0D01011A /* S */
#define OID_802_11_INFRASTRUCTURE_MODE 0x0D010108 /* Q S */
#define OID_802_11_SUPPORTED_RATES 0x0D01020E /* Q */
#define OID_802_11_CONFIGURATION 0x0D010211 /* Q S */
#define OID_802_11_ADD_WEP 0x0D010113 /* S */
#define OID_802_11_WEP_STATUS 0x0D01011B /* Q S */
#define OID_802_11_REMOVE_WEP 0x0D010114 /* S */
#define OID_802_11_DISASSOCIATE 0x0D010115 /* S */
#define OID_802_11_AUTHENTICATION_MODE 0x0D010118 /* Q S */
#define OID_802_11_RELOAD_DEFAULTS 0x0D01011C /* S */
/* OID_GEN_MINIPORT_INFO constants */
#define NDIS_MINIPORT_BUS_MASTER 0x00000001
#define NDIS_MINIPORT_WDM_DRIVER 0x00000002
#define NDIS_MINIPORT_SG_LIST 0x00000004
#define NDIS_MINIPORT_SUPPORTS_MEDIA_QUERY 0x00000008
#define NDIS_MINIPORT_INDICATES_PACKETS 0x00000010
#define NDIS_MINIPORT_IGNORE_PACKET_QUEUE 0x00000020
#define NDIS_MINIPORT_IGNORE_REQUEST_QUEUE 0x00000040
#define NDIS_MINIPORT_IGNORE_TOKEN_RING_ERRORS 0x00000080
#define NDIS_MINIPORT_INTERMEDIATE_DRIVER 0x00000100
#define NDIS_MINIPORT_IS_NDIS_5 0x00000200
#define NDIS_MINIPORT_IS_CO 0x00000400
#define NDIS_MINIPORT_DESERIALIZE 0x00000800
#define NDIS_MINIPORT_REQUIRES_MEDIA_POLLING 0x00001000
#define NDIS_MINIPORT_SUPPORTS_MEDIA_SENSE 0x00002000
#define NDIS_MINIPORT_NETBOOT_CARD 0x00004000
#define NDIS_MINIPORT_PM_SUPPORTED 0x00008000
#define NDIS_MINIPORT_SUPPORTS_MAC_ADDRESS_OVERWRITE 0x00010000
#define NDIS_MINIPORT_USES_SAFE_BUFFER_APIS 0x00020000
#define NDIS_MINIPORT_HIDDEN 0x00040000
#define NDIS_MINIPORT_SWENUM 0x00080000
#define NDIS_MINIPORT_SURPRISE_REMOVE_OK 0x00100000
#define NDIS_MINIPORT_NO_HALT_ON_SUSPEND 0x00200000
#define NDIS_MINIPORT_HARDWARE_DEVICE 0x00400000
#define NDIS_MINIPORT_SUPPORTS_CANCEL_SEND_PACKETS 0x00800000
#define NDIS_MINIPORT_64BITS_DMA 0x01000000
#define NDIS_MEDIUM_802_3 0x00000000
#define NDIS_MEDIUM_802_5 0x00000001
#define NDIS_MEDIUM_FDDI 0x00000002
#define NDIS_MEDIUM_WAN 0x00000003
#define NDIS_MEDIUM_LOCAL_TALK 0x00000004
#define NDIS_MEDIUM_DIX 0x00000005
#define NDIS_MEDIUM_ARCENT_RAW 0x00000006
#define NDIS_MEDIUM_ARCENT_878_2 0x00000007
#define NDIS_MEDIUM_ATM 0x00000008
#define NDIS_MEDIUM_WIRELESS_LAN 0x00000009
#define NDIS_MEDIUM_IRDA 0x0000000A
#define NDIS_MEDIUM_BPC 0x0000000B
#define NDIS_MEDIUM_CO_WAN 0x0000000C
#define NDIS_MEDIUM_1394 0x0000000D
#define NDIS_PACKET_TYPE_DIRECTED 0x00000001
#define NDIS_PACKET_TYPE_MULTICAST 0x00000002
#define NDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004
#define NDIS_PACKET_TYPE_BROADCAST 0x00000008
#define NDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010
#define NDIS_PACKET_TYPE_PROMISCUOUS 0x00000020
#define NDIS_PACKET_TYPE_SMT 0x00000040
#define NDIS_PACKET_TYPE_ALL_LOCAL 0x00000080
#define NDIS_PACKET_TYPE_GROUP 0x00000100
#define NDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00000200
#define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400
#define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800
#define NDIS_MEDIA_STATE_CONNECTED 0x00000000
#define NDIS_MEDIA_STATE_DISCONNECTED 0x00000001
#define NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA 0x00000001
#define NDIS_MAC_OPTION_RECEIVE_SERIALIZED 0x00000002
#define NDIS_MAC_OPTION_TRANSFERS_NOT_PEND 0x00000004
#define NDIS_MAC_OPTION_NO_LOOPBACK 0x00000008
#define NDIS_MAC_OPTION_FULL_DUPLEX 0x00000010
#define NDIS_MAC_OPTION_EOTX_INDICATION 0x00000020
#define NDIS_MAC_OPTION_8021P_PRIORITY 0x00000040
#define NDIS_MAC_OPTION_RESERVED 0x80000000
#endif /* _LINUX_NDIS_H */
/** @} */

View File

@@ -0,0 +1,199 @@
#ifndef __OSA_CFG_NVM_H__
#define __OSA_CFG_NVM_H__
/******************************************************************************
******************************************************************************
Copyright: - 2017, All rights reserved by AirM2M Ltd.
File name: - osacfgnvm.h
Description: - OSA EC config NVM file operation code
History: - 2021/04/06, Originated by Jason
******************************************************************************
******************************************************************************/
#ifdef WIN32
#include "winsys.h"
#else
#include "commontypedef.h"
#endif
#include "osanvm.h"
/******************************************************************************
******************************************************************************
1. "NVMCFG" use the struture:
a> TV: LF: Length Flag: 0, T: Parameter Type, V: Value
15 14 12 11 0
+-----+-----+----------------+
|LF(0)|RSVD |ParamId(12 bits)|
+-----+-----+----------------+
| Value (16 bits) |
+----------------------------+
b> TLV: LF: Length Flag: 1, T: Value type, L: Value byte length, V: Value
15 14 12 11 0
+-----+-----+----------------+
|LF(1)|RSVD |ParamId(12 bits)|
+-----+-----+----------------+
|Value byte length (16 bits) |
+----------------------------+
\ Value \
+----------------------------+
2. The 3 "RSVD" bits must set to 0, and used for future;
3. The "paramId" is 12 bits, with the range: [0 ~ 4095]
a> [0 ~ 1023], reserved for PS
b> [1024 ~ 1535], reserved for middle ware
******************************************************************************
******************************************************************************/
/******************************************************************************
*****************************************************************************
* MARCO
*****************************************************************************
******************************************************************************/
/*
* 12 bits parameter ID
*/
#define OSA_CFG_NVM_MAX_PARAM_ID 0xFFF
/*
* TV type, paramter value max size, 2 bytes
*/
#define OSA_CFG_TV_PARAM_VALUE_MAX_SIZE 2
/*
* update config NVM, when read/update, need to reserve some more buffer
*/
#define OSA_CFG_UPDATE_NVM_RSVD_LEN 128
/*
*/
#define OSA_CFG_SET_DEFAULT_TV_VALUE(paramId, value) {(paramId), (value)}
/******************************************************************************
*****************************************************************************
* STRUCT/ENUM
*****************************************************************************
******************************************************************************/
typedef enum OsaCfgType_Enum
{
OSA_CFG_TV_TYPE = 0,
OSA_CFG_TLV_TYPE = 1 //OsaCfgParam->lf = 1
}OsaCfgType;
/******************************************************************************
1. "NVMCFG" use the struture:
a> TV: LF: Length Flag: 0, T: Parameter Type, V: Value
15 14 12 11 0
+-----+-----+----------------+
|LF(0)|RSVD |ParamId(12 bits)|
+-----+-----+----------------+
| Value (16 bits) |
+----------------------------+
b> TLV: LF: Length Flag: 1, T: Value type, L: Value byte length, V: Value
15 14 12 11 0
+-----+-----+----------------+
|LF(1)|RSVD |ParamId(12 bits)|
+-----+-----+----------------+
|Value byte length (16 bits) |
+----------------------------+
\ Value \
+----------------------------+
******************************************************************************/
typedef struct OsaCfgParam_Tag
{
UINT16 paramId : 12;
UINT16 rsvd : 3; //must set to 0
UINT16 lf : 1; //length flag
union
{
UINT8 tvVal[2];
UINT16 tlvLen;
}valOrLen; /* if lf == OSA_CFG_TV_TYPE, this is the value, and must limited in 2 bytes
* if lf == OSA_CFG_TLV_TYPE, this is the value length
*/
UINT8 tlvVal[]; /* if lf == OSA_CFG_TLV_TYPE, this is the value of this parameter */
}OsaCfgParam;
typedef struct OsaCfgTVTypeValue_Tag
{
UINT16 paramId;
UINT16 val;
}OsaCfgTVTypeValue;
/*
* Read/parse every parameter in the CFG NVM file
*/
typedef struct OsaCfgParseInfo_Tag
{
OsaNvmBodyInfo *pBodyInfo;
UINT16 parseOffset; /* parse position */
UINT16 rsvd;
}OsaCfgParseInfo;
/******************************************************************************
*****************************************************************************
* FUNC
*****************************************************************************
******************************************************************************/
/**
\fn OsaNvmRet OsaCfgNvmGetNextParam(OsaCfgParam **pCfgParam, OsaCfgParseInfo *pNvmParseInfo)
\brief Get next config parameters info from NVM body info, used when parse all CFG NVM file
\param[out] pCfgParam return cfg parameter info
\param[in] pNvmParseInfo CFG NVM parse info
\returns OsaNvmRet
\ Note: a) if all parsed, return OSA_NVM_SUCC, and "*pCfgParam" set to PNULL
\ b) if CFG NVM file error, return ERR, and caller should delete this cfg file
*/
OsaNvmRet OsaCfgNvmGetNextParam(OsaCfgParam **pCfgParam, OsaCfgParseInfo *pNvmParseInfo);
/**
\fn void OsaCfgNvmRemoveParamFromParseInfo(OsaCfgParam *pRmCfg, OsaCfgParseInfo *pNvmParseInfo)
\brief Remove config parameters info from NVM body info, and update the parse offset
\param[out] pRmCfg config parameter info which need remove
\param[in] pNvmParseInfo CFG NVM parse info
\returns void
*/
void OsaCfgNvmRemoveParamFromParseInfo(OsaCfgParam *pRmCfg, OsaCfgParseInfo *pNvmParseInfo);
/**
\fn OsaCfgNvmUpdateParam(UINT16 paramId, UINT8 cfgType, UINT16 paramLen, void *pParamValue, OsaNvmBodyInfo *pNvmBufInfo)
\brief Update one configuration into NVM body, note: not write to flash in this API
\param[in] paramId 12 bits parameter ID
\param[in] cfgType TV or TLV type
\param[in] paramLen parameter length
\param[in] pParamValue parameter value
\param[in] pNvmBodyInfo NVM body buffer info
\returns INT32 //OsaNvmRet
*/
OsaNvmRet OsaCfgNvmUpdateParam(UINT16 paramId, UINT8 cfgType, UINT16 paramLen, void *pParamValue, OsaNvmBodyInfo *pNvmBodyInfo);
/**
\fn OsaNvmRet OsaCfgNvmAddParam(UINT16 paramId, UINT8 cfgType, UINT16 paramLen, void *pParamValue, OsaNvmBodyInfo *pNvmBodyInfo)
\brief Add one configuration into end of NVM body
\param[in] paramId 12 bits parameter ID
\param[in] cfgType TV or TLV type
\param[in] paramLen parameter length
\param[in] pParamValue parameter value
\param[in] pNvmBodyInfo NVM body buffer info
\returns INT32 //OsaNvmRet
\Note: The caller must make sure no this cfg already in the NVM
*/
OsaNvmRet OsaCfgNvmAddParam(UINT16 paramId, UINT8 cfgType, UINT16 paramLen, void *pParamValue, OsaNvmBodyInfo *pNvmBodyInfo);
#endif

View File

@@ -0,0 +1,117 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename: osadlfcmem.h
*
* Description:
*
* History: 2021/8/15 created by xuwang
*
* Notes: memroy operations with an attribute of DownLink Flow Controlling policy.
*
******************************************************************************/
#ifndef OSA_DLFC_MEM_H
#define OSA_DLFC_MEM_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#include "pspdu.h"
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
#define OSA_DLFC_MFI_INNER_MASK ((1 << (OSA_DLFC_MFI_INNER_END - OSA_DLFC_MFI_INNER_BEGIN + 1)) - 1)
#define OSA_DLFC_MFI_OUTER_MASK (((1 << (OSA_DLFC_MFI_OUTER_END - OSA_DLFC_MFI_OUTER_BEGIN + 1)) - 1) << OSA_DLFC_MFI_OUTER_BEGIN)
/* dlfc malloc buffer with/without a (pbuf+)dlpdu header in blocking/non-blocking mode?
* usage: only for application's exchange data, mostly downlink data.
*/
#define OsaDlfcAllocMemBlocking(wantedSize) OsaDlfcAllocMem((wantedSize), 0, 0, 1, 0)
#define OsaDlfcAllocMemNonBlocking(wantedSize) OsaDlfcAllocMem((wantedSize), 0, 0, 0, 0)
#define OsaDlfcAllocDlPduBlocking(wantedSize) OsaDlfcAllocMem((wantedSize), 0, 1, 1, 0)
#define OsaDlfcAllocDlPduNonBlocking(wantedSize) OsaDlfcAllocMem((wantedSize), 0, 1, 0, 0)
#define OsaDlfcAllocPbufDlPduBlocking(wantedSize) OsaDlfcAllocMem((wantedSize), 1, 1, 1, 0)
#define OsaDlfcAllocPbufDlPduNonBlocking(wantedSize) OsaDlfcAllocMem((wantedSize), 1, 1, 0, 0)
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
typedef struct
{
uint16_t magicNum;
uint16_t extras;
uint32_t memSize; /* aligned size */
}OsaDlfcMemHdr_t;
typedef enum
{
/* inner factors */
OSA_DLFC_MFI_INNER_BEGIN = 0,
OSA_DLFC_MFI_MEM_THRES = OSA_DLFC_MFI_INNER_BEGIN,
OSA_DLFC_MFI_INNER_END = 9,
/* outer factors */
OSA_DLFC_MFI_OUTER_BEGIN = 10,
OSA_DLFC_MFI_MSG_QUEUE = OSA_DLFC_MFI_OUTER_BEGIN,
OSA_DLFC_MFI_OUTER_END = 31,
OSA_DLFC_MFI_MAXNUM
}OsaDlfcMemFactorId_e;
typedef enum
{
OSA_DLFC_MEF_LOW_WATER = 0,
OSA_DLFC_MEF_HIGH_WATER,
OSA_DLFC_MEF_MAXNUM
}OsaDlfcMemEvtFlags_e;
typedef struct
{
uint32_t memUsed;
uint32_t extras;
}OsaDlfcMemEvtArgs_t;
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
uint32_t OsaDlfcGetMemUsedThresAlertPct(void);
void OsaDlfcSetMemUsedThresAlertPct(uint8_t alertPct);
uint32_t OsaDlfcGetMemUsedSizeThres(void);
void OsaDlfcSetMemUsedSizeThres(uint32_t usedSize);
void OsaDlfcSetMemOuterFactor(OsaDlfcMemFactorId_e fid);
void OsaDlfcClrMemOuterFactor(OsaDlfcMemFactorId_e fid);
uint32_t OsaDlfcQueryMemAvlbSize(void);
void* OsaDlfcAllocMem(uint32_t wantedSize, uint8_t hasPbuf, uint8_t hasDldpu, uint8_t isBlocking, uint16_t extras);
void OsaDlfcFreeMem(void *ptr);
void OsaDlfcReallocMem(void *ptr, uint32_t wantedSize);
void OsaDlfcNotifyMemEvent(OsaDlfcMemEvtFlags_e flags, OsaDlfcMemEvtArgs_t *args);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,126 @@
#ifndef __OSA_NVM_H__
#define __OSA_NVM_H__
/******************************************************************************
******************************************************************************
Copyright: - 2017, All rights reserved by AirM2M Ltd.
File name: - osanvm.h
Description: - OSA EC NVM operation code
History: - 2021/04/06, Originated by Jason
******************************************************************************
******************************************************************************/
#ifdef WIN32
#include "winsys.h"
#else
#include "commontypedef.h"
#endif
/******************************************************************************
*****************************************************************************
* MARCO/ENUM
*****************************************************************************
******************************************************************************/
/*
* NVM file now should limited in 4KB
*/
#define OSA_NVM_FILE_BODY_MAX_SIZE 4096
/*
*/
typedef enum OsaNvmRet_enum
{
OSA_NVM_SUCC = 0,
OSA_NVM_ERR = -1,
OSA_NVM_NO_FILE_ERR = -2, /* if read only, no file exist */
OSA_NVM_NO_MEM_ERR = -3,
OSA_NVM_CKS_ERR = -4, /* checksum err */
OSA_NVM_FILE_ERR = -5, /* file format/context not right */
OSA_NVM_INPUT_ERR = -6,
}OsaNvmRetE;
typedef INT32 OsaNvmRet;
/******************************************************************************
*****************************************************************************
* STRUCT
*****************************************************************************
******************************************************************************/
/*
* EC NVM file header struct
*/
#define OSA_NVM_FILE_NAME_SIZE 32
typedef struct OsaNvmHeader_Tag
{
UINT8 fName[OSA_NVM_FILE_NAME_SIZE];
UINT16 fileBodySize; //file body size, not include size of header
UINT16 checkSum;
UINT8 version;
UINT8 rsvd0;
UINT16 rsvd1;
}OsaNvmHeader; //40 bytes
/*
* OSA NVM file body info
*/
typedef struct OsaNvmBodyInfo_Tag
{
UINT8 *pBuf; //allocated in heap: OsaAllocMemory()/OsaFreeMemory()
/*
* As the caller maybe need to write new parameter into NVM, here reserve more memory
* 1> "bodySize": real NVM body data size
* 2> "bufSize": allcated buffer size
* 3> "bufSize" >= "bodySize", and reserved size: "bufSize" - "bodySize"
*/
UINT16 bodySize;
UINT16 bufSize;
}OsaNvmBodyInfo; // 8 bytes
/******************************************************************************
*****************************************************************************
* FUNC
*****************************************************************************
******************************************************************************/
/*
* Read whole NVM file, the file size should limited in 4KB
* Note: if file not exist, return: OSA_NVM_NO_FILE_ERR, and not allocate buffer for NVM body
*/
OsaNvmRet OsaNvmRead(const CHAR *pName, UINT8 *pVer, OsaNvmBodyInfo *pBodyInfo, UINT16 rsvdLen);
/*
* Write whole NVM file
*/
OsaNvmRet OsaNvmWrite(const CHAR *pName, UINT8 ver, void *pData, UINT32 size);
/*
* remove file
*/
OsaNvmRet OsaNvmRemove(const CHAR *pName);
/*
* After the NVM body used/parsed, need to free the memory
*/
void OsaNvmFreeBody(OsaNvmBodyInfo *pNvmBodyInfo);
/*
* Allocate buffer to store NVM file body
*/
void OsaNvmAllocBody(OsaNvmBodyInfo *pNvmBodyInfo, UINT16 bufSize);
/*
* realloc/enlarge buffer to store NVM file body
*/
void OsaNvmReAllocBody(OsaNvmBodyInfo *pNvmBodyInfo, UINT16 newBufSize);
#endif

View File

@@ -0,0 +1,216 @@
#ifndef __PS_OSA_SIG_H__
#define __PS_OSA_SIG_H__
/******************************************************************************
******************************************************************************
Copyright: - 2017, All rights reserved by AirM2M
File name: - osasig.h
Description: - OSA signal operation
History:
******************************************************************************
******************************************************************************/
#include "commontypedef.h"
#include "cmsis_os2.h"
/******************************************************************************
*****************************************************************************
* MARCO
*****************************************************************************
******************************************************************************/
/*
* offset of body in a structure
*/
#ifndef OFFSETOF
#define OFFSETOF(type, body) ((UINT32)&(((type *)0)->body))
#endif
#define OSA_BIG_FAST_SIG_BODY_MAX_SIZE 128
/*
* OSA related common signal ID
*/
typedef enum _SIG_EPAT_OSASIGIDTAG
{
SIG_TIMER_EXPIRY = 0x0100, //OsaTimerExpiry
SIG_HIB_TIMER_EXPIRY, //OsaHibTimerExpiry
SIG_OSA_FAST_IPC, //OsaFastIpcSig
SIG_CP_PAGING_IMG_EVENT_IND, //CpPagingImgEventInd
SIG_OSA_SIG_END = 0x0110,
SIG_C2A_FREE_AP_MEMORY_REQ = 0x3102, /* Same ID: C2A_FREE_AP_MEMORY_REQ, add here, only used for EPAT logging */
}OSASIGID;
/******************************************************************************
*****************************************************************************
* STRUCT
*****************************************************************************
******************************************************************************/
/*
* SIGID: SIG_TIMER_EXPIRY
*/
typedef struct OsaTimerExpiry_Tag
{
UINT16 timerEnum;
UINT16 destTaskId;
}OsaTimerExpiry;
/*
* SIGID: SIG_OSA_FAST_IPC
* 1> Fast IPC message (> 128)
* Signal A2C fast IPC CP ISR signal: SIG_OSA_FAST_IPC, to PHY task
* 31 0 31 0
* 31 0 +--------+--------+ +--------+--------+
* +--------+--------+ -------------<-+-+ | ipcId |F|ipclen| | ipcId | ipclen |
* | sigId | bodyLen| (bodyLen > 128)| | +--------+--------+ +--------+--------+
* +--------+--------+ | +--> | Signal_Addr | = +-- | Signal_Addr |
* / / | +--------+--------+ | +--------+--------+
* / sig body / +--------<-----------------------<-+
* / /
* +--------+--------+
* a) ipcId = sigId; F_flag = 1; ipcLen = sigBodyLen + 4 (Signal header length)
* 'Signal_Addr' set the signal address, NOT SIGNAL BODY address
* b) Signal should allocated by: ACAlloApMemory();
* c) When CP process done, should send the "C2A_FREE_AP_MEMORY_REQ" IPC to let AP free the memory
*/
typedef struct OsaFastIpcSig_Tag
{
UINT16 ipcMsgId; //For easy IPC MSG ID, just the same as signalID
UINT16 msgBodyLen; //siganl read len, including 4 bytes signal header (sigBodyLen + 4)
UINT8 *pIpcMsg; //point to "SignalBuf", this msg buffer in fact allocated in another core, should call to free it.
}OsaFastIpcSig;
/*
* SIGID: SIG_HIB_TIMER_EXPIRY
*/
typedef struct OsaHibTimerExpiry_Tag
{
UINT8 hibTimerId;
UINT8 reserved0;
UINT16 reserved1;
}OsaHibTimerExpiry;
/*
* The result of handling CP Paging image evert, i.e. whether wake up AP/CP full image
*/
typedef enum _EPAT_CpPagingImgEventRet_enum
{
BOOT_RET_NO_WAKEUP = 0, /* Stay in HIB/SLEEP2 state not wakeup */
BOOT_RET_AP_CP_WAKEUP = 1, /* wakeup CP for sure, send CephyCpWakeupInd */
BOOT_RET_AP_WAKEUP = 2, /* wakeup CP or not is undetermined */
}CpPagingImgEventRet;
/*
* CP/PHY paging image event ID
*/
typedef enum _EPAT_CpPagingImgEventId_enum
{
CP_PAGING_IMG_NO_EVENT = 0,
CP_UE_PAGING_EVENT = 1, /* recv UE paging */
CP_MEAS_EVENT = 2, /* recv Cell measurement */
CP_RE_SELECT_EVENT = 3 /* recv measurement, need wakeup PS, and send CephyStartRelectionInd to RRC */
}CpPagingImgEventId;
/*
* SIG_CP_PAGING_IMG_EVENT_IND
* Signal send to ERRC, to proc CP/PHY paging/measurment event
*/
typedef struct CpPagingImgEventInd_Tag
{
UINT8 eventId; //CpPagingImgEventId
BOOL bWakeupCp; //TRUE if cerrc boot API returns BOOT_RET_AP_CP_WAKEUP, need send CephyCpWakeupInd to PHY
UINT16 eventSize; //event body/buffer size
/*
* ID event size
* CP_UE_PAGING_EVENT CephyPagingInd PHY_MSMB_PAGING_SHARE_MEM_SIZE (>= sizeof(CephyPagingInd))
* CP_MEAS_EVENT CephyCellMeasInd PHY_MSMB_MEASUREMENT_SHARE_MEM_SIZE (>= sizeof(CephyCellMeasInd))
* CP_RE_SELECT_EVENT CephyStartRelectionInd 0 !!! here, size is 0 !!!
*/
void *pEvent; /* event body/buffer, !!! not need to free, as using AP/CP share global memory !!! */
}CpPagingImgEventInd; // 8 bytes
/******************************************************************************
* OS signal struct definition
*****************************************************************************/
typedef struct SignalBuf_Tag
{
UINT16 sigId;
UINT16 sigBodyLen;
UINT8 sigBody[];
}SignalBuf;
#define OSA_GET_SIGNAL_FROM_BODY(pSigBody) (SignalBuf *)(((UINT8 *)(pSigBody)) - OFFSETOF(SignalBuf, sigBody))
/******************************************************************************
* EMPTY SIGNAL
******************************************************************************/
typedef UINT32 OsaEmptySignal;
/******************************************************************************
******************************************************************************
* external SYS/OSA API
******************************************************************************
*****************************************************************************/
/*
* OSA Signal functions
*/
void OsaCreateSignal(UINT16 sigId, UINT16 sigBodySize, SignalBuf **signal);
void OsaCreateZeroSignal(UINT16 sigId, UINT16 sigBodySize, SignalBuf **signal);
void OsaCreateFastSignal(UINT16 sigId, UINT16 sigBodySize, SignalBuf **signal);
void OsaCreateZeroFastSignal(UINT16 sigId, UINT16 sigBodySize, SignalBuf **signal);
//void OsaSendSignal(UINT16 taskId, SignalBuf **signal);
void OsaSendSignalToFront(UINT16 taskId, SignalBuf **signal);
void OsaDestroySignal(SignalBuf **signal);
void OsaDestroyFastSignal(SignalBuf **signal);
void OsaReceiveSignal(UINT16 taskId, SignalBuf **signal); // if no signal received, just blocked
void OsaSendNoLogSignal(UINT16 taskId, SignalBuf **signal); /*no signal record*/
void OsaSendDumpSignal(UINT16 taskId, SignalBuf **signal); /*dump signal entity*/
void OsaSendNoDumpSignal(UINT16 taskId, SignalBuf **signal); /*not dump the signal, only record the signalId/destTaskId*/
void OsaSendCustNoLogSignal(osMessageQueueId_t mq_id, SignalBuf **signal);
void OsaReceiveCustSignal(osMessageQueueId_t mq_id, SignalBuf **signal, UINT32 timeOut);
#define OsaCreateIsrSignal OsaCreateFastSignal
#define OsaCreateZeroIsrSignal OsaCreateZeroFastSignal
#define OsaDestroyIsrSignal OsaDestroyFastSignal
/*
* void OsaSendSignal(UINT16 taskId, SignalBuf **signal);
*/
#define OsaSendSignal OsaSendDumpSignal
/**
* Get signal number in current task queue
*/
UINT32 OsaGetSignalCount(UINT16 taskId);
/**
* Get signal space of current task queue, how many signals could be input.
*/
UINT32 OsaGetSignalSpace(UINT16 taskId);
#endif

View File

@@ -0,0 +1,469 @@
#ifndef __PS_OSA_SYS_H__
#define __PS_OSA_SYS_H__
/******************************************************************************
******************************************************************************
Copyright: - 2017, All rights reserved by AirM2M
File name: - osasys.h
Description: - OSA system common include header files, and common MARCO
History:
******************************************************************************
******************************************************************************/
#include "cmsis_os2.h"
#include "osasig.h"
#include "osautil.h"
#include "FreeRTOS.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
#include "debug_trace.h"
#include "cmsis_compiler.h"
#include "time.h"
#include "Driver_Common.h"
#include "os_common.h"
#include DEBUG_LOG_HEADER_FILE
/******************************************************************************
*****************************************************************************
* MARCO
*****************************************************************************
******************************************************************************/
#define SECONDS_TO_TICKS(S) (UINT32)((S)*configTICK_RATE_HZ)
#define MINUTES_TO_TICKS(M) (SECONDS_TO_TICKS((M)*60))
//
#define MILLISECONDS_TO_TICKS(MS) (SECONDS_TO_TICKS((MS))/1000)
#define SECONDS_TO_MILLISECONDS(S) (UINT32)((S) * 1000)
#define MINUTES_TO_MILLISECONDS(M) (SECONDS_TO_MILLISECONDS((M)*60))
#define TICKS_TO_SECONDS(T) (UINT32)((T)/configTICK_RATE_HZ)
#define TICKS_TO_MILLISECONDS(T) (UINT32)(((UINT64)(T)*1000)/configTICK_RATE_HZ)
/******************************************************************************
* UnitQueue
* Use to buffer a fixed size message/signal/entity, FIFO
* 8 bytes
******************************************************************************/
typedef struct UnitQueue_Tag
{
UINT8 totalNum; /*total number of entity, which memory allocated in *queue*/
UINT8 validNum; /*how many entity already stored in this queue*/
UINT8 header; /*queue header (first entity index), so the input tail index: (header+validNum)%totalNum */
UINT8 entitySize; /*each element size*/
UINT8 *buf;
}UnitQueue;
#define UNIT_QUE_STEP 4 /*allo 4/8/12/16 entity memory*/
#define UNIT_QUE_MAX_SIZE 32
/******************************************************************************
* SignalQueue
* OS task internal FIFO queue, which used to buffer signal internally
*****************************************************************************/
typedef UnitQueue SignalQueue;
/******************************************************************************
******************************************************************************
* TIMER/SYS time ticks info, which need to still runing in HIBERNATE STATE
******************************************************************************
******************************************************************************/
/*
* HIB time enum ID
*/
typedef enum _EPAT_OsaHibTimerId_enum
{
OSA_HIB_INVALID_TIMER = 0,
PS_HIB_PLMN_PERIOD_OR_OOS_TIMER = 1,
PS_HIB_EMM_T3245_TIMER,
PS_HIB_EMM_T3247_TIMER,
PS_HIB_EMM_T3324_TIMER,
PS_HIB_EMM_T3325_TIMER,
PS_HIB_EMM_T3346_TIMER,
PS_HIB_EMM_T3402_TIMER,
PS_HIB_EMM_T3411_TIMER,
PS_HIB_EMM_T3412_TIMER,
PS_HIB_EMM_T3448_TIMER = 10,
PS_HIB_EMM_FORBIDDEN_TA_TIMER_ID,
PS_HIB_EMM_BLOCK_PLMN_TIMER_ID,
//PS_HIB_ESM_T3396_TIMER,
PS_HIB_POWER_ON_DELAY_TIMER,
PS_HIB_EMM_EMERGENCY_CAMP_TIMER_ID,
PS_HIB_ERRC_T320_TIMER = 30,
PS_HIB_ERRC_T325_TIMER,
PS_HIB_ERRC_T330_TIMER,
PS_HIB_ERRC_BCCH_MOD_TIMER,
PS_HIB_ERRC_LOG_INTERVAL_TIMER,
PS_HIB_MAX_TIMER = 0x40, /* 64 HIB timer resversed for PS */
CMS_HIB_POWER_ON_DELAY_TIMER = 0x41, /* Now, power on random delay handled in CMS task */
OSA_HIB_MAX_TIMER = 0xFF
}OsaHibTimerId;
/*
* RTC ticks, which should be also need to recorded during Hibernate state
*/
typedef UINT32 OsaHibMs;
typedef UINT32 OsaHibSecond;
#define EC_TIME_RANG_MAX (10) /* 10s */
#define EC_TIME_FLASH_VERSION ((0x11) & 0xFFFFU)
typedef __PACKED_STRUCT _timer_value
{
/* UTCtimer1 ---UINT16 year--UINT8 mon--UINT8 day */
/* UTCtimer2 ---UINT8 hour--UINT8 mins--UINT8 sec--INT8 tz */
//unsigned int UTCtimer1;
//unsigned int UTCtimer2;
unsigned int UTCsecs; /*secs since 1970*/
unsigned int UTCms; /*current ms */
unsigned int CTtimer;
unsigned int Swtimer;
unsigned int timeZone;
} timer_value_t;
typedef __PACKED_STRUCT _utc_timer_value
{
/* UTCtimer1 ---UINT16 year--UINT8 mon--UINT8 day */
/* UTCtimer2 ---UINT8 hour--UINT8 mins--UINT8 sec--INT8 tz */
unsigned int UTCtimer1;
unsigned int UTCtimer2;
unsigned int UTCsecs; /*secs since 1970*/
unsigned int UTCms; /*current ms */
int timeZone;
} utc_timer_value_t;
typedef enum {
SYNC_NITZ_LOCAL_TIME,
SET_LOCAL_TIME = 1,
}AtTimeOptVal;
typedef enum {
NITZ_TIME_SRC,
SNTP_TIME_SRC = 1,
APP_TIME_SRC = 2,
OTHER_TIME_SRC,
}AtTimeSrcVal;
typedef enum {
AT_FLASH_TIME = 1,
AT_FLASH_MAX,
}AtGetFlashVal;
/******************************************************************************
* OsaHibTimerStart
* Description: Start HIB timer
* input: OsaHibTimerExpiryFunc callback; //time expiry callback
* OsaHibTimerId timerId; //which HIB timer
* OsaHibMs nMs; //timer period
* output: void
* Comment:
* if "timerId" already start before, just print a warning, and restart it
******************************************************************************/
void OsaHibTimerStart(OsaHibTimerId timerId, OsaHibMs nMs);
/******************************************************************************
* OsaHibTimerIsRunning
* Description: whether the HIB timer is running
* input: OsaHibTimerId timerId
* output: BOOL
* Comment:
******************************************************************************/
BOOL OsaHibTimerIsRunning(OsaHibTimerId timerId);
/******************************************************************************
* OsaHibTimerStopAndDel
* Description: delete HIB timer
* input: OsaHibTimerId timerId
* output: void
* Comment:
******************************************************************************/
void OsaHibTimerStopAndDel(OsaHibTimerId timerId);
/******************************************************************************
* OsaHibTimerGetRemainMs
* Description: Get HIB timer remaining time value in milli-seconds
* input: OsaHibTimerId hibTId
* output: UINT32
* Comment:
******************************************************************************/
UINT32 OsaHibTimerGetRemainMs(OsaHibTimerId hibTId);
/*
* OSA Task Flags functionc
*/
UINT32 OsaTaskFlagsSet(UINT16 taskId, UINT32 flags);
UINT32 OsaTaskFlagsWait(UINT32 waitFlags);
UINT32 OsaTaskFlagsClear(UINT32 clearFlags);
/******************************************************************************
******************************************************************************
externl functions
******************************************************************************
******************************************************************************/
#define PSOSA 0x01 //useless, add it just to remove compilation warning
#define OsaPrintf(level, fmt, ...)
/******************************************************************************
* GosCheck/GosDebugBegin/GosDebugEnd
******************************************************************************/
extern void GosLogDebugAssertInfo(UINT8 *pCond, UINT8 *pFile, UINT16 line, UINT32 var1, UINT32 var2, UINT32 var3);
extern void GosLogAssertInfo(UINT8 *pCond, UINT8 *pFile, UINT16 line, UINT32 var1, UINT32 var2, UINT32 var3);
/******************************************************************************
* OSA signal timer function
* When timer expiry, timer task will create a signal (TIMER_EXPIRY) to SRC task
******************************************************************************/
typedef osTimerId_t OsaTimerId;
#define OSA_TIMER_NOT_CREATE 0
void OsaTimerExpiryFunc(void *argument);
//GosTimerId GosTimerNew(UINT16 taskId, UINT16 timerEnum, osTimerType_t type);
//osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)
#define OsaTimerNew(taskId, timerEnum, type) \
osTimerNew(OsaTimerExpiryFunc, type, (void *)(((taskId)<<16)|((timerEnum)&0xffff)), PNULL)
#define OsaTimerStart(TID, TICKS) osTimerStart((TID), (TICKS))
#define OsaTimerStop(TID) osTimerStop((TID))
#define OsaTimerIsRunning(TID) osTimerIsRunning((TID))
//osStatus_t GosTimerDelete(GosTimerId *timer_id);
#define OsaTimerDelete(pTID) \
do { \
OsaCheck((pTID) != PNULL && *(pTID) != OSA_TIMER_NOT_CREATE, (pTID), 0, 0); \
osTimerDelete(*(pTID)); \
*(pTID) = OSA_TIMER_NOT_CREATE; \
}while(FALSE)
/* Get how many ticks remained */
UINT32 OsaTimerGetRemainTicks(OsaTimerId timerId);
/******************************************************************************
* UNIT QUEUE function
******************************************************************************/
void UnitQueueInit(UnitQueue *queue, UINT8 entitySize);
void UnitEnQueue(UnitQueue *queue, void *entity);
void UnitDeQueue(UnitQueue *queue, void *entity);
BOOL UnitOnQueue(UnitQueue *queue);
void UnitFlushQueue(UnitQueue *queue);
/******************************************************************************
* NV FILE function
******************************************************************************/
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#define RET_FILE_OK 0
#define RET_FILE_ERR 1
typedef UINT32 NVFILE_HANDLER;
NVFILE_HANDLER NVFopen(UINT32 fileId, UINT8 *mode);
UINT32 NVFclose(NVFILE_HANDLER fd);
UINT32 NVFread(void* buf, UINT32 size, UINT32 count, NVFILE_HANDLER fd);
UINT32 NVFwrite(void* buf, UINT32 size, UINT32 count, NVFILE_HANDLER fd);
UINT32 NVFtell(NVFILE_HANDLER fd);
UINT32 NVFseek(NVFILE_HANDLER fd, UINT32 offset, UINT8 seekType);
UINT32 NVFremove(NVFILE_HANDLER fd); //fake
/**
\fn UINT8 OsaCalcCrcValue(const UINT8 *dataBuf, UINT16 bufSize)
\brief Calculate the "CRC" value of data buffer
\param[in] dataBuf data buffer pointer
\param[in] bufSize data buffer size
\returns crcValue
\code
The implementation of this function is listed below:
UINT8 OsaCalcCrcValue(const UINT8 *dataBuf, UINT16 bufSize)
{
UINT32 i;
UINT32 a = 1, b = 0;
OsaCheck(dataBuf != PNULL && bufSize > 0, dataBuf, bufSize, 0);
for (i = bufSize; i > 0; )
{
a += (UINT32)(dataBuf[--i]);
b += a;
}
return (UINT8)(((a>>24)&0xFF)^((a>>16)&0xFF)^((a>>8)&0xFF)^((a)&0xFF)^
((b>>24)&0xFF)^((b>>16)&0xFF)^((b>>8)&0xFF)^((b)&0xFF)^
(bufSize&0xFF));
}
\endcode
*/
UINT8 OsaCalcCrcValue(const UINT8 *dataBuf, UINT16 bufSize);
/******************************************************************************
* OSA FILE function (little filesystem)
******************************************************************************/
typedef void* OSAFILE;
/**
\fn OSAFILE OsaFopen(UINT8 *fileName, UINT8* mode)
\brief OSA open one file
\param[in] fileName file name
\param[in] mode file open mode (read/write/etc)
currently supported modes are:
"r" or "rb" : read only
"w" : write only
"r+" or "rb+" : read & write
"wb" : write & create
"wb+" : read & write & create
\returns OSAFILE
*/
OSAFILE OsaFopen(const char *fileName, const char* mode);
/**
\fn INT32 OsaFtell(OSAFILE fp)
\brief Return the position of the file
\param[in] fp file description
\returns INT32 On success, return the "fp" current offset; On failure, -1 is returned.
*/
INT32 OsaFtell(OSAFILE fp);
/**
\fn INT32 OsaFclose(OSAFILE fp)
\brief OSA close one file, and free the file description
\param[in] OSAFILE fp
\returns int
*/
INT32 OsaFclose(OSAFILE fp);
/**
\fn UINT32 OsaFread(void *buf, UINT32 size, UINT32 count, OSAFILE fp)
\brief read file content into buffer
\param[out] *buf output buffer
\param[in] size one context/entity size
\param[in] count how many context/entity need to read
\param[in] fp file description
\returns UINT32 the total number of context/entity successfully read
*/
UINT32 OsaFread(void *buf, UINT32 size, UINT32 count, OSAFILE fp);
/**
\fn UINT32 OsaFwrite(void *buf, UINT32 size, UINT32 count, GOSFILE fp)
\brief write buffer content into file
\param[out] *buf output buffer
\param[in] size one context/entity size
\param[in] count how many context/entity need to write
\param[in] fp file description
\returns UINT32 the total number of context/entity successfully written
*/
UINT32 OsaFwrite(void *buf, UINT32 size, UINT32 count, OSAFILE fp);
/**
\fn INT32 OsaFseek(OSAFILE fp, INT32 offset, UINT8 seekType)
\brief Change the position of the file
\param[in] fp file description
\param[in] offset offset to set
\param[in] seekType valid values:
- SEEK_SET : beginning of file
- SEEK_CUR : current position of the file pointer
- SEEK_END : end of file
\returns INT32 If successful, returns 0, otherwise -1 is returned.
*/
INT32 OsaFseek(OSAFILE fp, INT32 offset, UINT8 seekType);
/**
\fn INT32 OsaFsize(OSAFILE fp)
\brief Return the size of the file
\param[in] fp file description
\returns INT32 On success, return the size of file in unit of bytes; On failure, -1 is returned.
*/
INT32 OsaFsize(OSAFILE fp);
/**
\fn UINT32 OsaFremove(const char *fileName)
\brief Deletes the file specified by fileName
\param[in] fileName file name
\returns 0
*/
UINT32 OsaFremove(const char *fileName);
/******************************************************************************
* OSA Signal QUEUE function
******************************************************************************/
#define OsaSigQueueInit(Q) UnitQueueInit((Q), sizeof(void *))
//void OsaSigEnQueue(SignalQueue *que, SignalBuf **signal);
#define OsaSigEnQueue(Q, S) \
do { \
OsaCheck((S) != PNULL && *(S) != PNULL, (S), 0, 0); \
UnitEnQueue((Q), (S)); \
*(S) = PNULL; \
}while(FALSE)
//void OsaSigDeQueue(SignalQueue *que, SignalBuf **signal);
#define OsaSigDeQueue(Q, S) \
do { \
OsaCheck((S) != PNULL && *(S) == PNULL, (S), 0, 0); \
UnitDeQueue((Q), (S)); \
OsaCheck((S) != PNULL && *(S) != PNULL, (S), 0, 0); \
}while(FALSE)
//BOOL OsaSigOnQueue(SignalQueue *que);
#define OsaSigOnQueue(Q) UnitOnQueue((Q))
//void OsaSigFlushQueue(SignalQueue *que);
#define OsaSigFlushQueue (Q) \
do { \
SignalBuf *sig = PNULL; \
while (UnitOnQueue((Q))) \
{ \
UnitDeQueue((Q), &sig); \
OsaCheck(sig != PNULL, 0, 0, 0); \
OsaDestroySignal(&sig); \
OsaCheck(sig == PNULL, sig, 0, 0); \
} \
UnitFlushQueue((Q)); \
}while(FALSE)
#if defined(__CC_ARM)
typedef unsigned int time_t;
#endif
CHAR *strdup(const CHAR *string);
BOOL OsaGetImeiNumSync(CHAR* imei);
INT32 OsaTimerSync(UINT32 srcType, UINT32 cmd, UINT32 Timer1, UINT32 Timer2, UINT32 Timer3);
time_t OsaSystemTimeReadSecs(void);
utc_timer_value_t *OsaSystemTimeReadUtc(void);
utc_timer_value_t *OsaSystemTimeReadRamUtc(void);
/*
* From LSB(right/low) to MSB (left/high), to find the first postion of bit 0
*/
UINT8 OsaUintBit0Search(UINT32 data);
/*
* From LSB(right/low) to MSB (left/high), to find the first postion of bit 1
*/
UINT8 OsaUintBit1Search(UINT32 data);
void OsaSrand(void);
UINT32 OsaRand(void);
struct tm *gmtime_ec(const time_t* tim_p, struct tm* res);
#endif

View File

@@ -0,0 +1,116 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename: osaulfcmem.h
*
* Description:
*
* History: 2022/2/14 created by xuwang
*
* Notes: memroy operations with an attribute of UpLink Flow Controlling policy.
*
******************************************************************************/
#ifndef OSA_ULFC_MEM_H
#define OSA_ULFC_MEM_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#include "pspdu.h"
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
#define OSA_ULFC_MEM_USED_THRES_ANY_ALERT_PCT 0xff
#define OSA_ULFC_MEM_USED_THRES_ANY 0xffff
/* ulfc malloc buffer with/without a (pbuf+)ulpdu header in blocking/non-blocking mode?
* usage: only for application's exchange data, mostly uplink data.
*/
#define OsaUlfcAllocMemBlocking(wantedSize, chanNo) OsaUlfcAllocMem(wantedSize, 0, 0, 1, chanNo)
#define OsaUlfcAllocMemNonBlocking(wantedSize, chanNo) OsaUlfcAllocMem(wantedSize, 0, 0, 0, chanNo)
#define OsaUlfcAllocUlPduBlocking(wantedSize, chanNo) OsaUlfcAllocMem(wantedSize, 0, 1, 1, chanNo)
#define OsaUlfcAllocUlPduNonBlocking(wantedSize, chanNo) OsaUlfcAllocMem(wantedSize, 0, 1, 0, chanNo)
#define OsaUlfcAllocPbufUlPduBlocking(wantedSize, chanNo) OsaUlfcAllocMem(wantedSize, 1, 1, 1, chanNo)
#define OsaUlfcAllocPbufUlPduNonBlocking(wantedSize, chanNo) OsaUlfcAllocMem(wantedSize, 1, 1, 0, chanNo)
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
typedef struct
{
uint16_t magicNum;
uint16_t extras;
uint32_t memSize; /* aligned size */
}OsaUlfcMemHdr_t;
typedef enum
{
OSA_ULFC_MFI_MEM_THRES = 0,
OSA_ULFC_MFI_MAXNUM
}OsaUlfcMemFactorId_e;
typedef enum
{
OSA_ULFC_STI_CCIO_RX = 0,
OSA_ULFC_STI_MAXNUM
}OsaUlfcSrcTaskId_e;
typedef uint32_t OsaUlfcSrcTaskId_bm;
typedef enum
{
OSA_ULFC_MEF_LOW_WATER = 0,
OSA_ULFC_MEF_HIGH_WATER,
OSA_ULFC_MEF_MAXNUM
}OsaUlfcMemEvtFlags_e;
typedef struct
{
uint32_t memUsed;
uint32_t extras;
}OsaUlfcMemEvtArgs_t;
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
uint32_t OsaUlfcGetMemUsedThresAlertPct(uint8_t chanNo);
void OsaUlfcSetMemUsedThresAlertPct(uint8_t chanNo, uint8_t alertPct);
uint32_t OsaUlfcGetMemUsedSizeThres(uint8_t chanNo);
void OsaUlfcSetMemUsedSizeThres(uint8_t chanNo, uint32_t usedSize);
uint8_t OsaUlfcQueryEnableState(uint8_t chanNo);
uint32_t OsaUlfcQueryMemAvlbSize(uint8_t chanNo);
void* OsaUlfcAllocMem(uint32_t wantedSize, uint8_t hasPbuf, uint8_t hasUldpu, uint8_t isBlocking, uint16_t extras);
void OsaUlfcFreeMem(void *ptr);
void OsaUlfcReallocMem(void *ptr, uint32_t wantedSize);
void OsaUlfcEnable(uint8_t chanNo, uint8_t isBlocking, OsaUlfcSrcTaskId_e taskId);
void OsaUlfcDisable(uint8_t chanNo, OsaUlfcSrcTaskId_e taskId);
void OsaUlfcNotifyMemEvent(OsaUlfcMemEvtFlags_e flags, OsaUlfcMemEvtArgs_t *args);
void OsaUlfcConfmMemEvent(uint8_t chanNo);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,305 @@
#ifndef __OSA_UTIL_H__
#define __OSA_UTIL_H__
/******************************************************************************
******************************************************************************
Copyright: - 2017, All rights reserved by AirM2M Ltd.
File name: - osautil.h
Description: - defined some common functions/structures
History: - 2021/02/20, Originated by Jason
******************************************************************************
******************************************************************************/
#ifdef WIN32
#include "winsys.h"
#else
#include "commontypedef.h"
#endif
#include "pspdu.h"
/******************************************************************************
*****************************************************************************
* MARCO
*****************************************************************************
******************************************************************************/
#ifndef OsaBit1Set
/*
* set bit B to 1 in D
* example:
* OsaBit1Set(0x00, 0) = 0x01
* OsaBit1Set(0x01, 4) = 0x11
*/
#define OsaBit1Set(D, B) ((D) |= ((UINT32)1<<(B)))
#endif
#ifndef OsaBit0Set
/*
* set bit B to 0 in D
* example:
* OsaBit1Set(0xFF, 0) = 0xFE
* OsaBit1Set(0xFE, 4) = 0xEE
*/
#define OsaBit0Set(D, B) ((D) &= (~((UINT32)1<<(B))))
#endif
#ifndef OsaIsBit1
/*
* whether bit B in D is 1
* example:
* OsaIsBit1(1010 1010, 0) = FALSE
* OsaIsBit1(1010 1010, 1) = TRUE
*/
#define OsaIsBit1(D, B) ((((D)>>(B))&0x01) == 0x01)
#endif
#ifndef OsaIsBit0
/*
* whether bit B in D is 0
* example:
* OsaIsBit0(1010 1010, 0) = TRUE
* OsaIsBit0(1010 1010, 1) = FALSE
*/
#define OsaIsBit0(D, B) ((((D)>>(B))&0x01) == 0x00)
#endif
/*
* get byte length from bit length
* example:
* OsaBitsByteLen(1) = 1
* OsaBitsByteLen(7) = 1
* OsaBitsByteLen(9) = 2
*/
#define OsaBitsByteLen(bits) (((bits)+7)>>3)
/*
* Set N bits of D (UINT8) start from S to V,
* (D) &= ~((~(0xFFFFFFFF<<(N)))<<(S)); // set N bits to 0
* (D) |= (((V)&(~(0xFFFFFFFF<<(N))))<<(S)); // set N bits to V
* Example
* OsaSetUint8BitsN(1111 1111, 2, 4, 1010) => 1110 1011
* ^S
* OsaSetUint8BitsN(0000 0000, 4, 3, 101) => 0101 0000
* ^S
*/
#define OsaSetUint8BitsN(D, S, N, V) ((D) &= ~((~(0xFFFFFFFF<<(N)))<<(S)), (D) |= (((V)&(~(0xFFFFFFFF<<(N)))) << (S)))
/*
* Example
* OsaGetBitsN(0001 1000, 0, 4) = 0x08
* ^S
* OsaGetBitsN(0001 1000, 3, 2) = 0x03
* ^S
*/
#define OsaGetBitsN(D, S, N) (((D)>>(S))&(~(0xFFFFFFFF << (N))))
/*
*/
#define OSA_IE_BUF_STEP_SIZE 128
#define OSA_IE_BUF_MAX_SIZE 4096
/*
* Osa4ByteAlignLen(0) = 0
* Osa4ByteAlignLen(1) = 4
* Osa4ByteAlignLen(8) = 8
*/
#define Osa4ByteAlignLen(byteLen) (((byteLen)+3)&0xFFFFFFFC)
/*
* Single linked list operation MARCO
* !!!! STRUCT must have "pNext" element !!!
*/
#define OsaSingleLinkAddOne(pHdr, pTailer, pNew) \
do { \
if ((pHdr) == PNULL) \
{ \
OsaCheck((pTailer) == PNULL && (pNew) != PNULL && ((pNew)->pNext) == PNULL, (pTailer), ((pNew)->pNext), 0xABCDEF); \
(pHdr) = (pTailer) = (pNew); \
} \
else \
{ \
OsaCheck((pTailer) != PNULL && (pNew) != PNULL && ((pNew)->pNext) == PNULL, (pTailer), ((pNew)->pNext), 0xFEDCBA); \
(pTailer)->pNext = (pNew); \
(pTailer) = (pNew); \
} \
}while(FALSE)
/*
*/
#define OsaSingleLinkAddList(pHdr, pTailer, pNewHdr, pNewTailer) \
do { \
if ((pHdr) == PNULL) \
{ \
OsaCheck((pTailer) == PNULL && (pNewHdr) != PNULL && ((pNewTailer)->pNext) == PNULL, (pTailer), ((pNewTailer)->pNext), 0x12345678); \
(pHdr) = (pNewHdr); \
(pTailer) = (pNewTailer); \
} \
else \
{ \
OsaCheck((pTailer) != PNULL && (pNewHdr) != PNULL && ((pNewTailer)->pNext) == PNULL, (pTailer), ((pNewTailer)->pNext), 0x87654321); \
(pTailer)->pNext = (pNewHdr); \
(pTailer) = (pNewTailer); \
} \
}while(FALSE)
/******************************************************************************
*****************************************************************************
* STRUCT
*****************************************************************************
******************************************************************************/
/*
* Dynamic memory allocated for ASN1 read/decode
*/
typedef struct OsaIeBuffer_Tag
{
struct OsaIeBuffer_Tag *pNext;
/*
* total allocated size of current memory
*/
UINT16 totalSize;
/*
* free memory address = pStart + freeOffset
*/
UINT16 freeOffset;
UINT8 pStart[];
}OsaIeBuffer; // 8 bytes
typedef struct OsaIeMemInfo_Tag
{
OsaIeBuffer *pBufHdr;
}OsaIeMemInfo;
/******************************************************************************
*****************************************************************************
* FUNC
*****************************************************************************
******************************************************************************/
/******************************************************************************
* OsaBit1Search
* Description: From LSB(right/low) to MSB (left/high), to find the first postion
* of bit 1
* input: UINT32 data
* output: UINT8 //if not found, return 0xFF
* Comment:
* example: 10100100 00001000 10101111 11000000, return 6
* 0x00000000 return 0xFF
* 0xFFFFFFFF return 0
******************************************************************************/
UINT8 OsaBit1Search(UINT32 data);
/******************************************************************************
* OsaBit0Search
* Description: From LSB(right/low) to MSB (left/high), to find the first postion
* of bit 0
* input: UINT32 data
* output: UINT8 //if not found, return 0xFF
* Comment:
* example: 1010 1011, return 2
* 0000 0000, return 0
* 0xFFFFFFFF, return 0xFF
******************************************************************************/
UINT8 OsaBit0Search(UINT32 data);
/******************************************************************************
* OsaBeZeroMemory
* Description: Whether all memory are set to zero
* input:
* output: UINT32 // 0 - not all zero, 1 - all zero
*
******************************************************************************/
UINT32 OsaBeZeroMemory(const void *pMem, UINT32 size);
/******************************************************************************
* OsaIeMemInit
* Description: init PS IE (information element) memory info
* input: OsaIeMemInfo *pIeMemInfo //IE memory info
* UINT16 estIeSize //estimate IE structure size
* void **ppRootIebuf //output, return root IE buffer
* output: void
* Comment:
******************************************************************************/
void OsaIeMemInit(OsaIeMemInfo *pIeMemInfo, UINT16 estIeSize, void **ppRootIebuf);
/******************************************************************************
* OsaIeMemAllocate
* Description: Allocate memory from IE memory
* input: OsaIeMemInfo *pIeMemInfo //IE memory info
* UINT16 wantSize //want size
* output: void
* Comment:
******************************************************************************/
void* OsaIeMemAllocate(OsaIeMemInfo *pIeMemInfo, UINT16 wantSize);
/******************************************************************************
* OsaIeMemDestroy
* Description: destroy/free all IE memory
* input: OsaIeMemInfo *pIeMemInfo //IE memory info
* output: void
* Comment:
******************************************************************************/
void OsaIeMemDestroy(OsaIeMemInfo *pIeMemInfo);
/******************************************************************************
* OsaSetBufBitsValue
* Description: Set "bitLen" (MAX 32 bits) bits value in "pBuf" start from "bitOffset", to "value"
* input: UINT8 *pBuf;
* UINT32 *startBitOffset //IN & OUT put, output = *startBitOffset + bitsLen
* UINT8 bitsLen
* UINT32 value
* output: void
* Comment:
******************************************************************************/
void OsaSetBufBitsValue(UINT8 *pBuf, UINT32 *startBitOffset, UINT8 bitsLen, UINT32 value);
/******************************************************************************
* OsaGetBufBitsValue
* Description: Get "bitLen" (MAX 32 bits) bits value from "pBuf" start from "bitOffset"
* input: UINT8 *pBuf;
* UINT32 *startBitOffset //IN & OUT put, output = *startBitOffset + bitsLen
* UINT8 bitsLen
* output: UINT32
* Comment:
******************************************************************************/
UINT32 OsaGetBufBitsValue(const UINT8 *pBuf, UINT32 *startBitOffset, UINT8 bitsLen);
/*
* Alloc one "DlPduBlock" from heap, if failed, return PNULL
*/
DlPduBlock* OsaAllocDlPduBlock(UINT32 len);
/*
* Free one DL PDU block
*/
void OsaFreeOneDlPduBlock(DlPduBlock **pDlPduBlk);
/*
* Free DL PDU list
*/
void OsaFreeDlPduBlockList(DlPduBlock **pDlPduBlk);
/*
* Free one UL PDU block
*/
void OsaFreeOneUlPduBlock(UlPduBlock **pUlPduBlk);
/*
* Free UL PDU list
*/
void OsaFreeUlPduBlockList(UlPduBlock **pUlPduBlk);
#endif

View File

@@ -0,0 +1,291 @@
/****************************************************************************
*
* Copy right: 2017-, Copyrigths of AirM2M Ltd.
* File name: ostask.h
* Description: adpter layer for ps to use os task, queue API
* History:
*
****************************************************************************/
#ifndef _PS_OSTAS_H
#define _PS_OSTAS_H
#ifndef CORE_IS_CP //for AP
#include "commontypedef.h"
#include "cmsis_os2.h" // ::CMSIS:RTOS2
#define CMS_TASK_NAME "CmsTask"
/******************************************************************************
*
* Task STACK size
*
******************************************************************************/
#define PS_TASK_STACK_SIZE 1536
#define UICC_CTRL_TASK_STACK_SIZE 2048
#define UICC_DRV_TASK_STACK_SIZE 1536
//#define TCPIP_THREAD_STACKSIZE 2048
#define LWIP_TASK_STACK_SIZE 1536
/******************************************************************************
*
* Task signal queue size
*
******************************************************************************/
#define PS_TASK_QUEUE_SIZE 20 // queue size of ps tasks
/******************************************************************************
*
* Task priority, from low -> high
*
******************************************************************************/
#define OTHER_TASK_PRIORITY osPriorityNormal /* all APP task priority should <= osPriorityNormal*/
#define CMS_TASK_PRIORITY osPriorityNormal2
//#define TCPIP_THREAD_PRIO 26 //osPriorityNormal2
#define CCM_TASK_PRIORITY osPriorityAboveNormal
#define UICC_CTRL_TASK_PRIORITY osPriorityAboveNormal1
#define CENAS_TASK_PRIORITY osPriorityAboveNormal2
#define CERRC_TASK_PRIORITY osPriorityAboveNormal4
#define CEUP_TASK_PRIORITY osPriorityAboveNormal7
//#define configTIMER_TASK_PRIORITY 40 //osPriorityHigh
#define UICC_DRV_TASK_PRIORITY osPriorityHigh1 //UICC DRV task should have more high priority
typedef enum OsaTaskIdTag /* tasks sent to identified by their task ids */
{
CCM_TASK_ID, // 0
NAS_TASK_ID, // 1
CERRC_TASK_ID, // 2
CEUP_TASK_ID, // 3
UICC_CTRL_TASK_ID, // 4
UICC_DRV_TASK_ID, // 5
CMS_TASK_ID, // 6, CMS (Communication Modem Service) task
NUM_OF_REAL_TASKS,
CEPHY_TASK_ID ,
} OsaTaskId;
/*******************************************************************************
* Typedef : PsTaskInitDefTag
*
* Type : structure
* Description : This structure is used to hold information about a task that
* needs to be created at run time. This is the base type of
* the psTaskInitTable array. NOTE: that this must hold only
* things that are known at compile time as the psTaskInitTable
* array is marked as constant i.e. in ROM.
*******************************************************************************/
typedef struct PsTaskInitDefTag
{
/* Member: task id of this task. */
OsaTaskId taskId;
/* Member: void *() entryPoint = Pointer to entry point function for
** this task. */
void (*entryPoint)();
/* Member: void *stack = A pointer to the memory to use for this tasks
** stack. */
void *stack;
/* Member: Int16 stackSize = The number bytes in this tasks stack. */
INT16 stackSize;
/* Member: Int16 priority = The priority of this task. */
INT16 priority;
void *queue;
INT16 queueSize;
const CHAR* taskName;
} PsTaskInitDef;
/** Function prototype for functions callback */
typedef void (*app_callback_fn)(void *ctx);
typedef struct appFunCbTag
{
app_callback_fn function;
void *ctx;
} appFunCb;
// number of Message Queue objects
#define MSGQUEUE_OBJECTS (4)
// message queue element typedef
typedef struct
{
uint32_t uart_chann; // current uart chann
uint32_t recv_cnt; // current receiver buffer coounter
} msgqueue_obj_t;
/*
* CMS task create
*/
void CmsTaskAndQCeate(osThreadFunc_t func, UINT32 stackSize, UINT32 queueCount, void *pStackMem, void *pQueueMem);
/*
* Whether CMS & AT task createds
*/
BOOL CmsTaskIsCreated(void);
/*
* Get CMS task ID
*/
osThreadId_t CmsTaskGetId(void);
/*
* create all PS tasks and their associated queues.
*/
void PsInitialiseTasks(BOOL taskCreatedBefore);
void PsOsGetLwipTaskMemory(void **tcbBuf, int *tcbSize, void **stackBuf, int *stackSize);
void registerAppEntry(osThreadFunc_t func, void *arg);
#else
#include "commontypedef.h"
#include "cmsis_os2.h" // ::CMSIS:RTOS2
/******************************************************************************
*
* Task STACK size
*
******************************************************************************/
#define PHY_HIGH_TASK_STACK_SIZE 1536
#define PHY_MID_TASK_STACK_SIZE 2048 // NOTE: 1536 is not enough, verified by zlfu @20200511
#define PHY_LOW_TASK_STACK_SIZE 1536 // NOTE: 1024 is not enough, verified by zlfu @20200511
//#define TCPIP_THREAD_STACKSIZE 2048
#define LWIP_TASK_STACK_SIZE 1536
/******************************************************************************
*
* Task signal queue size
*
******************************************************************************/
#define PHY_HIGH_TASK_QUEUE_SIZE 10 // queue size of phy tasks
#define PHY_MID_TASK_QUEUE_SIZE 10 // queue size of phy tasks
#define PHY_LOW_TASK_QUEUE_SIZE 10 // queue size of phy tasks
/******************************************************************************
*
* Task priority, from low -> high
*
******************************************************************************/
#define PHY_LOW_TASK_PRIORITY osPriorityHigh5 //L1 low priority task
#define PHY_MID_TASK_PRIORITY osPriorityHigh6 //L1 task should have high priority
#define PHY_HIGH_TASK_PRIORITY osPriorityHigh7 //L1 low priority task
typedef enum OsaTaskIdTag /* tasks sent to identified by their task ids */
{
PHY_HIGH_TASK_ID, // For PHY HwTask Config only
PHY_MID_TASK_ID, // L1 task, used for parse message from PS
PHY_LOW_TASK_ID, // L1 low priority task
NUM_OF_REAL_TASKS
} OsaTaskId;
/*******************************************************************************
* Typedef : PsTaskInitDefTag
*
* Type : structure
* Description : This structure is used to hold information about a task that
* needs to be created at run time. This is the base type of
* the psTaskInitTable array. NOTE: that this must hold only
* things that are known at compile time as the psTaskInitTable
* array is marked as constant i.e. in ROM.
*******************************************************************************/
typedef struct PsTaskInitDefTag
{
/* Member: TaskId taskId = The GKI task id of this task. */
OsaTaskId taskId;
/* Member: void *() entryPoint = Pointer to entry point function for
** this task. */
void (*entryPoint)();
/* Member: void *stack = A pointer to the memory to use for this tasks
** stack. */
void *stack;
/* Member: Int16 stackSize = The number bytes in this tasks stack. */
INT16 stackSize;
/* Member: Int16 priority = The priority of this task. */
INT16 priority;
void *queue;
INT16 queueSize;
const CHAR* taskName;
} PsTaskInitDef;
/** Function prototype for functions callback */
typedef void (*app_callback_fn)(void *ctx);
typedef struct appFunCbTag
{
app_callback_fn function;
void *ctx;
} appFunCb;
// number of Message Queue objects
#define MSGQUEUE_OBJECTS (4)
// message queue element typedef
typedef struct
{
uint32_t uart_chann; // current uart chann
uint32_t recv_cnt; // current receiver buffer coounter
} msgqueue_obj_t;
//extern osThreadId_t psTaskIdTable[NUM_OF_REAL_TASKS];
//extern osMessageQueueId_t psQueueHandleTable[NUM_OF_REAL_TASKS];
void PsInitialiseTasks(void);
void registerAppEntry(osThreadFunc_t func, void *arg);
#endif
#endif

View File

@@ -0,0 +1,442 @@
#ifndef __PS_PDU_H__
#define __PS_PDU_H__
/******************************************************************************
******************************************************************************
Copyright: - 2017, All rights reserved by AirM2M Ltd.
File name: - pspdu.h
Description: - PS DATA PDU info
History: - 10/19/2018, Originated by Jason
******************************************************************************
******************************************************************************/
#ifdef WIN32
#include "winsys.h"
#else
#include "commontypedef.h"
#endif
/*
* UL PDU memory type
*/
typedef enum UlPduMemType_Tag
{
UL_HEAP_MEM = 0, // dynamic memory, OsaAllocMemory/OsaAllocZeroMemory/OsaFreeMemory
UL_LWIP_PKG_MEM, // LwipFreeUlIpPkgMem() free it
UL_STACK_MEM, // stack memory, don't need to free
UL_RBUF_MEM, // uldp rbuf memory, uldpRbufDequeue
UL_AFC_MEM, // ulfc memory, OsaUlfcFreeMem
UL_MEM_TYPE_MAX = 15
}UlPduMemType;
/*
* ticks type, which carried in "UlPduBlock"
*/
typedef enum UlPduTickType_Tag
{
UL_PDU_NO_TICK_INFO = 0,// no tick info
UL_PDU_DISCARD_TICK, // this UL PDU could be discarded if exceed this tick: "current tick" > "UL_PDU_DISCARD_TICK"
UL_PDU_START_TICK // systick when LWIP create/send this UL PDU
}UlPduTickType;
/*
* UL data PDU info, this just the UL user data need to send to NW
*
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* A: if UL data is "IP PKG" from LWIP, memtype = "UL_LWIP_PKG_MEM"
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Maybe need ROHC:
* Before ROHC:
* +------------------+-----------------------------------+
* | ip/udp/other hdr | payload |
* +------------------+-----------------------------------+
* ^
* |ptr
* |<------------------- length ------------------------->|
*
* After ROHC:
* 1> if (ip/udp/other hdr length) >= (comp len): (most case)
* +---------+--------+-----------------------------------+
* | |comp hdr| payload |
* +---------+--------+-----------------------------------+
* ^
* |ptr
* |<------->|validOffset
* | |<-------------- length -------------------->|
*
* 2> if (ip/udp/other hdr length) < (comp len):
* i> need to create a new "data_pdu_info" to store the compressed header
* ii> and this "data_pdu_info" only contain the payload info;
* +--------------------+
* | comp hdr |
* +--------------------+
* ^
* |ptr
* |<---- length ------>|
* bContinue = TRUE, and pNext ->
* +------------------+-----------------------------------+
* | ip/udp/other hdr | payload |
* +------------------+-----------------------------------+
* ^
* |ptr
* |<---------------->|validOffset
* | |<----------- length -------------->|
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* B: if UL data is not from LWIP, maybe from ATCMD, memtype = "UL_HEAP_MEM"
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* +------------------------------------------------------+
* | UL USER DATA |
* +------------------------------------------------------+
* ^
* |ptr
* |<------------------- length ------------------------->|
*
*/
typedef struct UlPduBlock_Tag
{
UINT8 memType :4; /* UlPduMemType
* indicate the "ptr" memory type, which would affect how to free the "*ptr" memory
*/
UINT8 bSameMem :1; /* whether the UlPduBlock and "ptr" use the same memory,
* if TRUE, this memory only need to free once,
* if not, UlPduBlock struct should allocated in heap, the memType indicated the memory type of ptr
*/
UINT8 bFreed :1; /* whether this UlPduBlock and ptr are freed, only used for USB Rx Cycle buffer */
UINT8 bContinue :1; /* Whether following seg belong to the same IP PKG:
* TRUE - next seg is the same IP PKG PDU
* FALSE - Not the same IP PKG PDU
*/
UINT8 pbufBefore :1; /* whether consecutive memory for "struct pbuf" before this block, set when allocate buffer */
UINT8 validOffset; /* Valid/real data offset, start from: ptr */
UINT16 length;
UINT8 *ptr;
struct UlPduBlock_Tag *pNext;
/*
* Other DATA info
*/
UINT32 epsId :4; /* epsId, should set in ESM task */
UINT32 esmRai :2; /* DataRelAssistIndEnum, release assistance indication, set in APP */
UINT32 bExceptData :1; /* need to pass to CEMM/CERRC, if "Except Data", CERRC need to establish connection even if it's barred, set in APP */
UINT32 bRohcFeedback :1; /* Whether this pkg is ROHC feedback pkg only, set in ROHC task */
UINT32 bRohcComped :1; /* Whether ROHC compressed in this pkg */
UINT32 bTestLoopback :1; /* Whether this UL data is test loop back data*/
UINT32 tickType :2; /* UlPduTickType, indicate the "sysTick" type */
UINT32 pppCrcNok :1; /* PPP deescape, whether CRC checked failed */
UINT32 fastPathNextAction :2; /*the ul pdu hase process by fastpath. and the next action is rohc process*/ /*UlPduNextActType*/
UINT32 rsvd0 :1;
UINT32 chanNo :5; /* for uldp UL_RBUF_MEM */
UINT32 rsvd :11;
/*
* Note:
* 1> if "systick" is "UL_PDU_DISCARD_TICK", then PS (DR/ESM/EMM) MAYBE (not must) discard this pkg, if "current sys tick" > "sysTick";
* LWIP could set this if has a clear valid period for this UL PKG, such as: TCP pkg, or DNS/IPv6 RS pkg (as has retry timer);
* 2> if "systick" is "UL_PDU_START_TICK", then PS (DR/ESM/EMM) MAYBE (not must) discard this pkg in case:
* a> the time passed more than 20s, and b> has anyother UL pkg followed;
* 3> if "systick" is "UL_PDU_NO_TICK_INFO", then PS (DR/ESM/EMM) could try best to send it, don't discard it easily;
*
* Another note:
* 1> DR/ESM will pending not more then (3*1500) bytes pkgs, or not more then 10 pkgs;
* if exceeded, will discard the oldest pkg;
*/
UINT32 sysTick; /*system tick, type is indicated by: tickType */
}UlPduBlock; //20 bytes
#define UL_PDU_BLOCK_SET_BASICS(ulpdu, chno, mtype, bsame, buf, len, bpbuf, bcont, next) \
do\
{\
((UlPduBlock*)(ulpdu))->chanNo = (chno);\
((UlPduBlock*)(ulpdu))->memType = (mtype);\
((UlPduBlock*)(ulpdu))->bSameMem = (bsame);\
((UlPduBlock*)(ulpdu))->ptr = (buf);\
((UlPduBlock*)(ulpdu))->validOffset = 0;\
((UlPduBlock*)(ulpdu))->length = (len);\
((UlPduBlock*)(ulpdu))->pbufBefore = (bpbuf);\
((UlPduBlock*)(ulpdu))->bContinue = (bcont);\
((UlPduBlock*)(ulpdu))->pNext = (next);\
}while(0)
#define UL_PDU_BLOCK_INCR(ulpdu, n) \
do\
{\
EC_ASSERT(((UlPduBlock*)(ulpdu))->length >= (n), ((UlPduBlock*)(ulpdu))->length, n, ulpdu);\
((UlPduBlock*)(ulpdu))->validOffset += (n);\
((UlPduBlock*)(ulpdu))->length -= (n);\
}while(0)
#define UL_PDU_BLOCK_DECR(ulpdu, n) \
do\
{\
EC_ASSERT(((UlPduBlock*)(ulpdu))->validOffset >= (n), ((UlPduBlock*)(ulpdu))->validOffset, n, ulpdu);\
((UlPduBlock*)(ulpdu))->validOffset -= (n);\
((UlPduBlock*)(ulpdu))->length += (n);\
}while(0)
/******************************************************************************
******************************************************************************
* DL PDU defination
******************************************************************************
******************************************************************************/
/*
* Reserved for ROHC decompression;
* 80 = ipv6 + udp + rtp + 20 others
*/
#define ROHC_DL_HDR_RSVD_LEN 80
#define LWIP_PBUF_STRUCT_LEN 24 //sizeof(pbuf)
/*
* +----------+----------+----------+---------+------------------------------------+---------+---------+
* | pbuf |DlPduBlock| RNDIS HDR|Ether HDR| ip pkg (len <= MTU) |Ether CRC|RNDIS PAD|
* +----------+----------+----------+---------|------------------------------------+---------+---------+
* | 24 bytes | 16 bytes | 44 bytes | 14 bytes| 28 ~ 1500 bytes | 4 bytes | 3 bytes |
*
* RNDIS_ETH_NET_DL_RESV_LEN = 44+14+7 = 65 ~= 68
*/
#define RNDIS_ETH_NET_DL_RSVD_HDR_LEN 60 // 44+14 = 58 ~= 60
#define RNDIS_ETH_NET_DL_RSVD_TAILER_LEN 8 // 4+3 = 7 ~= 8
/*
* Magic word
*/
#define DL_PDU_MAGIC_WORD 0xA7C5
/*
* set and check one magic byte
*/
#define DL_PDU_BLOCK_SET_MAGIC_WORD(pDlPduBlock) ((pDlPduBlock)->magicWord = DL_PDU_MAGIC_WORD)
#define DL_PDU_BLOCK_CHECK_MAGIC_WORD(pDlPduBlock) ((pDlPduBlock)->magicWord == DL_PDU_MAGIC_WORD)
/*
* DL PDU memory type
*/
typedef enum DlPduMemType_Tag
{
DL_HEAP_MEM = 0, // dynamic memory, GosAllocMemory/GosAllocZeroMemory/GosFreeMemory
DL_PS_PKG_MEM,
DL_AFC_MEM, // OsaDlfcFreeMem
DL_MEM_TYPE_MAX = 15
}DlPduMemType;
/*
* DL PDU memory type
*/
typedef enum DlPduIpType_Tag
{
DL_PDU_IP_TYPE_INVALID = 0, // invalid ip type
DL_PDU_IP_TYPE_V4 = 1, // invalid ip type
DL_PDU_IP_TYPE_V6 = 2, // invalid ip type
}DlPduIpType;
/*
* How LWIP/Txtask proc this DL PDU
*/
typedef enum DlPduNextActType_Tag
{
DL_PDU_NO_ACT = 0, /* No special action, default value.
* Case example: DLPDU(AT CMD) only need to transmit to USB host.
*/
DL_PDU_PARSE = 0, /* need parse received IP pkg, LWIP task response how to proc this DL IP pkg.
* 1> when PS (L2) recv a DL IP pkg, set to this value.
*/
DL_PDU_DISCARD = 1, /* This DL PDU need to discard, as PDU memory can't be freed in ISR, then if
* this DL PDU is useless, could set to this value, and discard it later in task
*/
DL_PDU_NAT_PAT_MAP = 2, /* This DL PDU need to NAT/PAT transliation
* Note: NAT/PAT transliation is handled in LWIP task
*/
DL_PDU_NEED_FRAGEMENT = 3, /* This DL PDU is too large, IP pkg length > LAN MTU size, it need fragment
*/
DL_PDU_NEED_MSS_CHECK = 4, /* TCP MSS adpt */
DL_PDU_NEED_WINDOWS_CHECK = 5, /* TCP widnows adpt, TCP SYN PKG */
DL_PDU_NEED_NDS_RELAY = 6, /* for RNDIS private IP solution, host DNS resolve need relay */
/* === to RNDIS host === */
DL_PDU_ADD_IPV4_ETH_RNDIS_HDR = 7, /* DL PDU to RNDIS host, need to add ethernet ipv4 header and RNDIS header */
DL_PDU_ADD_IPV6_ETH_RNDIS_HDR_0 = 8, /* DL PDU to RNDIS host, need to add ethernet ipv6 header and RNDIS header */
DL_PDU_ADD_IPV6_ETH_RNDIS_HDR_1 = 9, /* DL PDU to RNDIS host, need to add ethernet ipv6 header and RNDIS header */
DL_PDU_ADD_IPV6_ETH_RNDIS_HDR_2 = 10, /* DL PDU to RNDIS host, need to add ethernet ipv6 header and RNDIS header */
DL_PDU_ADD_RNDIS_HDR = 11, /* DL PDU to RNDIS host, need to add RNDIS header
* 1> if eth_type is not ipv4(0x0800U)/ipv6(0x86DDU) (enum eth_type in ethernet.h)
* need to set it in LWIP task
*/
/* === to PPP host === */
DL_PDU_ADD_IPV4_PPP_HDR = 12, /* DL PDU to PPP host, need to add IPv4 PPP header */
DL_PDU_ADD_IPV6_PPP_HDR = 13, /* DL PDU to PPP host, need to add IPv6 PPP header */
/* === to ECM host === */
DL_PDU_ADD_IPV4_ETH_ECM_HDR = 14, /* DL PDU to ECM host, need to add ethernet ipv4 header and ECM header */
DL_PDU_ADD_IPV6_ETH_ECM_HDR_0 = 15, /* DL PDU to ECM host, need to add ethernet ipv6 header and ECM header */
DL_PDU_ADD_IPV6_ETH_ECM_HDR_1 = 16, /* DL PDU to ECM host, need to add ethernet ipv6 header and ECM header */
DL_PDU_ADD_IPV6_ETH_ECM_HDR_2 = 17, /* DL PDU to ECM host, need to add ethernet ipv6 header and ECM header */
DL_PDU_ADD_ECM_HDR = 18, /* DL PDU to ECM host, need to add ECM HDR
* 1> if eth_type is not ipv4(0x0800U)/ipv6(0x86DDU) (enum eth_type in ethernet.h)
* need to set it in LWIP task
*/
/* === to local wan/UE local socket APP === */
DL_PDU_TO_LOCAL_WAN = 19, /* DL PDU is sent to local WAN/local socket APP */
DL_PDU_TO_LOCAL_TCP_WINDOWS_CHECK_ETH = 20,
DL_PDU_TO_LOCAL_TCP_WINDOWS_CHECK_PPP = 21,
DL_PDU_ACT_TYPE_MAX = 31
}DlPduNextActType;
/*
* How LWIP proc this UL PDU
*/
typedef enum UlPduNextActType_Tag
{
UL_PDU_PARSE = 0, /*need lwip parse and process*/
UL_PDU_ROHC_IP4 = 1, /*need do rohc with ip4 channel*/
UL_PDU_ROHC_IP6 = 2, /*need do rohc with ip6 channel*/
UL_PDU_ACT_TYPE_MAX = 3,
}UlPduNextActType;
/*
* DL PDU BLOCK info, just the DL user data
*
* 1> !!! "DlPduBlock" and "DL user data" should use the continuous memory !!!
* 2> !!! One "DlPduBlock" one DL IP packet !!!
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* A. if DL user PDU is IP PKG data, and need to pass to up layer
* this memory should be allocated in memory: DL_PS_PKG_MEM
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* DL IP PDU buffer:
* 1. If no ROHC:
* +----------+----------+----------+---------+------------------------------------+---------+---------+
* | pbuf |DlPduBlock| RNDIS HDR|Ether HDR| ip pkg (len <= MTU) |Ether CRC|RNDIS PAD|
* +----------+----------+----------+---------|------------------------------------+---------+---------+
* | 24 bytes | 16 bytes | 44 bytes | 14 bytes| 28 ~ 1500 bytes | 4 bytes | 3 bytes |
* *payload--------------------------------^
* pPdu-------------------------^
* length = |<---------------------------------->|
*
* 2. If ROHC Feedback:
* +--------------+---------------------------+
* | DlPduBlock | ROHC Feedback |
* +--------------+---------------------------+
* pPdu-----^
* length = |<------------------------->|
*
* 3. If ROHC, before decomp:
* +----------+----------+----------+---------+--------------------+--------+---------------------+---------+---------+
* | pbuf |DlPduBlock| RNDIS HDR|Ether HDR|ROHC_DL_HDR_RSVD_LEN|comp hdr| pkg data |Ether CRC|RNDIS PAD|
* +----------+----------+----------+---------|--------------------+--------+---------------------+---------+---------+
* | 24 bytes | 16 bytes | 44 bytes | 14 bytes| 80 bytes | 3 ~ 1500 bytes | 4 bytes | 3 bytes |
* pPdu----------------------------------------------^
* length = |<---------------------------->|
*
* Note: ROHC_DL_HDR_RSVD_LEN = 80, reserved for decompressed IP header, 80 = ipv6 + udp + rtp + 20 others
*
* After decomp:
* 3.1> If reserved 80 bytes is enough (most case):
* +----------+----------+----------+---------+------------+----------------+---------------------+---------+---------+
* | pbuf |DlPduBlock| RNDIS HDR|Ether HDR| | decomped ip hdr| pkg data |Ether CRC|RNDIS PAD|
* +----------+----------+----------+---------|------------+----------------+---------------------+---------+---------+
* | 24 bytes | 16 bytes | 44 bytes | 14 bytes|RSVD/useless| 28 ~ 1500 bytes | 4 bytes | 3 bytes |
* pPdu--------------------------------------^
* length = |<------------------------------------>|
* *payload----------------------------------------------^
*
* 3.2> If reserved 80 bytes is not enough (rarely)
* ROHC decompression side, need to allocate a new block (suggest also from : DL_PS_PKG_MEM), and soft copy to this new block;
* i> copy to ->
* +----------+----------+----------+---------+----------------+---------------------+---------+---------+
* | pbuf |DlPduBlock| RNDIS HDR|Ether HDR| decomped ip hdr| pkg data |Ether CRC|RNDIS PAD|
* +----------+----------+----------+---------|----------------+---------------------+---------+---------+
* | 24 bytes | 16 bytes | 44 bytes | 14 bytes| 28 ~ 1500 bytes | 4 bytes | 3 bytes |
* *payload--------------------------------^
* pPdu-------------------------^
* length = |<------------------------------------>|
*
* ii> Free the old block
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* A. if DL user PDU is not IP PKG data, (if need to LOOPBACK, or non-ip data)
* This memory should be allcated in HEAP
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* +----------+-----------------------------------+
* |DlPduBlock| PDCP User data |
* +----------+-----------------------------------+
* pPdu------^
* length = |<--------------------------------->|
*
*/
typedef struct DlPduBlock_Tag
{
UINT16 magicWord; // used to memory protection
UINT16 length;
/*
* !!! "DlPduBlock" and "pPdu" should use the continuous memory !!!
*/
UINT8 *pPdu;
struct DlPduBlock_Tag *pNext;
/*
* Other DATA info
*/
UINT32 dlMemType : 4; /* DlPduMemType */
UINT32 bOnlyDecomp : 1; /* Whether only need to do ROHC DECOMP, but don't need to pass to LWIP;
* Note:
* 1> During PDCP DL re-establishment procedure, here, as PDCP COUNT maybe re-order, DL PDCP SDU need to
* deciphered & decompressed, and stored in PDCP side;
* 2> Here, set it (in PDCP task), notify LWIP(ROHC) task only do decompression, but don't pass to LWIP task;
* 3> Set & Clear it in PDCP task;
*/
UINT32 bIgnoreDecomp : 1; /* If configed ROHC, whether need to ignore decompression for this pkg;
* Note:
* 1> PDCP set it, if pass re-order PDCP SDU, which decomped before
*/
UINT32 bRohcFeedback : 1; /* The PDU is ROHC feedback, not IP data, PDCP set it. */
UINT32 bRohcBuffRsvd : 1; /* whether reserved ROHC buffer with length: ROHC_DL_HDR_RSVD_LEN, in this DL PDU */
UINT32 pbufBefore : 1; /* whether memory for "struct pbuf" before this block, set when allocate buffer */
UINT32 bNetHdrRsvd : 1; /* whether reserved RNDIS/Ethernet header and padding, in this DL PDU */
UINT32 reserved0 : 1;
UINT32 nextAct : 5; /* DlPduNextActType, how LWIP/Tx task proc this DL PDU */
UINT32 reserved : 16;
}DlPduBlock; // 16 bytes
#define DL_PDU_BLOCK_SET_BASICS(dlpdu, mtype, buf, len, bpbuf, next) \
do\
{\
((DlPduBlock*)(dlpdu))->magicWord = DL_PDU_MAGIC_WORD;\
((DlPduBlock*)(dlpdu))->dlMemType = (mtype);\
((DlPduBlock*)(dlpdu))->pPdu = (buf);\
((DlPduBlock*)(dlpdu))->length = (len);\
((DlPduBlock*)(dlpdu))->pbufBefore = (bpbuf);\
((DlPduBlock*)(dlpdu))->pNext = (next);\
}while(0)
#endif

View File

@@ -0,0 +1,189 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename: reset.h
*
* Description: header of reset.c, for reset reason check
*
* History: 2021.04.02 initiated by Zhao Weiqi
*
* Notes:
*
******************************************************************************/
#ifndef RESET_H
#define RESET_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
#define RESET_REASON_MAGIC (0xACD20E00)
#define RESET_REASON_MASK (0xFFFFFF00)
#define DUMP_UNREADY_MAGIC (0x8)
#define DUMP_UNREADY_MASK (0xF)
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
typedef enum _EPAT_ResetReason_e
{
RESET_REASON_CLEAR = 0x80,
RESET_REASON_CPPOR = 0x90,
RESET_REASON_HARDFAULT = 0xA0,
RESET_REASON_ASSERT = 0xB0,
RESET_REASON_WDT = 0xC0,
RESET_REASON_BAT = 0xD0,
RESET_REASON_TEMP = 0xE0,
RESET_REASON_FOTA = 0xF0,
}ResetReason_e;
typedef enum
{
LAST_RESET_POR = 0,
LAST_RESET_NORMAL, // can be sleep2/hib
LAST_RESET_SWRESET,
LAST_RESET_HARDFAULT,
LAST_RESET_ASSERT,
LAST_RESET_WDTSW,
LAST_RESET_WDTHW,
LAST_RESET_LOCKUP,
LAST_RESET_AONWDT,
LAST_RESET_BATLOW,
LAST_RESET_TEMPHI,
LAST_RESET_FOTA,
LAST_RESET_CPRESET,
LAST_RESET_UNKNOWN,
LAST_RESET_MAXNUM,
}LastResetState_e;
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
#ifdef CORE_IS_CP
/**
* @brief ResetReasonWriteCP
* @details CP write reset reason
* @param
* @note
*/
void ResetReasonWriteCP(ResetReason_e reason);
/**
* @brief cpNVIC_SystemReset
* @details call this api to process cp system reset,
do not call __NVIC_SystemReset
* @param
* @note
*/
void cpNVIC_SystemReset(void);
/**
* @brief cpClearBootFlag
* @details clear cp boot flag when enter hardfault or assert, in case of lockup happens
* @param
* @note
*/
void cpClearBootFlag(void);
#else
/**
* @brief ResetReasonWriteAP
* @details AP write reset reason
* @param
* @note
*/
void ResetReasonWriteAP(ResetReason_e reason);
/**
* @brief ResetCheckCpNeedPorReset
* @details or cp reset ap cases, always trigger a por reset
* @param
* @note
*/
void ResetCheckCpNeedPorReset(void);
/**
* @brief ResetReasonInit
* @details call in AP bsp customInit to print reset reason
* @param
* @note
*/
void ResetReasonInit(void);
/**
* @brief ResetReasonCpRstCheck
* @details call in CP Rst Irq to update cp reset reason
* @param
* @note
*/
void ResetReasonCpRstCheck(void);
/**
* @brief ResetStateGet
* @details get last reset state
* @param
* @note
*/
void ResetStateGet(LastResetState_e *apRstState, LastResetState_e *cpRstState);
/**
* @brief ResetLockupCfg
* @details set ap and cp lockup process, this settings will store in aon
set true to reset when lockup happen. set false will stop cpu when lockup happen
* @param
* @note
*/
void ResetLockupCfg(bool apLockupRstEn, bool cpLockupRstEn);
/**
* @brief ResetApplyAPLockupCfg
* @details get ap lockup settings from aon and apply
* @param
* @note
*/
void ResetApplyAPLockupCfg(void);
/**
* @brief ResetECSystemReset
* @details System reset, call this api is more safe than _NVIC_SystemReset
* @param
* @note
*/
void ResetECSystemReset(void);
/**
* @brief ResetStartPorReset
* @details process a por reset, a reset magic is write to flash in this api
* @param
* @note
*/
void ResetStartPorReset(ResetReason_e reason);
/**
* @brief ResetIsSwPorReset
* @details check flash to decide whether it is por reset
use to bypass pwrkey debounce flow
* @param
* @note
*/
bool ResetIsSwPorReset(ResetReason_e *pReason);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,118 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename: rndis_entity.h
*
* Description:
*
* History: 2021/1/19 created by xuwang
*
* Notes:
*
******************************************************************************/
#ifndef RNDIS_ENTITY_H
#define RNDIS_ENTITY_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
#if 0
typedef struct
{
/* inherited field & MUST be placed on the top! */
CcioEntity_t base;
uint8_t lanState; /* refer to 'CcioLanMediaState_e', via monitor/user */
uint8_t pdp4Cid; /* ipv4 pdp context Id, via monitor */
uint8_t pdp6Cid; /* ipv6 pdp context Id, via monitor */
uint8_t rsvd;
void *extras; /* for user context. */
/* TODO: statistic, via monitor */
}RndisEntity_t;
#else
typedef EtherEntity_t RndisEntity_t;
#endif
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
/**
* @brief crioInitEntity(SerialEntity_t *serlEnt, chentStatusCallback statusCb, void *extras)
* @details create a rndis entity
*
* @param rndisEnt The entity to be created
* @param status_cb The handler of entity status
* @param extras The user's extra info/useful context
* @return 0 succ; < 0 failure with errno.
*/
int32_t crioInitEntity(RndisEntity_t *rndisEnt,
chentStatusCallback statusCb,
void *extras);
/**
* @brief crioDeinitEntity(RndisEntity_t *rndisEnt)
* @details delete/reset a rndis entity
*
* @param rndisEnt The entity to be deleted
* @return 0 succ; < 0 failure with errno.
*/
int32_t crioDeinitEntity(RndisEntity_t *rndisEnt);
/**
* @brief crioSetUpChannel(RndisEntity_t *rndisEnt)
* @details establish a rndis channel
*
* @param rndisEnt The entity to be established the channel
* @return 0 succ; < 0 failure with errno.
*/
int32_t crioSetUpChannel(RndisEntity_t *rndisEnt);
/**
* @brief crioPullDownChannel(RndisEntity_t *rndisEnt)
* @details destroy a rndis channel
*
* @param rndisEnt The entity to be destroied the channel
* @return 0 succ; < 0 failure with errno.
*/
int32_t crioPullDownChannel(RndisEntity_t *rndisEnt);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,317 @@
#ifndef _RNDIS_H
#define _RNDIS_H
#include <stdint.h>
#define RNDIS_MAJOR_VERSION 1
#define RNDIS_MINOR_VERSION 0
#define RNDIS_STATUS_SUCCESS 0X00000000
#define RNDIS_STATUS_FAILURE 0XC0000001
#define RNDIS_STATUS_INVALID_DATA 0XC0010015
#define RNDIS_STATUS_NOT_SUPPORTED 0XC00000BB
#define RNDIS_STATUS_MEDIA_CONNECT 0X4001000B
#define RNDIS_STATUS_MEDIA_DISCONNECT 0X4001000C
/* Message set for Connectionless (802.3) Devices */
#define REMOTE_NDIS_PACKET_MSG 0x00000001
#define REMOTE_NDIS_INITIALIZE_MSG 0X00000002
#define REMOTE_NDIS_HALT_MSG 0X00000003
#define REMOTE_NDIS_QUERY_MSG 0X00000004
#define REMOTE_NDIS_SET_MSG 0X00000005
#define REMOTE_NDIS_RESET_MSG 0X00000006
#define REMOTE_NDIS_INDICATE_STATUS_MSG 0X00000007
#define REMOTE_NDIS_KEEPALIVE_MSG 0X00000008
#define REMOTE_NDIS_INITIALIZE_CMPLT 0X80000002
#define REMOTE_NDIS_QUERY_CMPLT 0X80000004
#define REMOTE_NDIS_SET_CMPLT 0X80000005
#define REMOTE_NDIS_RESET_CMPLT 0X80000006
#define REMOTE_NDIS_KEEPALIVE_CMPLT 0X80000008
typedef uint32_t rndis_MessageType_t;
typedef uint32_t rndis_MessageLength_t;
typedef uint32_t rndis_RequestId_t;
typedef uint32_t rndis_MajorVersion_t;
typedef uint32_t rndis_MinorVersion_t;
typedef uint32_t rndis_MaxTransferSize_t;
typedef uint32_t rndis_Status_t;
/* Device Flags */
#define RNDIS_DF_CONNECTIONLESS 0x00000001
#define RNDIS_DF_CONNECTION_ORIENTED 0x00000002
typedef uint32_t rndis_DeviceFlags_t;
/* Mediums */
#define RNDIS_MEDIUM_802_3 0x00000000
typedef uint32_t rndis_Medium_t;
typedef uint32_t rndis_MaxPacketsPerTransfer_t;
typedef uint32_t rndis_PacketAlignmentFactor_t;
typedef uint32_t rndis_AfListOffset_t;
typedef uint32_t rndis_AfListSize_t;
/*** Remote NDIS Generic Message type ***/
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
} rndis_generic_msg_t;
/*** Remote NDIS Initialize Message ***/
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_RequestId_t RequestId;
rndis_MajorVersion_t MajorVersion;
rndis_MinorVersion_t MinorVersion;
rndis_MaxTransferSize_t MaxTransferSize;
} rndis_initialize_msg_t;
/* Response: */
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_RequestId_t RequestId;
rndis_Status_t Status;
rndis_MajorVersion_t MajorVersion;
rndis_MinorVersion_t MinorVersion;
rndis_DeviceFlags_t DeviceFlags;
rndis_Medium_t Medium;
rndis_MaxPacketsPerTransfer_t MaxPacketsPerTransfer;
rndis_MaxTransferSize_t MaxTransferSize;
rndis_PacketAlignmentFactor_t PacketAlignmentFactor;
rndis_AfListOffset_t AfListOffset;
rndis_AfListSize_t AfListSize;
} rndis_initialize_cmplt_t;
/*** Remote NDIS Halt Message ***/
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_RequestId_t RequestId;
} rndis_halt_msg_t;
typedef uint32_t rndis_Oid_t;
typedef uint32_t rndis_InformationBufferLength_t;
typedef uint32_t rndis_InformationBufferOffset_t;
typedef uint32_t rndis_DeviceVcHandle_t;
/*** Remote NDIS Query Message ***/
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_RequestId_t RequestId;
rndis_Oid_t Oid;
rndis_InformationBufferLength_t InformationBufferLength;
rndis_InformationBufferOffset_t InformationBufferOffset;
rndis_DeviceVcHandle_t DeviceVcHandle;
} rndis_query_msg_t;
/* Response: */
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_RequestId_t RequestId;
rndis_Status_t Status;
rndis_InformationBufferLength_t InformationBufferLength;
rndis_InformationBufferOffset_t InformationBufferOffset;
} rndis_query_cmplt_t;
/*** Remote NDIS Set Message ***/
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_RequestId_t RequestId;
rndis_Oid_t Oid;
rndis_InformationBufferLength_t InformationBufferLength;
rndis_InformationBufferOffset_t InformationBufferOffset;
rndis_DeviceVcHandle_t DeviceVcHandle;
} rndis_set_msg_t;
/* Response */
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_RequestId_t RequestId;
rndis_Status_t Status;
}rndis_set_cmplt_t;
/* Information buffer layout for OID_GEN_RNDIS_CONFIG_PARAMETER */
typedef uint32_t rndis_ParameterNameOffset_t;
typedef uint32_t rndis_ParameterNameLength_t;
typedef uint32_t rndis_ParameterType_t;
typedef uint32_t rndis_ParameterValueOffset_t;
typedef uint32_t rndis_ParameterValueLength_t;
#define PARAMETER_TYPE_STRING 2
#define PARAMETER_TYPE_NUMERICAL 0
typedef struct{
rndis_ParameterNameOffset_t ParameterNameOffset;
rndis_ParameterNameLength_t ParameterNameLength;
rndis_ParameterType_t ParameterType;
rndis_ParameterValueOffset_t ParameterValueOffset;
rndis_ParameterValueLength_t ParameterValueLength;
}rndis_config_parameter_t;
typedef uint32_t rndis_Reserved_t;
/*** Remote NDIS Soft Reset Message ***/
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_Reserved_t Reserved;
} rndis_reset_msg_t;
typedef uint32_t rndis_AddressingReset_t;
/* Response: */
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_Status_t Status;
rndis_AddressingReset_t AddressingReset;
} rndis_reset_cmplt_t;
/*** Remote NDIS Indicate Status Message ***/
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_Status_t Status;
rndis_Status_t StatusBufferLength;
rndis_Status_t StatusBufferOffset;
} rndis_indicate_status_t;
typedef uint32_t rndis_DiagStatus_t;
typedef uint32_t rndis_ErrorOffset_t;
typedef struct {
rndis_DiagStatus_t DiagStatus;
rndis_ErrorOffset_t ErrorOffset;
}rndis_diagnostic_info_t;
/*** Remote NDIS Keepalive Message */
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_RequestId_t RequestId;
}rndis_keepalive_msg_t;
/* Response: */
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_RequestId_t RequestId;
rndis_Status_t Status;
}rndis_keepalive_cmplt_t;
/*** Remote NDIS Data Packet ***/
typedef uint32_t rndis_DataOffset_t;
typedef uint32_t rndis_DataLength_t;
typedef uint32_t rndis_OOBDataOffset_t;
typedef uint32_t rndis_OOBDataLength_t;
typedef uint32_t rndis_NumOOBDataElements_t;
typedef uint32_t rndis_PerPacketInfoOffset_t;
typedef uint32_t rndis_PerPacketInfoLength_t;
typedef struct{
rndis_MessageType_t MessageType;
rndis_MessageLength_t MessageLength;
rndis_DataOffset_t DataOffset;
rndis_DataLength_t DataLength;
rndis_OOBDataOffset_t OOBDataOffset;
rndis_OOBDataLength_t OOBDataLength;
rndis_NumOOBDataElements_t NumOOBDataElements;
rndis_PerPacketInfoOffset_t PerPacketInfoOffset;
rndis_PerPacketInfoLength_t PerPacketInfoLength;
rndis_DeviceVcHandle_t DeviceVcHandle;
rndis_Reserved_t Reserved;
}rndis_data_packet_t;
typedef uint32_t rndis_ClassInformationOffset_t;
typedef uint32_t rndis_Size_t;
typedef uint32_t rndis_Type_t;
typedef struct{
rndis_Size_t Size;
rndis_Type_t Type;
rndis_ClassInformationOffset_t ClassInformationType;
}rndis_OOB_packet_t;
#include "ndis.h"
typedef enum rnids_state_e {
rndis_uninitialized,
rndis_initialized,
rndis_data_initialized
} rndis_state_t;
typedef struct {
uint32_t txok;
uint32_t rxok;
uint32_t txbad;
uint32_t rxbad;
uint16_t ext_notifyok;
uint16_t int_encbuf_notifyok;
uint8_t int_listbuf_notifyok;
uint8_t int_encbuf_srcmiss; //enc buf is send, but no encbuf src flag is set
uint8_t int_listbuf_srcmiss;
uint8_t int_listbuf_overlap_cnt;
uint8_t int_listbuf_rstdrop_cnt;
uint8_t int_listbuf_livedrop_cnt;
} usb_eth_stat_t;
typedef struct
{
rndis_state_t rndis_state;
uint32_t oid_packet_filter;
usb_eth_stat_t usb_eth_stat;
}rndis_ctrl_data_st;
void RdsProInitalMsgHdl(rndis_generic_msg_t *msgIn);
void RdsProQueryHdl(rndis_query_msg_t *m, rndis_ctrl_data_st *p_ctrl_data);
void FuncRndisInitNotify(void);
void FuncRndisHaltNotify(void);
void FuncRndisResetNotify(void);
uint32_t RndisGetEncBufSize(void);
void RdsProInitalMsgHdl(rndis_generic_msg_t *msgIn);
void RdsProQueryCmplt(rndis_query_msg_t *m, int status, const void *data, int size);
void RdsProQueryCmplt32(rndis_query_msg_t *m, int status, uint32_t data);
void RdsProQueryHdl(rndis_query_msg_t *m, rndis_ctrl_data_st *p_ctrl_data);
void RdsProCfgParaHdl(const char *data, int keyoffset, int valoffset, int keylen, int vallen);
void RdsProPktFilter(uint32_t newfilter);
void RdsProSetMsgHdl(rndis_set_msg_t *msgIn, rndis_ctrl_data_st *p_ctrl_data);
void RdsProResetMsgHdl(rndis_reset_cmplt_t *m, rndis_ctrl_data_st *p_ctrl_data);
void RdsProKeepAliveMsgHdl(rndis_keepalive_cmplt_t *m, uint32_t RequestId, rndis_ctrl_data_st *p_ctrl_data);
#define RNDIS_MTU 1500
#define RNDIS_LINK_SPEED 100000000
#define RNDIS_VENDOR "AirM2M"
#define RNDIS_HWADDR 0x20,0x89,0x84,0x6A,0x96,0xAB
#define RNDIS_MAX_PACK_PER_XFER 10
#define ETH_HEADER_SIZE 14
#define ETH_MAX_PACKET_SIZE ETH_HEADER_SIZE + RNDIS_MTU
#define ETH_MIN_PACKET_SIZE 60
#define RNDIS_RX_BUFFER_SIZE ((((ETH_MAX_PACKET_SIZE + sizeof(rndis_data_packet_t)) + 99) / 100) * 100 * 2)
#define RNDIS_TX_BUFFER_SIZE (ETH_MAX_PACKET_SIZE + sizeof(rndis_data_packet_t))
#endif /* _RNDIS_H */
/** @} */

View File

@@ -0,0 +1,209 @@
#ifndef __SCT_USB_TX_API_H__
#define __SCT_USB_TX_API_H__
/******************************************************************************
******************************************************************************
Copy right: 2017-, Copyrigths of AirM2M Ltd.
File name: sct_usb_tx_api.h
Description: SCT PPP and CRC API, external provide to app
History: 2020/12/02 Originated by Jason
******************************************************************************
******************************************************************************/
#include "pspdu.h"
/******************************************************************************
*****************************************************************************
* MARCO
*****************************************************************************
******************************************************************************/
/******************************************************************************
*****************************************************************************
* STRUCT
*****************************************************************************
******************************************************************************/
typedef enum
{
SCT_USB_TX_RET_OK = 0,
SCT_USB_TX_ERR = -1,
SCT_USB_TX_BUSY = -2
}SctUsbTxRetEnum;
typedef INT32 SctUsbTxRet;
/*
* USB Tx Block
*/
typedef DlPduBlock SctUsbTxBlock;
/*
* SCT USB ISR event
*/
typedef enum
{
SCT_USB_DEINT = 0, /* when USB plug out, or suspended */
SCT_USB_INIT = 1, /* USB is OK (EP enumed), and SCT could sent data to USBC TxFIFO, when USB plug in, or resumed */
SCT_USB_RESET = 2 /* USB is reseted, SCT USB channel should be reset, and wait USB init(OK) again. */
}SctUsbStateEvent;
/******************************************************************************
*****************************************************************************
* Functions
*****************************************************************************
******************************************************************************/
#define SCT_USB_TX_EP_PARALLEL
#ifdef SCT_USB_TX_EP_PARALLEL
/*
* SCT USB channel init config, and not enable EEA (Cipher) function.
*/
void SctUsbChanlInitConfig(BOOL timeOutInit);
/******************************************************************************
* SctUsbTxRawDataNew
* Description: SCT USB Tx raw data, without cipher/CRC/PPP operation.
* input: UINT32 epId //USB EP ID < 16
* SctUsbTxBlock *pTxHead //input, Tx block header
* SctUsbTxBlock *pTxTail //input, Tx block header
* BOOL allowConcatenated //input, whether allow serveral PDU Tx in one USB transfer
* output: SctUsbTxRet
* Comment:
* 1> As the MAX USB Tx transfer size is limited, Tx block maybe can't transmit one time
* then, "pRetHead" will return the next not transmited block header
* 2> This API return OK, just means block inserted into SCT FIFO, not means already
* transmited to USB host, so the caller: !!! can't free the block memory !!!
* let the SCT responsible for freeing it after SCT done
* 3> This API could only be called in USB TX task
* 4> The caller don't need any handling after called this API
******************************************************************************/
SctUsbTxRet SctUsbTxRawDataNew(UINT32 epId, SctUsbTxBlock *pTxHead, SctUsbTxBlock *pTxTail, BOOL allowConcatenated);
/******************************************************************************
* SctUsbTxPppDataNew
* Description: SCT USB Tx raw data, data need PPP escaption.
* input: UINT32 epId //USB EP ID < 16
* SctUsbTxBlock *pTxHead //input, Tx block header
* SctUsbTxBlock *pTxTail //input, Tx block header
* output: SctUsbTxRet
* Comment:
* 1> As the MAX USB Tx transfer size is limited, Tx block maybe can't transmit one time
* then, "pRetHead" will return the next not transmited block header
* 2> This API return OK, just means block inserted into SCT FIFO, not means already
* transmited to USB host, so the caller: !!! can't free the block memory !!!
* let the SCT responsible for freeing it after SCT done
* 3> This API could only be called in USB TX task
* 4> The caller don't need any handling after called this API
******************************************************************************/
SctUsbTxRet SctUsbTxPppDataNew(UINT32 epId, SctUsbTxBlock *pTxHead, SctUsbTxBlock *pTxTail);
#else
/*
* SCT USB channel init config, and not enable EEA (Cipher) function.
*/
//void SctUsbChanlInitConfig(void);
/******************************************************************************
* SctUsbTxRawData
* Description: SCT USB Tx raw data, without cipher/CRC/PPP operation.
* input: UINT32 epId //USB EP ID < 16
* SctUsbTxBlock *pTxHdr //input, Tx block header
* SctUsbTxBlock **pRetNext //output, next not Tx block header
* output: SctUsbTxRet
* Comment:
* 1> As the MAX USB Tx transfer size is limited, Tx block maybe can't transmit one time
* then, "pRetNext" will return the next not transmited block header
* 2> This API return OK, just means block inserted into SCT FIFO, not means already
* transmited to USB host, so the caller: !!! can't free the block memory !!!
* let the SCT responsible for freeing it after SCT done
* 3> This API could only be called in USB TX task
******************************************************************************/
SctUsbTxRet SctUsbTxRawData(UINT32 epId, SctUsbTxBlock *pTxHdr, SctUsbTxBlock **pRetNext);
/******************************************************************************
* SctUsbTxPppData
* Description: SCT USB Tx raw data, data need PPP escaption.
* input: UINT32 epId //USB EP ID < 16
* SctUsbTxBlock *pTxHdr //input, Tx block header
* SctUsbTxBlock **pRetNext //output, next not Tx block header
* output: SctUsbTxRet
* Comment:
* 1> As the MAX USB Tx transfer size is limited, Tx block maybe can't transmit one time
* then, "pRetNext" will return the next not transmited block header
* 2> This API return OK, just means block inserted into SCT FIFO, not means already
* transmited to USB host, so the caller: !!! can't free the block memory !!!
* let the SCT responsible for freeing it after SCT done
* 3> This API could only be called in USB TX task
* 4> The header and tailer PPP flag: "7E" inserted in this API, don't need to fill in caller
******************************************************************************/
SctUsbTxRet SctUsbTxPppData(UINT32 epId, SctUsbTxBlock *pTxHdr, SctUsbTxBlock **pRetNext);
#endif
/******************************************************************************
* SctUsbProcDoneChainInfo
* Description: SCT USB process chain done info
* input: BOOL *pSctAvailable //
* output: void
* Comment:
* 1> Called when USB Tx task scheduled
* 2> if "pSctAvailable" return TRUE, just means SCT USB channel is available again
* and the caller could Tx data again
******************************************************************************/
void SctUsbProcDoneChainInfo(BOOL *pSctAvailable);
/******************************************************************************
* SctUsbProcUsbEvent
* Description: SCT USB process USB event notification
* input: SctUsbStateEvent usbState
* output: void
* Comment:
* 1> Called when USB Tx task when USB event signal/message received
******************************************************************************/
void SctUsbProcUsbEvent(SctUsbStateEvent usbEvent);
#ifdef SCT_USB_TX_EP_PARALLEL
/******************************************************************************
* SctUsbProcTimerExpiry
* Description: SCT USB retry timer expiry handling
* input: UINT32 tid
* output: void
* Comment: Called when CCIO Tx task
******************************************************************************/
void SctUsbProcTimerExpiry(UINT32 tid);
/*
* SCT USB proc EP unblock signal, EP unblock now
*/
void SctUsbProcEpUnblock(UINT32 epId);
#endif
/******************************************************************************
* SctUsbCtsBeAllowSend
* Description: whether CTS(Clear to Send) signal (trigger in MCU side) allow UE
* to send data
* input: UINT32 epId
* BOOL bAllow //TRUE - allow to send, FALSE - not allow
* output: void
* Comment: Called in Tx task
* 1> if virtual CTS signal is not allow to send data via current USB EP,
* current USB EP will be blocked 10 seconds waiting for CTS allow signal,
* data will be pended during this time
* 2> if exceed 10 seconds, the pending data and following data are all discarded.
******************************************************************************/
void SctUsbCtsBeAllowSend(UINT32 epId, BOOL bAllow);
#endif

View File

@@ -0,0 +1,83 @@
#ifndef SCT_DEF_H
#define SCT_DEF_H
#ifndef RAM_BOOT_AP
#define RAM_BOOT_AP
#define RAM_BOOT_CODE __attribute__((__section__(".ramBootCode")))
#endif
//boost power up speed clk init code
#define QSPI_XIPSTART_IN_AP_RAM __attribute__((__section__(".XIPStartRamCode")))
// for plat use only, only used in bootloader for HW SHA256, since SCT could only access MSMB
// But this area should init by user
#define PLAT_BL_SCT_ZI __attribute__((__section__(".platBlSctZIData")))
// ap section define
// for ps use only, load before paging image, placed in asmb
#define PS_PA_RAMCODE __attribute__((__section__(".psPARamcode")))
// for ps use only, load before paging image, placed in msmb
#define PS_PM_RAMCODE __attribute__((__section__(".psPMRamcode")))
// for ps use only, load before full image, placed in asmb
#define PS_FA_RAMCODE __attribute__((__section__(".psFARamcode")))
// for ps use only, load before full image, placed in msmb
#define PS_FM_RAMCODE __attribute__((__section__(".psFMRamcode")))
// for plat use only, load before paging image, placed in asmb
#define PLAT_BOOT_RAMCODE_FLASHCLK __attribute__((__section__(".platBootRamcodeFCLK")))
// for plat use only, load before paging image, placed in asmb
#define PLAT_PA_RAMCODE __attribute__((__section__(".platPARamcode")))
// for plat use only, load before paging image, placed in msmb
#define PLAT_PM_RAMCODE __attribute__((__section__(".platPMRamcode")))
// for plat use only, load before full image, placed in asmb
#define PLAT_FA_RAMCODE __attribute__((__section__(".platFARamcode")))
// for plat use only, load before full image, placed in msmb
#define PLAT_FM_RAMCODE __attribute__((__section__(".platFMRamcode")))
// ram code to set flash clock
#define PLAT_PM_RAMCODE_FLASHCLK __attribute__((__section__(".platPMRamcodeFCLK")))
// data placed in asmb
#define PLAT_FA_ZI __attribute__((__section__(".platFAZIData")))
#define PLAT_FA_DATA __attribute__((__section__(".platFARWData")))
// rw and zi for ps use, init when fullimage start(only from hibernate and power on)
// never re-init if asmb not power off
#define PS_FA_ZI __attribute__((__section__(".psFAZIData")))
#define PS_FA_DATA __attribute__((__section__(".psFARWData")))
// up and down buffer
#define CAT_PSPHY_SHAREDATA __attribute__((__section__(".catShareBuf")))
// cp section define
// Most timing critical code, both used in paging&full image
// so need to copy from FLASH when wakeup from HIB
// NOTE: Paging&PreSync related CODE should only allocated to PHY_CODE_IN_CSMB0 or FLASH
#define CP_PLAT_CODE_IN_CSMB __attribute__((__section__(".cpPlatCodeCsmb")))
// Most timing critical code, only used in full image
// TX/RA/CSI/ConnMeas/CDRX should be allocate to CSMB1 or MSMB1
// so NO need to copy from FLASH when wakeup from HIB(these code do not used in paging image)
#define CP_PLAT_CODE_IN_MSMB __attribute__((__section__(".cpPlatCodeMsmb")))
#define CP_PLAT_CODE_IN_FLASH __attribute__((__section__(".cpPlatCodeFlash")))
// OS related, all dynamic allocated data, other static global data
#define CP_PLAT_DATA_IN_MSMB __attribute__((__section__(".cpPlatDataMsmb")))
#define CP_PLAT_DATA_IN_FLASH __attribute__((__section__(".cpPlatDataFlash")))
#ifndef USED
#define USED __attribute__((used))
#endif
#endif

View File

@@ -0,0 +1,248 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename: serial_entity.h
*
* Description:
*
* History: 2021/1/19 created by xuwang
*
* Notes:
*
******************************************************************************/
#ifndef SERIAL_ENTITY_H
#define SERIAL_ENTITY_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#include "lwip/netif.h"
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
#define ATOS_ENTITY_FLAGS_INIT 0x01 /* created */
#define ATOS_ENTITY_FLAGS_ACT 0x02 /* activated */
typedef uint8_t AtosEntFlags;
typedef enum
{
SERIAL_CHM_CMD_OFFLINE = 0,
SERIAL_CHM_CMD_ONLINE,
SERIAL_CHM_DATA_ONLINE,
SERIAL_CHM_MAXNUM
}SerialChanMode_e;
typedef struct
{
uint8_t flags; /* AtosEntFlags */
uint8_t atCid; /* at context Id between ps */
uint8_t outFmt; /* CcioOutXferFormat_e */
uint8_t rsvd;
void *extras; /* for user context. */
}AtosEntity_t;
typedef struct
{
uint8_t lanState; /* refer to 'CcioLanMediaState_e', via monitor/user */
uint8_t pdp4Cid; /* ipv4 pdp context Id, via monitor */
uint8_t pdp6Cid; /* ipv6 pdp context Id, via monitor */
uint8_t needAct; /* 0/1: need to activate pdp context or not? */
struct netif pppIf;
void *extras; /* for user context. */
//struct stats_proto link; /* statistic, via user */
}PpposEntity_t;
typedef struct
{
/* inherited field & MUST be placed on the top! */
CcioEntity_t base;
uint8_t baseOnly :1; /* if set 1, other fields are meaningless except baseEnt. */
uint8_t isChgMode :1; /* is channel mode changing or not? */
uint8_t rsvdBits :6;
uint8_t chanMode; /* refer to 'SerialChanMode_e', via monitor */
uint8_t rsvd[2];
uint32_t memThres; /* dlfc memory threshold */
osSemaphoreId_t semaId;
UlPduBlockList_t inList; /* for raw ppp via sct */
DlPduBlockList_t outList; /* for uart raw ppp */
AtosEntity_t at;
PpposEntity_t *ppp;
}SerialEntity_t;
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
/**
* @brief csioInitAtEntity(SerialEntity_t *serlEnt, chentStatusCallback statusCb, void *extras)
* @details create an AToS entity
*
* @param serlEnt The entity to be created
* @param isForPpp The entity is for ppp service or not
* @param status_cb The handler of entity status
* @param extras The user's extra info/useful context
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioInitAtEntity(SerialEntity_t *serlEnt,
uint8_t isForPpp,
chentStatusCallback statusCb,
void *extras);
/**
* @brief csioDeinitAtEntity(SerialEntity_t *serlEnt)
* @details delete/reset an AToS entity
*
* @param serlEnt The entity to be deleted
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioDeinitAtEntity(SerialEntity_t *serlEnt);
/**
* @brief csioInitPppEntity(SerialEntity_t *serlEnt, void *extras)
* @details create an PPPoS entity
*
* @param serlEnt The entity to be created
* @param extras The user's extra info/useful context
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioInitPppEntity(SerialEntity_t *serlEnt, void *extras);
/**
* @brief csioDeinitPppEntity(SerialEntity_t *serlEnt)
* @details delete/reset an PPPoS entity
*
* @param serlEnt The entity to be deleted
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioDeinitPppEntity(SerialEntity_t *serlEnt);
/**
* @brief csioInitDiagEntity(SerialEntity_t *serlEnt, chentStatusCallback statusCb, void *extras)
* @details create an DIAGoS entity
*
* @param serlEnt The entity to be created
* @param status_cb The handler of entity status
* @param extras The user's extra info/useful context
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioInitDiagEntity(SerialEntity_t *serlEnt,
chentStatusCallback statusCb,
void *extras);
/**
* @brief csioDeinitDiagEntity(SerialEntity_t *serlEnt)
* @details delete/reset an DIAGoS entity
*
* @param serlEnt The entity to be deleted
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioDeinitDiagEntity(SerialEntity_t *serlEnt);
/**
* @brief csioInitOpaqEntity(SerialEntity_t *serlEnt, chentStatusCallback statusCb, void *extras)
* @details create an opaqos entity
*
* @param serlEnt The entity to be created
* @param status_cb The handler of entity status
* @param extras The user's extra info/useful context
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioInitOpaqEntity(SerialEntity_t *serlEnt,
chentStatusCallback statusCb,
void *extras);
/**
* @brief csioDeinitOpaqEntity(SerialEntity_t *serlEnt)
* @details delete/reset an opaqoS entity
*
* @param serlEnt The entity to be deleted
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioDeinitOpaqEntity(SerialEntity_t *serlEnt);
/**
* @brief csioSetUpChannel(SerialEntity_t *serlEnt)
* @details establish a serial(AT or PPP) channel
*
* @param serlEnt The entity to be established the channel
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioSetUpChannel(SerialEntity_t *serlEnt);
/**
* @brief csioPullDownChannel(SerialEntity_t *serlEnt)
* @details destroy a serial(AT or PPP) channel
*
* @param serlEnt The entity to be destroied the channel
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioPullDownChannel(SerialEntity_t *serlEnt);
/**
* @brief csioSetChanMode(SerialEntity_t *serlEnt, SerialChanMode_e chanMode)
* @details set/change the serial channel mode
*
* @param serlEnt The serial entity whose chanMode is changed
* @param chanMode The value of new chan mode
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioSetChanMode(SerialEntity_t *serlEnt, SerialChanMode_e chanMode);
/**
* @brief csioTryAdjustDlfcMemThres(SerialEntity_t *serlEnt)
* @details try to adjust dlfc memory threshold according the serial baudrate
*
* @param serlEnt The serial entity whose dlfc memory threshold will be adjusted
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioTryAdjustDlfcMemThres(SerialEntity_t *serlEnt);
/**
* @brief csioTryRestoreDlfcMemThres(SerialEntity_t *serlEnt)
* @details try to restore dlfc memory threshold if adjusted
*
* @param serlEnt The serial entity whose dlfc memory threshold will be restored
* @return 0 succ; < 0 failure with errno.
*/
int32_t csioTryRestoreDlfcMemThres(SerialEntity_t *serlEnt);
/**
* @brief ccioHoldOnPppSessn(SerialEntity_t *serlEnt)
* @details switch to online command mode and hold on ppp sessn
*
* @param serlEnt The serial entity whose ppp sessn will be hold on
* @return 0 succ; < 0 failure with errno.
*/
int32_t ccioHoldOnPppSessn(SerialEntity_t *serlEnt);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,896 @@
/****************************************************************************
*
* Copy right: 2017-, Copyrigths of AirM2M Ltd.
* File name: slp_manager.h
* Description: EC618 platform sleep management header file
* History: 09/28/2018 Originated by wqzhao
*
****************************************************************************/
#ifndef SLP_MANAGER_H
#define SLP_MANAGER_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "mem_map.h"
#include "apmu_external.h"
/*
AT+ECPMUCFG=0,0 disable pmu and can debug on keil
AT+ECPMUCFG=1,1 enable pmu and enter wfi only
AT+ECPMUCFG=1,2 enable pmu and can enter sleep1
AT+ECPMUCFG=1,3 enable pmu and can enter sleep2
AT+ECPMUCFG=1,4 enable pmu and can enter hibernate
AT+ECPMUCFG? check current pmu state
*/
#define GD_FALSH 1
#define PY_FLASH 0
#define PMU_TIMING_CB_NUM 8
#if GD_FALSH
#define PMU_FLASH_WRITE_TIME_1SECTOR (39) // page write max time 2.4ms, 1 sector 38.4ms
#define PMU_PREHIB_EXPECTED_CODE_RUNNING_TIME (PMU_FLASH_WRITE_TIME_1SECTOR*4+2) // time for code running before sleep
#define PMU_PRESLP2_EXPECTED_CODE_RUNNING_TIME (PMU_FLASH_WRITE_TIME_1SECTOR*4+2) // time for code running before sleep
#endif
#define PMU_WORTH_HIB_TIME (80+PMU_PREHIB_EXPECTED_CODE_RUNNING_TIME)
#define PMU_POSTHIB_EXPECTED_CODE_RUNNING_TIME (27)
#define PMU_WORTH_SLP2_TIME (80+PMU_PRESLP2_EXPECTED_CODE_RUNNING_TIME)
#define PMU_POSTSLP2_EXPECTED_CODE_RUNNING_TIME (27)
#define PMU_PRESLP_EXPECTED_CODE_RUNNING_TIME (5)
#define PMU_POSTSLP_EXPECTED_CODE_RUNNING_TIME (2)
#define PMU_WORTH_SLEEP_TIME (50+PMU_PRESLP_EXPECTED_CODE_RUNNING_TIME+PMU_POSTSLP_EXPECTED_CODE_RUNNING_TIME)
typedef enum
{
DEEPSLP_TIMER_ID0 = 0, // num 0/1: 2 AONTimer, without flash storage, 2.5 hour in 100Hz
DEEPSLP_TIMER_ID1,
DEEPSLP_TIMER_ID2, // num 2-6: 5 HibTimer, need flash storage, 740 hour in 100Hz
DEEPSLP_TIMER_ID3,
DEEPSLP_TIMER_ID4,
DEEPSLP_TIMER_ID5,
DEEPSLP_TIMER_ID6,
DEEPSLP_TIMER_ID7 = 7, // num 7-9: Internal HibTimer for AirM2M only, 740 hour in 100Hz
DEEPSLP_TIMER_ID8 = 8,
DEEPSLP_TIMER_ID9 = 9,
}slpManTimerID_e;
typedef struct
{
uint16_t flash_write_time;
uint16_t prehib_coderun_time;
uint16_t preslp2_coderun_time;
uint16_t preslp1_coderun_time;
uint16_t posthib_coderun_time;
uint16_t postslp2_coderun_time;
uint16_t postslp1_coderun_time;
uint16_t worth_hib_time;
uint16_t worth_slp2_time;
uint16_t worth_slp1_time;
}pmuTimeCfg_t;
typedef enum
{
AonIOLatch_Disable = 0,
AonIOLatch_Enable = 1,
}IOLatchEn;
/*
//boot flag defination
typedef enum
{
BOOT_FROM_POWER_ON = 0x0,
BOOT_FROM_UNDEF = 0x1,
BOOT_FROM_SLEEP1 = 0x4,
BOOT_FROM_SLEEP2 = 0x5,
BOOT_FROM_HIBERNATE1 = 0x6,
BOOT_FROM_HIBERNATE2 = 0x7,
}BootFlag_e;
*/
/**
\addtogroup slpman_interface_gr
\{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
#define SLP_CALLBACK_USRDEF_MAX_NUM 8
#define SLP_PLAT_VOTE_MAX_NUM 32
#define SLP_PLAT_VOTE_INFO_LEN 9
// Flash mem for APP backup in power management-----just consider based on PS/PHY + offset(8K)
#define APP_BACKUP_XIP_ADDR (FLASH_MEM_BACKUP_ADDR + 0x2000)
#define APP_BACKUP_NONXIP_ADDR (FLASH_MEM_BACKUP_ADDR-FLASH_XIP_ADDR + 0x2000)
#define APP_BACKUP_SIZE (0x1000)
/**
\brief slpManLpState, to indicate in which sleep state should we call the backup and restore function.
*/
typedef enum
{
SLPMAN_INVALID_STATE = 0, /**< invalid deepsleep state */
SLPMAN_SLEEP1_STATE, /**< sleep1 state */
SLPMAN_SLEEP2_STATE, /**< sleep2 state */
SLPMAN_HIBERNATE_STATE, /**< hibernate state */
MAX_SLEEP_STATE,
}slpManLpState;
/**
\brief enum of sleep status for voting. we should always try to vote a higher status for power saving.
*/
typedef enum
{
SLP_ACTIVE_STATE = 0, /**< active state */
SLP_IDLE_STATE, /**< idle state */
SLP_SLP1_STATE, /**< sleep1 state */
SLP_SLP2_STATE, /**< sleep2 state */
SLP_HIB_STATE, /**< hibernate state */
SLP_STATE_MAX
}slpManSlpState_t;
typedef enum _EPAT_slpManWakeSrc_e_TAG
{
WAKEUP_FROM_POR = 0,
WAKEUP_FROM_RTC,
WAKEUP_FROM_PAD,
WAKEUP_FROM_LPUART,
WAKEUP_FROM_LPUSB,
WAKEUP_FROM_PWRKEY,
WAKEUP_FROM_CHARG,
}slpManWakeSrc_e;
/**
\brief definition of backup callback(called before sleep)
*/
typedef void(* slpManBackupCb_t)(void *pdata, slpManLpState state);
/**
\brief definition of restore callback(called after sleep)
*/
typedef void(* slpManRestoreCb_t)(void *pdata, slpManLpState state);
/**
\brief definition of deepsleep timer callback function
*/
typedef void (*slpManUsrDeepSlpTimerCb_Func)(uint8_t id);
/**
\brief definition of deepsleep timer callback function
*/
typedef void (*slpManPmuTimingChangeCb_Func)(void);
typedef slpManSlpState_t (* slpUserdefSleepCb_Func)(void);
/**
\brief a stucture for array to store backup function and it's parameters.
*/
typedef struct
{
slpManBackupCb_t backup_func; /**< function execute before enter sleep */
void *pdata; /**< a pointer to the input param of callback function */
}slpManBackupCbFunc_t;
/**
\brief a stucture for array to store restore function and it's parameters.
*/
typedef struct
{
slpManBackupCb_t restore_func; /**< function execute after sleep is exited. When sleep2 or hibernate success the function will not execute */
void *pdata; /**< a pointer to the input param of callback function */
}slpManRestoreCbFunc_t;
/**
\brief enum of error code used in slp manager
*/
typedef enum
{
RET_TRUE, /**< Error code: no error */
RET_UNKNOW_FALSE, /**< Error code: unknow error */
RET_CB_ARRAY_FULL, /**< Error code: callback array is full */
RET_CALLBACK_EXIST, /**< Error code: duplicate callback in callback array */
RET_CALLBACK_UNEXIST, /**< Error code: callback unexist */
RET_VOTE_SLP_OVERFLOW, /**< Error code: vote overflow (above 256) */
RET_VOTE_SLP_UNDERFLOW, /**< Error code: vote underflow (below 0) */
RET_ZERO_NAME_LEN, /**< Error code: input name is empty */
RET_INVALID_NAME, /**< Error code: input name has illegal character */
RET_VOTE_HANDLE_FULL, /**< Error code: no place for more vote handle */
RET_INVALID_HANDLE, /**< Error code: vote handle is invalid */
RET_INVALID_VOTE, /**< Error code: the vote state is invalid */
RET_VOTE_CONFLICT, /**< Error code: vote conflict */
RET_GIVEBACK_FAILED, /**< Error code: vote handle give back error */
RET_HANDLE_NOT_FOUND, /**< Error code: vote handle not found */
}slpManRet_t;
/**
\brief enum of predefined module for backup and restore functions.
*/
typedef enum
{
SLP_CALLBACK_GPR_MODULE = 0, /**< sleep callback of gpr module */
SLP_CALLBACK_PAD_MODULE, /**< sleep callback of pad module */
SLP_CALLBACK_DMA_MODULE, /**< sleep callback of dma module */
SLP_CALLBACK_GPIO_MODULE, /**< sleep callback of gpio module */
SLP_CALLBACK_LPUSART_MODULE, /**< sleep callback of lpusart module */
SLP_CALLBACK_LPUSB_MODULE, /**< sleep callback of lpusb module */
SLP_CALLBACK_USART_MODULE, /**< sleep callback of usart module */
SLP_CALLBACK_SPI_MODULE, /**< sleep callback of spi module */
SLP_CALLBACK_I2S_MODULE, /**< sleep callback of i2s module */
SLP_CALLBACK_UNILOG_MODULE, /**< sleep callback of unilog module */
SLP_CALLBACK_TIMER_MODULE, /**< sleep callback of timer module */
SLP_CALLBACK_I2C_MODULE, /**< sleep callback of i2c module */
SLP_CALLBACK_ADC_MODULE, /**< sleep callback of adc module */
SLP_CALLBACK_SIM_MODULE, /**< sleep callback of sim module */
SLP_CALLBACK_SCT_MODULE, /**< sleep callback of SCT module */
SLP_CALLBACK_WDT_MODULE, /**< sleep callback of WDT module */
SLP_CALLBACK_ALM_MODULE, /**< sleep callback of alarm module */
SLP_CALLBACK_ULDP_MODULE, /**< sleep callback of ULDP module */
SLP_CALLBACK_UTFC_MODULE, /**< sleep callback of UTFC module */
SLP_CALLBACK_KPC_MODULE, /**< sleep callback of KPC module */
SLP_CALLBACK_ATCMD_MODULE, /**< sleep callback of ATCMD module */
SLP_CALLBACK_MAX_NUM,
}slpCbModule_t;
typedef enum
{
// @ 1.8V level
IOVOLT_1_65V = 0,
IOVOLT_1_70V,
IOVOLT_1_75V,
IOVOLT_1_80V,
IOVOLT_1_85V,
IOVOLT_1_90V,
IOVOLT_1_95V,
IOVOLT_2_00V,
// @ 2.8V level
IOVOLT_2_65V = 8,
IOVOLT_2_70V,
IOVOLT_2_75V,
IOVOLT_2_80V,
IOVOLT_2_85V,
IOVOLT_2_90V,
IOVOLT_2_95V,
IOVOLT_3_00V,
// @ 3.3V level
IOVOLT_3_05V = 16,
IOVOLT_3_10V,
IOVOLT_3_15V,
IOVOLT_3_20V,
IOVOLT_3_25V,
IOVOLT_3_30V,
IOVOLT_3_35V,
IOVOLT_3_40V,
}IOVoltageSel_t;
/**
\brief enum of predefined module for backup and restore functions.
*/
typedef enum
{
SLP_VOTE_USART = 0, /**< vote module: Usart */
SLP_VOTE_LPUSART, /**< vote module: Lpusart */
SLP_VOTE_LPUSB, /**< vote module: Lpusb */
SLP_VOTE_I2C, /**< vote module: I2C */
SLP_VOTE_SPI, /**< vote module: SPI */
SLP_VOTE_I2S, /**< vote module: I2S */
SLP_VOTE_ADC, /**< vote module: ADC */
SLP_VOTE_DMA, /**< vote module: DMA */
SLP_VOTE_TIMER, /**< vote module: Timer */
SLP_VOTE_PWRKEY, /**< vote module: Pwrkey */
SLP_VOTE_MAX_NUM,
}slpDrvVoteModule_t;
/**
\brief a stucture to store driver vote flag and vote counter.
*/
typedef struct
{
uint32_t drv_vote_slp_bitmap; /**< vote bitmap of driver */
uint8_t vote_counter[SLP_VOTE_MAX_NUM]; /**< vote counter */
}slpManDrvVote_t;
/**
\brief a stucture to store platform(user defined) vote information.
*/
typedef struct
{
uint32_t plat_vote_slp1_bitmap; /**< vote bitmap of sleep1 */
uint32_t plat_vote_slp2_bitmap; /**< vote bitmap of sleep2 */
uint32_t plat_vote_hib_bitmap; /**< vote bitmap of hibernate */
uint32_t plat_vote_valid; /**< valid flag of platform vote */
uint8_t vote_counter[SLP_PLAT_VOTE_MAX_NUM]; /**< platform vote counter */
uint8_t plat_vote_info[SLP_PLAT_VOTE_MAX_NUM][SLP_PLAT_VOTE_INFO_LEN]; /**< platform vote information */
}slpManPlatVote_t;
/**
\fn slpManRet_t slpManRegisterPredefinedBackupCb(slpCbModule_t module, slpManBackupCb_t backup_cb,
void *pdata, slpManLpState state)
\brief Register the predefined backup callback functions.
\param[in] module predefined module
\param[in] backup_cb pointer to the function of backup
\param[in] pdata the input param of backup function
\return error code
*/
slpManRet_t slpManRegisterPredefinedBackupCb(slpCbModule_t module, slpManBackupCb_t backup_cb, void *pdata);
/**
\fn slpManRet_t slpManRegisterPredefinedRestoreCb(slpCbModule_t module, slpManBackupCb_t restore_cb,
void *pdata, slpManLpState state)
\brief Register the predefined restore callback functions.
\param[in] module predefined module
\param[in] restore_cb pointer to the function of restore
\param[in] pdata the input param of restore function
\return error code
*/
slpManRet_t slpManRegisterPredefinedRestoreCb(slpCbModule_t module, slpManRestoreCb_t restore_cb, void *pdata);
/**
\fn slpManRet_t slpManRegisterUsrdefinedBackupCb(slpManBackupCb_t backup_cb,
void *pdata)
\brief Register the usrdefined backup callback functions.
\param[in] backup_cb pointer to the function of backup
\param[in] pdata the input param of backup function
\return error code
*/
slpManRet_t slpManRegisterUsrdefinedBackupCb(slpManBackupCb_t backup_cb, void *pdata);
/**
\fn slpManRet_t slpManRegisterUsrdefinedRestoreCb(slpManBackupCb_t restore_cb,
void *pdata)
\brief Register the usrdefined restore callback functions.
\param[in] restore_cb pointer to the function of restore
\param[in] pdata the input param of restore function
\return error code
*/
slpManRet_t slpManRegisterUsrdefinedRestoreCb(slpManRestoreCb_t restore_cb, void *pdata);
/**
\fn slpManRet_t slpManUnregisterPredefinedBackupCb(slpCbModule_t module);
\brief Unregister the Predefined callback according to module
\param[in] module predefined module whose callback need unregister
\return error code
*/
slpManRet_t slpManUnregisterPredefinedBackupCb(slpCbModule_t module);
/**
\fn slpManRet_t slpManUnregisterPredefinedRestoreCb(slpCbModule_t module);
\brief Unregister the Predefined callback according to module
\param[in] module predefined module whose callback need unregister
\return error code
*/
slpManRet_t slpManUnregisterPredefinedRestoreCb(slpCbModule_t module);
/**
\fn slpManRet_t slpManUnregisterUsrdefinedBackupCb(slpManBackupCb_t backup_cb)
\brief Unregister the userdefined callback according to the callback function.
\param[in] backup_cb user defined callback which need unregister
\return error code
*/
slpManRet_t slpManUnregisterUsrdefinedBackupCb(slpManBackupCb_t backup_cb);
/**
\fn slpManRet_t slpManUnregisterUsrdefinedRestoreCb(slpManBackupCb_t restore_cb)
\brief Unregister the userdefined callback according to the callback function.
\param[in] restore_cb user defined callback which need unregister
\return error code
*/
slpManRet_t slpManUnregisterUsrdefinedRestoreCb(slpManRestoreCb_t restore_cb);
/**
\fn void slpManSetDrvVoteMask(uint32_t mask)
\brief driver vote mask. The vote of the driver is already done by sdk, but we can mask specific vote result.
\param[in] mask driver vote mask to set
\return none
*/
void slpManSetDrvVoteMask(uint32_t mask);
/**
\fn uint32_t slpManGetDrvVoteMask(void)
\brief get driver vote mask
\return driver vote mask
*/
uint32_t slpManGetDrvVoteMask(void);
/**
\fn void slpManGetDrvBitmap(uint32_t *bitmap, uint32_t *mask)
\brief get the driver's vote information
\param[out] bitmap the bitmap of vote information.
\param[out] mask set 1 means the specific driver always alow to sleep
\return none.
*/
void slpManGetDrvBitmap(uint32_t *bitmap, uint32_t *mask);
/**
\fn slpManSlpState_t slpManPlatGetSlpState(void)
\brief get which sleep state can we go now
\return the sleep state we can go.
*/
slpManSlpState_t slpManPlatGetSlpState(void);
/**
\fn slpManWakeSrc_e slpManGetWakeupSrc(void)
\brief get the reason of wakeup, por,rtc,pad...
\return wakeup reason.
*/
slpManWakeSrc_e slpManGetWakeupSrc(void);
/**
\fn void slpManGetPlatBitmap(uint32_t *slp_bitmap, uint32_t *slp2_bitmap, uint32_t *hib_bitmap)
\brief get the bitmap of vote information
\param[in] slp_bitmap the bitmap vote to sleep state.
\param[in] slp2_bitmap the bitmap vote to sleep2 state.
\param[in] hib_bitmap the bitmap vote to hibernate state.
\return none.
*/
void slpManGetPlatBitmap(uint32_t *slp_bitmap, uint32_t *slp2_bitmap, uint32_t *hib_bitmap);
/**
\fn slpManRet_t slpManApplyPlatVoteHandle(const char* name, uint8_t *handle)
\brief apply for a vote handle.
\param[in] name the name of the handle(max length is 8)
\param[out] handle the handle allocate to use
\return error code.
*/
slpManRet_t slpManApplyPlatVoteHandle(const char* name, uint8_t *handle);
/**
\fn slpManRet_t slpManGivebackPlatVoteHandle(uint8_t handle)
\brief give back the platform vote handle
\param[in] handle the platform vote handle.
\return error code.
*/
slpManRet_t slpManGivebackPlatVoteHandle(uint8_t handle);
/**
\fn uint8_t *slpManGetVoteInfo(uint8_t handle)
\brief Get Vote handle Name information according to the handle
\param[in] handle the platform vote handle.
\return error code.
*/
uint8_t *slpManGetVoteInfo(uint8_t handle);
/**
\fn slpManRet_t slpManPlatVoteDisableSleep(uint8_t handle, slpManSlpState_t status);
\brief vote for keep wakeup
\param[in] handle the platform vote handle.
\param[in] status input the sleep status. A handle can only vote to a specific status.
\return error code.
*/
slpManRet_t slpManPlatVoteDisableSleep(uint8_t handle, slpManSlpState_t status);
/**
\fn slpManRet_t slpManPlatVoteEnableSleep(uint8_t handle, slpManSlpState_t status);
\brief vote for going to sleep
\param[in] handle the platform vote handle.
\param[in] status input the sleep status. A handle can only vote to a specific status.
\return error code.
*/
slpManRet_t slpManPlatVoteEnableSleep(uint8_t handle, slpManSlpState_t status);
/**
\fn slpManRet_t slpManPlatVoteEnableSleep(uint8_t handle, slpManSlpState_t status);
\brief vote for going to sleep, and force the specific handle to clear all vote counter. This API should be
carefully use as it may force sleep without consider the vote counter
\param[in] handle the platform vote handle.
\param[in] status input the sleep status. A handle can only vote to a specific status.
\return error code.
*/
slpManRet_t slpManPlatVoteForceEnableSleep(uint8_t handle, slpManSlpState_t status);
/**
\fn slpManRet_t slpManCheckVoteState(uint8_t handle, slpManSlpState_t *pstate, uint8_t *counter);
\brief Check vote state according to the vote handle
\param[in] handle the platform vote handle.
\param[out] pstate output the sleep status of current handle, if return SLP_ACTIVE_STATE, means this handle is not used.
\param[out] counter vote counter, indicate how many times the specific handle votes,
slpManPlatVoteDisableSleep let the counter count down,
slpManPlatVoteEnableSleep let the counter count up
when conter = 0 the specific handle enable the sleep.
\return error code.
*/
slpManRet_t slpManCheckVoteState(uint8_t handle, slpManSlpState_t *pstate, uint8_t *counter);
/**
\fn slpManRet_t slpManFindPlatVoteHandle(const char* name, uint8_t *handle);
\brief Find a vote handle applied before according to the name
\param[in] name string of handle name.
\param[out] handle the platform vote handle.
\return error code.
*/
slpManRet_t slpManFindPlatVoteHandle(const char* name, uint8_t *handle);
/**
\fn void slpManSetPmuSleepMode(bool pmu_enable, slpManSlpState_t mode, bool save2flash);
\brief Disable or Enable Pmu, and set the deepest sleep mode.
\param[in] pmu_enable when enable pmu set pmu_enable = true
\param[in] mode valid only when pmu_enable is true.
\param[in] save2flash set whether the settings need to flush into flash
\return none.
*/
void slpManSetPmuSleepMode(bool pmu_enable, slpManSlpState_t mode, bool save2flash);
/**
\fn void slpManRegisterUsrSlpDepthCb(pmuUserdefSleepCb_Func callback);
\brief register a user callback function to control sleep depth
\param[in] callback input a callback function
\return none.
*/
void slpManRegisterUsrSlpDepthCb(slpUserdefSleepCb_Func callback);
/**
\fn void slpManAONIOLatchEn(IOLatchEn en);
\brief set to enable io retention during sleep, can use in bootloader
\param[in] en enable io retention
\return none.
*/
void slpManAONIOLatchEn(IOLatchEn en);
/**
\fn void slpManUsim1LatchEn(IOLatchEn en);
\brief when usim1 is used some AONIO will use, ec call this api to latch usim1 IO
\param[in] en enable io retention
\return none.
*/
void slpManUsim1LatchEn(IOLatchEn en);
/**
\fn IOLatchEn slpManAONIOGetLatchCfg(void);
\brief get io latch config
\return io latch config.
*/
IOLatchEn slpManAONIOGetLatchCfg(void);
/**
\fn void slpManAONIOPowerOn(void);
\brief power on ldo of aonio. Call this function and than use gpio driver to config the aonio. Can use in bootloader
\return none.
*/
void slpManAONIOPowerOn(void);
/**
\fn void slpManAONIOPowerOff(void);
\brief power off ldo of aonio. All AonIO will switch to low because of power loss. Can use in bootloader
\return none.
*/
void slpManAONIOPowerOff(void);
/**
\fn slpManSlpState_t slpManGetLastSlpState(void);
\brief check last sleep state
\return last sleep state
*/
slpManSlpState_t slpManGetLastSlpState(void);
/**
\fn void slpManDeepSlpTimerRegisterExpCb(slpManUsrDeepSlpTimerCb_Func cb);
\brief register user deep sleep timer expired callback
\param[in] cb input callback function
\return none
*/
void slpManDeepSlpTimerRegisterExpCb(slpManTimerID_e timerId, slpManUsrDeepSlpTimerCb_Func cb);
/**
\fn void slpManDeepSlpTimerStart(uint8_t timerId, uint32_t nMs);
\brief Start a User Deep Sleep Timer
\param[in] timerId timer id
\param[in] nMs timer value
\return none
*/
void slpManDeepSlpTimerStart(slpManTimerID_e timerId, uint32_t nMs);
/**
\fn bool slpManDeepSlpTimerIsRunning(uint8_t timerId);
\brief Check whether the deep sleep timer is running
\param[in] timerId timer id
\return true or false
*/
bool slpManDeepSlpTimerIsRunning(uint8_t timerId);
/**
\fn void slpManDeepSlpTimerDel(uint8_t timerId);
\brief Delete a deep sleep timer
\param[in] timerId timer id
\return none
*/
void slpManDeepSlpTimerDel(uint8_t timerId);
/**
\fn uint32_t slpManDeepSlpTimerRemainMs(uint8_t timerId);
\brief Delete a deep sleep timer
\param[in] timerId timer id
\return millisecond to timer expired, return 0xffffffff when timerId is invalid
*/
uint32_t slpManDeepSlpTimerRemainMs(uint8_t timerId);
/**
\fn uint8_t slpManGetWakeupPinValue(void);
\brief Get the bitmap of 6 Wakeup Pin Value, can use in bootloader
e.g. return 0x13 = 0b010011 means wakeup pad 4, wakeup pad 1 and wakeup pad 0 is high level,
the other wakeup pads is low level.
return 0x3F = 0b111111 means all wakeup pads are high level.
return 0x00 = 0b000000 means all wakeup pads are low level.
\return a bitmap of 6 pin value
*/
uint8_t slpManGetWakeupPinValue(void);
/**
\fn void slpManUpdateUserNVMem(void);
\brief Call this API to tell SDK that user NVMem area need update to flash.
The Update actually happened before sleep2 or hibernate.
\return none
*/
void slpManUpdateUserNVMem(void);
/**
\fn void slpManRestoreUsrNVMem(void)
\brief Restore UserNVMem from FileSystem to ram
\return none
*/
void slpManRestoreUsrNVMem(void);
/**
\fn uint8_t * slpManGetUsrNVMem(void);
\brief Get the pointer to the header of user NVMem which has the maximum size of (2048-32)=2016e.
User NVMem will be recovered by sdk after wakeup from sleep2, hibernate or power on.
User can access to user NVMem freely. It's the user's responsibility to ensure the data integrity of this area.
Illegal access to the offset larger than 4064 will cause hardfault.
\return none
*/
uint8_t * slpManGetUsrNVMem(void);
/**
\fn void slpManFlushUsrNVMem(void);
\brief Flush the User none volatile memory immediately to File System.
\return none
*/
void slpManFlushUsrNVMem(void);
/**
\fn void slpManStartWaitATTimer(void);
\brief Once Receive AT Command, can use this funtion to add a delay before sleep. The delay is slpWaitTime
Use AT+ECPCFG="slpWaitTime",4000 to set the slpWaitTime to 4000ms
\return none
*/
void slpManStartWaitATTimer(void);
/**
\fn void slpManWaitATTimerSet(uint16_t nMs, bool save2flash);
\brief Set the slpWaitTime used by slpManStartWaitATTimer function.
\param[in] nMs set slpWaitTime in micro second
\param[in] save2flash choose whether to save slpWaitTime settings to flash or not. We suggest to save this setting, as in hib/slp2 the setting will lost
\return none
*/
void slpManWaitATTimerSet(uint16_t nMs, bool save2flash);
/**
\fn void slpManNormalIOVoltSet(IOVoltageSel_t sel);
\brief select normal io voltage, can use in bootloader
\return none
*/
void slpManNormalIOVoltSet(IOVoltageSel_t sel);
/**
\fn IOVoltageSel_t slpManNormalIOVoltGet(void);
\brief Get normal io voltage, can use in bootloader
\return none
*/
IOVoltageSel_t slpManNormalIOVoltGet(void);
/**
\fn IOVoltageSel_t slpManAONIOVoltGet(void);
\brief Get normal io voltage, can use in bootloader
\return none
*/
IOVoltageSel_t slpManAONIOVoltGet(void);
/**
\fn void slpManAONIOVoltSet(IOVoltageSel_t sel);
\brief select aon io voltage, can use in bootloader
\return none
*/
void slpManAONIOVoltSet(IOVoltageSel_t sel);
/**
\fn bool slpManGetIOSelPin(void);
\brief IO 1828 Sel status read, can use in bootloader
\return true: NC, false: GND
*/
bool slpManGetIOSelPin(void);
/**
\fn bool slpManGetChargePinValue(void);
\brief get charge pad pin value, can use in bootloader
\return true: floating or high false: low
*/
bool slpManGetChargePinValue(void);
/**
\fn bool slpManGetPwrkeyPinValue(void);
\brief get pwrkey pin value, can use in bootloader
\return true: floating or high false: low
*/
bool slpManGetPwrkeyPinValue(void);
/**
\fn void slpManNormalIoPowerCtrl(bool isPwrOn);
\brief set normal io power on/off
\return none
*/
void slpManNormalIoPowerCtrl(bool isPwrOn);
/**
\fn void slpManSavePmuTimingCfg(pmuTimeCfg_t *cfg);
\brief Set Pmu Timing configure if presleep/postsleep callback takes too much time
\param[in] cfg new configure
\return none
*/
void slpManSavePmuTimingCfg(pmuTimeCfg_t *cfg);
/**
\fn void slpManGetCurrentPmuTimingCfg(pmuTimeCfg_t *cfg);
\brief Get current Pmu Timing configure for changing and set back by calling slpManSetPmuTimingCfg
\param[out] cfg current configure
\return none
*/
void slpManGetCurrentPmuTimingCfg(pmuTimeCfg_t *cfg);
/**
\fn uint32_t slpManGetEstimateSlpTime(void)
\brief Get estimated sleep time, used in userdefined backup callback.
The actual sleep time may be a little bit shorter(less than 100ms)
\return slpTime in ms
*/
uint32_t slpManGetEstimateSlpTime(void);
/**
\fn void slpManAPPSetAONFlag1(bool flag);
\brief One bit flag for app to use, valid in all sleep mode
when wakeup from hib/sleep2/sleep1, it is still the value before sleep
\param[in] flag one bit flag for app use
\return none
*/
void slpManAPPSetAONFlag1(bool flag);
/**
\fn bool slpManAPPGetAONFlag1(void);
\brief Get one bit flag set by slpManAPPSetAONFlag1
\return flag
*/
bool slpManAPPGetAONFlag1(void);
/**
\fn void slpManAPPSetAONFlag2(bool flag);
\brief One bit flag for app to use, valid in all sleep mode
when wakeup from hib/sleep2/sleep1, it is still the value before sleep
\param[in] flag one bit flag for app use
\return none
*/
void slpManAPPSetAONFlag2(bool flag);
/**
\fn bool slpManAPPGetAONFlag2(void);
\brief Get one bit flag set by slpManAPPSetAONFlag2
\return flag
*/
bool slpManAPPGetAONFlag2(void);
bool slpManExtIntPreProcess(uint8_t bitmap);
/**
\fn uint8_t slpManExcutePredefinedBackupCb(slpManLpState state)
\brief Excute the predefined backup function.
\param[in] state input the state of current sleep process
\return how many callback have been excute.
*/
uint8_t slpManExcutePredefinedBackupCb(slpManLpState state);
/**
\fn uint8_t slpManExcutePredefinedRestoreCb(slpManLpState state)
\brief Excute the predefined restore function.
\param[in] state input the state of current sleep process
\return how many callback have been excute.
*/
uint8_t slpManExcutePredefinedRestoreCb(slpManLpState state);
/**
\fn uint8_t slpManExcuteUsrdefinedBackupCb(slpManLpState state)
\brief Excute the user defined backup function.
\param[in] state input the state of current sleep process
\return how many callback have been excute.
*/
uint8_t slpManExcuteUsrdefinedBackupCb(slpManLpState state);
/**
\fn uint8_t slpManExcuteUsrdefinedRerstoreCb(slpManLpState state)
\brief Excute the user defined restore function.
\param[in] state input the state of current sleep process
\return how many callback have been excute.
*/
uint8_t slpManExcuteUsrdefinedRestoreCb(slpManLpState state);
/**
\fn slpManRet_t slpManDrvVoteSleep(slpDrvVoteModule_t module, slpManSlpState_t status)
\brief drivers vote to sleep.
\param[in] module input the vote module.
\param[in] status input the sleep status, user should try to vote to the deepest state.
\return error code
*/
slpManRet_t slpManDrvVoteSleep(slpDrvVoteModule_t module, slpManSlpState_t status);
/**
\fn void slpManProductionTest(uint8_t mode)
\brief for current test for sleep mode in production line only
\param[in] mode SLEEP1 = 0,
SLEEP2 = 1,
HIBERNATE1 = 2,
HIBERNATE2 = 3,
OFF = 4
\return none
*/
void slpManProductionTest(uint8_t mode);
/**
\fn uint32_t slpManGetWakeupSlowCnt(void)
\brief Get wakeup slow cnt
\return wakeup slow cnt
*/
uint32_t slpManGetWakeupSlowCnt(void);
/**
\fn uint32_t slpManGetCurSlowCnt(void)
\brief Get current slow cnt
\return current slow cnt
*/
uint32_t slpManGetCurSlowCnt(void);
/**
\fn uint32_t slpManGetSleepTime(void)
\brief Get sleep time
\return sleep time
*/
uint32_t slpManGetSleepTime(void);
/**
\fn void slpManStartPowerOff(void)
\brief call this api to enter off state
\return null
*/
void slpManStartPowerOff(void);
/**
\fn void slpManAonWdtFeed(void)
\brief Feed Aon Watch dog
\return null
*/
void slpManAonWdtFeed(void);
/**
\fn void slpManAonWdtStop(void)
\brief aon watchdog is always open when system start,
but you can stop aon watch dog through this api
\return null
*/
void slpManAonWdtStop(void);
/**
\fn void slpManGetRawFlashEraseCnt(void *flashCntAry)
\brief get pmu raw flash erase cnt
\return null
*/
void slpManGetRawFlashEraseCnt(void *flashCntAry);
/**
\fn slpManRet_t slpManRegisterPmuTimingCb(slpManPmuTimingChangeCb_Func timingCb)
\brief add a pmu timing change callback
\return null
*/
slpManRet_t slpManRegisterPmuTimingCb(slpManPmuTimingChangeCb_Func timingCb);
/**
\fn slpManRet_t slpManUnregisterPmuTimingCb(slpManPmuTimingChangeCb_Func timingCb)
\brief delete a pmutiming change callback
\return null
*/
slpManRet_t slpManUnregisterPmuTimingCb(slpManPmuTimingChangeCb_Func timingCb);
/**
\fn void slpManPmuTimingChangedReq(void)
\brief indicate pmu timing may change
\return null
*/
void slpManPmuTimingChangedReq(void);
/**
\fn void slpManGetCPVoteStatus(bool *cpSleeped, uint8_t *cpVote)
\brief get cp vote and sleep status
\return null
*/
void slpManGetCPVoteStatus(bool *cpSleeped, uint8_t *cpVote);
/**
\fn bool slpManGetCPWakeupFlag(void)
\brief 1: ap is wakeup for cp, 0: ap is wakeup by itself
\return null
*/
bool slpManGetCPWakeupFlag(void);
/**
\fn bool slpManIsLocalTimePrecise(void)
\brief whether the system time is sync to network
\return null
*/
bool slpManIsLocalTimePrecise(void);
/**
* @brief slpManGet6P25HZGlobalCnt
* @details A global count, to indicate how many second from power on till now, in 6.25HZ
* @param null
* @return global count in 6.25HZ
* @note
*/
uint32_t slpManGet6P25HZGlobalCnt(void);
/**
* @brief void slpManSetSleepLimitTime(bool slpLimitEn, uint32_t slpLimitTime)
* @details to limit the maximum sleep time.
In cfun0 state only, it always wakeup to application. Other wise it may keep in paging flow when cp time is shorter
* @param slpLimitEn: enable sleep time limit. slpLimitTime: sleep time in ms
* @return null
* @note
*/
void slpManSetSleepLimitTime(bool slpLimitEn, uint32_t slpLimitTime);
/** \} */
#endif

View File

@@ -0,0 +1,28 @@
#ifndef TIME_TRANSLATE_H
#define TIME_TRANSLATE_H
#include <stdint.h>
#include <stdbool.h>
typedef enum
{
SC_FREQ_32K=0,
SC_FREQ_2048=1,
SC_FREQ_100=2,
SC_FREQ_32000,
SC_FREQ_XXK,
// other possiable value
}ScFreq;
uint32_t SlowCounterToSysTick(uint32_t scCntValue, ScFreq freq);
uint32_t SlowCounterToMs(uint32_t scCntValue, ScFreq freq);
uint32_t SysTickToSlowCounter(uint32_t ticks, ScFreq freq);
uint32_t SlowCounterTo8HzCounter(uint32_t delta_sc_value, ScFreq freq, uint32_t *remain, bool need_compensate);
void SlowCounter32KTSave(uint32_t freq);
uint32_t SlowCounter32KTFreqGet(void);
#endif

View File

@@ -0,0 +1,494 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename:
*
* Description:
*
* History:
*
* Notes:
*
******************************************************************************/
#ifndef ULDP_H
#define ULDP_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#include "ec618.h"
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
/*DEFINE ULDP return code*/
#define ULDP_RET_OK (0)
#define ULDP_RET_ALREADY_EN (-1)
#define ULDP_PARA_ERROR (-2)
#define ULDP_NOT_INIT (-3)
#define ULDP_RET_FAIL (-4)
#define MAX_OEP_NUM 14
#define ULDP_REG_BASE 0x40070000
//#define USBC_REG_BASE 0x1A000000
//#define USBC_GRXSTSP_ADDR (USBC_REG_BASE+0x20)
//#define USBC_RXFIFO_BASE_ADDR (USBC_REG_BASE+0x1000)
#define DEST_BUFF_BASE_ADDR 0x00400000
#define RING_BUF_SIZE (0x2000)
#define PT_TEST_DATA_SIZE 0x20
/*5 USB devices
VCOM1: OUT=EP1 IN=EP2
VCOM2: OUT=EP2 IN=EP4
VCOM3: OUT=EP3 IN=EP6
VCOM4: OUT=EP4 IN=EP8
VCOM5: OUT=EP5 IN=EP10
RNDIS simulation use COM1, RX EP NUM=1 SCT TX EP NUM=2
AT use COM2, RX EP NUM=2,SCT TX EP NUM=4
UNILOG use COM3 RX EP NUM=3 TX EP=6
PPP use COM4 ,RX EP NUM=4 SCT TX EP NUM=8
TXFIFO NUM should be same as EP NUM
*/
#define ULDP_HDR_MAGIC 0x5B8E
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
// temp define here, should be a common define for ALL EP according to usage
typedef enum
{
USB_RX_EP_0= 0,
USB_RX_EP_1,
USB_RX_EP_2,
USB_RX_EP_3,
USB_RX_EP_4,
USB_RX_EP_5,
USB_RX_EP_6,
USB_RX_EP_7,
USB_RX_EP_8,
USB_RX_EP_9,
USB_RX_EP_10,
USB_RX_EP_11,
USB_RX_EP_12,
USB_RX_EP_13,
USB_RX_EP_SW=USB_RX_EP_13,
USB_RX_EP_MAX
} UsbRxEpNum_e;
// epn process mode
typedef enum
{
EPN_DATA_PROCESS_MODE_PT=0,
EPN_DATA_PROCESS_MODE_EXTRACT,
EPN_DATA_PROCESS_MODE_MAX
} UldpEPnMode_e;
// pt mode input data endian(byte order)
typedef enum
{
PT_MODE_RXDATA_LITTLE_ENDIAN=0,//default
PT_MODE_RXDATA_BIG_ENDIAN,
PT_MODE_RXDATA_ENDIAN_MAX
} UldpPTRxEndian_e;
//CRC method select
typedef enum
{
CRC_METHOD_RNDIS=0,//default
CRC_METHOD_PPP,
CRC_METHOD_COMMON,
CRC_METHOD_MAX
} UldpCrcMethod_e;
//RNDIS/PPP rx data(input to ULDP) endian(byte order)
typedef enum
{
RNDIS_PPP_RXDATA_BYTE_ORDER_NO_CHANGE=0,//default
RNDIS_PPP_RXDATA_BYTE_ORDER_CHANGE,
RNDIS_PPP_RXDATA_BYTE_ORDER_MAX
} UldpRdsPppRxByteOrder_e;
//uldp work mode
typedef enum
{
ULDP_RNDIS_MODE=0,
ULDP_PPP_MODE=1,
ULDP_PASS_THROUGH_MODE=2
}UldpWorkMode_e;
//rndis crc byte cnt
typedef enum
{
RNDIS_CRC_1_BYTE=0,//default
RNDIS_CRC_2_BYTE,
RNDIS_CRC_3_BYTE,
RNDIS_CRC_4_BYTE,
RNDIS_CRC_BYTE_MAX
}UldpRdsCrcByteCnt_e;
//rndis input byte bit swap
typedef enum
{
RNDIS_INBYTE_FROM_BIT7=0,
RNDIS_INBYTE_FROM_BIT0,//default
RNDIS_INBYTE_MAX
}UldpRdsInByteBitSwap_e;
//rndis CRC output bit swap
typedef enum
{
RNDIS_CRC_OUT_BIT_NO_SWAP=0,
RNDIS_CRC_OUT_BIT_SWAP,//default
RNDIS_CRC_OUT_BIT_SWAP_MAX
}UldpRdsCrcOutBitSwap_e;
//rndis CRC output bit complement
typedef enum
{
RNDIS_CRC_OUT_BIT_NO_COMPLE=0,
RNDIS_CRC_OUT_BIT_COMPLE,//default
RNDIS_CRC_OUT_BIT_COMPLE_MAX
}UldpRdsCrcOutBitComple_e;
//ppp input byte bit swap
typedef enum
{
PPP_INBYTE_FROM_BIT7=0,//default
PPP_INBYTE_FROM_BIT0,
PPP_INBYTE_MAX
}UldpPppInByteBitSwap_e;
//common CRC output bit swap
typedef enum
{
COMMON_CRC_OUT_BIT_NO_SWAP=0,
COMMON_CRC_OUT_BIT_SWAP,//default
COMMON_CRC_OUT_BIT_SWAP_MAX
}UldpComCrcOutBitSwap_e;
//common input byte bit swap
typedef enum
{
COMMON_INBYTE_FROM_BIT7=0,//default
COMMON_INBYTE_FROM_BIT0,
COMMON_INBYTE_MAX
}UldpComInByteBitSwap_e;
//common CRC output bit complement
typedef enum
{
COMMON_CRC_OUT_BIT_NO_COMPLE=0,//default
COMMON_CRC_OUT_BIT_COMPLE,
COMMON_CRC_OUT_BIT_COMPLE_MAX
}UldpComCrcOutBitComple_e;
//common crc byte cnt
typedef enum
{
COMMON_CRC_1_BYTE=0,//default
COMMON_CRC_2_BYTE,
COMMON_CRC_3_BYTE,
COMMON_CRC_4_BYTE,
COMMON_CRC_BYTE_MAX
}UldpComCrcByteCnt_e;
typedef struct UldpHdrInfo
{
uint32_t magicNum : 16; /* magic number use as a flag */
uint32_t descpInvalidDataNum : 8; /* PPP de-escape invalid data number*/
uint32_t resv24to31 : 8; /* reserve 8 bits */
uint32_t crcValue; /* crc value caculated by ULDP, SW may use it */
uint32_t msgLen: 16; /* byte counter only for data , no need to 4 bytes aligned */
uint32_t isRdsPppCmpl: 1; /* whether current RNDIS (PPP)packets in the transfer is complete 1-cmpl*/
uint32_t crcResult: 1; /* whether crc checking result is correct 1-correct*/
uint32_t resv18to23: 6; /* reserve 6 bits*/
uint32_t isPppHasInvalidData: 1; /* whether PPP has invalid data when de-escape 1-ppp has invalid data*/
uint32_t firstNoStartFlagPppPkt: 1; /* first PPP packet without 7E at the begainning*/
uint32_t resv26to27: 2; /* reserve 2 bits*/
uint32_t errRndisMsgType: 1; /* whether RNDIS message type is error, should be 0x1 1-error*/
uint32_t errRndisMsgLen: 1; /* whether RNDIS message length is error, should be >MinLen configured < MaxLen configured 1-error*/
uint32_t errRndisDataLen: 1; /* whether RNDIS data len is error,dataOffset+((dataLen+3)/4)*4 > msgLen 1-error*/
uint32_t errRndisMsgOfst: 1; /* whether RNDIS data offset is error, dataOffset should >=8 and 4 Bytes aligned, 1-error*/
}UldpHdrInfo_t; // 3*4=12 bytes
// typedef of register 'uldp_err_int_info'
typedef struct {
uint8_t uldpMode;// set uldp to PPP/RNIDS/PT(pass through)
uint8_t uldpHdrLen;//ULDP header len, should be 0 when PT mode, and should set to uldphdr(hw fill)+dlpduhdr(sw)
uint8_t crcEn; // CRC enable
uint8_t crcMethodSel;// PPP/RNDNIS/COMMON(defined by user)
//PT mode
uint8_t ptModeByteOrder;// only for PT mode ,0-- default little endian 1--big endian
//PPP mode
uint32_t pppInDataEndian;//0--default fetch RX data as little endian 1--fetch RX data as big endian
uint32_t pppCrcInitVal;//CRC init value,default 0xffff
uint32_t pppCrcFinalVal;//CRC expected final value, used to match with CRC result,default 0xf0b8
uint32_t pppInByteSwap;// 0--default CRC from in data[7], 1--CRC from in data[0]
uint32_t pppSpecData; // special match data pattern, should be "+++"
//RNDIS mode
uint32_t rndisMinLen;// min valid RNDIS length
uint32_t rndisInByteOrder;//0--default not change RX data byte order 1-- change RX data byte order
uint32_t rndisMaxLen;//RNDIS max length, if received length exceed this value, trigger int
uint32_t rndisCrcInitVal;//RNDIS init CRC value
uint32_t rndisCrcByteCnt;//0--1 byte 1--2 bytes 2--3 bytes 3--4 bytes, also for common CRC!!!!
uint32_t rndisInDataSwap;//1--default crc from in data[0] 0---crc from in data[7]
uint32_t rndisCrcInCompleCnt;//how many bytes should be ~ ,should be 4 and default is 4
uint32_t rndisOutBitSwap;// swap bit in CRC result
uint32_t rndisCrcBitComple;//0--CRC bit not ~ 1--default CRC bit ~
//common crc
uint32_t comCrcPoly;// Poly to direct how to do CRC
uint32_t comCrcInitVal;//CRC init value
uint32_t comCrcOutBitSwap;//CRC result bit swap
uint32_t comCrcInByteSwap; //0--default CRC from in data[7], 1--CRC from in data[0]
uint32_t comCrcOutComple;//0--default CRC reuslt not ~ 1--CRC reuslt ~
uint32_t comCrcInCompleCnt;//how many bytes shold be ~
uint32_t comCrcBitCnt;//0--8 bits 1-- 16 bits 2--24 bits 3--32 bits
} UldpCfgInfo_t;
typedef void (*uldpCallback_t)(uint8_t epNum, uint32_t xferCnt,uint32_t event);
// typedef of uldp galobal info
typedef struct {
uint8_t isUldpEnabled;// whether uldp is enbaled
uldpCallback_t uldpCallback;
} UldpCtrl_t;
/****** ULDP Event *****/
#define ULDP_EVENT_XFER_COMPLETE (1UL << 0) ///< current ULDP transfer is complete
#define ULDP_EVENT_PPP_SPECIAL_MATCH (1UL << 1) ///< current ULDP trasnfer is complete and last 3 bytes match special pattern,only for PPP OEP
#define ULDP_EVENT_BUF_NOT_AVLB (1UL << 2) ///< buffer is not enough
#define ULDP_EVENT_RNDIS_LEN_ERROR (1UL << 3) ///< RNDIS length is not correct
#define ULDP_EVENT_USB_STATUS_ERROR (1UL << 4) ///< USB fatal error, receive invalid rx status
#define ULDP_EVENT_AHB_ADDR_ERROR (1UL << 5) ///< USB AHB access error, sw bug
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
/**
\fn uldpInit(uldpCallback_t callback)
\brief used by USB driver, called when USBC init.
\param[in] callback pointer to ULDP int callback function
\note called when usb init, ULDP global and static configure
*/
int32_t uldpInit(uldpCallback_t callback);
/**
\fn uldpDinit( void )
\brief used by USB driver, called when USBC deinit.
\note called when usb init, ULDP global and static configure
*/
int32_t uldpDinit( void );
/**
\fn uldpCfgDataProc(UldpCfgInfo_t * pUldpCfg,UsbRxEpNum_e epNum)
\brief used by USB driver, called before enable next RX.
\param[in] pUldpCfg pointer to the configuration set by user
\param[in] epNum out endpoint number
\note 2 level configure for the ULDP process
1st level, ep configure pass through or data extract mode
2nd level: ep select data extract mode, configure PPP/RDNIS
select a need CRC method.
*/
int32_t uldpCfgDataProc(UldpCfgInfo_t * pUldpCfg,UsbRxEpNum_e epNum);
/**
\fn uldpCfgRxEpStaticPara(UsbRxEpNum_e epNum, uint32_t bufAddr,uint32_t buflen)
\brief static ep rx buffer configure, only need in case of ringbuf change e.g. BNA triggered
\param[in] epNum out endpoint number
\param[in] bufAddr buffer start address, should be 4 bytes aligned
\param[in] buflen buffer total length, should be 4 bytes aligned
\note called during init stage or BNA triggered stage
*/
int32_t uldpCfgRxEpStaticPara(UsbRxEpNum_e epNum, uint32_t bufAddr,uint32_t buflen);
/**
\fn int32_t uldpCfgRxEpPara(UsbRxEpNum_e epNum, uint8_t needUpdIdx, uint32_t idx,uint32_t avlbSize)
\brief used by USB driver, called before enable next RX.
\param[in] epNum out endpoint num
\param[in] needUpdIdx whether need to update rx index
\param[in] idx index which need tobe configured
\param[in] avlbSize avlbSize which need tobe configured
\note dynamic configure when transfer complete,called by USB driver
*/
int32_t uldpCfgRxEpPara(UsbRxEpNum_e epNum, uint8_t needUpdIdx, uint32_t idx,uint32_t avlbSize);
/**
\fn int32_t uldpEpBufInfoGet(uint8_t * para)
\brief used to get epn ringbuf current idx and avlbSize
\param[in] epNum out endpoint num
\param[in] pointer of idx used to return idx read from register
\param[in] pointer of avlbSize used to return avlbSize read from register
\return int32_t
\note idx and avlbSize is updated automaticly by ULDP HW when receive data from USB FIFO
*/
int32_t uldpEpBufInfoGet(UsbRxEpNum_e epNum, uint32_t * idx, uint32_t *avlbSize);
/**
\fn uldpCfgSwEpSrcPara(uint8_t * srcAddr, uint16_t * len)
\brief ram2ram mode source data setting
\param[in] srcAddr pointer to source address
\param[in] len data length which need tobe processed by ULDP
\note called when source data is prepared
*/
int32_t uldpCfgSwEpSrcPara(uint8_t * srcAddr, uint16_t len);
/**
\fn uldpCfgSwEpSrcPara(uint8_t * srcAddr, uint16_t * len)
\brief ram2ram mode source data setting
\param[in] srcAddr pointer to source address
\param[in] len data length which need tobe processed by ULDP
\note called when source data is prepared
*/
void uldpStartSwEp( void);
/**
\fn uldpSetPppDescpBmTbl(uint8_t* bmTblPtr,uint8_t offset,uint8_t len)
\brief used to configure the PPP de-escape bitmap table.
\param[in] bmTblPtr pointer to the table to be set ,should be uint32_t pointer
\param[in] offset the location to start set
\param[in] len actual set length(32bits*length)
\note called by PPP module when PPP neigoation. should be set per 32bits,
since ULDP register is 32bits. Offset indicates which 32bits to set,
offset=0 means set from the 1st register
*/
void uldpSetPppDescpBmTbl(uint32_t* bmTblPtr,uint8_t offset,uint8_t len);
/**
\fn int32_t uldpResume( void )
\brief used to resume ULDP after blocked by BNA error.
*/
void uldpResume( void );
/**
\fn uldpReset( void )
\brief called when need to reset ULDP.
\note called when need to reset ULDP.
*/
void uldpReset( void );
/**
\fn void uldpPppSpecDataSet(uint8_t * para)
\brief used to set PPP specical matching data, most case it should be "+++".
\param[in] para pointer to specical parameter need to be set
\return void
\note called when PPP initialized
*/
void uldpPppSpecDataSet(uint8_t * para);
/**
\fn uldpSetSetupAddr( uint32_t addr )
\brief used to set setup recv buffer addr.
\note called when need to reset ULDP.
*/
void uldpSetSetupAddr( uint32_t addr );
/**
\fn uldpRdsPppClr( void )
\brief called when need to clear ULDP RNDIS/PPP state.
\note called when need to clear ULDP RNDIS/PPP state.
*/
void uldpRdsPppClr( void );
/**
\fn uldpUsbEp0RecvHandle( void )
\brief used to handle EP0 recv data in polling mode
\return void
\note called only in EEh dump
*/
int32_t uldpUsbEp0RecvHandle( void );
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,29 @@
#ifndef __USB_BL_API_H__
#define __USB_BL_API_H__
#define VCOM_DBGEN
#ifdef VCOM_DBGEN
void vcomdbg_hex(uint32_t hex);
void vcomdbg_str(uint8_t* str);
void vcomdbg_str_and_hex(uint8_t* str, uint32_t hex);
#define VCDBG_STR(str) vcomdbg_str((uint8_t*)str)
#define VCDBG_STR_AND_HEX(str, hex) vcomdbg_str_and_hex((uint8_t*)str, hex)
#else
void vcomdbg_hex(uint32_t hex);
void vcomdbg_str(uint8_t* str);
void vcomdbg_str_and_hex(uint8_t* str, uint32_t hex);
#define VCDBG_STR(str)
#define VCDBG_STR_AND_HEX(str, hex)
#endif
#define ERR_DEV_BASE (-200)
#define ERR_DEV_NUM_REDEF(err) (ERR_DEV_BASE + err)
#define ERR_DEV_NO_CONNECT ERR_DEV_NUM_REDEF(-2)
#define ERR_DEV_RX_TIMOUT ERR_DEV_NUM_REDEF(-32)
#define ERR_DEV_TX_TIMOUT ERR_DEV_NUM_REDEF(-33)
#endif

View File

@@ -0,0 +1,137 @@
#ifndef __USB_EXT_INC_H__
#define __USB_EXT_INC_H__
uint8_t usblpw_retwkup_stack_restore(void);
void usblpw_retwkup_stack_enable(void);
//Important, do not modify this macro
#define USBC_CTRL_HIB_LITE_MODE 1
#if (USBC_CTRL_HIB_LITE_MODE==1)
#define USB_WKMON_TASK_EXIST 0
#else
#define USB_WKMON_TASK_EXIST 1
#endif
uint8_t usblpw_is_retwkups2_start(void);
uint8_t usblpw_is_retothwks2_start(void);
typedef enum {
usblpw_retothwk_stg_none =0,
usblpw_retothwk_stg_bt_pre_idle,
usblpw_retothwk_stg_bt_later_idle,
usblpw_retothwk_stg_bt_actv,
usblpw_retothwk_stg_hibslp2_wkmon,
usblpw_retothwk_stg_slp1_wkmon,
usblpw_retothwk_stg_succ,
usblpw_retothwk_stg_teminate,
}usblpw_retothwk_stg_type;
uint8_t usblpw_retothwk_set_bt_pre_idle_stage(void);
uint8_t usblpw_retothwk_set_bt_later_idle_stage(void);
uint8_t usblpw_retothwk_set_bt_actv_stage(void);
uint8_t usblpw_retothwk_set_hibslp2_wkmon_stage(void);
uint8_t usblpw_retothwk_set_slp1_wkmon_stage(void);
uint8_t usblpw_retothwk_set_terminate_stage(void);
uint8_t usblpw_retothwk_set_succ_stage(void);
void usblpw_clear_retothwk_proc_stat(void);
uint8_t usblpw_get_retothwk_stage(void);
usblpw_retothwk_stg_type usblpw_retothwk_get_cur_stg(void);
uint8_t usblpw_retothwk_cur_stg_none(void);
uint8_t usblpw_retothwk_cur_stg_bt_pre_idle(void);
uint8_t usblpw_retothwk_cur_stg_bt_later_idle(void);
uint8_t usblpw_retothwk_cur_stg_bt_actv(void);
uint8_t usblpw_retothwk_cur_stg_hibslp2_wkmon(void);
uint8_t usblpw_retothwk_cur_stg_slp1_wkmon(void);
uint8_t usblpw_retothwk_cur_stg_terminate(void);
uint8_t usblpw_retothwk_cur_stg_success(void);
#if (USBC_CTRL_HIB_LITE_MODE==0)
void usblpw_retothwk_set_pre_rest_illegal(uint8_t stage);
uint8_t usblpw_retothwk_pre_rest_chk_illegal(uint8_t stage);
uint8_t usblpw_retothwk_poll_gpwr_match(uint8_t stage);
uint8_t usblpw_retothwk_chk_pre_rest_worth(void);
uint8_t usblpw_retothwk_try_pre_restore(uint8_t stage);
uint8_t usblpw_retothwk_stackrest_chk_illegal(uint8_t stage);
void usblpw_retothwk_set_stack_rest_illegal(uint8_t stage);
void usblpw_retothwk_set_stack_rest_fail(uint8_t stage);
uint8_t usblpw_retwkup_slp1_stack_restore(void);
uint8_t usblpw_retothwk_hibslp2_stack_restore(uint8_t stage);
uint8_t usblpw_retothwk_hibslp2_try_stack_rest(uint8_t stage);
uint8_t usblpw_retothwk_slp1_try_stack_rest(uint8_t stage);
uint8_t usblpw_retothwk_bt_pre_idle_stage_proc(void);
uint8_t usblpw_retothwk_hibslp2_bt_later_idle_stage_proc(void);
uint8_t usblpw_retothwk_slp1_bt_later_idle_stage_proc(void);
uint8_t usblpw_retothwk_hibslp2_bt_actv_stage_proc(void);
uint8_t usblpw_retothwk_slp1_bt_actv_stage_proc(void);
uint8_t usblpw_retothwk_wkmon_idle_to_actv_proc(void);
uint8_t usblpw_retothwk_hibslp2_wkmon_actv_proc(void);
uint8_t usblpw_retothwk_slp1_wkmon_actv_proc(void);
uint8_t usblpw_retothwk_wkmon_actv_proc(void);
uint8_t usblpw_get_retothwk_proc_stat(void);
uint8_t usblpw_retothwk_cur_proc_stat_gpwr_umatch(void);
void usblpw_retothwk_clear_errinfo(void);
int usb_wkmon_pre_init(void);
int usb_wkmon_cmmon_clear(void);
void usb_wkmon_task_init(void);
int usb_wkmon_hibslp2_stat_evt_start(void);
int usb_wkmon_slp1_stat_evt_start(void);
extern void usblpw_wkmon_ll_enter_ctx_clear(void);
extern uint8_t usblpw_wkmon_ll_enter_ctx_get(void);
extern void usblpw_enter_wkmon_chk_abort_ll_inirq(void);
extern void usblpw_wkmon_lpusbwkup_flag_clear(void);
extern void usblpw_wkmon_lpusbwkup_flag_set(void);
extern uint8_t usblpw_wkmon_lpusbwkup_flag_get(void);
#endif
#if (USBC_CTRL_HIB_LITE_MODE==1)
uint8_t usblpw_retothwk_hibslp2_stack_restore(uint8_t stage);
#endif
void usblpw_enable_lpusbwkup_src(void);
uint32_t usblpw_clear_lpusbwkup_src(void);
uint8_t usbstack_init(void);
uint8_t usbstack_deinit(void);
void usblpw_get_pwr_info(uint8_t* p_pwr_state, uint8_t* p_boot_stat, uint8_t* p_last_wkup);
uint8_t usblpw_is_retwkup_support(void);
void usbc_trace_cfg(uint32_t usb_sw_trace);
#endif

View File

@@ -0,0 +1,7 @@
#ifndef __USB_PORTMON_H__
#define __USB_PORTMON_H__
#endif

View File

@@ -0,0 +1,7 @@
#ifndef __USB_WKMON_H__
#define __USB_WKMON_H__
#endif

View File

@@ -0,0 +1,54 @@
#ifndef __USBC_BASIC_DEF_H__
#define __USBC_BASIC_DEF_H__
#include "sctdef.h"
#define USBC_CTRL_CORE_BASE_ADDR 0x1A000000
#define USBC_MAX_EP_UNUM (1+12)
#define USBC_GRXSTSP_ADDR (USBC_CTRL_CORE_BASE_ADDR+0x20)
//ALIGN TO USBC_CTRL_DATA_FIFO_OFFSET
#define USBC_FIFO_BASE_ADDR (USBC_CTRL_CORE_BASE_ADDR+0x1000)
#define MAX_EP_IN_NUM USBC_MAX_EP_UNUM
#define MAX_EP_OUT_NUM USBC_MAX_EP_UNUM
typedef struct usb_setup_req {
uint8_t bmRequest;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
} usb_setup_req_st;
typedef enum {
EPOUT_TYPE = 0,
EPIN_TYPE =1,
EP_MAX_TYPE = 2
}USBC_EP_TYPE;
typedef struct
{
uint16_t func_idx :4; /* usb func idx */
uint16_t cls_type :4; /* cls type */
uint16_t bulk_epin_valid :1;
uint16_t bulk_epout_valid :1;
uint16_t int_epin_valid :1;
uint16_t resv_0 :1;
uint16_t bulk_epin_idx :4;
uint16_t bulk_epout_idx :4;
uint16_t int_epin_idx :4;
uint16_t resv_1 :8;
}usbd_locmap_elem_st;
typedef struct
{
uint8_t func_elem_arr_cnt;
uint8_t epout_func_idx_arr_cnt;
usbd_locmap_elem_st *p_func_elem_arr;
uint8_t * p_epout_func_idx_arr;
}usbd_locmap_para_st;
#endif

View File

@@ -0,0 +1,121 @@
#ifndef __USBD_CDC_H__
#define __USBD_CDC_H__
#include "stdint.h"
#include "string.h"
#include "usbd_desc_def.h"
typedef struct
{
uint32_t bitrate;
uint8_t format;
uint8_t paritytype;
uint8_t datatype;
}line_coding_st;
//cdc class descriptor
struct tag_usb_cdc_header_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubType;
uint8_t bcdCDC_Low;
uint8_t bcdCDC_High;
} __attribute__ ((packed));
struct tag_usb_cdc_call_mgmt_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubType;
uint8_t bmCapabilities;
uint8_t bDataInterface;
} __attribute__ ((packed));
struct tag_usb_cdc_acm_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubType;
uint8_t bmCapabilities;
} __attribute__ ((packed));
struct tag_usb_cdc_union_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubType;
uint8_t bMasterInterface0;
uint8_t bSlaveInterface0;
} __attribute__ ((packed));
struct tag_usb_cdc_ether_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubType;
uint8_t iMacAddr;
uint32_t bmEthStat; //statis tic
uint16_t wMaxSegSz;
uint16_t wNumMCFilters;
uint8_t bNumPwrFilters;
} __attribute__ ((packed));
struct tag_usb_cdc_notification {
uint8_t bmReqType;
uint8_t bNotifyType;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
} __attribute__ ((packed));
typedef struct tag_usb_cdc_header_desc usb_cdc_header_desc_st;
typedef struct tag_usb_cdc_call_mgmt_descriptor usb_cdc_call_mgmt_descriptor_st;
typedef struct tag_usb_cdc_acm_descriptor usb_cdc_acm_descriptor_st;
typedef struct tag_usb_cdc_union_desc usb_cdc_union_desc_st;
typedef struct tag_usb_cdc_ether_desc usb_cdc_ether_desc_st;
typedef struct tag_usb_cdc_notification usb_cdc_notification_st;
struct tag_usbd_cdc_desc
{
usb_config_desc_st cfg_desc;
usb_intf_assoc_desc_st intf_asso_desc;
usb_interface_descriptor_st intf_ctrl_desc;
usb_cdc_header_desc_st cdc_head_desc;
usb_cdc_call_mgmt_descriptor_st cdc_callmgr_desc;
usb_cdc_acm_descriptor_st cdc_acm_desc;
usb_cdc_union_desc_st cdc_union_desc;
usb_endpoint_descriptor_st cdc_cmd_ep_desc;
usb_interface_descriptor_st intf_data_desc;
usb_endpoint_descriptor_st cdc_doep_desc;
usb_endpoint_descriptor_st cdc_diep_desc;
}__attribute__ ((packed));
typedef struct tag_usbd_cdc_desc usbd_cdc_desc_st;
struct tag_usbd_cdc_ccinst_desc_inhrnt
{
usb_intf_assoc_desc_st intf_asso_desc;
usb_interface_descriptor_st intf_ctrl_desc;
usb_cdc_header_desc_st cdc_head_desc;
usb_cdc_call_mgmt_descriptor_st cdc_callmgr_desc;
usb_cdc_acm_descriptor_st cdc_acm_desc;
usb_cdc_union_desc_st cdc_union_desc;
usb_endpoint_descriptor_st cdc_cmd_ep_desc;
usb_interface_descriptor_st intf_data_desc;
usb_endpoint_descriptor_st cdc_doep_desc;
usb_endpoint_descriptor_st cdc_diep_desc;
}__attribute__ ((packed));
#endif

View File

@@ -0,0 +1,45 @@
#ifndef __USBD_CDC_CUSTQUEC_H__
#define __USBD_CDC_CUSTQUEC_H__
//#include "usbd_conf.h"
#include "usbd_desc_def.h"
//#include "usbd_function.h"
//#include "usbd_clsdev.h"
#define USBD_CDC_QUEC_TP1 1
#define USBD_CDC_QUEC_TP2 2
#define CDC_QUEC_ASSO_SUPP 0
struct tag_usbd_cdc_desc_custp1
{
usb_interface_descriptor_st intf_ctrl_desc;
usb_endpoint_descriptor_st cdc_doep_desc;
usb_endpoint_descriptor_st cdc_diep_desc;
}__attribute__ ((packed));
struct tag_usbd_cdc_desc_custp2
{
usb_interface_descriptor_st intf_ctrl_desc;
usb_cdc_header_desc_st cdc_head_desc;
usb_cdc_call_mgmt_descriptor_st cdc_callmgr_desc;
usb_cdc_acm_descriptor_st cdc_acm_desc;
usb_cdc_union_desc_st cdc_union_desc;
usb_endpoint_descriptor_st cdc_cmd_ep_desc;
usb_endpoint_descriptor_st cdc_diep_desc;
usb_endpoint_descriptor_st cdc_doep_desc;
}__attribute__ ((packed));
#ifndef EPIN_MARK_DIR
#define EPIN_MARK_DIR(FUNC_EP) ((FUNC_EP)|0x80)
#endif
typedef struct tag_usbd_cdc_desc_custp1 usbd_cdc_desc_custp1_st;
typedef struct tag_usbd_cdc_desc_custp2 usbd_cdc_desc_custp2_st;
#endif

View File

@@ -0,0 +1,58 @@
#ifndef __USBD_DESC_DEF_H__
#define __USBD_DESC_DEF_H__
struct tag_usb_config_desc
{
uint8_t bLength; //config desc size
uint8_t bDescriptorType;
uint8_t wTotalLength_Low; // wTotalLength
uint8_t wTotalLength_High; // wTotalLength
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t bMaxPower;
}__attribute__ ((packed));
struct tag_usb_intf_assoc_desc {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bFirstInterface;
uint8_t bInterfaceCount;
uint8_t bFunctionClass;
uint8_t bFunctionSubClass;
uint8_t bFunctionProtocol;
uint8_t iFunction;
} __attribute__ ((packed));
struct tag_usb_interface_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bNumEndpoints;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t iInterface;
} __attribute__ ((packed));
struct tag_usb_endpoint_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress;
uint8_t bmAttributes;
uint8_t wMaxPacketSize_Low;
uint8_t wMaxPacketSize_High;
uint8_t bInterval;
} __attribute__ ((packed));
typedef struct tag_usb_config_desc usb_config_desc_st;
typedef struct tag_usb_intf_assoc_desc usb_intf_assoc_desc_st;
typedef struct tag_usb_interface_descriptor usb_interface_descriptor_st;
typedef struct tag_usb_endpoint_descriptor usb_endpoint_descriptor_st;
#endif

View File

@@ -0,0 +1,113 @@
#ifndef __USBD_ERRINFO_H__
#define __USBD_ERRINFO_H__
typedef enum
{
usb_ctrl_mod = 0x10,
usb_lpwmod = 0x20,
usb_func_vcom_mod = 0x100,
usb_func_ecm_mod ,
usb_func_rndis_mod ,
usb_dev_vcom_mod,
usb_dev_ecm_mod ,
usb_dev_rndis_mod ,
usb_mdev_lib_mod,
usb_user_base_mod = 0x1000,
usb_ccinst_inhrnt_mod ,
}usb_stat_mod_type;
typedef enum
{
usbc_ctrl_fifo_cfg_err = 110,
usbc_ctrl_fifo_retwkup_cfg_err,
usbpcd_deinit_terminate_err,
usbpcd_deinit_bsp_err,
mdev_lib_load_reset_err = 180,
mdev_lib_load_init_err,
mdev_lib_load_upd_err,
mdev_lib_load_end_err,
mdev_lib_load_stat_err,
mdev_lib_load_cnt_err,
mdev_lib_bind_upd_err,
mdev_lib_init_start_ptr_nul_err = 190,
mdev_lib_init_fin_ptr_nul_err,
mdev_lib_init_func_bind_err,
mdev_lib_init_clstype_bind_err,
mdev_lib_cust_ptr_nul_err =210,
mdev_lib_devnm_nul_err,
mdev_lib_elem_cnt_err,
mdev_lib_elem_swap_err,
mdev_lib_map_residx_err,
mdev_lib_func_nul_err,
mdev_lib_cls_nul_err,
mdev_lib_clsbase_nul_err,
mdev_lib_ccinfo_map_err,
mdev_lib_ccinst_nul_err,
mdev_lib_ccset_nul_err,
mdev_cls_deinit_terminate_start_err = 230,
mdev_cls_deinit_terminate_finish_err,
mdev_cls_deinit_unbind_err,
func_bind_flag_err = 240,
func_data_null_err,
func_malloc_fail_err,
func_intf_cnt_err,
func_intf_id_err,
func_oep_id_err,
func_iep_id_err,
func_cmdep_id_err,
func_buf_type_err,
func_txbuf_null_err,
func_rxbuf_null_err,
func_terminate_initstat_err,
func_ccinst_bind_fail_err,
func_ccinst_invalid_err,
func_ccinst_maintp_err,
func_ccinst_desc_ass_err,
func_ccinst_desc_parse_err,
func_inst_id_err ,
func_str_id_err,
func_set_strdesc_err,
desc_parse_err_base = 280,
desc_parse_err_tpinvalid,
desc_parse_err_ass0,
desc_parse_err_len0,
desc_parse_err_len_ovf,
desc_parse_err_epdesclen,
desc_parse_err_epdescptr_1,
desc_parse_err_epdescptr_2,
desc_parse_err_intfdesclen,
desc_parse_err_parserslt,
usblpw_retothwk_pre_rest_illegal = 0x300,
usblpw_retothwk_pre_rest_fail,
usblpw_retothwk_gpwr_match_fail,
usblpw_retothwk_stack_rest_illeagl,
usblpw_retothwk_stack_rest_fail,
}usb_mod_err_type;
void usbd_set_mod_last_err(uint16_t mod, uint16_t err_no);
uint32_t usbd_get_mod_last_err(void);
#endif

View File

@@ -0,0 +1,148 @@
#ifndef __USBD_FUNC_CC_H__
#define __USBD_FUNC_CC_H__
typedef enum
{
ccinst_setting_mainttp_none = 0,
ccinst_setting_cdc_vcom_maintp = 1,
}ccinst_setting_maintype;
typedef enum
{
ccinst_setting_subtp_none = 0,
ccinst_setting_vcom_subtp0_inhrnt =1,
ccinst_setting_vcom_subtp1_2ep,
ccinst_setting_vcom_subtp2_3ep,
}ccinst_setting_subtype;
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
#define USB_STRING_DESCRIPTOR_TYPE 0x03
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
#define STANDARD_ENDPOINT_DESC_SIZE 0x07
struct tag_usb_func_ccinst;
typedef struct {
uint8_t *p_desc_buff_ptr;
uint16_t desc_buff_size;
uint8_t b_intf_ctrl_desc_upd: 1;
uint8_t rsv: 7;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
}ccinst_desc_call_data_st;
typedef struct {
uint8_t intf_str_id;
uint8_t ep_ctrl_num : 4;
uint8_t ep_datain_num: 4;
uint8_t ep_dataout_num: 4;
uint8_t interface_cnt:4;
uint8_t intf_base_idx: 4;
uint8_t intf_1st_idx :4;
uint8_t intf_2nd_idx:4;
uint8_t rsv:4;
}ccinst_bind_call_data_st;
typedef struct tag_ccinst_setting_base
{
ccinst_setting_maintype setting_maintp;
ccinst_setting_subtype setting_subtp;
}ccinst_setting_base_st;
typedef struct tag_ccinst_cdc_setting
{
ccinst_setting_base_st bs_set;
uint8_t map_flag : 1;
uint8_t desc_assigned : 1;
uint8_t desc_parsed : 1;
uint8_t binded :1;
uint8_t epctrl_valid : 1;
uint8_t epout_valid : 1;
uint8_t epin_valid: 1;
uint8_t rsv_1: 2;
uint8_t interface_cnt:4;
uint8_t rsv_2:4;
uint8_t ep_ctrl_num : 4;
uint8_t ep_datain_num: 4;
uint8_t ep_dataout_num: 4;
uint8_t intf_base_idx: 4;
uint8_t intf_1st_idx :4;
uint8_t intf_2nd_idx:4;
uint8_t intf_str_id;
uint16_t desc_src_size;
usb_endpoint_descriptor_st * p_epctrl_d;
usb_endpoint_descriptor_st * p_epin_d;
usb_endpoint_descriptor_st * p_epout_d;
const uint8_t *p_desc_src;
}ccinst_cdc_setting_st;
struct tag_usb_func_ccinst;
typedef uint8_t (*pfn_func_ccinst_desc_ass)(struct tag_usb_func_ccinst *p_func_ccinst);
typedef uint8_t (*pfn_func_ccinst_desc_parse)(struct tag_usb_func_ccinst *p_func_ccinst);
typedef uint8_t (*pfn_func_ccinst_bind)(struct tag_usb_func_ccinst *p_func_ccinst, ccinst_bind_call_data_st *p_bind_call_data);
typedef void (*pfn_func_ccinst_reset)(struct tag_usb_func_ccinst *p_func_ccinst, uint8_t speed);
typedef uint8_t (*pfn_func_ccinst_init)(struct tag_usb_func_ccinst *p_func_ccinst, uint8_t cfgidx);
typedef uint8_t (* pfn_func_ccinst_deinit)(struct tag_usb_func_ccinst *p_func_ccinst, uint8_t cfgidx);
typedef uint8_t (* pfn_func_ccinst_get_desc)(struct tag_usb_func_ccinst *p_func_ccinst, ccinst_desc_call_data_st* p_desc_call_data);
typedef uint8_t (*pfn_func_ccisnt_unbind)(struct tag_usb_func_ccinst *p_func_ccinst);
typedef struct tag_usb_func_ccinst
{
void * p_cc_setting;
pfn_func_ccinst_desc_ass func_desc_ass;
pfn_func_ccinst_desc_parse func_desc_parse;
pfn_func_ccinst_bind func_bind;
pfn_func_ccinst_get_desc func_get_desc;
pfn_func_ccinst_get_desc func_get_othspd_desc;
pfn_func_ccinst_init func_init;
pfn_func_ccinst_deinit func_deinit;
pfn_func_ccisnt_unbind func_unbind;
#if 0
pfn_func_setup func_setup;
pfn_func_ep0_din_stage_comp func_ep0_din_stage_comp;
pfn_func_ep0_dout_stage_comp func_ep0_dout_stage_comp;
pfn_func_data_in_proc func_data_in_proc;
pfn_func_data_out_proc func_data_out_proc;
pfn_func_sof_proc func_sof_proc;
pfn_func_desc_get_ptr func_desc_get_ptr;
pfn_func_desc_get_size func_desc_get_size;
pfn_func_desc_get_othcfg_ptr func_desc_get_othcfg_ptr;
pfn_func_desc_get_othcfg_size func_desc_get_othcfg_size;
pfn_func_desc_get_intf_num func_desc_get_intf_num;
pfn_func_desc_get_clstype func_desc_get_clstype;
pfn_func_desc_get_cfginfo func_desc_get_cfginfo;
#endif
}usb_func_ccinst_st;

View File

@@ -0,0 +1,23 @@
#ifndef __FUNC_VCOM_CONF_H__
#define __FUNC_VCOM_CONF_H__
//#include "usbc_ctrl_config.h"
#define USBD_CFG_MAX_NUM 1
#define CDC_DATA_MAX_PACKET_SIZE 512
#define CDC_IN_FRAME_INTERVAL 40
#ifndef USE_USBC_CTRL_HS
#define USE_USBC_CTRL_HS
#endif
#endif

View File

@@ -0,0 +1,48 @@
#ifndef __USBD_MACRO_DEF_H__
#define __USBD_MACRO_DEF_H__
#ifndef INVALID_EP_NUM
#define INVALID_EP_NUM 0xff
#endif
#ifndef INVALID_INTF_NUM
#define INVALID_INTF_NUM 0xff
#endif
#ifndef INVALID_FUNC_NUM
//#define INVALID_FUNC_NUM 0xff
#endif
#define USBC_CTRL_EP_CONTROL 0
#define USBC_CTRL_EP_ISOC 1
#define USBC_CTRL_EP_BULK 2
#define USBC_CTRL_EP_INTR 3
#define USB_DEVICE_DESCRIPTOR_TYPE 0x01
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
#define USB_STRING_DESCRIPTOR_TYPE 0x03
#define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
#define STANDARD_INTERFACE_DESC_SIZE 0x09
#define STANDARD_ENDPOINT_DESC_SIZE 0x07
#ifndef LOBYTE
#define LOBYTE(x) ((uint8_t)(x & 0x00FF))
#endif
#ifndef HIBYTE
#define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8))
#endif
typedef enum {
usbd_ret_no_err = 0,
usbd_ret_busy,
usbd_ret_fail,
}usbd_ret_type;
#endif

View File

@@ -0,0 +1,17 @@
#ifndef __USBD_MULTI_CLSTYPE_H__
#define __USBD_MULTI_CLSTYPE_H__
typedef enum
{
multidev_tp_none = 0,
multidev_tp_rndis = 1,
multidev_tp_ecm,
multidev_tp_vcom_at,
multidev_tp_vcom_log,
multidev_tp_vcom_ppp,
multidev_tp_vcom_com,
}multidev_cls_type;
#endif

View File

@@ -0,0 +1,29 @@
#ifndef __USBD_MULTI_EXTMSG_H__
#define __USBD_MULTI_EXTMSG_H__
typedef enum
{
MULTIDEV_EXT_MSG_NONE = 0,
MULTIDEV_EXT_NTF_REQ = 1,
}multidev_extmsg_type;
struct tag_multidev_ext_msg
{
uint8_t multidev_load_idx;
uint8_t dev_cls_type;
uint16_t msgtype;
uint16_t msg_len;
uint8_t *p_msg;
uint8_t mid_para_valid; // for internal usage
void * p_mid_para; // for internal usage
} __attribute__ ((packed));
typedef struct tag_multidev_ext_msg multidev_ext_msg_st;
int usbd_multi_lib_dev_extmsg(multidev_ext_msg_st *p_ext_msg);
#endif

View File

@@ -0,0 +1,245 @@
#ifndef __USBD_MULTI_USRCFG_H__
#define __USBD_MULTI_USRCFG_H__
#include "usbd_multi_clstype.h"
#include "usbd_errinfo.h"
/*----------------------------------------------------------------------------*
* USB CUSTOM MULTIDEV CFG MACRO DEFINE *
*----------------------------------------------------------------------------*/
#define VCOM_CCINST_ORG_CASE 0
#define VCOM_CCINST_CUST_CASE 1
#define VCOM_CCINST_CASE_SEL VCOM_CCINST_ORG_CASE
//#define VCOM_CCINST_CASE_SEL VCOM_CCINST_CUST_CASE
#if (VCOM_CCINST_CASE_SEL==VCOM_CCINST_ORG_CASE)
#define VCOM_CCINST_SUBTP0_INHERENT_CNT 4
#define VCOM_CCINST_SUBTP1_2EP_CNT 0
#define VCOM_CCINST_SUBTP2_3EP_CNT 0
#endif
#if (VCOM_CCINST_CASE_SEL==VCOM_CCINST_CUST_CASE)
#define VCOM_CCINST_SUBTP0_INHERENT_CNT 0
#define VCOM_CCINST_SUBTP1_2EP_CNT 1
#define VCOM_CCINST_SUBTP2_3EP_CNT 2
#endif
#define VCOM_CCINST_TOTAL_CNT (VCOM_CCINST_SUBTP0_INHERENT_CNT+ \
VCOM_CCINST_SUBTP1_2EP_CNT + \
VCOM_CCINST_SUBTP2_3EP_CNT)
/*----------------------------------------------------------------------------*
* USB CUSTOM MULTIDEV CFG DESCRIPTOR *
*----------------------------------------------------------------------------*/
struct tag_usbcust_md_intf_assoc_desc {
uint8_t bFunctionClass;
uint8_t bFunctionSubClass;
uint8_t bFunctionProtocol;
} __attribute__ ((packed));
struct tag_usbcust_md_interface_descriptor
{
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
}__attribute__ ((packed));
typedef struct tag_usbcust_md_intf_assoc_desc ucmd_intf_assoc_desc_st;
typedef struct tag_usbcust_md_interface_descriptor ucmd_interface_descriptor_st;
//md renamed to mdcd md call data
typedef struct {
uint8_t cls_type;
uint8_t inst_id;
uint8_t *p_func_name;
uint8_t string_id;
uint8_t valid;
uint8_t * p_str;
}usbcust_mdcd_strdesc_st;
struct tag_usbcust_cmndesc_data{
//uint8_t b_intf_asso_desc_upd: 1;
uint8_t b_intf_ctrl_desc_upd: 1;
//uint8_t b_intf_data_desc_upd: 1;
uint8_t rsv: 7;
//ucmd_intf_assoc_desc_st intf_asso_desc;
ucmd_interface_descriptor_st intf_ctrl_desc;
//ucmd_interface_descriptor_st intf_data_desc;
}__attribute__ ((packed));
typedef struct tag_usbcust_cmndesc_data usbcust_cmndesc_data_st;
typedef struct {
uint8_t cls_type;
uint8_t inst_id;
uint8_t *p_func_name;
usbcust_cmndesc_data_st t_cmndesc_data;
}usbcust_mdcd_cmndesc_st;
typedef struct {
uint8_t cls_type;
uint8_t inst_id;
uint8_t *p_func_name;
ccinst_setting_maintype setting_maintp;
ccinst_setting_subtype setting_subtp;
usb_func_ccinst_st *p_func_ccinst;
}usbcust_mdcd_ccinfo_st;
typedef struct {
uint32_t cmd; //Bit 31 : 0 host to dev, 1 dev to host
uint8_t* buf;
uint32_t len;
}usbcust_mdctl_req_st;
typedef struct {
uint8_t cls_type;
uint8_t inst_id;
uint8_t func_idx;
uint8_t *p_func_name;
usbcust_mdctl_req_st t_ctl_req;
}usbcust_md_ctrl_st;
typedef struct {
uint8_t cls_type;
uint8_t inst_id;
uint8_t *p_func_name;
}usbcust_md_cb_paradef_st;
#define USBD_DEV_NAME_LEN_MAX 10
#define MULTI_DEV_RESOURCE_NUM 6
#define MULTI_DEV_CNT_MAX 6
#define MULTI_DEV_LOADCNT_MAX (MULTI_DEV_CNT_MAX-1)
#define MULTI_DEV_LOAD_NONE 0
#define MULTI_DEV_LOAD_RESET 1
#define MULTI_DEV_LOAD_UPDATED 2
#define MULTI_DEV_LOAD_END_SUC 3
#define MULTI_DEV_LOAD_BIND_SUC 4
//cust concrete type
#define MULTI_DEV_CUST_CC_TYPE_NONE 0
typedef struct {
const uint8_t* p_dev_name;
multidev_cls_type cls_type;
ccinst_setting_maintype setting_maintp;
ccinst_setting_subtype setting_subtp;
}multidev_custom_element;
typedef struct {
uint8_t elem_cnt;
multidev_custom_element elem_arr[MULTI_DEV_CNT_MAX];
}multidev_custom_info_st;
typedef struct {
uint8_t dev_enable;
uint8_t map_res_index;
multidev_cls_type cls_type;
ccinst_setting_maintype setting_maintp;
ccinst_setting_subtype setting_subtp;
const uint8_t* p_dev_name;
}multidev_load_element;
typedef struct {
uint8_t load_stat;
uint8_t load_cnt;
uint8_t filter_cnt;
multidev_load_element elem_arr[MULTI_DEV_CNT_MAX];
}multidev_load_info_st;
extern uint8_t usbcustom_multidev_cfg_reset(void);
extern multidev_custom_info_st* usbcustom_multidev_cfg_update(void);
extern uint8_t usbcustom_multidev_cfg_end(multidev_load_info_st *p_multidev_load);
#define USBD_CUST_MAX_INEP_CNT 4
#define USBD_CUST_MAX_OUTEP_CNT 4
typedef struct {
uint8_t epin_num;
uint8_t epout_num;
uint8_t epin_idx_arr[USBD_CUST_MAX_INEP_CNT];
uint8_t epout_idx_arr[USBD_CUST_MAX_OUTEP_CNT];
uint8_t epin_trans_attr[USBD_CUST_MAX_INEP_CNT];
uint8_t epout_trans_attr[USBD_CUST_MAX_OUTEP_CNT];
uint16_t epin_maxpkt_sz[USBD_CUST_MAX_INEP_CNT];
uint16_t epout_maxpkt_sz[USBD_CUST_MAX_OUTEP_CNT];
}usbd_cust_ep_info_st;
#define USBD_CUST_MAX_INTFNUM 2
typedef struct
{
uint8_t custCfgValid;
uint8_t wTotalLength;
uint8_t *pDesc;
uint8_t bNumInterfaces;
usbd_cust_ep_info_st tEpInfo;
}usbd_cust_config_st;
typedef struct
{
uint8_t (*multidev_reset)(void);
multidev_custom_info_st* (*multidev_update)(void);
uint8_t (*multidev_end)(multidev_load_info_st *p_multidev_load);
uint8_t (*multidev_ccinfo_map)(usbcust_mdcd_ccinfo_st *p_mdcd_ccinfo);
uint8_t * (*multidev_strdesc)(usbcust_mdcd_strdesc_st *p_mdcd_strdesc);
uint8_t (*multidev_cmndesc)(usbcust_mdcd_cmndesc_st *p_mdcd_cmndesc);
uint8_t (*multidev_ctrl_proc)(usbcust_md_ctrl_st* p_usbcust_md_ctrl);
}usbcustom_multidev_cb_ops_st, *ptr_usbcustom_multidev_cb_ops_st;
/*----------------------------------------------------------------------------*
* FUNCTIONS DECLEARATION FOR MULTIDEV DESCRIPTOR *
*----------------------------------------------------------------------------*/
uint8_t usbcustom_multidev_ccinfo_map(usbcust_mdcd_ccinfo_st *p_mdcd_ccinfo);
uint8_t *usbcustom_multidev_strdesc(usbcust_mdcd_strdesc_st *p_mdcd_strdesc);
uint8_t usbcustom_multidev_cmndesc(usbcust_mdcd_cmndesc_st *p_mdcd_cmndesc);
uint8_t usbcustom_multidev_ctrl_proc(usbcust_md_ctrl_st* p_usbcust_md_ctrl);
uint8_t *usbd_multi_lib_strdesc_cb(usbcust_mdcd_strdesc_st *p_mdcd_strdesc);
uint8_t usbd_multi_lib_cmndesc_cb(usbcust_mdcd_cmndesc_st *p_mdcd_cmndesc);
//#define usbd_multi_libcall_intfstr_desc usbd_multi_lib_intfstr_desc_cb
//uint8_t *usbd_multi_libcall_intfstr_desc(usbcust_mdcd_desc_st *p_usbcust_md_desc);
//extern uint8_t usbd_multi_lib_set_cmndesc_para(usb_func_st *p_usb_func,
// usbcust_mdcd_cmndesc_st* p_mdcd_cmndesc);
extern uint8_t usbd_multi_libcall_cmndesc(usbcust_mdcd_cmndesc_st *p_mdcd_cmndesc);
extern uint8_t* usbd_multi_libcall_strdesc(usbcust_mdcd_strdesc_st *p_mdcd_strdesc);
#endif

View File

@@ -0,0 +1,37 @@
#ifndef __USBD_VCOM_EXTMSG_H__
#define __USBD_VCOM_EXTMSG_H__
typedef enum
{
VCOM_EXT_NTF_REQ_NONE = 0,
VCOM_EXT_NTF_REQ_STAT = 1,
}vcom_ext_ntf_req_type;
struct tag_vcom_ntf_req_basedef {
uint8_t bmRequest;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
} __attribute__ ((packed));
typedef struct tag_vcom_ntf_req_basedef vcom_ntf_req_basedef_st;
struct tag_vcom_ext_ntf_msg
{
uint8_t ext_req_used;
vcom_ntf_req_basedef_st base_req;
uint16_t len;
uint8_t *p_data;
} __attribute__ ((packed));
typedef struct tag_vcom_ext_ntf_msg vcom_ext_ntf_msg_st;
#endif

View File

@@ -0,0 +1,61 @@
#ifndef __USBMST_EXTERNAL_H__
#define __USBMST_EXTERNAL_H__
#define ERR_DEV_BASE (-200)
#define ERR_DEV_NUM_REDEF(err) (ERR_DEV_BASE + err)
#define ERR_DEV_NO_INIT ERR_DEV_NUM_REDEF(-1)
#define ERR_DEV_NO_CONNECT ERR_DEV_NUM_REDEF(-2)
#define ERR_DEV_NOTIFY_COND_DEFAULT_ERR ERR_DEV_NUM_REDEF(-40)
#define ERR_DEV_NOTIFY_COND_EXIST_ERR ERR_DEV_NUM_REDEF(-41)
#define ERR_DEV_NOTIFY_HOSTNODET_ERR ERR_DEV_NUM_REDEF(-43)
int serial_vcom0_uplink_xfer_cfg(uint16_t xfsiz);
int serial_vcom0_uplink_get_epnum(void);
int serial_vcom0_downlink_get_epnum(void);
int serial_vcom1_uplink_xfer_cfg(uint16_t xfsiz);
int serial_vcom1_uplink_get_epnum(void);
int serial_vcom1_downlink_get_epnum(void);
int serial_vcom2_uplink_xfer_cfg(uint16_t xfsiz);
int serial_vcom2_uplink_get_epnum(void);
int serial_vcom2_downlink_get_epnum(void);
typedef enum
{
rndis_stat_connect = 0,
rndis_stat_disconn = 1
}rndis_conn_stat_type;
typedef enum
{
ecm_stat_disconn = 0,
ecm_stat_connect = 1,
}ecm_conn_stat_type;
typedef struct tag_ecm_ext_conn_info
{
uint8_t conn_stat;
uint32_t speed;
}ecm_ext_conninfo_msg_st;
int32_t rndis0_uplink_xfer_cfg(uint16_t xfsiz);
int32_t rndis0_uplink_get_epnum(void);
int32_t rndis0_downlink_get_epnum(void);
int32_t rndis0_sig_conn_test(rndis_conn_stat_type conn_stat);
int32_t rndis0_sig_conn_stat(rndis_conn_stat_type conn_stat);
int ecm0_sig_conn_stat(ecm_conn_stat_type conn_stat);
int ecm0_sig_conn_info(ecm_ext_conninfo_msg_st *p_conn_info);
#define NOTIFY_MSG_INIT 0x00000002
#define NOTIFY_MSG_HALT 0x00000003
#define NOTIFY_MSG_RESET 0x00000004
extern void usbDevNotifyRndisEvent(uint32_t flag, void* args);
#endif

View File

@@ -0,0 +1,174 @@
#ifndef __USBMST_TOP_H__
#define __USBMST_TOP_H__
#include "usbc_basic_def.h"
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
#if 0
/*usbc low level defination*/
#define USBC_CTRL_CORE_BASE_ADDR 0x1A000000
#define USBC_GRXSTSP_ADDR (USBC_CTRL_CORE_BASE_ADDR+0x20)
#define USBC_FIFO_BASE_ADDR (USBC_CTRL_CORE_BASE_ADDR+0x1000)
#define MAX_EP_OUT_NUM (13)
#endif
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
#define LOCMAP_MAX_SUPPORT_FUNCTION 5
#define LOCMAP_MAX_EP_OUT_NUM 13
#define LOCMAP_INVALID_FUNC_NUM 0xf
typedef struct
{
usbd_locmap_elem_st func_elem_arr[LOCMAP_MAX_SUPPORT_FUNCTION];
uint8_t epout_func_idx_arr[LOCMAP_MAX_EP_OUT_NUM];
}usbd_locmap_st;
typedef struct {
//fix len 8
uint8_t* setup_dest_base_addr;
}usbc_uldpmgr_setup_trans;
typedef struct {
uint8_t * xfer_buff;
uint32_t xfer_len;
}usbc_uldpmgr_oep_trans;
typedef struct {
uint32_t total_size;
uint8_t * extract_addr;//extract mode addr, used only for rndis, ppp
}usbc_uldpmgr_extract_trans;//not used
struct tag_usbmst_top;
typedef struct tag_usbmst_cmn_lowlevel_ops
{
void (*reset_handler)(void *pdev ,uint8_t speed);
int32_t (*init_handler) (struct tag_usbmst_top *ptop , uint8_t cfgidx);
int32_t (*deinit_handler) (struct tag_usbmst_top *ptop , uint8_t cfgidx);
int32_t (*suspend_handler) (struct tag_usbmst_top *ptop);
int32_t (*resume_handler) (struct tag_usbmst_top *ptop);
}usbmst_cmn_lowlevel_ops;
typedef struct tag_usbmst_uldp_lowlevel_ops
{
int32_t (*cfg_setup_trans) (struct tag_usbmst_top *p_usbmst_top, usbc_uldpmgr_setup_trans*);
int32_t (*cfg_ep_trans) (struct tag_usbmst_top *p_usbmst_top, uint8_t epnum, usbc_uldpmgr_oep_trans*);
int32_t (*get_avail_size) (struct tag_usbmst_top *p_usbmst_top, uint8_t epnum);
int32_t (*get_ep_all_cmpl_stat) (struct tag_usbmst_top *p_usbmst_top);
int32_t (*clear_epn_cmpl_stat) (struct tag_usbmst_top *p_usbmst_top, uint8_t epnum, uint8_t usb_intr_ctx);
}usbmst_uldp_lowlevel_ops;
typedef struct tag_usbmst_tftc_lowlevel_ops
{
int32_t (*func_rsv)(struct tag_usbmst_top *ptop);
}usbmst_tftc_lowlevel_ops;
typedef struct tag_usbmst_uldp_ctrl_ep
{
uint8_t is_packet_extract_mode;
uint32_t extract_head_len;
uint32_t idx;
uint32_t avail_size_end;
uint32_t avail_size_start;
uint32_t total_size;
uint8_t * extract_addr;//extract mode addr, used only for rndis, ppp
}usbmst_uldp_ctrl_ep_st;
typedef struct tag_usbmst_uldp_ep_trans_stat
{
uint8_t ep_idx;
uint8_t ep_event;
}usbmst_uldp_ep_trans_stat_st;
typedef struct tag_usbmst_uldp_trans_stat
{
uint8_t ep_cnt;
usbmst_uldp_ep_trans_stat_st ep_arr[MAX_EP_OUT_NUM];
}usbmst_uldp_ctrl_trans_stat_st;
struct tag_usbmst_uldp_dev;
typedef uint32_t (* pfn_usbmst_uldp_handler)(struct tag_usbmst_top *pdev);
typedef struct tag_usbmst_top_dev
{
uint8_t wkup_first_reset;
uint8_t enum_spd;
usbmst_uldp_ctrl_ep_st out_ep[MAX_EP_OUT_NUM];//not used
usbmst_cmn_lowlevel_ops *p_usbmst_cmn_lowlevel_ops;//common usb event callback, provided by uplayer, called by usbc
usbmst_uldp_lowlevel_ops *p_usbmst_uldp_lowlevel_ops;//uldp event callback, provided by uplayer, called by usbc
usbmst_tftc_lowlevel_ops *p_usbmst_tftc_lowlevel_ops;//currently reserved
usbd_locmap_st t_usbd_locmap;
uint8_t *setup_pkt_addr;
uint8_t zlp_xfer_buff_fix[64];
}usbmst_top_dev_st;
typedef struct tag_usbmst_top
{
usbmst_top_dev_st dev;
usbmst_uldp_ctrl_trans_stat_st t_trans_stat;/*filled by uldp rx callback, to pass event info to usbc, current only for ep0*/
pfn_usbmst_uldp_handler ptr_usbmst_uldp_handler;/*provided by usbc, called by uldp rx callback to indicate ep0 recv info to usbc*/
}
usbmst_top_st;
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
/**
\fn uint32_t usbmst_top_early_init(usbmst_top_st *p_usbmst_top)
\brief provide by uplayer, called by usbc driver to get callbacks
\param[in] p_usbmst_top pointer to usbmst top var
\return uint32_t
\note
*/
uint32_t usbmst_top_early_init(usbmst_top_st *p_usbmst_top);
/**
\fn uint32_t usbmst_get_oep_xfer_reg(uint32_t epnum)
\brief provide by usbc, called by uldp callback to get transfer info
raw register info.
\param[in] epnum out ep number
\return uint32_t
\note called in uldp rx callback,interrupt context
*/
uint32_t usbmst_get_oep_xfer_reg(uint32_t epnum);
/**
\fn uint32_t usbmst_get_oep_real_xfercnt(uint32_t epnum)
\brief provide by usbc, called by uldp callback to get current
transfer cnt
\param[in] epnum out ep number
\return uint32_t
\note called in uldp rx callback,interrupt context
pass to rx task for recv length checking
*/
uint32_t usbmst_get_oep_real_xfercnt(uint32_t epnum);
int serial_vcom0_uplink_xfer_cfg(uint16_t xfsiz);
int serial_vcom1_uplink_xfer_cfg(uint16_t xfsiz);
int serial_vcom2_uplink_xfer_cfg(uint16_t xfsiz);
int32_t usbmst_transfer_devcfg_uplink_transfer(uint8_t multidev_load_idx, uint8_t dev_cls_type, uint16_t xfer_size);
void usbc_usbmst_mgr_resume_hook(void);
void usbc_usbmst_mgr_suspend_hook(void);
#endif

View File

@@ -0,0 +1,340 @@
/******************************************************************************
*(C) Copyright 2018 AirM2M International Ltd.
* All Rights Reserved
******************************************************************************
* Filename:
*
* Description:
*
* History:
*
* Notes:
*
******************************************************************************/
#ifndef UTFC_H
#define UTFC_H
/*----------------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------------*/
#include "ec618.h"
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*
* MACROS *
*----------------------------------------------------------------------------*/
/*DEFINE UTFC return code*/
#define UTFC_RET_OK (0)
#define UTFC_RET_ALREADY_EN (-1)
#define UTFC_PARA_ERROR (-2)
#define UTFC_NOT_INIT (-3)
#define UTFC_RET_FAIL (-4)
#define UTFC_EP_NOT_SUPPORT (-5)
#define UTFC_REG_BASE 0x40060000
#define UTFC_CODE_BASE_ADDR 0x00400000
#define UTFC_MAX_IF_NUM (5)// max 5 ifs, 5 code section, --ulg=4 resv 1
#define UTFC_INVALID_EP_NUM (0xffffffff)
#define UTFC_REL_EP_MAGIC (0xbcdb0000)
#define UTFC_NUM_OF_USB_CODE 0x03
//base addr for 3 code, same for all ep
#define UTFC_CFG_REG1_BASE_ADDR (0x1A000000+0x908)
#define UTFC_CFG_REG2_BASE_ADDR (0x1A000000+0x910)
#define UTFC_CFG_REG3_BASE_ADDR (0x1A000000+0x900)
#define UTFC_CFG_REG1_VALUE 0x00000001
#define UTFC_CFG_REG2_VALUE 0x03
//bit25-22 txfnum bit21---16=0, bit15=1,USBActEP bit14:11=0, bit10:0 MPS=512=0x200*/
#define UTFC_CFG_REG3_VALUE (0x84088200)
//bit25-22 txfnum bit21---16=0, bit15=1,USBActEP bit14:11=0, bit10:0 MPS=64=0x040*/
#define UTFC_CFG_REG3_FS_VALUE (0x84088040)
//zi setting reg2 val, same for all ep, only for sct
#define UTFC_CFG_ZL_REG2_VALUE ((0x1<<19)|(0x0))//pakcnt=1,xfersize=0 for ZI packet
#define UTFC_ULG_CFG_REG2_VALUE ((0x1<<19)|(448))//pakcnt=1,xfersize=512-64
#define UTFC_ULG_CFG_REG2_FS_VALUE ((0x2<<19)|(96))//pakcnt=2,xfersize=96
#define UTFC_MAX_XFER_SIZE (1024*64)//64k
#define UTFC_EP_MPS (512)//may include from USB later
#define UTFC_EP_FS_MPS (64)// may include from USB later
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
// temp define here, should be a common define for ALL EP according to usage
typedef enum
{
UTFC_START_ADDR_SW= 0,
UTFC_START_ADDR_HW
} UsbStartAddrSel_e;
// uta request source
typedef enum
{
UTA_REQ_SRC_SW = 0,
UTA_REQ_SRC_ULDP = 1,
UTA_REQ_SRC_SCT = 2,
UTA_REQ_SRC_ULG = 3,
UTA_REQ_SRC_MAX
} UtaReqSrc_e;
// utfc code array
typedef enum
{
UTFC_ULG_CODE = 0,
UTFC_RNDIS_ZI_CODE = 1,
UTFC_AT_ZI_CODE = 2,
UTFC_PPP_ZI_CODE = 3,
UTFC_CODE_MAX
} UtfcCfgCode_e;
// temp define here, should be a common define for ALL EP according to usage
typedef enum
{
USB_TX_EP_0= 0,
USB_TX_EP_1,
USB_TX_EP_2,
USB_TX_EP_3,
USB_TX_EP_4,
USB_TX_EP_5,
USB_TX_EP_6,
USB_TX_EP_7,
USB_TX_EP_8,
USB_TX_EP_9,
USB_TX_EP_10,
USB_TX_EP_11,
USB_TX_EP_12,
USB_TX_EP_MAX
} UsbTxEpNum_e;
typedef enum
{
UTFC_ERROR_STATE = -1, /* SW check error */
UTFC_IDLE_STATE = 0,
UTFC_START_CFG = 1, /* UTFC READ the command to config the USB REG */
UTFC_PACKET = 2, /* UTFC Tx data to USB TxFIFO, and wait for USB Tx_complete */
UTFC_ZL_PEND = 3, /* If ZERO PKG need, after Recv Tx_complete, enter this state */
UTFC_CL_CFG = 4, /* UTFC config ZERO PKG command */
UTFC_ZL_PACKET = 5 /* wait for ZERO PKG USB Tx_complete */
}UtfcState_e;
/*----------------------------------------------------------------------------*
* DATA TYPE DEFINITION *
*----------------------------------------------------------------------------*/
// typedef of register 'UtfcCfgInfo_t'
typedef struct {
uint32_t codeBaseAddr;// base address of the code
UsbStartAddrSel_e startAddrSel;// 0:select from SW, configure in register 1: select from HW(SCT)
uint8_t zlStageEn;// 0:disable 1: enable. normally SW should not enable ZI
uint16_t swAddrOffset;// code address offset for epn, 9 bits word address
uint16_t ziAddrOffset;// ZI code address offset for epn,9 bits word address
} UtfcCfgInfo_t;
// typedef of utfc galobal info
typedef struct {
uint8_t isUtfcEnabled;// whether utfc is enbaled
//add more global control var here if needed
} UtfcCtrl_t;
/* |32bits --number of code, 0:3 valid, 4:31 reserved|
|32bits --usb cfg register address, 0:1 should be 0|
|32bits --usb cfg register value|
|32bits --usb cfg register address, 0:1 should be 0|
|32bits --usb cfg register value|
.................
.................
max 15 cfg
*/
// typedef of utfc usb in ep cfg section
typedef struct {
uint32_t usbRegAddr;
uint32_t usbRegVal;
} UtfcUsbRegCfg_t;
// typedef of utfc usb in ep cfg section
typedef struct {
uint32_t numOfCode;
UtfcUsbRegCfg_t usbCode[UTFC_NUM_OF_USB_CODE];
uint32_t rEpInfo;//related ep info, 4B for 4 align
} UtfcUsbCfgCode_t;
/*----------------------------------------------------------------------------*
* GLOBAL FUNCTIONS DECLEARATION *
*----------------------------------------------------------------------------*/
/**
\fn utfcInit( void )
\brief used by unilog and SCT.
\note called when when UNILOG/SCT USB direct path enabled
*/
int32_t utfcInit(void);
/**
\fn utfcDinit( void )
\brief used by USB driver, called when USBC deinit.
\note
*/
int32_t utfcDinit(void);
/**
\fn utfcReset( void )
\brief used to reset UTFC
\note called when needed
*/
void utfcReset(void);
/**
\fn utfcEpnCfg( UtfcCfgInfo_t * utfcCfg, UsbTxEpNum_e epNum )
\brief used by unilog/sct driver, called when unilog to USB path en or SCT to USB path en.
\note currently, SW only use for unilog, SCT will only need to configure utfcCfg->startAddrSel=1
*/
int32_t utfcEpnCfg( UtfcCfgInfo_t * utfcCfg, UsbTxEpNum_e epNum );
/**
\fn utfcEpnStartReq( UsbTxEpNum_e epNum )
\brief used by unilog driver, called when unilog first start.
\note
*/
int32_t utfcEpnStartReq( UsbTxEpNum_e epNum );
/**
\fn utfcEpnClear( UtfcCfgInfo_t * utfcCfg, UsbTxEpNum_e epNum )
\brief used by unilog/sct, called to clear UTFC EP
\note
*/
int32_t utfcEpnClear(UsbTxEpNum_e epNum);
/**
\fn UtfcState_e utfcEpnGetState(UsbTxEpNum_e epNum)
\brief used by unilog/sct, called to get UTFC state
\note
*/
UtfcState_e utfcEpnGetState(UsbTxEpNum_e epNum);
/**
\fn utfcUlgCfg( UsbTxEpNum_e epNum )
\brief used by unilog driver, called when unilog first start.
\note
*/
int32_t utfcUlgCfg( UsbTxEpNum_e epNum );
/**
\fn utfcSetZLForSct(uint8_t idx, UsbTxEpNum_e epNum )
\brief used by sct driver to set zero length packet cfg code
\note
*/
int32_t utfcSetZLForSct(uint8_t idx, UsbTxEpNum_e epNum );
/**
\fn utfcSetCodeForSct(UsbTxEpNum_e epNum,uint16_t xferSize,uint32_t *codeBuf)
\brief used by sct driver to set normal length packet cfg code
\note
*/
int32_t utfcSetCodeForSct(UsbTxEpNum_e epNum,uint16_t xferSize,uint32_t *codeBuf);
/**
\fn utaReqClr( UtaReqSrc_e reqSrc )
\brief used by usb TXFIFO master to clear the request, normally used when the request source
is working, it will also clear the working state
should be set to 1 to clear, HW self clear
\note HW clear
*/
int32_t utaReqClr( UtaReqSrc_e reqSrc );
/**
\fn utaReqSrcDisEn( UtaReqSrc_e reqSrc, uint8_t disEn )
\brief used by usb TXFIFO master to disable the request
should be set disEn to 1 to disable, disEn=0 to enable
\note !!! 1 is disable, 0 (default) is enable !!!
*/
int32_t utaReqSrcDisEn(UtaReqSrc_e reqSrc, uint8_t disEn);
/**
\fn utaSwAckStateRd( void )
\brief used by usb sw device IN transfer e.g. VCOM_SEND
polling this bit until it is set to 0b001, 1 means get the ack, sw could write USB TX FIFO
\note usb sw polling
*/
uint32_t utaAckStateRd(void);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long