PebbleOS v4.44.0-46-gef116268a
Loading...
Searching...
No Matches
spi_mem.h File Reference
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <pbl/device.h>
#include <pbl/util/bits.h>

Data Structures

struct  pbl_spi_mem_op
 An operation. More...
 
struct  pbl_spi_mem_dirmap
 A memory-mapped read window, see pbl_spi_mem_dirmap_create(). More...
 
struct  pbl_spi_mem_pm
 Memory commands that put it in and out of its lowest power state. More...
 
struct  pbl_spi_mem_suspend
 Memory commands that suspend and resume a long operation, see pbl_spi_mem_poll_status(). More...
 
struct  pbl_spi_mem_ops
 Controller driver operations. More...
 
struct  pbl_spi_mem
 A SPI memory controller. More...
 
struct  pbl_spi_mem_op.cmd
 Command phase. More...
 
struct  pbl_spi_mem_op.addr
 Address phase. More...
 
struct  pbl_spi_mem_op.dummy
 Dummy phase. More...
 
struct  pbl_spi_mem_op.data
 Data phase. More...
 
union  pbl_spi_mem_op.data.buf
 Buffer. More...
 

Macros

#define PBL_SPI_MEM_OP_CMD(_opcode, _buswidth)   {.opcode = (_opcode), .buswidth = (_buswidth)}
 Command phase, for PBL_SPI_MEM_OP().
 
#define PBL_SPI_MEM_OP_ADDR(_nbytes, _val, _buswidth)    {.nbytes = (_nbytes), .buswidth = (_buswidth), .val = (_val)}
 Address phase, for PBL_SPI_MEM_OP().
 
#define PBL_SPI_MEM_OP_NO_ADDR
 No address phase.
 
#define PBL_SPI_MEM_OP_DUMMY(_nbytes, _buswidth)   {.nbytes = (_nbytes), .buswidth = (_buswidth)}
 Dummy phase, for PBL_SPI_MEM_OP().
 
#define PBL_SPI_MEM_OP_NO_DUMMY
 No dummy phase.
 
#define PBL_SPI_MEM_OP_DATA_IN(_nbytes, _buf, _buswidth)    {.dir = PBL_SPI_MEM_DATA_IN, .buswidth = (_buswidth), .nbytes = (_nbytes), .buf.in = (_buf)}
 Data phase reading from the memory, for PBL_SPI_MEM_OP().
 
#define PBL_SPI_MEM_OP_DATA_OUT(_nbytes, _buf, _buswidth)    {.dir = PBL_SPI_MEM_DATA_OUT, .buswidth = (_buswidth), .nbytes = (_nbytes), .buf.out = (_buf)}
 Data phase writing to the memory, for PBL_SPI_MEM_OP().
 
#define PBL_SPI_MEM_OP_NO_DATA
 No data phase.
 
#define PBL_SPI_MEM_OP(_cmd, _addr, _dummy, _data)
 Build an operation from its phases.
 
#define PBL_SPI_MEM_XIP   PBL_BIT(0)
 The CPU executes from the memory on this controller.
 
#define PBL_SPI_MEM_STATE_DEFINE(sym)
 Define the class state of controller sym, for the PBL_SPI_MEM_*_DEFINE() macro of a driver.
 
#define PBL_SPI_MEM_INIT(sym, _name, _deps, _ops, _flags)
 Initializer for the struct pbl_spi_mem of controller sym.
 

Typedefs

typedef void(* pbl_spi_mem_pm_fn_t) (void *arg)
 Function run while the memory is powered down, see pbl_spi_mem_power_down().
 

Enumerations

enum  pbl_spi_mem_data_dir { PBL_SPI_MEM_NO_DATA , PBL_SPI_MEM_DATA_IN , PBL_SPI_MEM_DATA_OUT }
 Data direction of an operation. More...
 

Functions

static bool pbl_spi_mem_is_xip (const struct pbl_spi_mem *mem)
 Check whether the CPU executes from the memory on a controller.
 
bool pbl_spi_mem_supports_op (const struct pbl_spi_mem *mem, const struct pbl_spi_mem_op *op)
 Check whether the controller can run an operation.
 
int pbl_spi_mem_adjust_op_size (const struct pbl_spi_mem *mem, struct pbl_spi_mem_op *op)
 Reduce the data of an operation to what one run carries.
 
int pbl_spi_mem_exec_op (const struct pbl_spi_mem *mem, const struct pbl_spi_mem_op *op)
 Run an operation.
 
int pbl_spi_mem_poll_status (const struct pbl_spi_mem *mem, const struct pbl_spi_mem_op *op, const struct pbl_spi_mem_op *status, uint8_t mask, uint8_t match, const struct pbl_spi_mem_suspend *susp)
 Run an operation, then poll a status register until it matches.
 
int pbl_spi_mem_dirmap_create (const struct pbl_spi_mem *mem, struct pbl_spi_mem_dirmap *desc)
 Create a memory-mapped read window.
 
int pbl_spi_mem__dirmap_read_ops (const struct pbl_spi_mem *mem, const struct pbl_spi_mem_dirmap *desc, uint32_t offs, void *buf, size_t len)
 
static int pbl_spi_mem_dirmap_read (const struct pbl_spi_mem *mem, const struct pbl_spi_mem_dirmap *desc, uint32_t offs, void *buf, size_t len)
 Read through a memory-mapped read window.
 
void pbl_spi_mem_dirmap_invalidate (const struct pbl_spi_mem *mem, const struct pbl_spi_mem_dirmap *desc, uint32_t offs, size_t len)
 Drop cached copies of a range of a window, after programming or erasing it.
 
void pbl_spi_mem_power_down (const struct pbl_spi_mem *mem, const struct pbl_spi_mem_pm *pm, pbl_spi_mem_pm_fn_t fn, void *arg)
 Power the memory and the controller down while a function runs, with interrupts disabled.
 
void pbl_spi_mem_set_polling (const struct pbl_spi_mem *mem, bool polling)
 Poll for completion instead of sleeping, e.g.
 
static bool pbl_spi_mem_is_polling (const struct pbl_spi_mem *mem)
 Check whether the controller polls for completion, for drivers.