AlcapDAQ  1
Macros | Functions
p30.h File Reference
#include <stdlib.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define FALSE   (0)
 
#define TRUE   (-1)
 
#define P30_READ_ARRAY   0x00FF
 
#define P30_READ_ID   0x0090
 
#define P30_BUFFERED_PROGRAM   0x00E8
 
#define P30_BUFFERED_PROGRAM_CONFIRM   0x00D0
 
#define P30_BLOCK_LOCK_SETUP   0x0060
 
#define P30_BLOCK_UNLOCK   0x00D0
 
#define P30_BLOCK_ERASE_SETUP   0x0020
 
#define P30_BLOCK_ERASE_CONFIRM   0x00D0
 
#define P30_READ_CFI   0x0098
 
#define P30_READ_STATUS   0x0070
 
#define P30_CLEAR_STATUS   0x0050
 
#define P30_STAT_BLOCK_LOCKED   0x0002
 
#define P30_STAT_PROGRAM_SUSPENDED   0x0004
 
#define P30_STAT_VPP_LOW   0x0008
 
#define P30_STAT_PROGRAM_ERROR   0x0010
 
#define P30_STAT_ERASE_ERROR   0x0020
 
#define P30_STAT_ERASE_SUSPENDED   0x0040
 
#define P30_STAT_STATUS_READY   0x0080
 
#define TOTAL_NUMBLOCKS   0x102
 
#define MAIN_BLOCK_NUMBYTES   0x20000 /* 64 K-Word block size */
 
#define PARM_BLOCK_NUMBYTES   0x8000 /* 16 K-Word block size */
 
#define TOP_PARTITION_BASE   0xFF0000 /* address */
 
#define BOTTOM_PARTITION_BASE   0x0000 /* address */
 
#define TOP_BLOCK_LOWER   0xFF
 
#define TOP_BLOCK_UPPER   0x102
 
#define BOTTOM_BLOCK_LOWER   0x0
 
#define BOTTOM_BLOCK_UPPER   0x3
 
#define TOTAL_SIZE   0x2000000
 
#define BLOCK_MASK   0xFFFF
 
#define PRINT_POINTS   1
 
#define A3818_BPI_FLASH_AD   (0x20)
 
#define A3818_BPI_FLASH_DT   (0x24)
 
#define A3818_BPI_FLASH_CMD   (0x28)
 
#define A3818_DMISCCS   (0x08)
 
#define A3818_DMISCCS_SPI_BPI_FLASH_SEL   (1 << 4)
 
#define mIsStatusReady(A)   ( ( A & P30_STAT_STATUS_READY ) == P30_STAT_STATUS_READY )
 

Functions

void A3818_EnableBPIAccess (int32_t handle)
 
void A3818_EnableSPIAccess (int32_t handle)
 
int bpi_flash_read (int32_t dev, uint32_t offset, uint32_t *bpi_data)
 
int bpi_flash_write (int32_t dev, uint32_t offset, uint32_t bpi_data)
 
int readFlash (int32_t dev, uint32_t *data, int address, int length)
 
unsigned int verifyFlash (uint32_t handle, uint32_t *buffer, uint32_t bufferLength, uint32_t startWordAddress)
 
int eraseFirmware (uint32_t handle, uint32_t baseAddress, uint32_t fwcopy)
 
void writeFlash (uint32_t handle, uint32_t *buffer, uint32_t bufferLength, uint32_t startWordAddress)
 

Macro Definition Documentation

#define A3818_BPI_FLASH_AD   (0x20)

Definition at line 89 of file p30.h.

#define A3818_BPI_FLASH_CMD   (0x28)

Definition at line 91 of file p30.h.

#define A3818_BPI_FLASH_DT   (0x24)

Definition at line 90 of file p30.h.

#define A3818_DMISCCS   (0x08)

Definition at line 92 of file p30.h.

#define A3818_DMISCCS_SPI_BPI_FLASH_SEL   (1 << 4)

Definition at line 93 of file p30.h.

#define BLOCK_MASK   0xFFFF

Definition at line 84 of file p30.h.

#define BOTTOM_BLOCK_LOWER   0x0

Definition at line 79 of file p30.h.

#define BOTTOM_BLOCK_UPPER   0x3

Definition at line 80 of file p30.h.

#define BOTTOM_PARTITION_BASE   0x0000 /* address */

Definition at line 74 of file p30.h.

#define FALSE   (0)
#define MAIN_BLOCK_NUMBYTES   0x20000 /* 64 K-Word block size */

Definition at line 70 of file p30.h.

#define mIsStatusReady (   A)    ( ( A & P30_STAT_STATUS_READY ) == P30_STAT_STATUS_READY )

Definition at line 96 of file p30.h.

Referenced by waitUntilReady().

#define P30_BLOCK_ERASE_CONFIRM   0x00D0

Definition at line 53 of file p30.h.

Referenced by eraseBlock().

#define P30_BLOCK_ERASE_SETUP   0x0020

Definition at line 52 of file p30.h.

Referenced by eraseBlock().

#define P30_BLOCK_LOCK_SETUP   0x0060

Definition at line 50 of file p30.h.

