Microchip® Advanced Software Framework

qspi.h File Reference

Quad Serial Peripheral Interface (QSPI) driver for SAM.

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

#include "compiler.h"
#include "string.h"
#include "status_codes.h"
#include <assert.h>
#include "sysclk.h"

Data Structures

union  qspi_inst_frame_t::_qspiinst_frame
 
struct  qspi_inst_frame_t::_qspiinst_frame::_qspiinst_frame_bitmap
 
struct  qspi_buffer_t
 Qspi buffer structure. More...
 
struct  qspi_config_t
 Qspi config structure. More...
 
struct  qspi_inst_frame_t
 Qspi frame structure for QSPI mode. More...
 
struct  qspi_mem_cmd_t
 Qspi command structure. More...
 
struct  qspid_t
 Qspi driver structure. More...
 

Macros

#define QSPI_WPMR_WPKEY_PASSWD   QSPI_WPMR_WPKEY((uint32_t) 0x515350)
 

Enumerations

enum  qspi_access {
  QSPI_CMD_ACCESS = 0,
  QSPI_READ_ACCESS,
  QSPI_WRITE_ACCESS
}
 Qspi access modes. More...
 
enum  qspi_cs_mode {
  QSPI_NOT_RELOADED = 0,
  QSPI_LASTXFER,
  QSPI_SYSTEMATICALLY
}
 QSPI chip select mode. More...
 
enum  qspi_run_mode {
  spi_mode = QSPI_MR_SMM_SPI,
  mem_mode = QSPI_MR_SMM_MEMORY
}
 Qspi enum types for QSPI modes. More...
 

Functions

static void qspi_disable (Qspi *qspi)
 Disables a QSPI peripheral. More...
 
static void qspi_disable_interrupt (Qspi *qspi, uint32_t sources)
 Disable QSPI interrupts. More...
 
static void qspi_disable_loopback (Qspi *qspi)
 Disable loop back mode. More...
 
static void qspi_enable (Qspi *qspi)
 Enables a QSPI peripheral. More...
 
static void qspi_enable_interrupt (Qspi *qspi, uint32_t sources)
 Enable QSPI interrupts. More...
 
static void qspi_enable_loopback (Qspi *qspi)
 Enable loop back mode. More...
 
enum status_code qspi_flash_access_memory (struct qspid_t *qspid, enum qspi_access read_write, uint8_t scramble_flag)
 Writes or reads the QSPI memory (0x80000000) to trasmit or receive data from Flash memory. More...
 
enum status_code qspi_flash_execute_command (struct qspid_t *qspid, enum qspi_access read_write)
 Functionality API – Serial Memory Mode. More...
 
void qspi_get_config_default (struct qspi_config_t *qspi_config)
 Get default config. More...
 
static uint32_t qspi_get_inst_frame (Qspi *qspi)
 Reads the Instruction frame of QSPI. More...
 
static uint32_t qspi_get_writeprotect_status (Qspi *qspi)
 Get write protection status. More...
 
enum status_code qspi_initialize (Qspi *qspi, struct qspi_config_t *qspi_config)
 Config qspi according the config struct. More...
 
enum status_code qspi_read (Qspi *qspi, uint16_t *us_data, uint32_t num_of_bytes)
 Qspi read data. More...
 
static void qspi_reset (Qspi *qspi)
 Resets a QSPI peripheral. More...
 
static enum status_code qspi_set_baudrate (Qspi *qspi, uint32_t baudrate)
 Set qspi clock baudrate. More...
 
static void qspi_set_clock_phase (Qspi *qspi, uint32_t phase)
 Set qspi clock phase. More...
 
static void qspi_set_clock_polarity (Qspi *qspi, uint32_t polarity)
 Set qspi clock polarity. More...
 
static void qspi_set_instruction_addr (Qspi *qspi, uint32_t addr)
 Set qspi instruction addr. More...
 
static void qspi_set_instruction_code (Qspi *qspi, struct qspi_mem_cmd_t instruction_code)
 Set qspi instruction code. More...
 
void qspi_set_instruction_frame (Qspi *qspi, struct qspi_inst_frame_t instruction_frame)
 Set qspi instruction frame. More...
 
static uint32_t qspi_set_scrambing_key (Qspi *qspi, uint32_t key)
 Set qspi scrambling key. More...
 
static void qspi_set_scrambling_mode (Qspi *qspi, uint32_t scr_enable, uint32_t random_mode)
 Set qspi scrambling mode. More...
 
static void qspi_set_writeprotect (Qspi *qspi, uint32_t enable)
 Enable write protection. More...
 
enum status_code qspi_write (Qspi *qspi, uint16_t *us_data, uint32_t num_of_bytes)
 Qspi write data. More...
 

#define QSPI_WPMR_WPKEY_PASSWD   QSPI_WPMR_WPKEY((uint32_t) 0x515350)

Referenced by qspi_set_writeprotect().

Qspi access modes.

