Microchip® Advanced Software Framework

at25dfx.c File Reference

AT25DFx SerialFlash driver implementation.

Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.

#include "at25dfx.h"
#include <at25dfx_priv_hal.h>

Data Structures

struct  at25dfx_command
 SerialFlash command container. More...
 

Macros

#define AT25DFX_COMMAND_MAX_SIZE   (1 + 3 + 2)
 Maximum length of a SerialFlash command. More...
 
#define AT25DFX_PAGE_SIZE   256
 AT25DFx page size in bytes. More...
 

Enumerations

enum  at25dfx_command_opcode {
  AT25DFX_COMMAND_PROGRAM_PAGE = 0x02,
  AT25DFX_COMMAND_READ_STATUS = 0x05,
  AT25DFX_COMMAND_READ_ARRAY = 0x0b,
  AT25DFX_COMMAND_READ_DEVICE_ID = 0x9f,
  AT25DFX_COMMAND_WRITE_ENABLE = 0x06,
  AT25DFX_COMMAND_WRITE_DISABLE = 0x04,
  AT25DFX_COMMAND_ERASE_CHIP = 0xc7,
  AT25DFX_COMMAND_ERASE_BLOCK_4KB = 0x20,
  AT25DFX_COMMAND_ERASE_BLOCK_32KB = 0x52,
  AT25DFX_COMMAND_ERASE_BLOCK_64KB = 0xd8,
  AT25DFX_COMMAND_WRITE_STATUS = 0x01,
  AT25DFX_COMMAND_PROTECT_SECTOR = 0x36,
  AT25DFX_COMMAND_UNPROTECT_SECTOR = 0x39,
  AT25DFX_COMMAND_READ_PROTECT_SECTOR = 0x3c,
  AT25DFX_COMMAND_SLEEP = 0xb9,
  AT25DFX_COMMAND_WAKE = 0xab
}
 SerialFlash command opcodes. More...
 
enum  at25dfx_status_field {
  AT25DFX_STATUS_BUSY = (1 << 0),
  AT25DFX_STATUS_ERROR = (1 << 5),
  AT25DFX_STATUS_GLOBAL_PROTECT = (0x0f << 2)
}
 SerialFlash status bits. More...
 

Functions

enum status_code at25dfx_chip_check_presence (struct at25dfx_chip_module *chip)
 Check presence of chip. More...
 
enum status_code at25dfx_chip_erase (struct at25dfx_chip_module *chip)
 Erase chip. More...
 
enum status_code at25dfx_chip_erase_block (struct at25dfx_chip_module *chip, at25dfx_address_t address, enum at25dfx_block_size block_size)
 Erase block. More...
 
enum status_code at25dfx_chip_get_sector_protect (struct at25dfx_chip_module *chip, at25dfx_address_t address, bool *protect)
 Get protection setting of a single sector. More...
 
enum status_code at25dfx_chip_read_buffer (struct at25dfx_chip_module *chip, at25dfx_address_t address, void *data, at25dfx_datalen_t length)
 Read data from chip. More...
 
enum status_code at25dfx_chip_set_global_sector_protect (struct at25dfx_chip_module *chip, bool protect)
 Set sector protection globally. More...
 
enum status_code at25dfx_chip_set_sector_protect (struct at25dfx_chip_module *chip, at25dfx_address_t address, bool protect)
 Set protection setting of a single sector. More...
 
enum status_code at25dfx_chip_sleep (struct at25dfx_chip_module *chip)
 Put device to sleep. More...
 
enum status_code at25dfx_chip_wake (struct at25dfx_chip_module *chip)
 Wake device from sleep. More...
 
enum status_code at25dfx_chip_write_buffer (struct at25dfx_chip_module *chip, at25dfx_address_t address, const void *data, at25dfx_datalen_t length)
 Write data to chip. More...
 
SerialFlash chip info helpers
static uint32_t _at25dfx_get_device_id (enum at25dfx_type type)
 Get the device ID of a specific SerialFlash type. More...
 
static uint32_t _at25dfx_get_device_size (enum at25dfx_type type)
 Get the storage size of a specific SerialFlash type. More...
 
Private chip helpers
static void _at25dfx_chip_select (struct at25dfx_chip_module *chip)
 Select the chip. More...
 
static void _at25dfx_chip_deselect (struct at25dfx_chip_module *chip)
 Deselect the chip. More...
 
static void _at25dfx_chip_enable_write (struct at25dfx_chip_module *chip)
 Issue command to enable writing. More...
 

#define AT25DFX_COMMAND_MAX_SIZE   (1 + 3 + 2)

Maximum length of a SerialFlash command.

