]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Nuvoton_Code/StdDriver/inc/mkromlib.h
Add Cortex M23 GCC and IAR ports. Add demo projects for Nuvoton NuMaker-PFM-2351.
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC / Nuvoton_Code / StdDriver / inc / mkromlib.h
1 /**************************************************************************//**
2  * @file     MKROMLib.h
3  * @version  V2.00
4  * @brief    MaskROM library header file
5  *
6  * @copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
7  *****************************************************************************/
8 #ifndef __MKROM_LIB_H__
9 #define __MKROM_LIB_H__
10
11 #ifdef __cplusplus
12 extern "C"
13 {
14 #endif
15
16
17 /** @addtogroup Standard_Driver Standard Driver
18   @{
19 */
20
21 /** @addtogroup MKROM_Driver MKROM Driver
22   @{
23 */
24
25 /** @addtogroup MKROM_EXPORTED_CONSTANTS MKROM Exported Constants
26   @{
27 */
28 /*--------------------------------------------------------------------------------------------------*/
29 /*  Status and Error Code Constant Definitions                                                      */
30 /*--------------------------------------------------------------------------------------------------*/
31 #define BL_ERR_TT_CHECK         0xF0F00000UL    /*!< Not a Non-secure parameter         */
32 #define BL_ERR_PARAMETER        0xF0F00001UL    /*!< Invalid parameter                  */
33 #define BL_PARAM_ALIGN          0xF0F00002UL    /*!< Parameter alignment error          */
34 #define BL_NOT_FLASH_ADDR       0xF0F00003UL    /*!< Invalid flash address              */
35 #define BL_NOT_SRAM_ADDR        0xF0F00004UL    /*!< Invalid sram address               */
36 #define BL_XOM_NOT_CONFIG       0xF0F00005UL    /*!< XOM is not configure yet           */
37 #define BL_XOM_HAS_CONFIG       0xF0F00006UL    /*!< XOM has beeen configured           */
38 #define BL_XOM_HAS_ACTIVE       0xF0F00007UL    /*!< XOM is actived                     */
39 #define BL_XOM_BASE_ERROR       0xF0F00008UL    /*!< Invalid XOM base address           */
40 #define BL_KPROM_NOT_ENABLE     0xF0F00009UL    /*!< KPROM is not enabled yet           */
41 #define BL_KPROM_KEY_FORBID     0xF0F0000AUL    /*!< KPROM comparison is forbidden      */
42 #define BL_KPROM_KEY_UNMATCH    0xF0F0000BUL    /*!< KPROM comparison is unmatched      */
43 #define BL_KPROM_KEY_LOCKED     0xF0F0000CUL    /*!< KPROM write-protect is enabled     */
44 #define BL_KPROM_SET_FAIL       0xF0F0000EUL    /*!< Set KPROM key fail                 */
45 #define BL_ISP_CMD_FAIL         (-1)            /*!< FMC command fail                   */
46 #define BL_FLASH_ALLONE         0xA11FFFFFUL    /*!< Check-all-one result is all one    */
47 #define BL_FLASH_NOT_ALLONE     0xA1100000UL    /*!< Check-all-one result is not all one*/
48
49 /*--------------------------------------------------------------------------------------------------*/
50 /*  Random Number Generator Constant Definitions                                                    */
51 /*--------------------------------------------------------------------------------------------------*/
52 #define BL_RNG_PRNG             (0UL)   /*!<Use H/W random number generator */
53 #define BL_RNG_SWRNG            (1UL)   /*!<Use S/W random number generator */
54 #define BL_RNG_LIRC32K          (0UL)   /*!<Use LIRC32 for random number generator */
55 #define BL_RNG_LXT              (2UL)   /*!<Use LXT for random number generator */
56 #define XTRNG_PRNG              (0UL)   /*!<Use H/W random number generator */
57 #define XTRNG_SWRNG             (1UL)   /*!<Use S/W random number generator */
58 #define XTRNG_LIRC32K           (0UL)   /*!<Use LIRC32 for random number generator */
59 #define XTRNG_LXT               (2UL)   /*!<Use LXT for random number generator */
60
61 /*--------------------------------------------------------------------------------------------------*/
62 /*  Maximum SecureISP Mode Transmit/Receive Packet Size Constant Definitions                        */
63 /*--------------------------------------------------------------------------------------------------*/
64 #define MAX_PKT_SIZE            64
65
66 /*@}*/ /* end of group MKROM_EXPORTED_CONSTANTS */
67
68
69 /** @addtogroup MKROM_EXPORTED_STRUCTS MKROM Exported Structs
70   @{
71 */
72 /**
73   * @details    Random number generator structure
74   */
75 typedef struct
76 {
77     uint32_t opt;       /*!< Operation mode */
78     int32_t data_len;   /*!< Internal use for random number generator */
79     uint8_t buf[32];    /*!< Internal use for random number generator */
80     uint8_t buf2[20];   /*!< Internal use for random number generator */
81 } BL_RNG_T;
82
83 typedef struct
84 {
85     uint32_t opt;       /*!< Operation mode */
86     int32_t data_len;   /*!< Internal use for random number generator */
87     uint8_t buf[32];    /*!< Internal use for random number generator */
88     uint8_t buf2[20];   /*!< Internal use for random number generator */
89 } XTRNG_T;
90
91
92 /**
93   * @details    XCRPT_T is structure for access MKROM Crypto library
94   */
95 typedef struct
96 {
97     CRPT_T      *crpt;       /*!< The pointer of the CRYPTO module */
98     ECC_CURVE   *pCurve;     /*!< Internal use for ECC */
99     ECC_CURVE   Curve_Copy;  /*!< Internal use for ECC */
100     uint32_t    AES_CTL[4];  /*!< AES channel selection */ 
101     uint32_t    TDES_CTL[4]; /*!< TDES channel selection */
102 } XCRPT_T;
103
104 /*---------------------------------------------------------------------------------------------------*/
105 /*  Define a global constant XCRPT as the access address of g_xcrpta for using MKROM Crypto library. */
106 /*---------------------------------------------------------------------------------------------------*/
107 extern XCRPT_T g_xcrpt;
108 #define XCRPT (&g_xcrpt)
109
110
111 /**
112   * @details    Command packet structure for transmit/receive data in SecureISP function
113   */
114 typedef struct
115 {
116     /* Word-0 */
117     uint16_t        u16CRC16;       /* CRC16 checksum of from u8CmdID to Word-13 */
118     uint16_t        u16CmdID;       /* Command ID */
119
120     /* Word-1 */
121     uint16_t        u16PacketID;    /* Packet ID */
122     uint16_t        u16Len;         /* Valid data length in command data field */
123
124     /* Word-2 ~ 13 */
125     uint32_t        au32Data[12];   /* Data fields */
126
127     /* Word-14 */
128     uint32_t        u32CRC32;       /* CRC32 from Word-0 to Word-13 for check cmd integrity */
129
130     /* Word-15 */
131     uint32_t        RSVD;           /* Reserved */
132
133 } CMD_PACKET_T;
134
135
136 /**
137   * @details    ECC public key structure
138   */
139 typedef struct
140 {
141     uint32_t        au32Key0[8];    /* 256-bits */
142     uint32_t        au32Key1[8];    /* 256-bits */
143 } __attribute__((packed)) ECC_PUBKEY_T;
144
145
146 /**
147   * @details    ECC ECDSA signature structure
148   */
149 typedef struct
150 {
151     uint32_t        au32R[8];   /* 256-bits */
152     uint32_t        au32S[8];   /* 256-bits */
153 } __attribute__((packed)) ECDSA_SIGN_T;
154
155
156 /**
157   * @details    SecureISP operation mode enumerate
158   */
159 typedef enum
160 {
161     USB_MODE        = 0x1,
162     UART_MODE       = 0x2,
163     USB_UART_MODE   = 0x3,
164     RESYNC_ISP      = 0x80, /* To set SecureISP in waiting connection state */
165 } E_ISP_MODE;
166
167
168 /**
169   * @details    Global ISP information data for perform SecureISP function
170   */
171 typedef void (*ISPCallback)(uint32_t *pu32Buf, uint32_t u32Data);
172 typedef void (*USBDEPFunc)(void);
173 typedef struct
174 {
175     uint32_t        u32CmdMask;         /* Disable the specify command in SecureISP */
176
177     uint32_t        au32AESKey[8];      /* AES-256 keys */
178     uint32_t        au32AESIV[4];       /* AES IV, 128-bits */
179
180     ECC_PUBKEY_T    ClientPubKey;       /* Client's ECC public key, 64-bytes (256-bits + 256-bits) */
181     ECC_PUBKEY_T    ServerPubKey;       /* Server's ECC public key, 64-bytes (256-bits + 256-bits) */
182
183     ECDSA_SIGN_T    sign;               /* 64-bytes (256-bits R + 256-bits S) */
184
185     uint32_t        IsConnectOK;        /* Internal use in SecureISP */
186     uint32_t        timeout;            /* Timeout period for connecting to SecureISP Tool */
187     
188     __attribute__((aligned(4))) uint8_t rcvbuf[MAX_PKT_SIZE]; /* Internal use in SecureISP */
189     __attribute__((aligned(4))) uint8_t rspbuf[MAX_PKT_SIZE]; /* Internal use in SecureISP */       
190
191     USBDEPFunc      pfnUSBDEP[USBD_MAX_EP]; /* Internal use in SecureISP */
192     uint32_t        IsUSBDataReady;     /* Internal use in SecureISP */
193
194     uint32_t        UARTClockFreq;      /* UART clock frequency */
195     uint32_t        UARTDataIdx;        /* Internal use in SecureISP */
196     uint32_t        IsUARTDataReady;    /* Internal use in SecureISP */
197
198     ISPCallback     pfnVendorFunc;      /* Vendor function address */
199
200     uint32_t        tmp0[8];            /* Internal use in SecureISP */
201     uint32_t        tmp1[8];            /* Internal use in SecureISP */
202   
203 } ISP_INFO_T;
204
205
206 /**
207   * @details    Global USBD data for SecureISP USB
208   * @note       This data is internal use in SecureISP operation
209   */
210 typedef struct
211 {
212     uint8_t             g_usbd_SetupPacket[8];  
213     volatile uint8_t    g_usbd_RemoteWakeupEn;  
214     volatile uint8_t    g_usbd_u8ZeroFlag;
215
216     volatile uint8_t    *g_usbd_CtrlInPointer;
217     volatile uint8_t    *g_usbd_CtrlOutPointer;
218     volatile uint32_t   g_usbd_CtrlInSize;
219     volatile uint32_t   g_usbd_CtrlOutSize;
220     volatile uint32_t   g_usbd_CtrlOutSizeLimit;
221     volatile uint32_t   g_usbd_UsbAddr;
222     volatile uint32_t   g_usbd_UsbConfig;
223     volatile uint32_t   g_usbd_CtrlMaxPktSize;
224     volatile uint32_t   g_usbd_UsbAltInterface;
225
226     S_USBD_INFO_T       *g_usbd_sInfo;                  
227
228     VENDOR_REQ          g_usbd_pfnVendorRequest;        
229     CLASS_REQ           g_usbd_pfnClassRequest;         
230     SET_INTERFACE_REQ   g_usbd_pfnSetInterface;         
231     SET_CONFIG_CB       g_usbd_pfnSetConfigCallback;
232     uint32_t            g_u32EpStallLock;              
233
234 } BL_USBD_INFO_T;
235
236
237 /*@}*/ /* end of group MKROM_EXPORTED_STRUCTS */
238
239
240 /** @addtogroup MKROM_EXPORTED_FUNCTIONS Bootloader Exported Functions
241   @{
242 */
243 /**
244   * @brief      Get MKROM Version Number
245   * @param      None
246   * @return     Version number of MKROM
247   * @details    This API will return the MKROM version number.
248   */
249 uint32_t BL_GetVersion(void);
250
251
252 /**
253   * @brief      Enable FMC ISP Function and return maximum APROM size
254   * @param      None
255   * @return     Maximum APROM size
256   * @details    This API will unlock register write-protect, enable relative settings for access FMC ISP commands
257   *             and return maximum APROM by chip package.
258   */
259 uint32_t BL_EnableFMC(void);
260
261
262 /**
263   * @brief      Disable FMC ISP Function
264   * @param      None
265   * @return     None
266   * @details    This API will disable relative settings for disable FMC ISP function and lock register write-protect
267   *             until last ISP operation is finished.
268   */
269 void BL_DisableFMC(void);
270
271
272 /**
273   * @brief      Get FMC ISP Busy Status
274   * @param      None
275   * @retval     0   ISP operation is finished
276   * @retval     1   ISP operation is in processing
277   * @details    This API indicates ISP operation in in processing or finished.
278   */
279 uint32_t BL_GetISPStatus(void);
280
281
282 /**
283   * @brief      Get Non-secure Boundary
284   * @param      None
285   * @return     Current Non-secure boundary
286   * @details    This API can get current Non-secure boundary address.
287   */
288 uint32_t BL_GetNSBoundary(void);
289
290
291 /**
292   * @brief      Set All Flash Region Lock
293   * @param      None
294   * @retval     -1      Set flash all lock failed
295   * @retval     0       Set flash all lock operation is success
296   * @details    This API will protect all flash region read/write operate by ICE interface.
297   */
298 int32_t BL_SetFlashAllLock(void);
299
300
301 /**
302   * @brief      Read Non-secure Flash Address Data (for Non-secure region)
303   * @param[in]  u32NSAddr   Non-secure flash address
304   * @retval     0xF0F00000  u32NSAddr isn't in Non-secure area
305   * @retval     0xF0F00001  u32NSAddr isn't word aligned
306   * @retval     0xF0F00003  u32NSAddr isn't valid flash address
307   * @retval     -1          Flash read failed
308   * @retval     The data of specified Non-secure address
309   * @details    To read word data from specified Non-secure flash address.
310   */
311 uint32_t BL_FlashRead(uint32_t u32NSAddr);
312
313
314 /**
315   * @brief      Read Multi-Word Data from Non-secure Flash Address (for Non-secure region)
316   * @param[in]  u32NSAddr       Starting Non-secure flash address
317   * @param[out] pu32NSRamBuf    Non-secure sram address to store reading data
318   * @param[in]  u32Size         Total read byte counts, it should be word aligned and maximum size is one page size.
319   * @retval     0xF0F00000      u32NSAddr or pu32NSRamBuf region isn't in Non-secure area
320   * @retval     0xF0F00001      Wrong u32NSAddr, pu32NSRamBuf or u32Size parameter
321   * @retval     0xF0F00003      u32NSAddr isn't valid flash address
322   * @retval     0xF0F00004      pu32NSRamBuf isn't valid sram address
323   * @retval     -1              Multi-words read failed
324   * @retval     0               Read operation is success
325   * @details    To read multi-words data start from specified Non-secure flash address.
326   *             And maximum read size is one page size, 2048 bytes.
327   */
328 int32_t BL_FlashMultiRead(uint32_t u32NSAddr, uint32_t *pu32NSRamBuf, uint32_t u32Size);
329
330
331 /**
332   * @brief      Program Data into Non-secure Flash Address (for Non-secure region)
333   * @param[in]  u32NSAddr   Non-secure flash address
334   * @param[in]  u32Data     32-bit Data to program
335   * @retval     0xF0F00000  u32NSAddr isn't in Non-secure area
336   * @retval     0xF0F00001  u32NSAddr isn't word aligned
337   * @retval     0xF0F00003  u32NSAddr isn't valid flash address
338   * @retval     -1          Flash write failed
339   * @retval     0           Program command is finished
340   * @details    To program word data into specified Non-secure flash address.
341   */
342 int32_t BL_FlashWrite(uint32_t u32NSAddr, uint32_t u32Data);
343
344
345 /**
346   * @brief      Program Multi-Word Data into Non-secure Flash Address (for Non-secure region)
347   * @param[in]  u32NSAddr       Starting Non-secure flash address
348   * @param[in]  pu32NSRamBuf    Non-secure sram buffer address to store program data
349   * @param[in]  u32Size         Total program byte counts, it should be word aligned and maximum size is one page size.
350   * @retval     0xF0F00000      u32NSAddr or pu32NSRamBuf region isn't in Non-secure area
351   * @retval     0xF0F00001      Wrong u32NSAddr, pu32NSRamBuf or u32Size parameter
352   * @retval     0xF0F00003      u32NSAddr isn't valid flash address
353   * @retval     0xF0F00004      pu32NSRamBuf isn't valid sram address
354   * @retval     -1              Multi-words write failed
355   * @retval     0               Program operation is finished
356   * @details    To program multi-words data start from specified Non-secure flash address.
357   *             And maximum program size is one page size, 2048 bytes.
358   */
359 int32_t BL_FlashMultiWrite(uint32_t u32NSAddr, uint32_t *pu32NSRamBuf, uint32_t u32Size);
360
361
362 /**
363   * @brief      Non-secure Flash Page Erase (for Non-secure region)
364   * @param[in]  u32NSAddr   Non-secure flash region to be erased and must be a page size aligned address.
365   * @retval     0xF0F00000  u32NSAddr region isn't in Non-secure area
366   * @retval     0xF0F00001  u32NSAddr isn't page size aligned
367   * @retval     0xF0F00003  u32NSAddr isn't valid flash address
368   * @retval     -1          Page erase failed
369   * @retval     0           Page erase success
370   * @details    This API is used to perform page erase command on specified Non-secure flash address.
371   *             And this address must be a page size aligned address.
372   */
373 int32_t BL_FlashPageErase(uint32_t u32NSAddr);
374
375
376 /**
377   * @brief      Get Non-secure Flash Area CRC32 Checksum (for Non-secure region)
378   * @param[in]  u32NSAddr       Non-secure flash region to be calculated. u32NSAddr must be a page size aligned address.
379   * @param[in]  u32ByteCount    Byte counts of Non-secure flash area to be calculated. It must be multiple of 2048 bytes.
380   * @retval     0xF0F00000      u32NSAddr region isn't in Non-secure area
381   * @retval     0xF0F00001      Wrong u32NSAddr or u32ByteCount parameter
382   * @retval     0xF0F00003      u32NSAddr isn't valid flash address
383   * @retval     -1              Execute CRC32 operation failed
384   * @retval     Result of CRC32 checksum
385   * @details    This API will calculate the CRC32 checksum result of specified non-secure flash area.
386   *             The starting address and calculated size must be all 2048 bytes page size aligned.
387   */
388 uint32_t BL_FlashChecksum(uint32_t u32NSAddr, uint32_t u32ByteCount);
389
390
391 /**
392   * @brief      Check Non-secure Flash Area Data are all ONE or not (for Non-secure region)
393   * @param[in]  u32NSAddr       Non-secure flash region to be calculated. u32NSAddr must be a page size aligned address.
394   * @param[in]  u32ByteCount    Byte counts of Non-secure flash area to be calculated. It must be multiple of 2048 bytes.
395   * @retval     0xF0F00000      u32NSAddr region isn't in Non-secure area
396   * @retval     0xF0F00001      Wrong u32NSAddr or u32ByteCount parameter
397   * @retval     0xF0F00003      u32NSAddr isn't valid flash address
398   * @retval     -1              Execute Check Flash All One operation failed
399   * @retval     0xA11FFFFF      The contents of verified Non-secure flash area are 0xFFFFFFFF
400   * @retval     0xA1100000      Some contents of verified Non-secure flash area are not 0xFFFFFFFF
401   * @details    This API is used to check specified Non-secure flash area are all 0xFFFFFFFF or not.
402   */
403 uint32_t BL_CheckFlashAllOne(uint32_t u32NSAddr, uint32_t u32ByteCount);
404
405
406 /**
407   * @brief      Read Company ID
408   * @param      None
409   * @return     The company ID (32-bit)
410   * @details    The company ID of Nuvoton is fixed to be 0xDA.
411   */
412 uint32_t BL_ReadCID(void);
413
414
415 /**
416   * @brief      Read Device ID
417   * @param      None
418   * @return     The device ID (32-bit)
419   * @details    This function is used to read device ID.
420   */
421 uint32_t BL_ReadDID(void);
422
423
424 /**
425   * @brief      Read Product ID
426   * @param      None
427   * @return     The product ID (32-bit)
428   * @details    This function is used to read product ID.
429   */
430 uint32_t BL_ReadPID(void);
431
432
433 /**
434   * @brief      Read UCID
435   * @param[in]  u32Index    Index of the UCID to read and u32Index must be 0, 1, 2, or 3.
436   * @return     The UCID of specified index
437   * @details    This function is used to read unique chip ID (UCID).
438   */
439 uint32_t BL_ReadUCID(uint32_t u32Index);
440
441
442 /**
443   * @brief      Read UID
444   * @param[in]  u32Index    UID index. 0 = UID[31:0], 1 = UID[63:32], 2 = UID[95:64]
445   * @return     The 32-bit unique ID data of specified UID index
446   * @details    To read out specified 32-bit unique ID.
447   */
448 uint32_t BL_ReadUID(uint32_t u32Index);
449
450
451 /**
452   * @brief      Get XOM Active Status
453   * @param[in]  u32XOM      Specified XOM region, it must be between 0~3.
454   * @retval     0xF0F00001  Invalid u32XOM number
455   * @retval     0           Current XOM region isn't active yet
456   * @retval     1           Current XOM region is active
457   * @details    This API will return specified XOM region active status.
458   */
459 uint32_t BL_GetXOMActiveStatus(uint32_t u32XOM);
460
461
462 /**
463   * @brief      Read XOM Setting (for Non-secure region)
464   * @param[in]  u32XOM          Specified XOM region, it must be between 0~3
465   * @param[out] pu32Base        Return specified XOM base address
466   * @param[out] pu32PageCnt     Return specified XOM page count
467   * @retval     0xF0F00000      pu32Base, pu32PageCnt or XOM base address isn't in Non-secure area
468   * @retval     0xF0F00001      Wrong u32XOM, pu32Base or pu32PageCnt parameter
469   * @retval     0xF0F00003      XOM base address isn't valid flash address
470   * @retval     0xF0F00004      pu32Base or pu32PageCnt isn't valid sram address
471   * @retval     0xF0F00005      XOM region isn't configured
472   * @retval     0               Read specified XOM setting success
473   * @details    This API will read specified XOM relative settings.
474   */
475 int32_t BL_ReadXOMRegion(uint32_t u32XOM, uint32_t *pu32Base, uint32_t *pu32PageCnt);
476
477
478 /**
479   * @brief      Set XOM Region and Active (for Non-secure region)
480   * @param[in]  u32XOM          Specified XOM region, it must be between 0~3
481   * @param[in]  u32Base         Base address of XOM region
482   * @param[in]  u32PageCnt      Page count of XOM region
483   * @param[in]  u32IsDebugMode  1: Enable XOM debug mode; others will disable XOM debug mode.
484   * @retval     0xF0F00000      XOM region isn't in Non-secure area
485   * @retval     0xF0F00001      Wrong u32XOM, u32Base or u32PageCnt parameter
486   * @retval     0xF0F00003      u32Base isn't valid flash address
487   * @retval     0xF0F00006      XOM region has configured
488   * @retval     0xF0F00007      XOM region has active
489   * @retval     -1              Set XOM failed
490   * @retval     0               Set specified XOM success
491   * @details    This API will set specified XOM active.
492   */
493 int32_t BL_SetXOMRegion(uint32_t u32XOM, uint32_t u32Base, uint32_t u32PageCnt, uint32_t u32IsDebugMode);
494
495
496 /**
497   * @brief      Erase XOM Setting (for Non-secure region)
498   * @param[in]  u32XOMBase  Specified XOM region to be erase
499   * @retval     0xF0F00000  u32XOMBase or erase XOM region isn't in Non-secure area
500   * @retval     0xF0F00001  u32XOMBase isn't page size aligned
501   * @retval     0xF0F00003  u32XOMBase isn't valid flash address
502   * @retval     0xF0F00008  Invalid u32XOMBase address
503   * @retval     -1          Erase XOM region failed
504   * @retval     0           Erase XOM region success
505   * @details    This API will erase specified XOM region data and relative XOM setting.
506   */
507 int32_t BL_EraseXOMRegion(uint32_t u32XOMBase);
508
509
510 /**
511   * @brief      Get XOM Erased Status
512   * @param      None
513   * @retval     -1      Erase XOM operation failed
514   * @retval     0       Erase XOM operation success
515   * @details    This API will return the XOM erase operation is success or not.
516   */
517 int32_t BL_GetXOMEraseStatus(void);
518
519
520 /**
521   * @brief      Read KPKEYSTS Status
522   * @param      None
523   * @return     KPKEYSTS register status
524   * @details    This API can read KPROM KPKEYSTS register status.
525   */
526 uint32_t BL_GetKPROMStatus(void);
527
528
529 /**
530   * @brief      Read KPKEYCNT Status
531   * @param      None
532   * @return     KPKEYCNT register status
533   * @details    This API can read KPROM KPKEYCNT register status.
534   */
535 uint32_t BL_GetKPROMCounter(void);
536
537
538 /**
539   * @brief      Read KPCNT Status
540   * @param      None
541   * @return     KPCNT register status
542   * @details    This API can read KPROM KPCNT register status.
543   */
544 uint32_t BL_GetKPROMPowerOnCounter(void);
545
546
547 /**
548   * @brief      Execute KPROM Key Comparison
549   * @param[in]  key0        KPROM key0
550   * @param[in]  key1        KPROM key1
551   * @param[in]  key2        KPROM key2
552   * @retval     0xF0F00009  KPROM function isn't enabled
553   * @retval     0xF0F0000A  Trigger KPROM key comparison is FORBID
554   * @retval     0xF0F0000B  KPROM Key is mismatch
555   * @retval     0xF0F0000C  KPROM key still locked
556   * @retval     0           KPROM Key are matched
557   * @details    With this API, user can unlock KPROM write-protection and then execute FMC program command well.
558   */
559 int32_t BL_TrgKPROMCompare(uint32_t key0, uint32_t key1, uint32_t key2);
560
561
562 /**
563   * @brief      Execute CHIP Reset
564   * @param      None
565   * @return     None
566   * @details    This API will perform reset CHIP command to reset chip.
567   */
568 void BL_ResetChip(void);
569
570
571 /*--------------------------------------------------------------------------------------------------*/
572 /*  The following functions are for Secure code only                                                */
573 /*--------------------------------------------------------------------------------------------------*/
574 /**
575   * @brief      Check if ECC Private Key Valid
576   * @param[in]  xcrpt       The pointer of the global XCRPT data
577   * @param[in]  ecc_curve   The pre-defined ECC curve.
578   * @param[in]  private_k   The input private key.
579   * @return     1   Is valid.
580   * @return     0   Is not valid.
581   * @return     -1  Invalid curve.
582   * @details    This API is used to check if the private key is placed in valid range of curve.
583   */
584 int32_t XECC_IsPrivateKeyValid(XCRPT_T *xcrpt, E_ECC_CURVE ecc_curve, char private_k[]);
585
586
587 /**
588   * @brief      Generate ECC Public Key
589   * @param[in]  xcrpt       The pointer of the global XCRPT data
590   * @param[in]  ecc_curve   The pre-defined ECC curve.
591   * @param[in]  private_k   The input private key.
592   * @param[out] public_k1   The output public key 1.
593   * @param[out] public_k2   The output public key 2.
594   * @return     0   Success.
595   * @return     -1  "ecc_curve" value is invalid.
596   * @details    This API is used to generate a public key pair by a specified ECC private key and ECC curve.
597   */
598 int32_t XECC_GeneratePublicKey(XCRPT_T *xcrpt, E_ECC_CURVE ecc_curve, char *private_k, char public_k1[], char public_k2[]);
599
600
601 /**
602   * @brief      Generate ECDSA Signature
603   * @param[in]  xcrpt       The pointer of the global XCRPT data
604   * @param[in]  ecc_curve   The pre-defined ECC curve.
605   * @param[in]  message     The hash value of source context.
606   * @param[in]  d           The private key.
607   * @param[in]  k           The selected random integer.
608   * @param[out] R           R of the (R,S) pair digital signature
609   * @param[out] S           S of the (R,S) pair digital signature
610   * @return     0   Success.
611   * @return     -1  "ecc_curve" value is invalid.
612   * @details    This API is used to generate an ECDSA digital signature.
613   */
614 int32_t XECC_GenerateSignature(XCRPT_T *xcrpt, E_ECC_CURVE ecc_curve, char *message, char *d, char *k, char *R, char *S);
615
616
617 /**
618   * @brief      Verify ECDSA Signature
619   * @param[in]  xcrpt       The pointer of the global XCRPT data
620   * @param[in]  ecc_curve   The pre-defined ECC curve.
621   * @param[in]  message     The hash value of source context.
622   * @param[in]  public_k1   The public key 1.
623   * @param[in]  public_k2   The public key 2.
624   * @param[in]  R           R of the (R,S) pair digital signature
625   * @param[in]  S           S of the (R,S) pair digital signature
626   * @return     0   Success.
627   * @return     -1  "ecc_curve" value is invalid.
628   * @return     -2  Verification failed.
629   * @details    This API is used to perform the ECDSA digital signature verification.
630   */
631 int32_t XECC_VerifySignature(XCRPT_T *xcrpt, E_ECC_CURVE ecc_curve, char *message, char *public_k1, char *public_k2, char *R, char *S);
632
633
634 /**
635   * @brief      Generate ECDH Secret Shared Key
636   * @param[in]  xcrpt       The pointer of the global XCRPT data
637   * @param[in]  ecc_curve   The pre-defined ECC curve.
638   * @param[in]  private_k   One's own private key.
639   * @param[in]  public_k1   The other party's public key 1.
640   * @param[in]  public_k2   The other party's public key 2.
641   * @param[out] secret_z    The ECC CDH secret Z.
642   * @return     0   Success.
643   * @return     -1  "ecc_curve" value is invalid.
644   * @details    This API is used to generate an ECDH shared key.
645   */
646 int32_t XECC_GenerateSecretZ(XCRPT_T *xcrpt, E_ECC_CURVE ecc_curve, char *private_k, char public_k1[], char public_k2[], char secret_z[]);
647
648
649 /**
650   * @brief      Convert Data to Hex Format
651   * @param[in]  count   Byte counts for convert.
652   * @param[in]  reg     The input data buffer.
653   * @param[out] output  The output data buffer.
654   * @return     None
655   * @details    This API is used to convert the data to hex format.
656   */
657 void XECC_Reg2Hex(int32_t count, uint32_t volatile reg[], char output[]);
658
659
660 /**
661   * @brief      Convert Data to Register Format
662   * @param[in]  input   The input data buffer.
663   * @param[out] reg     The output data buffer.
664   * @return     None
665   * @details    This API is used to convert the data in a register data format.
666   */
667 void XECC_Hex2Reg(char input[], uint32_t volatile reg[]);
668
669
670 /**
671   * @brief      Get ID ECC R, S digital signature (for Secure code)
672   * @param[out] R           R of the (R,S) pair digital signature
673   * @param[out] S           S of the (R,S) pair digital signature
674   * @retval     -1          Get R, S digital signature fail
675   * @retval     0           Success
676   * @details    This API will return ECC R, S digital signature of chip ID, include PDID, UID0~2 and UCID0~3.
677   */
678 int32_t XECC_GetIDECCSignature(uint32_t *R, uint32_t *S);
679
680
681 /**
682   * @brief      Open TDES Encrypt/Decrypt
683   * @param[in]  xcrpt       The pointer of the global XCRPT data
684   * @param[in]  u32Channel  TDES channel. Must be 0~3.
685   * @param[in]  u32EncDec   1: TDES encode; 0: TDES decode
686   * @param[in]  Is3DES      1: TDES; 0: DES
687   * @param[in]  Is3Key      1: TDES 3 key mode; 0: TDES 2 key mode
688   * @param[in]  u32OpMode   TDES operation mode, including:
689   *                 - \ref TDES_MODE_ECB
690   *                 - \ref TDES_MODE_CBC
691   *                 - \ref TDES_MODE_CFB
692   *                 - \ref TDES_MODE_OFB
693   *                 - \ref TDES_MODE_CTR
694   * @param[in]  u32SwapType is TDES input/output data swap control and word swap control, including:
695   *                 - \ref TDES_NO_SWAP
696   *                 - \ref TDES_WHL_SWAP
697   *                 - \ref TDES_OUT_SWAP
698   *                 - \ref TDES_OUT_WHL_SWAP
699   *                 - \ref TDES_IN_SWAP
700   *                 - \ref TDES_IN_WHL_SWAP
701   *                 - \ref TDES_IN_OUT_SWAP
702   *                 - \ref TDES_IN_OUT_WHL_SWAP
703   * @return     None
704   * @details    This API is used to enable TDES encrypt/decrypt function.
705   */
706 void XTDES_Open(XCRPT_T *xcrpt, uint32_t u32Channel, uint32_t u32EncDec, int32_t Is3DES, int32_t Is3Key, uint32_t u32OpMode, uint32_t u32SwapType);
707
708
709 /**
710   * @brief      Start TDES Encrypt/Decrypt
711   * @param[in]  xcrpt       The pointer of the global XCRPT data
712   * @param[in]  u32Channel  TDES channel. Must be 0~3.
713   * @param[in]  u32DMAMode  TDES DMA control, including:
714   *                 - \ref CRYPTO_DMA_ONE_SHOT  One shot TDES encrypt/decrypt.
715   *                 - \ref CRYPTO_DMA_CONTINUE  Continuous TDES encrypt/decrypt.
716   *                 - \ref CRYPTO_DMA_LAST      Last TDES encrypt/decrypt of a series of XTDES_Start.
717   * @return     None
718   * @details    This API is used to start TDES encrypt/decrypt.
719   */
720 void XTDES_Start(XCRPT_T *xcrpt, int32_t u32Channel, uint32_t u32DMAMode);
721
722
723 /**
724   * @brief      Set TDES Keys
725   * @param[in]  xcrpt           The pointer of the global XCRPT data
726   * @param[in]  u32Channel      TDES channel. Must be 0~3.
727   * @param[in]  au32Keys        The TDES keys. au32Keys[0][0] is Key0 high word and au32Keys[0][1] is key0 low word.
728   * @return     None
729   * @details    This API is used to set TDES keys.
730   */
731 void XTDES_SetKey(XCRPT_T *xcrpt, uint32_t u32Channel, uint32_t au32Keys[3][2]);
732
733
734 /**
735   * @brief      Set TDES Initial Vectors
736   * @param[in]  xcrpt       The pointer of the global XCRPT data
737   * @param[in]  u32Channel  TDES channel. Must be 0~3.
738   * @param[in]  u32IVH      TDES initial vector high word.
739   * @param[in]  u32IVL      TDES initial vector low word.
740   * @return     None
741   * @details    This API is used to set TDES initial vectors.
742   */
743 void XTDES_SetInitVect(XCRPT_T *xcrpt, uint32_t u32Channel, uint32_t u32IVH, uint32_t u32IVL);
744
745
746 /**
747   * @brief      Set TDES DMA Transfer Configuration
748   * @param[in]  xcrpt       The pointer of the global XCRPT data
749   * @param[in]  u32Channel  TDES channel. Must be 0~3.
750   * @param[in]  u32SrcAddr  TDES DMA source address
751   * @param[in]  u32DstAddr  TDES DMA destination address
752   * @param[in]  u32TransCnt TDES DMA transfer byte count
753   * @return     None
754   * @details    This API is used to configure the TDES DMA transfer.
755   */
756 void XTDES_SetDMATransfer(XCRPT_T *xcrpt, uint32_t u32Channel, uint32_t u32SrcAddr, uint32_t u32DstAddr, uint32_t u32TransCnt);
757
758
759 /**
760   * @brief      Open SHA Encrypt
761   * @param[in]  xcrpt       The pointer of the global XCRPT data
762   * @param[in]  u32OpMode   SHA operation mode, including:
763   *                 - \ref SHA_MODE_SHA1
764   *                 - \ref SHA_MODE_SHA224
765   *                 - \ref SHA_MODE_SHA256
766   *                 - \ref SHA_MODE_SHA384
767   *                 - \ref SHA_MODE_SHA512
768   * @param[in]  u32SwapType is the SHA input/output data swap control, including:
769   *                 - \ref SHA_NO_SWAP
770   *                 - \ref SHA_OUT_SWAP
771   *                 - \ref SHA_IN_SWAP
772   *                 - \ref SHA_IN_OUT_SWAP
773   * @param[in]  hmac_key_len    HMAC key byte count
774   * @return     None
775   * @details    This API is used to enable SHA encrypt function.
776   */
777 void XSHA_Open(XCRPT_T *xcrpt, uint32_t u32OpMode, uint32_t u32SwapType, uint32_t hmac_key_len);
778
779
780 /**
781   * @brief      Start SHA Encrypt
782   * @param[in]  xcrpt       The pointer of the global XCRPT data
783   * @param[in]  u32DMAMode  SHA DMA control, including:
784   *                 - \ref CRYPTO_DMA_ONE_SHOT  One shot SHA encrypt.
785   *                 - \ref CRYPTO_DMA_CONTINUE  Continuous SHA encrypt.
786   *                 - \ref CRYPTO_DMA_LAST      Last SHA encrypt of a series of XSHA_Start.
787   * @return     None
788   * @details    This API is used to start SHA encrypt.
789   */
790 void XSHA_Start(XCRPT_T *xcrpt, uint32_t u32DMAMode);
791
792
793 /**
794   * @brief      Set SHA DMA Transfer Configuration
795   * @param[in]  xcrpt       The pointer of the global XCRPT data
796   * @param[in]  u32SrcAddr  SHA DMA source address
797   * @param[in]  u32TransCnt SHA DMA transfer byte count
798   * @return     None
799   * @details    This API is used to configure the SHA DMA transfer.
800   */
801 void XSHA_SetDMATransfer(XCRPT_T *xcrpt, uint32_t u32SrcAddr, uint32_t u32TransCnt);
802
803
804 /**
805   * @brief      Read SHA Digest
806   * @param[in]  xcrpt       The pointer of the global XCRPT data
807   * @param[out] u32Digest   The SHA encrypt output digest.
808   * @return     None
809   * @details    This API is used to read the SHA digest.
810   */
811 void XSHA_Read(XCRPT_T *xcrpt, uint32_t u32Digest[]);
812
813
814 /**
815   * @brief      Open AES Encrypt/Decrypt
816   * @param[in]  xcrpt       The pointer of the global XCRPT data
817   * @param[in]  u32Channel  AES channel. Must be 0~3.
818   * @param[in]  u32EncDec   1: AES encode;  0: AES decode
819   * @param[in]  u32OpMode   AES operation mode, including:
820   *                 - \ref AES_MODE_ECB
821   *                 - \ref AES_MODE_CBC
822   *                 - \ref AES_MODE_CFB
823   *                 - \ref AES_MODE_OFB
824   *                 - \ref AES_MODE_CTR
825   *                 - \ref AES_MODE_CBC_CS1
826   *                 - \ref AES_MODE_CBC_CS2
827   *                 - \ref AES_MODE_CBC_CS3
828   * @param[in]  u32KeySize is AES key size, including:
829   *                 - \ref AES_KEY_SIZE_128
830   *                 - \ref AES_KEY_SIZE_192
831   *                 - \ref AES_KEY_SIZE_256
832   * @param[in]  u32SwapType is AES input/output data swap control, including:
833   *                 - \ref AES_NO_SWAP
834   *                 - \ref AES_OUT_SWAP
835   *                 - \ref AES_IN_SWAP
836   *                 - \ref AES_IN_OUT_SWAP
837   * @return     None
838   * @details    This API is used to enable AES encrypt/decrypt function.
839   */
840 void XAES_Open(XCRPT_T *xcrpt, uint32_t u32Channel, uint32_t u32EncDec, uint32_t u32OpMode, uint32_t u32KeySize, uint32_t u32SwapType);
841
842
843 /**
844   * @brief      Start AES Encrypt/Decrypt
845   * @param[in]  xcrpt       The pointer of the global XCRPT data
846   * @param[in]  u32Channel  AES channel. Must be 0~3.
847   * @param[in]  u32DMAMode  AES DMA control, including:
848   *                     - \ref CRYPTO_DMA_ONE_SHOT  One shot AES encrypt/decrypt.
849   *                     - \ref CRYPTO_DMA_CONTINUE  Continuous AES encrypt/decrypt.
850   *                     - \ref CRYPTO_DMA_LAST      Last AES encrypt/decrypt of a series of XAES_Start.
851   * @return     None
852   * @details    This API is used to start AES encrypt/decrypt.
853   */
854 void XAES_Start(XCRPT_T *xcrpt, int32_t u32Channel, uint32_t u32DMAMode);
855
856
857 /**
858   * @brief      Set AES Keys
859   * @param[in]  xcrpt       The pointer of the global XCRPT data
860   * @param[in]  u32Channel  AES channel. Must be 0~3.
861   * @param[in]  au32Keys    An word array contains AES keys.
862   * @param[in]  u32KeySize is AES key size, including:
863   *                 - \ref AES_KEY_SIZE_128
864   *                 - \ref AES_KEY_SIZE_192
865   *                 - \ref AES_KEY_SIZE_256
866   * @return     None
867   * @details    This API is used to set AES keys.
868   */
869 void XAES_SetKey(XCRPT_T *xcrpt, uint32_t u32Channel, uint32_t au32Keys[], uint32_t u32KeySize);
870
871
872 /**
873   * @brief      Set AES Initial Vectors
874   * @param[in]  xcrpt       The pointer of the global XCRPT data
875   * @param[in]  u32Channel  AES channel. Must be 0~3.
876   * @param[in]  au32IV      A four entry word array contains AES initial vectors.
877   * @return     None
878   * @details    This API is used to set AES initial vectors.
879   */
880 void XAES_SetInitVect(XCRPT_T *xcrpt, uint32_t u32Channel, uint32_t au32IV[]);
881
882
883 /**
884   * @brief      Set AES DMA Transfer Configuration
885   * @param[in]  xcrpt       The pointer of the global XCRPT data
886   * @param[in]  u32Channel   AES channel. Must be 0~3.
887   * @param[in]  u32SrcAddr   AES DMA source address
888   * @param[in]  u32DstAddr   AES DMA destination address
889   * @param[in]  u32TransCnt  AES DMA transfer byte count
890   * @return     None
891   * @details    This API is used to configure the AES DMA transfer.
892   */
893 void XAES_SetDMATransfer(XCRPT_T *xcrpt, uint32_t u32Channel, uint32_t u32SrcAddr, uint32_t u32DstAddr, uint32_t u32TransCnt);
894
895
896 /**
897   * @brief      Initial Random Number Generator (for Secure code)
898   *
899   * @param[in]  rng     The structure of random number generator
900   * @param[in]  opt     Operation modes. Possible options are,
901   *                         (XTRNG_PRNG | XTRNG_LIRC32K),
902   *                         (XTRNG_PRNG | XTRNG_LXT),
903   *                         (XTRNG_SWRNG | XTRNG_LIRC32K),
904   *                         (XTRNG_SWRNG | XTRNG_LXT)
905   * @retval     -1      Fail
906   * @retval     0       Success
907   *
908   * @details    This API is used to initial random number generator.
909   *             After initial this API success, user can call XTRNG_Random API to generate the random number.
910   */
911 int32_t XTRNG_RandomInit(XTRNG_T *rng, uint32_t opt);
912
913
914 /**
915   * @brief      Generate Random Number (for Secure code)
916   *
917   * @param[in]  rng     The structure of random number generator
918   * @param[out] p       Starting buffer address to store random number
919   * @param[in]  size    Total byte counts of random number
920   * @retval     -1      Fail
921   * @retval     0       Success
922   * @details    This API is used to generate random number.
923   */
924 int32_t XTRNG_Random(XTRNG_T *rng, uint8_t *p, uint32_t size);
925
926
927 /**
928   * @brief      Get ID ECC R, S Digital Signature (for Secure code)
929   * @param[out] R           R of the (R,S) pair digital signature
930   * @param[out] S           S of the (R,S) pair digital signature
931   * @retval     -1          Get R, S digital signature fail
932   * @retval     0           Success
933   * @details    This API will return ECC R, S digital signature of chip ID, include PDID, UID0~2 and UCID0~3.
934   */
935 int32_t BL_GetIDECCSignature(uint32_t *R, uint32_t *S);
936
937
938 /**
939   * @brief      Initial Random Number Generator (for Secure code)
940   *
941   * @param[in]  rng     The structure of random number generator
942   * @param[in]  opt     Operation modes. Possible options are,
943   *                         (BL_RNG_PRNG | BL_RNG_LIRC32K),
944   *                         (BL_RNG_PRNG | BL_RNG_LXT),
945   *                         (BL_RNG_SWRNG | BL_RNG_LIRC32K),
946   *                         (BL_RNG_SWRNG | BL_RNG_LXT)
947   * @retval     -1      Fail
948   * @retval     0       Success
949   *
950   * @details    This API is used to initial random number generator.
951   *             After initial this API success, user can perform BL_Random API to generate the random number.
952   */
953 int32_t BL_RandomInit(BL_RNG_T *rng, uint32_t opt);
954
955
956 /**
957   * @brief      Generate Random Number (for Secure code)
958   *
959   * @param[in]  rng     The structure of random number generator
960   * @param[out] p       Starting buffer address to store random number
961   * @param[in]  size    Total byte counts of random number
962   * @retval     -1      Fail
963   * @retval     0       Success
964   * @details    This API is used to generate random number.
965   */
966 int32_t BL_Random(BL_RNG_T *rng, uint8_t *p, uint32_t size);
967
968
969 /**
970   * @brief      Initialize SecureISP Function (for Secure code)
971   * @param[in]  pISPInfo    The ISP information data buffer address
972   * @param[in]  pUSBDInfo   USB data buffer for SecureISP USB
973   * @param[in]  mode        Operation mode. Possible options are
974   *                             - \ref USB_MODE
975   *                             - \ref UART_MODE
976   *                             - \ref USB_UART_MODE
977   *                             - \ref RESYNC_ISP
978   * @return     Return process status and exit SecureISP mode.
979   * @details    Executing this API will initialize USB or UART1 SecureISP function.
980   *             User can use SecureISP Tool to communicate with target chip.
981   * @note       Configure relate USB and UART1 settings are necessary before executing this API.
982   */
983 int32_t BL_SecureISPInit(ISP_INFO_T *pISPInfo, BL_USBD_INFO_T *pUSBDInfo, E_ISP_MODE mode);
984
985
986 /**
987   * @brief      Process USBD Interrupt (for Secure code)
988   * @param[in]  pfnEPTable      Starting address to store EP callback function
989   * @param[in]  pInfo           The ISP information data buffer address
990   * @param[in]  pUSBDInfo       USB data buffer for SecureISP USB
991   * @retval     -1      Execute API in Non-secure code
992   * @retval     0       Process USBD interrupt event success
993   * @details    This API is used to process USBD command and should be called in USBD_IRQHandler().
994   */
995 int32_t BL_ProcessUSBDInterrupt(uint32_t *pfnEPTable, uint32_t *pInfo, uint32_t *pUSBDInfo);
996
997
998 /**
999   * @brief      Process UART1 Interrupt (for Secure code)
1000   * @param[in]  pInfo   The ISP information data buffer address
1001   * @retval     -1      Execute API in Non-secure code
1002   * @retval     0       Process UART1 interrupt event success
1003   * @details    This API is used to process UART1 command and should be called in UART1_IRQHandler().
1004   */
1005 int32_t BL_ProcessUART1Interrupt(uint32_t *pInfo);
1006
1007
1008 /**
1009   * @brief      Get Vendor Data (for Secure code)
1010   * @param[in]  pInfo       The ISP information data buffer address
1011   * @param[out] pu32Data    Data buffer to store vendor data. Maximum buffer size is 44 bytes.
1012   * @param[in]  pu32Buf     Internal used data buffer address
1013   * @retval     0           Success
1014   * @retval     -1          Invalid command packet
1015   * @retval     -2          Not in vendor function
1016   * @details    This API is used to get the vendor data and should be called in the vendor function.
1017   */
1018 int32_t BL_GetVendorData(uint32_t *pInfo, uint32_t *pu32Data, uint32_t *pu32Buf);
1019
1020
1021 /**
1022   * @brief      Return Vendor Data (for Secure code)
1023   * @param[in]  pu32Data    Data buffer to store response data
1024   * @param[in]  u32Len      Data buffer length, maximum size is 40 bytes.
1025   * @param[in]  pu32Buf     Internal used data buffer address
1026   * @retval     0           Success
1027   * @retval     -1          Invalid buffer length
1028   * @retval     -2          Not in vendor function
1029   * @details    This API is used to return vendor data to server and should be called in the vendor function.
1030   */
1031 int32_t BL_ReturnVendorData(uint32_t *pu32Data, uint32_t u32Len, uint32_t *pu32Buf);
1032
1033
1034 /**
1035   * @brief      Generate Command Response Data (for Secure code)
1036   * @param[in]  pCMD        Buffer address to store command data
1037   * @param[in]  pISPInfo    The ISP information data buffer address
1038   * @retval     0           Command success
1039   * @retval     Other       Command fail
1040   * @details    This API is used to generate response data to server.
1041   */
1042 int32_t Cmd_GenRspPacket(CMD_PACKET_T *pCMD, ISP_INFO_T *pISPInfo);
1043
1044
1045 /**
1046   * @brief      Parse Command (for Secure code)
1047   * @param[in]  pCMD        Buffer address to store command
1048   * @param[in]  pISPInfo    The ISP information data buffer address
1049   * @retval     0           Command success
1050   * @retval     Other       Command fail
1051   * @details    This API is used to parse data from server.
1052   */
1053 int32_t Cmd_ParseReqPacket(CMD_PACKET_T *pCMD, ISP_INFO_T *pISPInfo);
1054
1055
1056 /**
1057   * @brief      Parse CONNECT Command (for Secure code)
1058   * @param[in]  pISPInfo    The ISP information data buffer address
1059   * @retval     0           Success
1060   * @retval     Other       Command fail
1061   * @details    This API is used for parse CONNECT command only.
1062   */
1063 int32_t ParseCONNECT(ISP_INFO_T *pISPInfo);
1064
1065
1066 /**
1067   * @brief      Parse related ECDH Commands (for Secure code)
1068   * @param[in]  pISPInfo    The ISP information data buffer address
1069   * @retval     0           Success
1070   * @retval     Other       Command fail
1071   * @details    This API is used for parse related ECDH commands.
1072   */
1073 int32_t ParseECDH(ISP_INFO_T *pISPInfo);
1074
1075
1076 /**
1077   * @brief      Parse Commands (for Secure code)
1078   * @param[in]  pISPInfo    The ISP information data buffer address
1079   * @retval     0           Success
1080   * @retval     Other       Command fail
1081   * @details    This API is used for parse all commands except CONNECT and related ECDH commands.
1082   */
1083 int32_t ParseCommands(ISP_INFO_T *pISPInfo);
1084
1085
1086 /**
1087   * @brief      Initialize USBD Module (for Secure code)
1088   * @param[in]  param           The structure of USBD information
1089   * @param[in]  pfnClassReq     USB Class request callback function
1090   * @param[in]  pfnSetInterface USB Set Interface request callback function
1091   * @param[in]  pUSBDInfo       USB data buffer for SecureISP USB mode
1092   * @retval     -1              Execute API in Non-secure code
1093   * @retval     0               Success
1094   * @details    This function will enable USB controller, USB PHY transceiver and pull-up resistor of USB_D+ pin. USB PHY will drive SE0 to bus.
1095   */
1096 int32_t BL_USBDOpen(const S_USBD_INFO_T *param, CLASS_REQ pfnClassReq, SET_INTERFACE_REQ pfnSetInterface, uint32_t *pUSBDInfo);
1097
1098
1099 /**
1100   * @brief      Install EP Callback Function (for Secure code)
1101   * @param[in]  ep              EP number
1102   * @param[in]  pfnEPHandler    EP callback function
1103   * @param[in]  pfnEPTable      Starting address to store EP callback function
1104   * @retval     -1      Fail
1105   * @retval     0       Success
1106   * @details    This function is used to set specific EP callback function
1107   */
1108 int32_t BL_USBDInstallEPHandler(uint32_t ep, void *pfnEPHandler, uint32_t *pfnEPTable);
1109
1110
1111 /**
1112   * @brief      Start USBD Function (for Secure code)
1113   * @param      None
1114   * @retval     -1      Execute API in Non-secure code
1115   * @retval     0       Success
1116   * @details    Enable WAKEUP, FLDET, USB and BUS interrupts. Disable software-disconnect function after 100ms delay with SysTick timer.
1117   */
1118 int32_t BL_USBDStart(void);
1119
1120
1121 /*@}*/ /* end of group MKROM_EXPORTED_FUNCTIONS */
1122
1123 /*@}*/ /* end of group MKROM_Driver */
1124
1125 /*@}*/ /* end of group Standard_Driver */
1126
1127
1128 #ifdef __cplusplus
1129 }
1130 #endif
1131
1132 #endif  /* __MKROM_LIB_H__ */
1133
1134 /*** (C) COPYRIGHT 2018 Nuvoton Technology Corp. ***/