AlcapDAQ  1
flash.h
Go to the documentation of this file.
1 #ifndef _FLASH_H
2 #define _FLASH_H
3 
4 #ifdef _WIN32
5 #include <windows.h>
6 #else
7 #include <sys/time.h>
8 #include <sys/types.h>
9 #include <unistd.h>
10 #include <stdint.h>
11 #endif
12 
13 #include <CAENComm.h>
14 
15 /*###########################################################################*/
16 /*
17 ** DEFINITIONS
18 */
19 /*###########################################################################*/
20 #ifdef WIN32
21 #define Wait_ms(t) Sleep(t)
22 #else
23 #define Wait_ms(t) usleep((t)*1000)
24 #endif
25 
26 #define CAENCOM_INVALID_FILE_HANDLE -1
27 // Opcodes for the flash memory
28 #define MAIN_MEM_PAGE_READ_CMD 0xD2
29 #define MAIN_MEM_PAGE_PROG_TH_BUF1_CMD 0x82
30 #define STATUS_READ_CMD 0xD7
31 
32 #define ROM_FLASH_PAGE 0
33 #define LICENSE_FLASH_PAGE 2
34 #define KEY_SIZE 64 // Number of bytes for key storage
35 #define LICENSE_DATA_SIZE 8 // Number of bytes for the licence data
36 #define MAX_MULTIACCESS_BUFSIZE 2048
37 
38 // Atmel AT45DB081D specific constants
39 typedef enum AT45_OPCODES
40 {
41  AT45_PAGE_SIZE = 264, // Number of bytes per page in the target flash
42  AT45_IDREG_LENGTH = 128, // Lunghezza (in bytes) del registro ID della flash Atmel
47 } AT45_OPCODES;
48 
49 typedef struct CROM_MAP
50 {
51  uint8_t crom_chksum; /* Configuration ROM checksum */
52  uint32_t crom_chksum_len; /* Configuration ROM checksum length */
53  uint32_t crom_const; /* Configuration ROM constant */
54  uint8_t crom_c_code; /* Configuration ROM c_code */
55  uint8_t crom_r_code; /* Configuration ROM r_code */
56  uint32_t crom_OUI; /* Configuration ROM Manufacturer identifier (IEEE OUI) */
57  uint8_t crom_version; /* Configuration ROM Purchased version of the Mod.V1724 */
58  uint32_t crom_board_id; /* Configuration ROM Board identifier \ref CVT_V17XX_ROM_CFG_BOARD_ID */
59  uint32_t crom_revision; /* Configuration ROM Hardware revision identifier */
60  uint16_t crom_serial; /* Configuration ROM Serial number */
61  uint8_t crom_VCXO_type; /* Configuration ROM VCXO type */
62 } CROM_MAP;
63 
64 
65 
66 typedef struct FlashAccess {
67  int Handle; // CAENComm handle for board access
68  unsigned long RW_Flash; // Address of the R/W Flash Register
69  unsigned long Sel_Flash; // Address of the Select Flash Register
70  unsigned long FlashEnable; // Flash Enable pin polarity
71  unsigned int RegSize; // Register Data Size (2 = D16, 4 = D32)
72  unsigned int PageSize; // Flash Page Size
74 
75 typedef enum cvupgrade_ErrorCode {
76 /* Error Types */
77  CvUpgrade_Success = 0, /* Operation completed successfully */
78  CvUpgrade_GenericError = -1, /* Generic error */
79  CvUpgrade_CAENCommError = -2, /* CAENComm function call error */
80  CvUpgrade_UnsupportedRegSize = -3, /* Unsupported Register Size from parameter file */
81  CvUpgrade_FileAccessError = -4 /* File access error */
83 
84 
85 int ReadFlashPage (cvFlashAccess *Flash, uint8_t *data, int pagenum);
86 int WriteFlashPage(cvFlashAccess *Flash, uint8_t *data, int pagenum);
87 int ReadFlashSecurityReg(cvFlashAccess *Flash, uint8_t *data);
88 
89 #endif // _FLASH_H