at45dbx.h File Reference


Detailed Description

Management of the AT45DBX data flash controller through SPI.

This file manages the accesses to the AT45DBX data flash components.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file at45dbx.h.

#include "conf_access.h"
#include "spi.h"

Go to the source code of this file.

Defines

#define AT45DBX_SECTOR_BITS   9
 Number of bits for addresses within sectors.
#define AT45DBX_SECTOR_SIZE   (1 << AT45DBX_SECTOR_BITS)
 Sector size in bytes.
Available AT45DBX Sizes
Number of address bits of available AT45DBX data flash memories.

Note:
Only memories with page sizes of at least 512 bytes (sector size) are supported.


#define AT45DBX_2MB   21
#define AT45DBX_4MB   22
#define AT45DBX_8MB   23

Functions

Control Functions
Bool at45dbx_init (spi_options_t spiOptions, unsigned int pba_hz)
 Initializes the data flash controller and the SPI channel by which the DF is controlled.
Bool at45dbx_mem_check (void)
 Performs a memory check on all DFs.
void at45dbx_read_close (void)
 Unselects the current DF memory.
Bool at45dbx_read_open (U32 sector)
 Opens a DF memory in read mode at a given sector.
void at45dbx_write_close (void)
 Fills the end of the current logical sector and launches page programming.
Bool at45dbx_write_open (U32 sector)
 This function opens a DF memory in write mode at a given sector.
Single-Byte Access Functions
U8 at45dbx_read_byte (void)
 Performs a single byte read from DF memory.
Bool at45dbx_write_byte (U8 b)
 Performs a single byte write to DF memory.
Multiple-Sector Access Functions
Bool at45dbx_read_multiple_sector (U16 nb_sector)
 Reads nb_sector sectors from DF memory.
void at45dbx_read_multiple_sector_callback (const void *psector)
 Callback function invoked after each sector read during at45dbx_read_multiple_sector.
Bool at45dbx_write_multiple_sector (U16 nb_sector)
 Writes nb_sector sectors to DF memory.
void at45dbx_write_multiple_sector_callback (void *psector)
 Callback function invoked before each sector write during at45dbx_write_multiple_sector.
Single-Sector Access Functions
Bool at45dbx_read_sector_2_ram (void *ram)
 Reads 1 DF sector to a RAM buffer.
Bool at45dbx_write_sector_from_ram (const void *ram)
 Writes 1 DF sector from a RAM buffer.


Define Documentation

#define AT45DBX_2MB   21

Definition at line 72 of file at45dbx.h.

#define AT45DBX_4MB   22

Definition at line 73 of file at45dbx.h.

#define AT45DBX_8MB   23

Definition at line 74 of file at45dbx.h.

#define AT45DBX_SECTOR_BITS   9

#define AT45DBX_SECTOR_SIZE   (1 << AT45DBX_SECTOR_BITS)


Function Documentation

Bool at45dbx_init ( spi_options_t  spiOptions,
unsigned int  pba_hz 
)

Initializes the data flash controller and the SPI channel by which the DF is controlled.

Parameters:
spiOptions Initialization options of the DF SPI channel.
pba_hz SPI module input clock frequency (PBA clock, Hz).
Return values:
OK Success.
KO Failure.

Definition at line 211 of file at45dbx.c.

References at45dbx_busy, AT45DBX_MEM_CNT, AT45DBX_SPI_FIRST_NPCS, spi_options_t::reg, SPI_OK, and spi_setupChipReg().

Referenced by at45dbx_resources_init().

00212 {
00213   // Setup SPI registers according to spiOptions.
00214   for (spiOptions.reg = AT45DBX_SPI_FIRST_NPCS;
00215        spiOptions.reg < AT45DBX_SPI_FIRST_NPCS + AT45DBX_MEM_CNT;
00216        spiOptions.reg++)
00217   {
00218     if (spi_setupChipReg(AT45DBX_SPI, &spiOptions, pba_hz) != SPI_OK) return KO;
00219   }
00220 
00221   // Memory ready.
00222   at45dbx_busy = FALSE;
00223 
00224   return OK;
00225 }

Bool at45dbx_mem_check ( void   ) 

Performs a memory check on all DFs.

Return values:
OK Success.
KO Failure.

Definition at line 248 of file at45dbx.c.