Referenced by eraseBlock().

#define P30_BLOCK_UNLOCK   0x00D0

Definition at line 51 of file p30.h.

Referenced by eraseBlock().

#define P30_BUFFERED_PROGRAM   0x00E8

Definition at line 48 of file p30.h.

Referenced by writeFlashPage().

#define P30_BUFFERED_PROGRAM_CONFIRM   0x00D0

Definition at line 49 of file p30.h.

Referenced by writeFlashPage().

#define P30_CLEAR_STATUS   0x0050

Definition at line 56 of file p30.h.

Referenced by eraseBlock().

#define P30_READ_ARRAY   0x00FF

Definition at line 46 of file p30.h.

Referenced by eraseBlock(), eraseFirmware(), readFlash(), and writeFlashPage().

#define P30_READ_CFI   0x0098

Definition at line 54 of file p30.h.

#define P30_READ_ID   0x0090

Definition at line 47 of file p30.h.

#define P30_READ_STATUS   0x0070

Definition at line 55 of file p30.h.

Referenced by readFlashStatus().

#define P30_STAT_BLOCK_LOCKED   0x0002

Definition at line 60 of file p30.h.

#define P30_STAT_ERASE_ERROR   0x0020

Definition at line 64 of file p30.h.

#define P30_STAT_ERASE_SUSPENDED   0x0040

Definition at line 65 of file p30.h.

#define P30_STAT_PROGRAM_ERROR   0x0010

Definition at line 63 of file p30.h.

#define P30_STAT_PROGRAM_SUSPENDED   0x0004

Definition at line 61 of file p30.h.

#define P30_STAT_STATUS_READY   0x0080

Definition at line 66 of file p30.h.

#define P30_STAT_VPP_LOW   0x0008

Definition at line 62 of file p30.h.

#define PARM_BLOCK_NUMBYTES   0x8000 /* 16 K-Word block size */

Definition at line 71 of file p30.h.

#define PRINT_POINTS   1

Definition at line 86 of file p30.h.

#define TOP_BLOCK_LOWER   0xFF

Definition at line 76 of file p30.h.

#define TOP_BLOCK_UPPER   0x102

Definition at line 77 of file p30.h.

#define TOP_PARTITION_BASE   0xFF0000 /* address */

Definition at line 73 of file p30.h.

#define TOTAL_NUMBLOCKS   0x102

Definition at line 69 of file p30.h.

#define TOTAL_SIZE   0x2000000

Definition at line 83 of file p30.h.

#define TRUE   (-1)

Function Documentation

void A3818_EnableBPIAccess ( int32_t  handle)

Definition at line 67 of file p30.c.

References A3818_DMISCCS, A3818_DMISCCS_SPI_BPI_FLASH_SEL, CAENVME_ReadRegister(), and CAENVME_WriteRegister().

Referenced by A3818UpgradeFromFile(), and A3818UpgradeFromMem().

67  {
68  uint32_t data;
69  CAENVME_ReadRegister(handle, A3818_DMISCCS | 0x1000, &data);
70  data = data | A3818_DMISCCS_SPI_BPI_FLASH_SEL;
72 }
void A3818_EnableSPIAccess ( int32_t  handle)

Definition at line 76 of file p30.c.

References A3818_DMISCCS, A3818_DMISCCS_SPI_BPI_FLASH_SEL, CAENVME_ReadRegister(), and CAENVME_WriteRegister().

Referenced by A3818UpgradeFromFile(), and A3818UpgradeFromMem().

76  {
77  uint32_t data;
78  CAENVME_ReadRegister(handle, A3818_DMISCCS | 0x1000, &data);
79  data = data & (~A3818_DMISCCS_SPI_BPI_FLASH_SEL);
81 }
int bpi_flash_read ( int32_t  dev,
uint32_t  offset,
uint32_t *  bpi_data 
)

Definition at line 11 of file p30.c.

References A3818_BPI_FLASH_AD, A3818_BPI_FLASH_CMD, A3818_BPI_FLASH_DT, CAENVME_ReadRegister(), and CAENVME_WriteRegister().

Referenced by readFlash(), and readFlashStatus().

11  {
12  uint32_t app_data;
13 
14  //Imposto indirizzo
15  app_data = offset << 1;
16  CAENVME_WriteRegister(dev, A3818_BPI_FLASH_AD | 0x1000, app_data);
17 
18  //Abbasso il CE
20 
21  //Abbasso OE
23 
24  //Rialzo OE
26 
27  //Alzo CE
29 
30  //Sono significativi, per la lettura, solo i 16 bit bassi
31  CAENVME_ReadRegister(dev, A3818_BPI_FLASH_DT | 0x1000, &app_data);
32  *bpi_data = app_data & 0x0000FFFF;
33 
34  return 0;
35 }
int bpi_flash_write ( int32_t  dev,
uint32_t  offset,
uint32_t  bpi_data 
)

Definition at line 38 of file p30.c.

References A3818_BPI_FLASH_AD, A3818_BPI_FLASH_CMD, A3818_BPI_FLASH_DT, and CAENVME_WriteRegister().

