OpenOCD
esirisc_flash.c File Reference
Include dependency graph for esirisc_flash.c:

Go to the source code of this file.

Data Structures

struct  esirisc_flash_bank
 

Macros

#define ADDRESS   0x20 /* Erase/Program Address */
 
#define CONTROL   0x00 /* Control Register */
 
#define CONTROL_AP   (1<<8) /* Auto-Program */
 
#define CONTROL_E   (1<<3) /* Erase */
 
#define CONTROL_EP   (1<<4) /* Erase Page */
 
#define CONTROL_ERC   (1<<6) /* Erase Reference Cell */
 
#define CONTROL_P   (1<<5) /* Program Flash */
 
#define CONTROL_R   (1<<7) /* Recall Trim Code */
 
#define CONTROL_SLM   (1<<0) /* Sleep Mode */
 
#define CONTROL_TIMEOUT   5000 /* 5s */
 
#define CONTROL_WP   (1<<1) /* Register Write Protect */
 
#define FLASH_PAGE_SIZE   4096
 
#define NUM_NS_PER_S   1000000000ULL
 
#define PB_DATA   0x24 /* Program Buffer Data */
 
#define PB_INDEX   0x28 /* Program Buffer Index */
 
#define PB_MAX   32
 
#define REDUN_0   0x30 /* Redundant Address 0 */
 
#define REDUN_1   0x34 /* Redundant Address 1 */
 
#define REDUN_P(x)   (((x) << 12) & 0x7f000) /* Redundant Page Address */
 
#define REDUN_R   (1<<0) /* Used */
 
#define STATUS   0x2c /* Status Register */
 
#define STATUS_BO   (1<<4) /* Brown Out */
 
#define STATUS_BUSY   (1<<0) /* Busy (Erase/Program) */
 
#define STATUS_DIS   (1<<3) /* Discharged */
 
#define STATUS_DR   (1<<2) /* Disable Redundancy */
 
#define STATUS_WER   (1<<1) /* Write Protect Error */
 
#define TERASE   40000000 /* 40ms */
 
#define TIMING0   0x04 /* Timing Register 0 */
 
#define TIMING0_F(x)   (((x) << 16) & 0xffff0000) /* Tnvh Clock Cycles */
 
#define TIMING0_R(x)   (((x) << 0) & 0x3f) /* Read Wait States */
 
#define TIMING1   0x08 /* Timing Register 1 */
 
#define TIMING1_E(x)   (((x) << 0) & 0xffffff) /* Tme/Terase/Tre Clock Cycles */
 
#define TIMING2   0x0c /* Timing Register 2 */
 
#define TIMING2_H(x)   (((x) << 16) & 0xff0000) /* Clock Cycles in 100ns */
 
#define TIMING2_P(x)   (((x) << 0) & 0xffff) /* Tprog Clock Cycles */
 
#define TIMING2_T(x)   (((x) << 24) & 0xf000000) /* Clock Cycles in 10ns */
 
#define TME   20000000 /* 20ms */
 
#define TNVH   5000 /* 5us */
 
#define TPROG   40000 /* 40us */
 
#define TRE   40000000 /* 40ms */
 
#define UNLOCK1   0x18 /* Unlock 1 */
 
#define UNLOCK2   0x1c /* Unlock 2 */
 

Functions

 COMMAND_HANDLER (handle_esirisc_flash_mass_erase_command)
 
 COMMAND_HANDLER (handle_esirisc_flash_ref_erase_command)
 
static int esirisc_flash_auto_probe (struct flash_bank *bank)
 
static int esirisc_flash_check_status (struct flash_bank *bank)
 
static int esirisc_flash_clear_status (struct flash_bank *bank)
 
static int esirisc_flash_control (struct flash_bank *bank, uint32_t control)
 
static int esirisc_flash_disable_protect (struct flash_bank *bank)
 
static int esirisc_flash_enable_protect (struct flash_bank *bank)
 
static int esirisc_flash_erase (struct flash_bank *bank, unsigned int first, unsigned int last)
 
static int esirisc_flash_fill_pb (struct flash_bank *bank, const uint8_t *buffer, uint32_t count)
 