References at45dbx_chipselect_df(), AT45DBX_CMDC_RD_STATUS_REG, AT45DBX_MEM_CNT, AT45DBX_MSK_DENSITY, spi_read(), spi_write(), and spi_write_dummy.

Referenced by at45dbx_example_check_mem(), and at45dbx_test_unit_ready().

00249 {
00250   U8 df;
00251   U16 status = 0;
00252 
00253   // DF memory check.
00254   for (df = 0; df < AT45DBX_MEM_CNT; df++)
00255   {
00256     // Select the DF memory to check.
00257     at45dbx_chipselect_df(df, TRUE);
00258 
00259     // Send the Status Register Read command.
00260     spi_write(AT45DBX_SPI, AT45DBX_CMDC_RD_STATUS_REG);
00261 
00262     // Send a dummy byte to read the status register.
00263     spi_write_dummy();
00264     spi_read(AT45DBX_SPI, &status);
00265 
00266     // Unselect the checked DF memory.
00267     at45dbx_chipselect_df(df, FALSE);
00268 
00269     // Unexpected device density value.
00270     if ((status & AT45DBX_MSK_DENSITY) < AT45DBX_DENSITY) return KO;
00271   }
00272 
00273   return OK;
00274 }

U8 at45dbx_read_byte ( void   ) 

Performs a single byte read from DF memory.

Returns:
The read byte.
Note:
First call must be preceded by a call to the at45dbx_read_open function.

Definition at line 440 of file at45dbx.c.

References at45dbx_busy, at45dbx_chipselect_df(), AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_BYTE, at45dbx_read_open(), AT45DBX_SECTOR_BITS, gl_ptr_mem, spi_read(), and spi_write_dummy.

Referenced by at45dbx_example_test_byte_mem().

00441 {
00442   U16 data;
00443 
00444   // Memory busy.
00445   if (at45dbx_busy)
00446   {
00447     // Being here, we know that we previously finished a page read.
00448     // => We have to access the next page.
00449 
00450     // Memory ready.
00451     at45dbx_busy = FALSE;
00452 
00453     // Eventually select the next DF and open the next page.
00454     // NOTE: at45dbx_read_open input parameter is a sector.
00455     at45dbx_read_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
00456   }
00457 
00458   // Send a dummy byte to read the next data byte.
00459   spi_write_dummy();
00460   spi_read(AT45DBX_SPI, &data);
00461   gl_ptr_mem++;
00462 
00463   // If end of page reached,
00464   if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
00465   {
00466     // unselect the DF memory gl_ptr_mem points to.
00467     at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
00468 
00469     // Memory busy.
00470     at45dbx_busy = TRUE;
00471   }
00472 
00473   return data;
00474 }

void at45dbx_read_close ( void   ) 

Unselects the current DF memory.

Definition at line 343 of file at45dbx.c.

References at45dbx_busy, at45dbx_chipselect_df(), AT45DBX_MEM_SIZE, and gl_ptr_mem.

Referenced by at45dbx_df_2_ram(), at45dbx_example_test_byte_mem(), at45dbx_example_test_multiple_sector(), at45dbx_example_test_RAM_mem(), and at45dbx_usb_read_10().

00344 {
00345   // Unselect the DF memory gl_ptr_mem points to.
00346   at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
00347 
00348   // Memory ready.
00349   at45dbx_busy = FALSE;
00350 }

Bool at45dbx_read_multiple_sector ( U16  nb_sector  ) 

Reads nb_sector sectors from DF memory.

Data flow is: DF -> callback.

Parameters:
nb_sector Number of contiguous sectors to read.
Return values:
OK Success.
KO Failure.
Note:
First call must be preceded by a call to the at45dbx_read_open function.

As AT45DBX_PAGE_SIZE is always a multiple of AT45DBX_SECTOR_SIZE, there is no need to check page end for each byte.

Definition at line 516 of file at45dbx.c.

References at45dbx_read_multiple_sector_callback(), at45dbx_read_sector_2_ram(), and sector_buf.

Referenced by at45dbx_example_test_multiple_sector(), and at45dbx_usb_read_10().

