AlcapDAQ  1
p30.h
Go to the documentation of this file.
1 #ifndef _P30_STRATAFLASH_
2 #define _P30_STRATAFLASH_
3 
4 #ifdef LINUX
5  #include <inttypes.h>
6  #include <unistd.h>
7 #endif
8 
9 #include <stdlib.h>
10 #include <stdio.h>
11 
12 
13 #ifdef WIN32
14 #include <windows.h>
15  #ifndef int8_t
16  #define int8_t INT8
17  #endif
18  #ifndef int16_t
19  #define int16_t INT16
20  #endif
21  #ifndef int32_t
22  #define int32_t INT32
23  #endif
24  #ifndef int64_t
25  #define int64_t INT64
26  #endif
27  #ifndef uint8_t
28  #define uint8_t UINT8
29  #endif
30  #ifndef uint16_t
31  #define uint16_t UINT16
32  #endif
33  #ifndef uint32_t
34  #define uint32_t UINT32
35  #endif
36  #ifndef uint64_t
37  #define uint64_t UINT64
38  #endif
39 #endif
40 
41 #ifndef WIN32
42 #define FALSE (0)
43 #define TRUE (-1)
44 #endif
45 // Numonyx P30 Command set
46 #define P30_READ_ARRAY 0x00FF
47 #define P30_READ_ID 0x0090
48 #define P30_BUFFERED_PROGRAM 0x00E8
49 #define P30_BUFFERED_PROGRAM_CONFIRM 0x00D0
50 #define P30_BLOCK_LOCK_SETUP 0x0060
51 #define P30_BLOCK_UNLOCK 0x00D0
52 #define P30_BLOCK_ERASE_SETUP 0x0020
53 #define P30_BLOCK_ERASE_CONFIRM 0x00D0
54 #define P30_READ_CFI 0x0098
55 #define P30_READ_STATUS 0x0070
56 #define P30_CLEAR_STATUS 0x0050
57 
58 
59 /* Status Register Values */
60 #define P30_STAT_BLOCK_LOCKED 0x0002
61 #define P30_STAT_PROGRAM_SUSPENDED 0x0004
62 #define P30_STAT_VPP_LOW 0x0008
63 #define P30_STAT_PROGRAM_ERROR 0x0010
64 #define P30_STAT_ERASE_ERROR 0x0020
65 #define P30_STAT_ERASE_SUSPENDED 0x0040
66 #define P30_STAT_STATUS_READY 0x0080
67 
68 /* P30 Flash parameters */
69 #define TOTAL_NUMBLOCKS 0x102
70 #define MAIN_BLOCK_NUMBYTES 0x20000 /* 64 K-Word block size */
71 #define PARM_BLOCK_NUMBYTES 0x8000 /* 16 K-Word block size */
72 
73 #define TOP_PARTITION_BASE 0xFF0000 /* address */
74 #define BOTTOM_PARTITION_BASE 0x0000 /* address */
75 
76 #define TOP_BLOCK_LOWER 0xFF
77 #define TOP_BLOCK_UPPER 0x102
78 
79 #define BOTTOM_BLOCK_LOWER 0x0
80 #define BOTTOM_BLOCK_UPPER 0x3
81 
82 
83 #define TOTAL_SIZE 0x2000000
84 #define BLOCK_MASK 0xFFFF
85 
86 #define PRINT_POINTS 1
87 
88 /* A3818 reg. address */
89 #define A3818_BPI_FLASH_AD (0x20) // R/W - BPI_FLASH TEST
90 #define A3818_BPI_FLASH_DT (0x24) // R/W
91 #define A3818_BPI_FLASH_CMD (0x28) // R/W
92 #define A3818_DMISCCS (0x08) // Device Miscellaneous Control Status
93 # define A3818_DMISCCS_SPI_BPI_FLASH_SEL (1 << 4) // BPI/SPI FLASH access select (default 0 = SPI FLASH)
94 
95 
96 #define mIsStatusReady(A) ( ( A & P30_STAT_STATUS_READY ) == P30_STAT_STATUS_READY )
97 
98 /*******************************************************************/
99 /* Funzioni per l'accesso alla FLASH BPI */
100 /*******************************************************************/
101 // abilita la BPI flash
102 void A3818_EnableBPIAccess(int32_t handle);
103 
104 // Disabilita l'accesso alla BPI flash.
105 void A3818_EnableSPIAccess(int32_t handle);
106 
107 /*-------------------------------------------------------------*/
108 /* offset deve essere allineato a 16 bit (BIT0 non significativo) */
109 int bpi_flash_read(int32_t dev, uint32_t offset, uint32_t* bpi_data);
110 /*-------------------------------------------------------------*/
111 int bpi_flash_write(int32_t dev, uint32_t offset, uint32_t bpi_data);
112 /*-------------------------------------------------------------*/
113 
114 
115 int readFlash(int32_t dev, uint32_t *data, int address, int length);
116 unsigned int verifyFlash(uint32_t handle,uint32_t *buffer, uint32_t bufferLength, uint32_t startWordAddress);
117 int eraseFirmware(uint32_t handle, uint32_t baseAddress, uint32_t fwcopy);
118 void writeFlash(uint32_t handle, uint32_t *buffer, uint32_t bufferLength, uint32_t startWordAddress);
119 
120 #endif // _P30_STRATAFLASH_