This file manages the accesses to the AT45DBX data flash components.
Definition in file at45dbx.c.
#include "conf_access.h"
#include "compiler.h"
#include "board.h"
#include "gpio.h"
#include "spi.h"
#include "conf_at45dbx.h"
#include "at45dbx.h"
Go to the source code of this file.
Defines | |
#define | AT45DBX_MSK_PTR_BYTE ((1 << AT45DBX_PAGE_BITS) - 1) |
Bit-mask for byte position within buffer in gl_ptr_mem. | |
#define | AT45DBX_MSK_PTR_PAGE (((1 << AT45DBX_PAGE_ADDR_BITS) - 1) << AT45DBX_PAGE_BITS) |
Bit-mask for page selection in gl_ptr_mem. | |
#define | AT45DBX_MSK_PTR_SECTOR ((1 << AT45DBX_SECTOR_BITS) - 1) |
Bit-mask for byte position within sector in gl_ptr_mem. | |
#define | AT45DBX_PAGE_ADDR_BITS (AT45DBX_MEM_SIZE - AT45DBX_PAGE_BITS) |
Address bits for page selection. | |
#define | AT45DBX_PAGE_BITS (AT45DBX_BYTE_ADDR_BITS - 1) |
Number of bits for addresses within pages. | |
#define | AT45DBX_PAGE_SIZE (1 << AT45DBX_PAGE_BITS) |
Page size in bytes. | |
#define | spi_write_dummy() spi_write(AT45DBX_SPI, 0xFF) |
Sends a dummy byte through SPI. | |
Bit-Masks and Values for the Status Register | |
#define | AT45DBX_BUSY 0x00 |
Busy status value (0x00 when busy, 0x80 when ready). | |
#define | AT45DBX_MSK_BUSY 0x80 |
Busy status bit-mask. | |
#define | AT45DBX_MSK_DENSITY 0x3C |
Device density bit-mask. | |
AT45DBX Group A Commands | |
#define | AT45DBX_CMDA_RD_ARRAY_AF_SM 0x0B |
Continuous Array Read, Any-Frequency Mode (Serial Mode). | |
#define | AT45DBX_CMDA_RD_ARRAY_LEG 0xE8 |
Continuous Array Read, Legacy Command (Serial/8-bit Mode). | |
#define | AT45DBX_CMDA_RD_ARRAY_LF_SM 0x03 |
Continuous Array Read, Low-Frequency Mode (Serial Mode). | |
#define | AT45DBX_CMDA_RD_PAGE 0xD2 |
Main Memory Page Read (Serial/8-bit Mode). | |
#define | AT45DBX_CMDA_RD_SECTOR_LKDN_REG 0x35 |
Read Sector Lockdown Register (Serial/8-bit Mode). | |
#define | AT45DBX_CMDA_RD_SECTOR_PROT_REG 0x32 |
Read Sector Protection Register (Serial/8-bit Mode). | |
#define | AT45DBX_CMDA_RD_SECURITY_REG 0x77 |
Read Security Register (Serial/8-bit Mode). | |
AT45DBX Group B Commands | |
#define | AT45DBX_CMDB_CMP_PAGE_TO_BUF1 0x60 |
Main Memory Page to Buffer 1 Compare (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_CMP_PAGE_TO_BUF2 0x61 |
Main Memory Page to Buffer 2 Compare (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_ER_BLOCK 0x50 |
Block Erase (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_ER_CHIP 0xC794809A |
Chip Erase (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_ER_PAGE 0x81 |
Page Erase (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_ER_SECTOR 0x7C |
Sector Erase (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_PR_BUF1_TO_PAGE 0x88 |
Buffer 1 to Main Memory Page Program without Built-in Erase (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_PR_BUF1_TO_PAGE_ER 0x83 |
Buffer 1 to Main Memory Page Program with Built-in Erase (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_PR_BUF2_TO_PAGE 0x89 |
Buffer 2 to Main Memory Page Program without Built-in Erase (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_PR_BUF2_TO_PAGE_ER 0x86 |
Buffer 2 to Main Memory Page Program with Built-in Erase (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_PR_PAGE_TH_BUF1 0x82 |
Main Memory Page Program through Buffer 1 (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_PR_PAGE_TH_BUF2 0x85 |
Main Memory Page Program through Buffer 2 (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_RWR_PAGE_TH_BUF1 0x58 |
Auto Page Rewrite through Buffer 1 (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_RWR_PAGE_TH_BUF2 0x59 |
Auto Page Rewrite through Buffer 2 (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_XFR_PAGE_TO_BUF1 0x53 |
Main Memory Page to Buffer 1 Transfer (Serial/8-bit Mode). | |
#define | AT45DBX_CMDB_XFR_PAGE_TO_BUF2 0x55 |
Main Memory Page to Buffer 2 Transfer (Serial/8-bit Mode). | |
AT45DBX Group C Commands | |
#define | AT45DBX_CMDC_RD_BUF1_AF_8M 0x54 |
Buffer 1 Read, Any-Frequency Mode (8-bit Mode). | |
#define | AT45DBX_CMDC_RD_BUF1_AF_SM 0xD4 |
Buffer 1 Read, Any-Frequency Mode (Serial Mode). | |
#define | AT45DBX_CMDC_RD_BUF1_LF_SM 0xD1 |
Buffer 1 Read, Low-Frequency Mode (Serial Mode). | |
#define | AT45DBX_CMDC_RD_BUF2_AF_8M 0x56 |
Buffer 2 Read, Any-Frequency Mode (8-bit Mode). | |
#define | AT45DBX_CMDC_RD_BUF2_AF_SM 0xD6 |
Buffer 2 Read, Any-Frequency Mode (Serial Mode). | |
#define | AT45DBX_CMDC_RD_BUF2_LF_SM 0xD3 |
Buffer 2 Read, Low-Frequency Mode (Serial Mode). | |
#define | AT45DBX_CMDC_RD_MNFCT_DEV_ID_SM 0x9F |
Manufacturer and Device ID Read (Serial Mode). | |
#define | AT45DBX_CMDC_RD_STATUS_REG 0xD7 |
Status Register Read (Serial/8-bit Mode). | |
#define | AT45DBX_CMDC_WR_BUF1 0x84 |
Buffer 1 Write (Serial/8-bit Mode). | |
#define | AT45DBX_CMDC_WR_BUF2 0x87 |
Buffer 2 Write (Serial/8-bit Mode). | |
AT45DBX Group D Commands | |
#define | AT45DBX_CMDD_DEEP_PWR_DN 0xB9 |
Deep Power-down (Serial/8-bit Mode). | |
#define | AT45DBX_CMDD_DIS_SECTOR_PROT 0x3D2A7F9A |
Disable Sector Protection (Serial/8-bit Mode). | |
#define | AT45DBX_CMDD_EN_SECTOR_PROT 0x3D2A7FA9 |
Enable Sector Protection (Serial/8-bit Mode). | |
#define | AT45DBX_CMDD_ER_SECTOR_PROT_REG 0x3D2A7FCF |
Erase Sector Protection Register (Serial/8-bit Mode). | |
#define | AT45DBX_CMDD_LKDN_SECTOR 0x3D2A7F30 |
Sector Lockdown (Serial/8-bit Mode). | |
#define | AT45DBX_CMDD_PR_CONF_REG 0x3D2A80A6 |
Program Configuration Register (Serial/8-bit Mode). | |
#define | AT45DBX_CMDD_PR_SECTOR_PROT_REG 0x3D2A7FFC |
Program Sector Protection Register (Serial/8-bit Mode). | |
#define | AT45DBX_CMDD_PR_SECURITY_REG 0x9B000000 |
Program Security Register (Serial/8-bit Mode). | |
#define | AT45DBX_CMDD_RSM_DEEP_PWR_DN 0xAB |
Resume from Deep Power-down (Serial/8-bit Mode). | |
Functions | |
Control Functions | |
static void | at45dbx_chipselect_df (U8 memidx, Bool bSelect) |
Selects or unselects a DF memory. | |
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. | |
static void | at45dbx_wait_ready (void) |
Waits until the DF is ready. | |
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. | |
Bool | at45dbx_write_multiple_sector (U16 nb_sector) |
Writes nb_sector sectors to DF memory. | |
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. | |
Variables | |
static Bool | at45dbx_busy |
Boolean indicating whether memory is in busy state. | |
static U32 | gl_ptr_mem |
Memory data pointer. | |
static U8 | sector_buf [AT45DBX_SECTOR_SIZE] |
Sector buffer. |
#define AT45DBX_BUSY 0x00 |
Busy status value (0x00 when busy, 0x80 when ready).
Definition at line 137 of file at45dbx.c.
Referenced by at45dbx_wait_ready().
#define AT45DBX_CMDA_RD_ARRAY_AF_SM 0x0B |
#define AT45DBX_CMDA_RD_ARRAY_LEG 0xE8 |
#define AT45DBX_CMDA_RD_ARRAY_LF_SM 0x03 |
#define AT45DBX_CMDA_RD_PAGE 0xD2 |
Main Memory Page Read (Serial/8-bit Mode).
Definition at line 73 of file at45dbx.c.
Referenced by at45dbx_read_open().
#define AT45DBX_CMDA_RD_SECTOR_LKDN_REG 0x35 |
#define AT45DBX_CMDA_RD_SECTOR_PROT_REG 0x32 |
#define AT45DBX_CMDA_RD_SECURITY_REG 0x77 |
#define AT45DBX_CMDB_CMP_PAGE_TO_BUF1 0x60 |
#define AT45DBX_CMDB_CMP_PAGE_TO_BUF2 0x61 |
#define AT45DBX_CMDB_ER_BLOCK 0x50 |
#define AT45DBX_CMDB_ER_CHIP 0xC794809A |
#define AT45DBX_CMDB_ER_PAGE 0x81 |
#define AT45DBX_CMDB_ER_SECTOR 0x7C |
#define AT45DBX_CMDB_PR_BUF1_TO_PAGE 0x88 |
#define AT45DBX_CMDB_PR_BUF1_TO_PAGE_ER 0x83 |
#define AT45DBX_CMDB_PR_BUF2_TO_PAGE 0x89 |
#define AT45DBX_CMDB_PR_BUF2_TO_PAGE_ER 0x86 |
#define AT45DBX_CMDB_PR_PAGE_TH_BUF1 0x82 |
Main Memory Page Program through Buffer 1 (Serial/8-bit Mode).
Definition at line 97 of file at45dbx.c.
Referenced by at45dbx_write_open().
#define AT45DBX_CMDB_PR_PAGE_TH_BUF2 0x85 |
#define AT45DBX_CMDB_RWR_PAGE_TH_BUF1 0x58 |
#define AT45DBX_CMDB_RWR_PAGE_TH_BUF2 0x59 |
#define AT45DBX_CMDB_XFR_PAGE_TO_BUF1 0x53 |
Main Memory Page to Buffer 1 Transfer (Serial/8-bit Mode).
Definition at line 89 of file at45dbx.c.
Referenced by at45dbx_write_open().
#define AT45DBX_CMDB_XFR_PAGE_TO_BUF2 0x55 |
#define AT45DBX_CMDC_RD_BUF1_AF_8M 0x54 |
#define AT45DBX_CMDC_RD_BUF1_AF_SM 0xD4 |
#define AT45DBX_CMDC_RD_BUF1_LF_SM 0xD1 |
#define AT45DBX_CMDC_RD_BUF2_AF_8M 0x56 |
#define AT45DBX_CMDC_RD_BUF2_AF_SM 0xD6 |
#define AT45DBX_CMDC_RD_BUF2_LF_SM 0xD3 |
#define AT45DBX_CMDC_RD_MNFCT_DEV_ID_SM 0x9F |
#define AT45DBX_CMDC_RD_STATUS_REG 0xD7 |
Status Register Read (Serial/8-bit Mode).
Definition at line 114 of file at45dbx.c.
Referenced by at45dbx_mem_check(), and at45dbx_wait_ready().
#define AT45DBX_CMDC_WR_BUF1 0x84 |
#define AT45DBX_CMDC_WR_BUF2 0x87 |
#define AT45DBX_CMDD_DEEP_PWR_DN 0xB9 |
#define AT45DBX_CMDD_DIS_SECTOR_PROT 0x3D2A7F9A |
#define AT45DBX_CMDD_EN_SECTOR_PROT 0x3D2A7FA9 |
#define AT45DBX_CMDD_ER_SECTOR_PROT_REG 0x3D2A7FCF |
#define AT45DBX_CMDD_LKDN_SECTOR 0x3D2A7F30 |
#define AT45DBX_CMDD_PR_CONF_REG 0x3D2A80A6 |
#define AT45DBX_CMDD_PR_SECTOR_PROT_REG 0x3D2A7FFC |
#define AT45DBX_CMDD_PR_SECURITY_REG 0x9B000000 |
#define AT45DBX_CMDD_RSM_DEEP_PWR_DN 0xAB |
#define AT45DBX_MSK_BUSY 0x80 |
#define AT45DBX_MSK_DENSITY 0x3C |
Device density bit-mask.
Definition at line 138 of file at45dbx.c.
Referenced by at45dbx_mem_check().
#define AT45DBX_MSK_PTR_BYTE ((1 << AT45DBX_PAGE_BITS) - 1) |
Bit-mask for byte position within buffer in gl_ptr_mem.
Definition at line 182 of file at45dbx.c.
Referenced by at45dbx_read_byte(), at45dbx_read_open(), at45dbx_read_sector_2_ram(), at45dbx_write_byte(), at45dbx_write_open(), and at45dbx_write_sector_from_ram().
#define AT45DBX_MSK_PTR_PAGE (((1 << AT45DBX_PAGE_ADDR_BITS) - 1) << AT45DBX_PAGE_BITS) |
Bit-mask for page selection in gl_ptr_mem.
Definition at line 185 of file at45dbx.c.
Referenced by at45dbx_read_open(), and at45dbx_write_open().
#define AT45DBX_MSK_PTR_SECTOR ((1 << AT45DBX_SECTOR_BITS) - 1) |
Bit-mask for byte position within sector in gl_ptr_mem.
Definition at line 188 of file at45dbx.c.
Referenced by at45dbx_write_close().
#define AT45DBX_PAGE_ADDR_BITS (AT45DBX_MEM_SIZE - AT45DBX_PAGE_BITS) |
#define AT45DBX_PAGE_BITS (AT45DBX_BYTE_ADDR_BITS - 1) |
#define AT45DBX_PAGE_SIZE (1 << AT45DBX_PAGE_BITS) |
#define spi_write_dummy | ( | ) | spi_write(AT45DBX_SPI, 0xFF) |
Sends a dummy byte through SPI.
Definition at line 193 of file at45dbx.c.
Referenced by at45dbx_mem_check(), at45dbx_read_byte(), at45dbx_read_open(), at45dbx_read_sector_2_ram(), and at45dbx_wait_ready().
static void at45dbx_chipselect_df | ( | U8 | memidx, | |
Bool | bSelect | |||
) | [static] |
Selects or unselects a DF memory.
memidx | Memory ID of DF to select or unselect. | |
bSelect | Boolean indicating whether the DF memory has to be selected. |
Definition at line 233 of file at45dbx.c.
References AT45DBX_SPI_FIRST_NPCS, spi_selectChip(), and spi_unselectChip().
Referenced by at45dbx_mem_check(), at45dbx_read_byte(), at45dbx_read_close(), at45dbx_read_open(), at45dbx_read_sector_2_ram(), at45dbx_wait_ready(), at45dbx_write_byte(), at45dbx_write_close(), at45dbx_write_open(), and at45dbx_write_sector_from_ram().
00234 { 00235 if (bSelect) 00236 { 00237 // Select SPI chip. 00238 spi_selectChip(AT45DBX_SPI, AT45DBX_SPI_FIRST_NPCS + memidx); 00239 } 00240 else 00241 { 00242 // Unselect SPI chip. 00243 spi_unselectChip(AT45DBX_SPI, AT45DBX_SPI_FIRST_NPCS + memidx); 00244 } 00245 }
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.
spiOptions | Initialization options of the DF SPI channel. | |
pba_hz | SPI module input clock frequency (PBA clock, Hz). |
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.
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.
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.
nb_sector | Number of contiguous sectors to read. |
OK | Success. | |
KO | Failure. |
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 }
Bool at45dbx_read_open | ( | U32 | sector | ) |
Opens a DF memory in read mode at a given sector.
sector | Start sector. |
OK | Success. | |
KO | Failure. |
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.
ram | Pointer to RAM buffer. |
OK | Success. | |
KO | Failure. |
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 }
static void at45dbx_wait_ready | ( | void | ) | [static] |
Waits until the DF is ready.
Definition at line 279 of file at45dbx.c.
References AT45DBX_BUSY, at45dbx_chipselect_df(), AT45DBX_CMDC_RD_STATUS_REG, AT45DBX_MEM_SIZE, AT45DBX_MSK_BUSY, gl_ptr_mem, spi_read(), spi_write(), and spi_write_dummy.
Referenced by at45dbx_read_open(), and at45dbx_write_open().
00280 { 00281 U16 status; 00282 00283 // Select the DF memory gl_ptr_mem points to. 00284 at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE); 00285 00286 // Send the Status Register Read command. 00287 spi_write(AT45DBX_SPI, AT45DBX_CMDC_RD_STATUS_REG); 00288 00289 // Read the status register until the DF is ready. 00290 do 00291 { 00292 // Send a dummy byte to read the status register. 00293 spi_write_dummy(); 00294 spi_read(AT45DBX_SPI, &status); 00295 } while ((status & AT45DBX_MSK_BUSY) == AT45DBX_BUSY); 00296 00297 // Unselect the DF memory gl_ptr_mem points to. 00298 at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE); 00299 }
Bool at45dbx_write_byte | ( | U8 | b | ) |
Performs a single byte write to DF memory.
b | The byte to write. |
OK | Success. | |
KO | Failure. |
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.
nb_sector | Number of contiguous sectors to write. |
OK | Success. | |
KO | Failure. |
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 }
Bool at45dbx_write_open | ( | U32 | sector | ) |
This function opens a DF memory in write mode at a given sector.
sector | Start sector. |
OK | Success. | |
KO | Failure. |
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.
ram | Pointer to RAM buffer. |
OK | Success. | |
KO | Failure. |
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 }
Bool at45dbx_busy [static] |
Boolean indicating whether memory is in busy state.
Definition at line 197 of file at45dbx.c.
Referenced by at45dbx_init(), at45dbx_read_byte(), at45dbx_read_close(), at45dbx_read_open(), at45dbx_read_sector_2_ram(), at45dbx_write_byte(), at45dbx_write_close(), at45dbx_write_open(), and at45dbx_write_sector_from_ram().
U32 gl_ptr_mem [static] |
Memory data pointer.
Definition at line 200 of file at45dbx.c.
Referenced by at45dbx_read_byte(), at45dbx_read_close(), at45dbx_read_open(), at45dbx_read_sector_2_ram(), at45dbx_wait_ready(), at45dbx_write_byte(), at45dbx_write_close(), at45dbx_write_open(), and at45dbx_write_sector_from_ram().
U8 sector_buf[AT45DBX_SECTOR_SIZE] [static] |
Sector buffer.
Definition at line 203 of file at45dbx.c.
Referenced by at45dbx_read_multiple_sector(), at45dbx_write_multiple_sector(), and stream_mem_to_mem().