00517 {
00518   while (nb_sector--)
00519   {
00520     // Read the next sector.
00521     at45dbx_read_sector_2_ram(sector_buf);
00522     at45dbx_read_multiple_sector_callback(sector_buf);
00523   }
00524 
00525   return OK;
00526 }

void at45dbx_read_multiple_sector_callback ( const void *  psector  ) 

Callback function invoked after each sector read during at45dbx_read_multiple_sector.

Parameters:
psector Pointer to read sector.

Definition at line 129 of file at45dbx_mem.c.

References at45dbx_example_error_cnt, AT45DBX_SECTOR_SIZE, and PATTERN_MULTIPLE_SECTOR.

Referenced by at45dbx_read_multiple_sector().

00130 {
00131   U16 data_to_transfer = AT45DBX_SECTOR_SIZE;
00132 
00133   // Transfer read sector to the USB interface.
00134   while (data_to_transfer)
00135   {
00136     while (!Is_usb_in_ready(g_scsi_ep_ms_in))
00137     {
00138       if(!Is_usb_endpoint_enabled(g_scsi_ep_ms_in))
00139          return; // USB Reset
00140     }         
00141 
00142     Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_in);
00143     data_to_transfer = usb_write_ep_txpacket(g_scsi_ep_ms_in, psector,
00144                                              data_to_transfer, &psector);
00145     Usb_ack_in_ready_send(g_scsi_ep_ms_in);
00146   }
00147 }

Bool at45dbx_read_open ( U32  sector  ) 

Opens a DF memory in read mode at a given sector.

Parameters:
sector Start sector.
Return values:
OK Success.
KO Failure.
Note:
Sector may be page-unaligned (depending on the DF page size).

Definition at line 302 of file at45dbx.c.

References at45dbx_busy, at45dbx_chipselect_df(), AT45DBX_CMDA_RD_PAGE, AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_BYTE, AT45DBX_MSK_PTR_PAGE, AT45DBX_SECTOR_BITS, at45dbx_wait_ready(), gl_ptr_mem, spi_write(), and spi_write_dummy.

Referenced by at45dbx_df_2_ram(), at45dbx_example_test_byte_mem(), at45dbx_example_test_multiple_sector(), at45dbx_example_test_RAM_mem(), at45dbx_read_byte(), at45dbx_read_sector_2_ram(), and at45dbx_usb_read_10().

00303 {
00304   U32 addr;
00305 
00306   // Set the global memory pointer to a byte address.
00307   gl_ptr_mem = sector << AT45DBX_SECTOR_BITS; // gl_ptr_mem = sector * AT45DBX_SECTOR_SIZE.
00308 
00309   // If the DF memory is busy, wait until it's ready.
00310   if (at45dbx_busy) at45dbx_wait_ready();
00311   at45dbx_busy = FALSE;
00312 
00313   // Select the DF memory gl_ptr_mem points to.
00314   at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);
00315 
00316   // Initiate a page read at a given sector.
00317 
00318   // Send the Main Memory Page Read command.
00319   spi_write(AT45DBX_SPI, AT45DBX_CMDA_RD_PAGE);
00320 
00321   // Send the three address bytes, which comprise:
00322   //  - (24 - (AT45DBX_PAGE_ADDR_BITS + AT45DBX_BYTE_ADDR_BITS)) reserved bits;
00323   //  - then AT45DBX_PAGE_ADDR_BITS bits specifying the page in main memory to be read;
00324   //  - then AT45DBX_BYTE_ADDR_BITS bits specifying the starting byte address within that page.
00325   // NOTE: The bits of gl_ptr_mem above the AT45DBX_MEM_SIZE bits are useless for the local
00326   // DF addressing. They are used for DF discrimination when there are several DFs.
00327   addr = (Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_PAGE) << AT45DBX_BYTE_ADDR_BITS) |
00328          Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE);
00329   spi_write(AT45DBX_SPI, LSB2W(addr));
00330   spi_write(AT45DBX_SPI, LSB1W(addr));
00331   spi_write(AT45DBX_SPI, LSB0W(addr));
00332 
00333   // Send 32 don't care clock cycles to initialize the read operation.
00334   spi_write_dummy();
00335   spi_write_dummy();
00336   spi_write_dummy();
00337   spi_write_dummy();
00338 
00339   return OK;
00340 }

Bool at45dbx_read_sector_2_ram ( void *  ram  ) 