static int esirisc_flash_info (struct flash_bank *bank, struct command_invocation *cmd)
 
static int esirisc_flash_init (struct flash_bank *bank)
 
static int esirisc_flash_mass_erase (struct flash_bank *bank)
 
static uint32_t esirisc_flash_num_cycles (struct flash_bank *bank, uint64_t ns)
 
static int esirisc_flash_probe (struct flash_bank *bank)
 
static int esirisc_flash_recall (struct flash_bank *bank)
 
static int esirisc_flash_ref_erase (struct flash_bank *bank)
 
static int esirisc_flash_unlock (struct flash_bank *bank)
 
static int esirisc_flash_wait (struct flash_bank *bank, int ms)
 
static int esirisc_flash_write (struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
 
 FLASH_BANK_COMMAND_HANDLER (esirisc_flash_bank_command)
 

Variables

const struct flash_driver esirisc_flash
 
static const struct command_registration esirisc_flash_command_handlers []
 
static const struct command_registration esirisc_flash_exec_command_handlers []
 

Macro Definition Documentation

◆ ADDRESS

#define ADDRESS   0x20 /* Erase/Program Address */

Definition at line 29 of file esirisc_flash.c.

◆ CONTROL

#define CONTROL   0x00 /* Control Register */

Definition at line 23 of file esirisc_flash.c.

◆ CONTROL_AP

#define CONTROL_AP   (1<<8) /* Auto-Program */

Definition at line 44 of file esirisc_flash.c.

◆ CONTROL_E

#define CONTROL_E   (1<<3) /* Erase */

Definition at line 39 of file esirisc_flash.c.

◆ CONTROL_EP

#define CONTROL_EP   (1<<4) /* Erase Page */

Definition at line 40 of file esirisc_flash.c.

◆ CONTROL_ERC

#define CONTROL_ERC   (1<<6) /* Erase Reference Cell */

Definition at line 42 of file esirisc_flash.c.

◆ CONTROL_P

#define CONTROL_P   (1<<5) /* Program Flash */

Definition at line 41 of file esirisc_flash.c.

◆ CONTROL_R

#define CONTROL_R   (1<<7) /* Recall Trim Code */

Definition at line 43 of file esirisc_flash.c.

◆ CONTROL_SLM

#define CONTROL_SLM   (1<<0) /* Sleep Mode */

Definition at line 37 of file esirisc_flash.c.

◆ CONTROL_TIMEOUT

#define CONTROL_TIMEOUT   5000 /* 5s */

Definition at line 83 of file esirisc_flash.c.

◆ CONTROL_WP

#define CONTROL_WP   (1<<1) /* Register Write Protect */

Definition at line 38 of file esirisc_flash.c.

◆ FLASH_PAGE_SIZE

#define FLASH_PAGE_SIZE   4096

Definition at line 84 of file esirisc_flash.c.

◆ NUM_NS_PER_S

#define NUM_NS_PER_S   1000000000ULL

Definition at line 87 of file esirisc_flash.c.

◆ PB_DATA

#define PB_DATA   0x24 /* Program Buffer Data */

Definition at line 30 of file esirisc_flash.c.

◆ PB_INDEX

#define PB_INDEX   0x28 /* Program Buffer Index */

Definition at line 31 of file esirisc_flash.c.

◆ PB_MAX

#define PB_MAX   32

Definition at line 85 of file esirisc_flash.c.

◆ REDUN_0

#define REDUN_0   0x30 /* Redundant Address 0 */

Definition at line 33 of file esirisc_flash.c.

◆ REDUN_1

#define REDUN_1   0x34 /* Redundant Address 1 */

Definition at line 34 of file esirisc_flash.c.

◆ REDUN_P

#define REDUN_P (   x)    (((x) << 12) & 0x7f000) /* Redundant Page Address */

Definition at line 63 of file esirisc_flash.c.

◆ REDUN_R

#define REDUN_R   (1<<0) /* Used */

Definition at line 62 of file esirisc_flash.c.

◆ STATUS

#define STATUS   0x2c /* Status Register */

Definition at line 32 of file esirisc_flash.c.

◆ STATUS_BO

#define STATUS_BO   (1<<4) /* Brown Out */

Definition at line 59 of file esirisc_flash.c.

◆ STATUS_BUSY

#define STATUS_BUSY   (1<<0) /* Busy (Erase/Program) */

Definition at line 55 of file esirisc_flash.c.

◆ STATUS_DIS

#define STATUS_DIS   (1<<3) /* Discharged */

Definition at line 58 of file esirisc_flash.c.

◆ STATUS_DR

#define STATUS_DR   (1<<2) /* Disable Redundancy */

Definition at line 57 of file esirisc_flash.c.

◆ STATUS_WER

#define STATUS_WER   (1<<1) /* Write Protect Error */

Definition at line 56 of file esirisc_flash.c.

◆ TERASE

#define TERASE   40000000 /* 40ms */

Definition at line 78 of file esirisc_flash.c.

◆ TIMING0

#define TIMING0   0x04 /* Timing Register 0 */

Definition at line 24 of file esirisc_flash.c.

◆ TIMING0_F

#define TIMING0_F (   x)    (((x) << 16) & 0xffff0000) /* Tnvh Clock Cycles */

Definition at line 48 of file esirisc_flash.c.

◆ TIMING0_R

#define TIMING0_R (   x)    (((x) << 0) & 0x3f) /* Read Wait States */

Definition at line 47 of file esirisc_flash.c.

◆ TIMING1

#define TIMING1   0x08 /* Timing Register 1 */

Definition at line 25 of file esirisc_flash.c.

◆ TIMING1_E

#define TIMING1_E (   x)    (((x) << 0) & 0xffffff) /* Tme/Terase/Tre Clock Cycles */

Definition at line 49 of file esirisc_flash.c.

◆ TIMING2

#define TIMING2   0x0c /* Timing Register 2 */

Definition at line 26 of file esirisc_flash.c.

◆ TIMING2_H

#define TIMING2_H (   x)    (((x) << 16) & 0xff0000) /* Clock Cycles in 100ns */

Definition at line 51 of file esirisc_flash.c.

◆ TIMING2_P

#define TIMING2_P (   x)    (((x) << 0) & 0xffff) /* Tprog Clock Cycles */

Definition at line 50 of file esirisc_flash.c.

◆ TIMING2_T

#define TIMING2_T (   x)    (((x) << 24) & 0xf000000) /* Clock Cycles in 10ns */

Definition at line 52 of file esirisc_flash.c.

◆ TME

#define TME   20000000 /* 20ms */

Definition at line 77 of file esirisc_flash.c.

◆ TNVH

#define TNVH   5000 /* 5us */

Definition at line 76 of file esirisc_flash.c.

◆ TPROG

#define TPROG   40000 /* 40us */

Definition at line 80 of file esirisc_flash.c.

◆ TRE

#define TRE   40000000 /* 40ms */

Definition at line 79 of file esirisc_flash.c.

◆ UNLOCK1

#define UNLOCK1   0x18 /* Unlock 1 */

Definition at line 27 of file esirisc_flash.c.

◆ UNLOCK2

#define UNLOCK2   0x1c /* Unlock 2 */

Definition at line 28 of file esirisc_flash.c.

Function Documentation

◆ COMMAND_HANDLER() [1/2]

COMMAND_HANDLER ( handle_esirisc_flash_mass_erase_command  )

◆ COMMAND_HANDLER() [2/2]

COMMAND_HANDLER ( handle_esirisc_flash_ref_erase_command  )

◆ esirisc_flash_auto_probe()

static int esirisc_flash_auto_probe ( struct flash_bank bank)
static

Definition at line 469 of file esirisc_flash.c.

References bank, ERROR_OK, esirisc_flash_probe(), and esirisc_flash_bank::probed.

◆ esirisc_flash_check_status()

static int esirisc_flash_check_status ( struct flash_bank bank)
static

◆ esirisc_flash_clear_status()

static int esirisc_flash_clear_status ( struct flash_bank bank)
static

Definition at line 189 of file esirisc_flash.c.

References bank, esirisc_flash_bank::cfg, ERROR_OK, STATUS, STATUS_WER, and target_write_u32().

Referenced by esirisc_flash_control().

◆ esirisc_flash_control()

◆ esirisc_flash_disable_protect()

◆ esirisc_flash_enable_protect()

◆ esirisc_flash_erase()

static int esirisc_flash_erase ( struct flash_bank bank,
unsigned int  first,
unsigned int  last 
)
static

◆ esirisc_flash_fill_pb()

static int esirisc_flash_fill_pb ( struct flash_bank bank,
const uint8_t *  buffer,
uint32_t  count 
)
static

◆ esirisc_flash_info()

static int esirisc_flash_info ( struct flash_bank bank,
struct command_invocation cmd 
)
static

◆ esirisc_flash_init()

◆ esirisc_flash_mass_erase()

◆ esirisc_flash_num_cycles()

static uint32_t esirisc_flash_num_cycles ( struct flash_bank bank,
uint64_t  ns 
)
static

Definition at line 394 of file esirisc_flash.c.

References bank, esirisc_flash_bank::clock, and NUM_NS_PER_S.

Referenced by esirisc_flash_init().

◆ esirisc_flash_probe()

static int esirisc_flash_probe ( struct flash_bank bank)
static

◆ esirisc_flash_recall()

static int esirisc_flash_recall ( struct flash_bank bank)
static

Definition at line 237 of file esirisc_flash.c.

References bank, CONTROL_R, and esirisc_flash_control().

Referenced by esirisc_flash_init().

◆ esirisc_flash_ref_erase()

static int esirisc_flash_ref_erase ( struct flash_bank bank)
static

◆ esirisc_flash_unlock()

static int esirisc_flash_unlock ( struct flash_bank bank)
static

◆ esirisc_flash_wait()

static int esirisc_flash_wait ( struct flash_bank bank,
int  ms 
)
static

◆ esirisc_flash_write()

static int esirisc_flash_write ( struct flash_bank bank,
const uint8_t *  buffer,
uint32_t  offset,
uint32_t  count 
)
static

◆ FLASH_BANK_COMMAND_HANDLER()

Variable Documentation

◆ esirisc_flash

const struct flash_driver esirisc_flash
Initial value:
= {
.name = "esirisc",
.usage = "flash bank bank_id 'esirisc' base_address size_bytes 0 0 target "
"cfg_address clock_hz wait_states",
.flash_bank_command = esirisc_flash_bank_command,
.auto_probe = esirisc_flash_auto_probe,
.erase_check = default_flash_blank_check,
.free_driver_priv = default_flash_free_driver_priv,
}
static int esirisc_flash_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count)
static int esirisc_flash_info(struct flash_bank *bank, struct command_invocation *cmd)
static int esirisc_flash_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
static int esirisc_flash_probe(struct flash_bank *bank)
static int esirisc_flash_auto_probe(struct flash_bank *bank)
int default_flash_blank_check(struct flash_bank *bank)
Provides default erased-bank check handling.
int default_flash_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
Provides default read implementation for flash memory.
void default_flash_free_driver_priv(struct flash_bank *bank)
Deallocates bank->driver_priv.

Definition at line 513 of file esirisc_flash.c.

◆ esirisc_flash_command_handlers

static const struct command_registration esirisc_flash_command_handlers
static
Initial value:
= {
{
.name = "flash",
.mode = COMMAND_EXEC,
.help = "eSi-TSMC Flash command group",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_EXEC
Definition: command.h:40
static const struct command_registration esirisc_flash_exec_command_handlers[]

Definition at line 1 of file esirisc_flash.c.

Referenced by FLASH_BANK_COMMAND_HANDLER().

◆ esirisc_flash_exec_command_handlers

const struct command_registration esirisc_flash_exec_command_handlers[]
static
Initial value:
= {
{
.name = "mass_erase",
.handler = handle_esirisc_flash_mass_erase_command,
.mode = COMMAND_EXEC,
.help = "erase all pages in data memory",
.usage = "bank_id",
},
{
.name = "ref_erase",
.handler = handle_esirisc_flash_ref_erase_command,
.mode = COMMAND_EXEC,
.help = "erase reference cell (uncommon)",
.usage = "bank_id",
},
}

Definition at line 513 of file esirisc_flash.c.