Enumerator
QSPI_CMD_ACCESS 
QSPI_READ_ACCESS 
QSPI_WRITE_ACCESS 

QSPI chip select mode.

Enumerator
QSPI_NOT_RELOADED 
QSPI_LASTXFER 
QSPI_SYSTEMATICALLY 

Qspi enum types for QSPI modes.

Enumerator
spi_mode 
mem_mode 

static void qspi_disable ( Qspi *  qspi)
inlinestatic

Disables a QSPI peripheral.

Parameters
qspiPointer to a Qspi instance.

Referenced by qspi_initialize().

static void qspi_disable_interrupt ( Qspi *  qspi,
uint32_t  sources 
)
inlinestatic

Disable QSPI interrupts.

Parameters
qspiPointer to an QSPI instance.
sourcesInterrupts to be disabled.
static void qspi_disable_loopback ( Qspi *  qspi)
inlinestatic

Disable loop back mode.

Parameters
qspiPointer to an QSPI instance.

Referenced by qspi_set_config().

static void qspi_enable ( Qspi *  qspi)
inlinestatic

Enables a QSPI peripheral.

Parameters
qspiPointer to a Qspi instance.

Referenced by qspi_initialize().

static void qspi_enable_interrupt ( Qspi *  qspi,
uint32_t  sources 
)
inlinestatic

Enable QSPI interrupts.

Parameters
qspiPointer to an QSPI instance.
sourcesInterrupts to be enabled.
static void qspi_enable_loopback ( Qspi *  qspi)
inlinestatic

Enable loop back mode.

Parameters
qspiPointer to an QSPI instance.

Referenced by qspi_set_config().

static uint32_t qspi_get_inst_frame ( Qspi *  qspi)
inlinestatic

Reads the Instruction frame of QSPI.

Parameters
pQspiPointer to an Qspi instance.
Returns
status QSPI frame value.

Referenced by qspi_flash_access_memory(), and qspi_flash_execute_command().

static uint32_t qspi_get_writeprotect_status ( Qspi *  qspi)
inlinestatic

Get write protection status.

Parameters
qspiPointer to a Qspi instance.
Returns
Write protection status.
status QSPI write protect status.
static void qspi_reset ( Qspi *  qspi)
inlinestatic

Resets a QSPI peripheral.

Parameters
qspiPointer to a Qspi instance.

Referenced by qspi_initialize().

static enum status_code qspi_set_baudrate ( Qspi *  qspi,
uint32_t  baudrate 
)
inlinestatic

Set qspi clock baudrate.

Parameters
qspiPointer to a Qspi instance.
baudrateBaud rate to be set.
Returns
status Baud rate set result.

References ERR_INVALID_ARG, STATUS_OK, and sysclk_get_peripheral_hz().

Referenced by qspi_set_config().

static void qspi_set_clock_phase ( Qspi *  qspi,
uint32_t  phase 
)
inlinestatic

Set qspi clock phase.

Parameters
qspiPointer to a Qspi instance.
phasePhase to be set.

Referenced by qspi_set_config().

static void qspi_set_clock_polarity ( Qspi *  qspi,
uint32_t  polarity 
)
inlinestatic

Set qspi clock polarity.

Parameters
qspiPointer to a Qspi instance.
polarityPolarity to be set.

Referenced by qspi_set_config().

static void qspi_set_instruction_addr ( Qspi *  qspi,
uint32_t  addr 
)
inlinestatic

Set qspi instruction addr.

Parameters
qspiPointer to a Qspi instance.
addrAddress to be set.

Referenced by qspi_flash_execute_command().

static void qspi_set_instruction_code ( Qspi *  qspi,
struct qspi_mem_cmd_t  instruction_code 
)
inlinestatic

Set qspi instruction code.

Parameters
qspiPointer to a Qspi instance.
instruction_codeCode to be set.

References qspi_mem_cmd_t::instruction, and qspi_mem_cmd_t::option.

Referenced by qspi_flash_access_memory(), and qspi_flash_execute_command().

static uint32_t qspi_set_scrambing_key ( Qspi *  qspi,
uint32_t  key 
)
inlinestatic

Set qspi scrambling key.

Parameters
qspiPointer to a Qspi instance.
modeMode to be set.
Returns
If write succeeded, return 0, else return 1.

Referenced by qspi_set_config().

static void qspi_set_scrambling_mode ( Qspi *  qspi,
uint32_t  scr_enable,
uint32_t  random_mode 
)
inlinestatic

Set qspi scrambling mode.

Parameters
qspiPointer to a Qspi instance.
modeMode to be set.

Referenced by qspi_flash_access_memory(), and qspi_set_config().

static void qspi_set_writeprotect ( Qspi *  qspi,
uint32_t  enable 
)
inlinestatic

Enable write protection.

Parameters
qspiPointer to a Qspi instance.
enableEnable or disable write protect. Protection status to be set.

References QSPI_WPMR_WPKEY_PASSWD.