Reads 1 DF sector to a RAM buffer.

Data flow is: DF -> RAM.

Parameters:
ram Pointer to RAM buffer.
Return values:
OK Success.
KO Failure.
Note:
First call must be preceded by a call to the at45dbx_read_open function.

Definition at line 550 of file at45dbx.c.

References at45dbx_busy, at45dbx_chipselect_df(), AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_BYTE, at45dbx_read_open(), AT45DBX_SECTOR_BITS, AT45DBX_SECTOR_SIZE, gl_ptr_mem, spi_read(), and spi_write_dummy.

Referenced by at45dbx_df_2_ram(), at45dbx_example_test_RAM_mem(), and at45dbx_read_multiple_sector().

00551 {
00552   U8 *_ram = ram;
00553   U16 i;
00554   U16 data;
00555 
00556   // Memory busy.
00557   if (at45dbx_busy)
00558   {
00559     // Being here, we know that we previously finished a page read.
00560     // => We have to access the next page.
00561 
00562     // Memory ready.
00563     at45dbx_busy = FALSE;
00564 
00565     // Eventually select the next DF and open the next page.
00566     // NOTE: at45dbx_read_open input parameter is a sector.
00567     at45dbx_read_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
00568   }
00569 
00570   // Read the next sector.
00571   for (i = AT45DBX_SECTOR_SIZE; i; i--)
00572   {
00573     // Send a dummy byte to read the next data byte.
00574     spi_write_dummy();
00575     spi_read(AT45DBX_SPI, &data);
00576     *_ram++ = data;
00577   }
00578 
00579   // Update the memory pointer.
00580   gl_ptr_mem += AT45DBX_SECTOR_SIZE;
00581 
00582 #if AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE
00583   // If end of page reached,
00584   if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
00585 #endif
00586   {
00587     // unselect the DF memory gl_ptr_mem points to.
00588     at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
00589 
00590     // Memory busy.
00591     at45dbx_busy = TRUE;
00592   }
00593 
00594   return OK;
00595 }

Bool at45dbx_write_byte ( U8  b  ) 

Performs a single byte write to DF memory.

Parameters:
b The byte to write.
Return values:
OK Success.
KO Failure.
Note:
First call must be preceded by a call to the at45dbx_write_open function.

Definition at line 477 of file at45dbx.c.

References at45dbx_busy, at45dbx_chipselect_df(), AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_BYTE, AT45DBX_SECTOR_BITS, at45dbx_write_open(), gl_ptr_mem, and spi_write().

Referenced by at45dbx_example_test_byte_mem().

00478 {
00479   // Memory busy.
00480   if (at45dbx_busy)
00481   {
00482     // Being here, we know that we previously launched a page programming.
00483     // => We have to access the next page.
00484 
00485     // Eventually select the next DF and open the next page.
00486     // NOTE: at45dbx_write_open input parameter is a sector.
00487     at45dbx_write_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
00488   }
00489 
00490   // Write the next data byte.
00491   spi_write(AT45DBX_SPI, b);
00492   gl_ptr_mem++;
00493 
00494   // If end of page reached,
00495   if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
00496   {
00497     // unselect the DF memory gl_ptr_mem points to in order to program the page.
00498     at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
00499 
00500     // Memory busy.
00501     at45dbx_busy = TRUE;
00502   }
00503 
00504   return OK;
00505 }

void at45dbx_write_close ( void   ) 

Fills the end of the current logical sector and launches page programming.

Definition at line 415 of file at45dbx.c.

References at45dbx_busy, at45dbx_chipselect_df(), AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_SECTOR, gl_ptr_mem, and spi_write().

Referenced by at45dbx_example_test_byte_mem(), at45dbx_example_test_multiple_sector(), at45dbx_example_test_RAM_mem(), at45dbx_ram_2_df(), and at45dbx_usb_write_10().

00416 {
00417   // While end of logical sector not reached, zero-fill remaining memory bytes.
00418   while (Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_SECTOR))
00419   {
00420     spi_write(AT45DBX_SPI, 0x00);
00421     gl_ptr_mem++;
00422   }
00423 
00424   // Unselect the DF memory gl_ptr_mem points to.
00425   at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
00426 
00427   // Memory busy.
00428   at45dbx_busy = TRUE;
00429 }