Referenced by _at25dfx_chip_issue_read_command_wait(), and _at25dfx_chip_issue_write_command_wait().

#define AT25DFX_PAGE_SIZE   256

AT25DFx page size in bytes.

Referenced by at25dfx_chip_write_buffer().

SerialFlash command opcodes.

Enumerator
AT25DFX_COMMAND_PROGRAM_PAGE 
AT25DFX_COMMAND_READ_STATUS 
AT25DFX_COMMAND_READ_ARRAY 
AT25DFX_COMMAND_READ_DEVICE_ID 
AT25DFX_COMMAND_WRITE_ENABLE 
AT25DFX_COMMAND_WRITE_DISABLE 
AT25DFX_COMMAND_ERASE_CHIP 
AT25DFX_COMMAND_ERASE_BLOCK_4KB 
AT25DFX_COMMAND_ERASE_BLOCK_32KB 
AT25DFX_COMMAND_ERASE_BLOCK_64KB 
AT25DFX_COMMAND_WRITE_STATUS 
AT25DFX_COMMAND_PROTECT_SECTOR 
AT25DFX_COMMAND_UNPROTECT_SECTOR 
AT25DFX_COMMAND_READ_PROTECT_SECTOR 
AT25DFX_COMMAND_SLEEP 
AT25DFX_COMMAND_WAKE 

SerialFlash status bits.

Enumerator
AT25DFX_STATUS_BUSY 
AT25DFX_STATUS_ERROR 
AT25DFX_STATUS_GLOBAL_PROTECT 

static void _at25dfx_chip_deselect ( struct at25dfx_chip_module chip)
inlinestatic

Deselect the chip.

This function deselects the specified chip by driving its CS line high.

Parameters
[in]chipAddress of SerialFlash chip instance to operate on.

References port_pin_set_output_level().

Referenced by _at25dfx_chip_get_nonbusy_status(), _at25dfx_chip_issue_read_command_wait(), and _at25dfx_chip_issue_write_command_wait().

static void _at25dfx_chip_enable_write ( struct at25dfx_chip_module chip)
inlinestatic

Issue command to enable writing.

This function issues the command that enables operations which change the SerialFlash content or operation, i.e., programming, erasing and protecting or unprotecting sectors.

Parameters
[in]chipAddress of SerialFlash chip instance to operate on.

References _at25dfx_chip_issue_write_command_wait(), at25dfx_command::address, AT25DFX_COMMAND_WRITE_ENABLE, at25dfx_command::command_size, at25dfx_command::data, at25dfx_command::length, NULL, at25dfx_command::opcode, and at25dfx_command::tx.

Referenced by at25dfx_chip_erase(), at25dfx_chip_erase_block(), at25dfx_chip_set_global_sector_protect(), at25dfx_chip_set_sector_protect(), and at25dfx_chip_write_buffer().

static void _at25dfx_chip_select ( struct at25dfx_chip_module chip)
inlinestatic

Select the chip.

This function selects the specified chip by driving its CS line low.

Parameters
[in]chipAddress of SerialFlash chip instance to operate on.

References port_pin_set_output_level().

Referenced by _at25dfx_chip_get_nonbusy_status(), _at25dfx_chip_issue_read_command_wait(), and _at25dfx_chip_issue_write_command_wait().

static uint32_t _at25dfx_get_device_id ( enum at25dfx_type  type)
inlinestatic

Get the device ID of a specific SerialFlash type.

Parameters
[in]typeType of SerialFlash.
Returns
SerialFlash device ID.

References Assert, AT25DFX_021, AT25DFX_041A, AT25DFX_041B, AT25DFX_081, AT25DFX_081A, AT25DFX_161, AT25DFX_321A, AT25DFX_512B, AT25DFX_641, AT25DFX_L161, and AT25DFX_Q161.

Referenced by at25dfx_chip_check_presence().

static uint32_t _at25dfx_get_device_size ( enum at25dfx_type  type)
inlinestatic

Get the storage size of a specific SerialFlash type.

Parameters
[in]typeType of SerialFlash.
Returns
SerialFlash storage size.

References Assert, AT25DFX_021, AT25DFX_041A, AT25DFX_041B, AT25DFX_081, AT25DFX_081A, AT25DFX_161, AT25DFX_321A, AT25DFX_512B, AT25DFX_641, AT25DFX_L161, and AT25DFX_Q161.

Referenced by at25dfx_chip_erase_block(), at25dfx_chip_get_sector_protect(), at25dfx_chip_read_buffer(), at25dfx_chip_set_sector_protect(), and at25dfx_chip_write_buffer().