ADuCM4x50 Device Drivers API Reference Manual  Release 4.0.0.0
adi_flash_def.h
1 
13 #ifndef ADI_FLASH_DEF_H
14 #define ADI_FLASH_DEF_H
15 
18 #include <drivers/dma/adi_dma.h>
19 #include <adi_flash_config.h>
20 
21 #include <drivers/flash/adi_flash.h>
22 
23 /* fixed number of flash controllers */
24 #define ADI_FEE_NUM_INSTANCES (1u)
25 
26 #if defined (__ADUCM4x50__)
27 /* STATUS register error mask */
28 #define ADI_FEE_STATUS_ERROR_MASK ( BITM_FLCC_STAT_ACCESS_MODE \
29  | BITM_FLCC_STAT_CACHESRAMPERR \
30  | BITM_FLCC_STAT_ECCDCODE \
31  | BITM_FLCC_STAT_ECCINFOSIGN \
32  | BITM_FLCC_STAT_SIGNERR \
33  | BITM_FLCC_STAT_OVERLAP \
34  | BITM_FLCC_STAT_ECCRDERR \
35  | BITM_FLCC_STAT_ECCERRCMD \
36  | BITM_FLCC_STAT_SLEEPING \
37  | BITM_FLCC_STAT_CMDFAIL)
38 #elif defined (__ADUCM302x__)
39 #define ADI_FEE_STATUS_ERROR_MASK ( BITM_FLCC_STAT_CACHESRAMPERR \
40  | BITM_FLCC_STAT_ECCDCODE \
41  | BITM_FLCC_STAT_ECCINFOSIGN \
42  | BITM_FLCC_STAT_SIGNERR \
43  | BITM_FLCC_STAT_OVERLAP \
44  | BITM_FLCC_STAT_ECCRDERR \
45  | BITM_FLCC_STAT_ECCERRCMD \
46  | BITM_FLCC_STAT_SLEEPING \
47  | BITM_FLCC_STAT_CMDFAIL)
48 #endif
49 
50 #if defined(__ECC__)
51 #define ALIGN
52 #define ALIGN4 _Pragma("align(4)")
53 #elif defined(__ICCARM__)
54 #define ALIGN _Pragma("pack()")
55 #define ALIGN4 _Pragma("pack(4)")
56 #elif defined (__GNUC__)
57 #define ALIGN _Pragma("pack()")
58 #define ALIGN4 _Pragma("pack(4)")
59 #endif
60 
61 #if (ADI_FEE_CFG_ECC_START_PAGE >= FEE_MAX_NUM_PAGES)
62 #error "ADI_FEE_CFG_ECC_START_PAGE range is invalid"
63 #endif
64 
65 
66 /* INTERNAL DRIVER STATIC FUNCTION PROTOTYPES */
67 
68 /* Send a command to the flash controller, but does no pend on it... */
69 static ADI_FEE_RESULT SendCommand (ADI_FEE_HANDLE const hDevice, uint32_t const cmd);
70 
71 /* generic transfer initiator... dispatches to InitiatePioTransfer() or InitiateDmaTransfer() */
72 static ADI_FEE_RESULT InitiateTransfer (ADI_FEE_HANDLE const hDevice);
73 
74 /* PIO initiator */
75 static ADI_FEE_RESULT InitiatePioTransfer (ADI_FEE_HANDLE const hDevice);
76 
77 /* DMA initiator */
78 static ADI_FEE_RESULT InitiateDmaTransfer (ADI_FEE_HANDLE const hDevice);
79 
80 /* interrupt handlers */
81 void Flash0_Int_Handler(void);
82 void DMA_FLASH0_Int_Handler (void);
83 
84 /* INTERNAL DRIVER DATATYPES */
85 
86 /*
87  *****************************************************************************
88  * FEE Configuration structure.
89  *****************************************************************************/
90 typedef struct __ADI_FEE_CONFIG {
91  uint32_t eccIrqEnables; /* ECC interrupt enables. */
92  uint32_t param0; /* TIME_PARAM0 register. */
93  uint32_t param1; /* TIME_PARAM1 register. */
94  uint32_t abortEnableLo; /* Lower interrupt abort enables (IRQs 0-31). */
95  uint32_t abortEnableHi; /* Upper interrupt abort enables (IRQs 32-63.) */
96  uint32_t eccConfig; /* ECC_CFG register. */
97 } ADI_FEE_CONFIG;
98 
99 
100 /* Flash physical device instance data */
101 typedef struct __ADI_FEE_DEVICE_INFO {
102 
103  ADI_FLCC_TypeDef *pDev; /* Pointer to the physical controller. */
104  IRQn_Type pioIrqNum; /* The flash controller PIO interrupt number. */
105  IRQn_Type dmaIrqNum; /* The flash controller DMA interrupt number. */
106  DMA_CHANn_TypeDef dmaChanNum; /* The flash controller DMA channel number. */
107  ADI_FEE_CONFIG *pConfig; /* Pointer to user config info. */
108  ADI_FEE_HANDLE hDevice; /* Pointer the device memory (supplied by the application). */
109 
110 } ADI_FEE_DEVICE_INFO;
111 
112 
113 /* Flash driver instance data structure */
114 typedef struct __ADI_FEE_DEV_DATA_TYPE {
115 
116  /* make sure to synchronize ANY size changes with ADI_FLASH_MEMORY_SIZE macro in adi_flash.h */
117 
118  /* NOTE: "volatile" storage class on all interrupt-modified valuables */
119 
120  /* device attributes */
121  ADI_FLCC_TypeDef *pDev; /* Pointer top physical flash controller. */
122  ADI_FEE_DEVICE_INFO *pDevInfo; /* Pointer to hardware device attributes. */
123 
124  /* callback info */
125  ADI_CALLBACK pfCallback; /* Registered callback function address. */
126  void *pCBParam; /* Registered callback user parameter. */
127 
128  /* internal driver state variables */
129  bool bUseDma; /* DMA control flag (from user). */
130  bool bSubmitCalled; /* Flag to identify if a buffer was "submitted". */
131  volatile uint32_t FlashStatusCopy; /* Clop of latest flash status register. */
132  volatile uint32_t feeError; /* Flash error collector. */
133  volatile ADI_FEE_RESULT dmaError; /* DMA error collector. */
134  volatile bool bTransferInProgress; /* Flag indicating if a transfer is in progress. */
135 
136  /* data info */
137  volatile uint32_t *pNextWriteAddress; /* Pointer to next write data in flash space. */
138  volatile uint32_t *pNextReadAddress; /* Pointer to next read data in user buffer. */
139  volatile uint32_t nRemainingBytes; /* Number of remaining bytes still to transfer. */
140 
141  SEM_VAR_DECLR /* Blocking object: "Semaphore" for rtos, "bLowPowerExitFlag" for non-rtos. */
142 
143 } ADI_FEE_DEV_DATA_TYPE;
144 
147 #endif /* ADI_FLASH_DEF_H */
struct __ADI_FEE_DEV_DATA_TYPE * ADI_FEE_HANDLE
Definition: adi_flash.h:58
ADI_FEE_RESULT
Definition: adi_flash.h:35