Bool at45dbx_write_multiple_sector ( U16  nb_sector  ) 

Writes nb_sector sectors to DF memory.

Data flow is: callback -> DF.

Parameters:
nb_sector Number of contiguous sectors to write.
Return values:
OK Success.
KO Failure.
Note:
First call must be preceded by a call to the at45dbx_write_open function.

As AT45DBX_PAGE_SIZE is always a multiple of AT45DBX_SECTOR_SIZE, there is no need to check page end for each byte.

Definition at line 529 of file at45dbx.c.

References at45dbx_write_multiple_sector_callback(), at45dbx_write_sector_from_ram(), and sector_buf.

Referenced by at45dbx_example_test_multiple_sector(), and at45dbx_usb_write_10().

00530 {
00531   while (nb_sector--)
00532   {
00533     // Write the next sector.
00534     at45dbx_write_multiple_sector_callback(sector_buf);
00535     at45dbx_write_sector_from_ram(sector_buf);
00536   }
00537 
00538   return OK;
00539 }

void at45dbx_write_multiple_sector_callback ( void *  psector  ) 

Callback function invoked before each sector write during at45dbx_write_multiple_sector.

Parameters:
psector Pointer to sector to write.

Definition at line 166 of file at45dbx_mem.c.

References AT45DBX_SECTOR_SIZE, and PATTERN_MULTIPLE_SECTOR.

Referenced by at45dbx_write_multiple_sector().

00167 {
00168   U16 data_to_transfer = AT45DBX_SECTOR_SIZE;
00169 
00170   // Transfer sector to write from the USB interface.
00171   while (data_to_transfer)
00172   {
00173     while (!Is_usb_out_received(g_scsi_ep_ms_out))
00174     {
00175       if(!Is_usb_endpoint_enabled(g_scsi_ep_ms_out))
00176          return; // USB Reset
00177     }         
00178 
00179     Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_out);
00180     data_to_transfer = usb_read_ep_rxpacket(g_scsi_ep_ms_out, psector,
00181                                             data_to_transfer, &psector);
00182     Usb_ack_out_received_free(g_scsi_ep_ms_out);
00183   }
00184 }

Bool at45dbx_write_open ( U32  sector  ) 

This function opens a DF memory in write mode at a given sector.

Parameters:
sector Start sector.
Return values:
OK Success.
KO Failure.
Note:
Sector may be page-unaligned (depending on the DF page size).

If AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE, page content is first loaded in buffer to then be partially updated by write byte or write sector functions.

Definition at line 353 of file at45dbx.c.

References at45dbx_busy, at45dbx_chipselect_df(), AT45DBX_CMDB_PR_PAGE_TH_BUF1, AT45DBX_CMDB_XFR_PAGE_TO_BUF1, AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_BYTE, AT45DBX_MSK_PTR_PAGE, AT45DBX_SECTOR_BITS, at45dbx_wait_ready(), gl_ptr_mem, and spi_write().

Referenced by at45dbx_example_test_byte_mem(), at45dbx_example_test_multiple_sector(), at45dbx_example_test_RAM_mem(), at45dbx_ram_2_df(), at45dbx_usb_write_10(), at45dbx_write_byte(), and at45dbx_write_sector_from_ram().

