PAN1080 Peripheral API
pan_fmc.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Panchip Technology Corp. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
16#ifndef __PAN_FMC_H__
17#define __PAN_FMC_H__
18
25#ifdef __cplusplus
26extern "C"
27{
28#endif
29
30
35#define CMD_ERASE_PAGE (0X81)
36#define CMD_ERASE_SECTOR (0X20)
37#define CMD_ERASE_32K (0X52)
38#define CMD_ERASE_64K (0Xd8)
39#define CMD_ERASE_CHIP (0xc7)
45#define CMD_READ_STATUS_L (0x05)
46#define CMD_READ_STATUS_H (0x35)
47#define CMD_WRITE_STATUS (0x01)
53#define OPS_WR_STU_REG_NOR (0x00)
54#define OPS_WR_STU_REG_ALL (0x01)
60#define CMD_FAST_READ (0x0b)
61#define CMD_NORM_READ (0x03)
62#define CMD_DREAD (0x3B)
63#define CMD_2READ (0xBB)
64#define CMD_QREAD (0x6B)
65#define CMD_4READ (0xEB)
71#define CMD_BURST_READ (0x77)
72#define BURST_READ_MODE_8 (0x00)
73#define BURST_READ_MODE_16 (0x01)
74#define BURST_READ_MODE_32 (0x02)
75#define BURST_READ_MODE_64 (0x03)
79#define CMD_TRIG (0x01)
80#define CMD_WRITE_ENABLE (0x06)
85#define FLASH_X1_MODE 0
86#define FLASH_X2_MODE 1
87#define FLASH_X4_MODE 2
90#define QUAD_ENABLE_Pos (9)
91#define QUAD_ENABLE_Msk (0x1ul << QUAD_ENABLE_Pos)
92#define Write_Enable_Latch_Pos (1)
93#define Write_Enable_Latch_Msk (0x1ul << Write_Enable_Latch_Pos)
94#define Write_In_Process_Pos (0)
95#define Write_In_Process_Msk (0x1ul << Write_In_Process_Pos)
96#define Long_Time_Op_Pos (17)
98#define PAGE_SIZE (256)
99#define SECTOR_SIZE (4096)
109/* #pragma anon_unions */
110typedef struct _flash_ids {
112 union {
113 uint8_t d[2];
114 struct {
117 };
118 };
119 uint8_t uid[16];
121
129__STATIC_FORCEINLINE void FMC_EnterDeepPowerDownMode(FLCTL_T *fmc)
130{
131 // enter flash dp mode
132 fmc->X_FL_CTL = (0<<8) | (0x01<<0);
133 fmc->X_FL_WD[0] = 0xB9;
134 fmc->X_FL_TRIG = CMD_TRIG;
135 while(fmc->X_FL_TRIG){};
136}
137
146__STATIC_FORCEINLINE void FMC_ExitDeepPowerDownMode(FLCTL_T *fmc)
147{
148 // exit flash dp mode
149 fmc->X_FL_CTL = (0<<8) | (0x01<<0);
150 fmc->X_FL_WD[0] = 0xAB;
151 fmc->X_FL_TRIG = CMD_TRIG;
152 while(fmc->X_FL_TRIG){};
153}
154
160extern void FMC_GetFlashUniqueId(FLCTL_T *fmc);
161
167extern void FMC_GetFlashJedecId(FLCTL_T *fmc);
168
174extern uint32_t FMC_GetFlashCodeAreaSize(FLCTL_T *fmc);
175
187extern int FMC_EraseSector(FLCTL_T *fmc,unsigned long adr);
204extern int FMC_EraseBlock32k(FLCTL_T *fmc,unsigned long addr);
221extern int FMC_EraseBlock64k(FLCTL_T *fmc,unsigned long addr);
235extern int FMC_EraseChip(FLCTL_T *fmc);
251extern int FMC_EraseCodeArea(FLCTL_T *fmc, uint32_t addr, uint32_t len);
252
261extern void InitIcache(FLCTL_T *fmc,uint32_t mode);
262
272extern int32_t FMC_GetCrc32Sum(FLCTL_T *fmc,uint32_t addr, uint32_t count, uint32_t *chksum);
273
282extern int BlankCheck (FLCTL_T *fmc,unsigned long adr, unsigned long sz);
283
293extern unsigned long Verify(FLCTL_T *fmc, unsigned long adr, unsigned long sz, unsigned char *buf);
294
304extern int ProgramPage (FLCTL_T *fmc, unsigned long adr, unsigned long sz, unsigned char *buf);
305
314extern unsigned char FMC_ReadStatusReg(FLCTL_T *fmc,unsigned char cmd);
315
321extern unsigned char FMC_WriteEnable(FLCTL_T *fmc);
322
332extern void FMC_WriteStatusReg(FLCTL_T *fmc, unsigned char ops, unsigned int buf);
333
341extern unsigned char FMC_ReadByte(FLCTL_T *fmc, unsigned int Addr, unsigned char cmd);
342
350extern void FMC_WriteByte(FLCTL_T *fmc, unsigned int addr, unsigned char data);
351
359extern void FMC_WriteHalfWord(FLCTL_T *fmc, unsigned int addr, unsigned short data);
360
368extern unsigned int FMC_ReadWord(FLCTL_T *fmc,unsigned int Addr, unsigned char cmd);
369
377extern unsigned char *FMC_ReadPage(FLCTL_T *fmc,unsigned int Addr,unsigned char cmd);
378
388extern int FMC_ReadStream(FLCTL_T *fmc, unsigned int Addr, unsigned char cmd, unsigned char *buf, unsigned int len);
389
398extern int FMC_WriteStream(FLCTL_T *fmc, unsigned int Addr, unsigned char *buf, unsigned int len);
409extern int FMC_ReadInfoArea(FLCTL_T *fmc, unsigned int Addr, unsigned char cmd, unsigned char *buf, unsigned int len);
419extern int FMC_WriteInfoArea(FLCTL_T *fmc, unsigned int Addr, unsigned char *buf, unsigned int len);
426extern int FMC_EraseInfoArea(FLCTL_T *fmc);
427
435extern void FMC_SetFlashMode(FLCTL_T *fmc, uint32_t mode, bool enhance);
436
442extern void FMC_ExitEnhanceMode(FLCTL_T *fmc);
443
451extern void FMC_EnterEnhanceMode(FLCTL_T *fmc, uint32_t mode);
452
458extern void FMC_EnableAutoDp(FLCTL_T *fmc);
459
465extern void FMC_DisableAutoDp(FLCTL_T *fmc);
466
473extern void FMC_SetRdpWaitCount(FLCTL_T *fmc, uint32_t cnt);
474
478#ifdef __cplusplus
479}
480#endif
481
482#endif /* __PAN_FMC_H__ */
483
__STATIC_FORCEINLINE void FMC_ExitDeepPowerDownMode(FLCTL_T *fmc)
Exit flash deep power down mode.
Definition: pan_fmc.h:146
void FMC_SetFlashMode(FLCTL_T *fmc, uint32_t mode, bool enhance)
This function is used to set flash work mode.
__STATIC_FORCEINLINE void FMC_EnterDeepPowerDownMode(FLCTL_T *fmc)
Enter flash deep power down mode.
Definition: pan_fmc.h:129
void FMC_GetFlashUniqueId(FLCTL_T *fmc)
This function is used to get flash unique id,.
int32_t FMC_GetCrc32Sum(FLCTL_T *fmc, uint32_t addr, uint32_t count, uint32_t *chksum)
Calculate and read the CRC32 checksum of a specified flash area.
unsigned long Verify(FLCTL_T *fmc, unsigned long adr, unsigned long sz, unsigned char *buf)
Verify in flash memory.
unsigned char * FMC_ReadPage(FLCTL_T *fmc, unsigned int Addr, unsigned char cmd)
This function is used to read a page size (256 bytes) of data from flash.
void FMC_WriteHalfWord(FLCTL_T *fmc, unsigned int addr, unsigned short data)
This function is used to write halfword to flash memory.
void FMC_WriteStatusReg(FLCTL_T *fmc, unsigned char ops, unsigned int buf)
This function is used to write status, The Read Status Register can be read at any time.
uint32_t FMC_GetFlashCodeAreaSize(FLCTL_T *fmc)
Get Size of Flash in Bytes.
struct _flash_ids FLASH_IDS_T
Structure with flash id.
void FMC_GetFlashJedecId(FLCTL_T *fmc)
This function is used to get flash jedec id,.
void FMC_WriteByte(FLCTL_T *fmc, unsigned int addr, unsigned char data)
This function is used to write one byte to flash memory.
void FMC_SetRdpWaitCount(FLCTL_T *fmc, uint32_t cnt)
This function is used to set wait count for release from Deep Power-down mode.
int FMC_WriteInfoArea(FLCTL_T *fmc, unsigned int Addr, unsigned char *buf, unsigned int len)
This function is used to write data to the flash 4KB INFO area.
int FMC_EraseBlock32k(FLCTL_T *fmc, unsigned long addr)
Erase a 32KB Block in Flash Memory.
int FMC_ReadStream(FLCTL_T *fmc, unsigned int Addr, unsigned char cmd, unsigned char *buf, unsigned int len)
This function is used to read data stream from flash.
int FMC_EraseCodeArea(FLCTL_T *fmc, uint32_t addr, uint32_t len)
Erase specific data in flash code area.
int FMC_ReadInfoArea(FLCTL_T *fmc, unsigned int Addr, unsigned char cmd, unsigned char *buf, unsigned int len)
This function is used to read data from the flash 4KB INFO area.
unsigned int FMC_ReadWord(FLCTL_T *fmc, unsigned int Addr, unsigned char cmd)
This function is used to read flash.
int FMC_EraseSector(FLCTL_T *fmc, unsigned long adr)
Erase a 4KB Sector in Flash Memory.
int FMC_WriteStream(FLCTL_T *fmc, unsigned int Addr, unsigned char *buf, unsigned int len)
This function is used to write data stream to flash.
unsigned char FMC_ReadStatusReg(FLCTL_T *fmc, unsigned char cmd)
This function is used to read status, The Read Status Register can be read at any time.
int FMC_EraseBlock64k(FLCTL_T *fmc, unsigned long addr)
Erase a 64KB Block in Flash Memory.
#define CMD_TRIG
Definition: pan_fmc.h:79
void FMC_DisableAutoDp(FLCTL_T *fmc)
This function is used to disable auto enter deep power down function.
int FMC_EraseChip(FLCTL_T *fmc)
Erase the whole flash memory.
int FMC_EraseInfoArea(FLCTL_T *fmc)
This function is used to erase the flash 4KB INFO area.
void FMC_ExitEnhanceMode(FLCTL_T *fmc)
This function is used to exit flash enhanced read mode.
unsigned char FMC_ReadByte(FLCTL_T *fmc, unsigned int Addr, unsigned char cmd)
This function is used to read flash,.
unsigned char FMC_WriteEnable(FLCTL_T *fmc)
This function is used to enable write function,.
int ProgramPage(FLCTL_T *fmc, unsigned long adr, unsigned long sz, unsigned char *buf)
Program page in flash memory.
int BlankCheck(FLCTL_T *fmc, unsigned long adr, unsigned long sz)
Blank check checks if memory is blank.
void FMC_EnableAutoDp(FLCTL_T *fmc)
This function is used to enable auto enter deep power down function.
void InitIcache(FLCTL_T *fmc, uint32_t mode)
This function is used to init Icache,.
void FMC_EnterEnhanceMode(FLCTL_T *fmc, uint32_t mode)
This function is used to enter flash enhanced read mode.
Structure with flash id.
Definition: pan_fmc.h:110
uint8_t memory_type_id
Definition: pan_fmc.h:115
uint8_t uid[16]
Definition: pan_fmc.h:119
uint8_t memory_density_id
Definition: pan_fmc.h:116
uint8_t manufacturer_id
Definition: pan_fmc.h:111
uint8_t d[2]
Definition: pan_fmc.h:113