Referenced by eraseBlock(), eraseFirmware(), readFlash(), readFlashStatus(), and writeFlashPage().

38  {
39  uint32_t data;
40 
41  //Imposto indirizzo
42  data = offset << 1;
43 
45 
46  //Imposto il dato
47  //Per la scrittura i 16 bit da scrivere vanno messi nella parte alta del registro.
48  data = bpi_data << 16;
50 
51  //Abbasso il CE
53 
54  //Abbasso WE
56 
57  //Rialzo WE
59 
60  //Alzo CE
62 
63  return 0;
64 }
int eraseFirmware ( uint32_t  handle,
uint32_t  baseAddress,
uint32_t  fwcopy 
)

Definition at line 286 of file p30.c.

References bpi_flash_write(), eraseBlock(), i, P30_READ_ARRAY, and printf().

Referenced by A3818UpgradeFromFile(), and A3818UpgradeFromMem().

286  {
287  int i;
288 
289  if (fwcopy == 0) {
290  // Cancella i primi 4 blocchi da 32KB = 128KB
291  for (i = 0; i < 4; i++) {
292  eraseBlock(handle, baseAddress + (i * (16 * 1024)));
293 #ifdef PRINT_POINTS
294 
295  printf(".");
296  fflush(stdout);
297 #endif
298  }
299  // Cancella 13 blocchi da 128KB
300  for (i = 4; i < 18; i++) {
301  eraseBlock(handle, baseAddress + ((i - 3) * (64 * 1024)));
302 #ifdef PRINT_POINTS
303  printf(".");
304  fflush(stdout);
305 #endif
306  }
307  } else {
308  // Cancella 15 blocchi da 128KB = cancella 15*128K = 1920KB
309  for (i = 0; i < 14; i++) {
310  eraseBlock(handle, baseAddress + (i * (64 * 1024)));
311 #ifdef PRINT_POINTS
312  printf(".");
313  fflush(stdout);
314 #endif
315  }
316  }
317 
318  // Ritorna in modalit� Read Array Mode
320  return 0;
321 }
int readFlash ( int32_t  dev,
uint32_t *  data,
int  address,
int  length 
)

Definition at line 226 of file p30.c.

References bpi_flash_read(), bpi_flash_write(), i, length, and P30_READ_ARRAY.

Referenced by verifyFlash().

226  {
227  int flash_addr;
228  int i;
229 
230  // Imposto Read Array Mode
232 
233  flash_addr = address;
234  for (i = 0; i < length; i++) {
235  bpi_flash_read(dev, flash_addr + i, &data[i]);
236  }
237 
238  return 0;
239 }
unsigned int verifyFlash ( uint32_t  handle,
uint32_t *  buffer,
uint32_t  bufferLength,
uint32_t  startWordAddress 
)

Definition at line 241 of file p30.c.

References i, printf(), and readFlash().

Referenced by A3818UpgradeFromFile(), and A3818UpgradeFromMem().

242  {
243  int finish, i;
244  unsigned int verify_err;
245  int bp, wc, pp;
246  uint32_t bpi_rd[32]; // 16-bit word read from flash
247 
248  wc = 0; // byte counter
249 
250 
251  bp = 0; // byte pointer in the page
252  finish = 0; // it goes high when eof is found
253  verify_err = 0; // number of errors during verify
254 
255  pp = 0;
256 
257  while (wc < bufferLength) {
258 
259 #ifdef PRINT_POINTS
260  if (((wc % (32 * 1024)) == 0) || finish) {
261  printf(".");
262  fflush(stdout);
263  }
264 #endif
265  readFlash(handle, bpi_rd, (pp * 32) + startWordAddress, 32); // read page
266 
267  for (i = 0; i < 32; i++) { // verify page
268  if (bpi_rd[i] != buffer[wc + i]) {
269  printf("page = %d; bpi_rd[%d]=%04X, buffer[%d]=%04X \n", pp,
270  i, bpi_rd[i], wc + i, buffer[wc + i]);
271  printf("\n\n Writing or Verify error at page %d - %d\n", pp, i);
272  ++verify_err;
273  }
274  }
275  bp = 0;
276  pp++;
277  wc += 32;
278  } // end of while loop
279 
280 
281  return verify_err;
282 
283 }
void writeFlash ( uint32_t  handle,
uint32_t *  buffer,
uint32_t  bufferLength,
uint32_t  startWordAddress 
)

Definition at line 323 of file p30.c.

References printf(), and writeFlashPage().

Referenced by A3818UpgradeFromFile(), and A3818UpgradeFromMem().

324  {
325 
326  int wc, pp;
327 
328  wc = 0;
329  pp = 0;
330 
331 #ifdef PRINT_POINTS
332  printf(".");
333  fflush(stdout);
334 #endif
335  while (wc < bufferLength) {
336 #ifdef PRINT_POINTS
337  if (((wc % (32 * 1024)) == 0)) {
338  printf(".");
339  fflush(stdout);
340  }
341 #endif
342  writeFlashPage(handle, buffer + (pp * 32),
343  startWordAddress + (pp * 32), 32);
344 
345  pp++;
346  wc += 32;
347  } // end of while loop
348 
349 }