00354 {
00355   U32 addr;
00356 
00357   // Set the global memory pointer to a byte address.
00358   gl_ptr_mem = sector << AT45DBX_SECTOR_BITS; // gl_ptr_mem = sector * AT45DBX_SECTOR_SIZE.
00359 
00360   // If the DF memory is busy, wait until it's ready.
00361   if (at45dbx_busy) at45dbx_wait_ready();
00362   at45dbx_busy = FALSE;
00363 
00364 #if AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE
00365   // Select the DF memory gl_ptr_mem points to.
00366   at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);
00367 
00368   // Transfer the content of the current page to buffer 1.
00369 
00370   // Send the Main Memory Page to Buffer 1 Transfer command.
00371   spi_write(AT45DBX_SPI, AT45DBX_CMDB_XFR_PAGE_TO_BUF1);
00372 
00373   // Send the three address bytes, which comprise:
00374   //  - (24 - (AT45DBX_PAGE_ADDR_BITS + AT45DBX_BYTE_ADDR_BITS)) reserved bits;
00375   //  - then AT45DBX_PAGE_ADDR_BITS bits specifying the page in main memory to be read;
00376   //  - then AT45DBX_BYTE_ADDR_BITS don't care bits.
00377   // NOTE: The bits of gl_ptr_mem above the AT45DBX_MEM_SIZE bits are useless for the local
00378   // DF addressing. They are used for DF discrimination when there are several DFs.
00379   addr = Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_PAGE) << AT45DBX_BYTE_ADDR_BITS;
00380   spi_write(AT45DBX_SPI, LSB2W(addr));
00381   spi_write(AT45DBX_SPI, LSB1W(addr));
00382   spi_write(AT45DBX_SPI, LSB0W(addr));
00383 
00384   // Unselect the DF memory gl_ptr_mem points to.
00385   at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
00386 
00387   // Wait for end of page transfer.
00388   at45dbx_wait_ready();
00389 #endif
00390 
00391   // Select the DF memory gl_ptr_mem points to.
00392   at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);
00393 
00394   // Initiate a page write at a given sector.
00395 
00396   // Send the Main Memory Page Program through Buffer 1 command.
00397   spi_write(AT45DBX_SPI, AT45DBX_CMDB_PR_PAGE_TH_BUF1);
00398 
00399   // Send the three address bytes, which comprise:
00400   //  - (24 - (AT45DBX_PAGE_ADDR_BITS + AT45DBX_BYTE_ADDR_BITS)) reserved bits;
00401   //  - then AT45DBX_PAGE_ADDR_BITS bits specifying the page in main memory to be written;
00402   //  - then AT45DBX_BYTE_ADDR_BITS bits specifying the starting byte address within that page.
00403   // NOTE: The bits of gl_ptr_mem above the AT45DBX_MEM_SIZE bits are useless for the local
00404   // DF addressing. They are used for DF discrimination when there are several DFs.
00405   addr = (Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_PAGE) << AT45DBX_BYTE_ADDR_BITS) |
00406          Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE);
00407   spi_write(AT45DBX_SPI, LSB2W(addr));
00408   spi_write(AT45DBX_SPI, LSB1W(addr));
00409   spi_write(AT45DBX_SPI, LSB0W(addr));
00410 
00411   return OK;
00412 }

Bool at45dbx_write_sector_from_ram ( const void *  ram  ) 

Writes 1 DF sector from a RAM buffer.

Data flow is: RAM -> DF.

Parameters:
ram Pointer to RAM buffer.
Return values:
OK Success.
KO Failure.
Note:
First call must be preceded by a call to the at45dbx_write_open function.

Definition at line 598 of file at45dbx.c.

References at45dbx_busy, at45dbx_chipselect_df(), AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_BYTE, AT45DBX_SECTOR_BITS, AT45DBX_SECTOR_SIZE, at45dbx_write_open(), gl_ptr_mem, and spi_write().

Referenced by at45dbx_example_test_RAM_mem(), at45dbx_ram_2_df(), and at45dbx_write_multiple_sector().

00599 {
00600   const U8 *_ram = ram;
00601   U16 i;
00602 
00603   // Memory busy.
00604   if (at45dbx_busy)
00605   {
00606     // Being here, we know that we previously launched a page programming.
00607     // => We have to access the next page.
00608 
00609     // Eventually select the next DF and open the next page.
00610     // NOTE: at45dbx_write_open input parameter is a sector.
00611     at45dbx_write_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
00612   }
00613 
00614   // Write the next sector.
00615   for (i = AT45DBX_SECTOR_SIZE; i; i--)
00616   {
00617     // Write the next data byte.
00618     spi_write(AT45DBX_SPI, *_ram++);
00619   }
00620 
00621   // Update the memory pointer.
00622   gl_ptr_mem += AT45DBX_SECTOR_SIZE;
00623 
00624 #if AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE
00625   // If end of page reached,
00626   if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
00627 #endif
00628   {
00629     // unselect the DF memory gl_ptr_mem points to in order to program the page.
00630     at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
00631 
00632     // Memory busy.
00633     at45dbx_busy = TRUE;
00634   }
00635 
00636   return OK;
00637 }


Generated on Thu Dec 17 19:57:40 2009 for AVR32 - AT45DBX Data Flash Driver by  doxygen 1.5.5