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

Go to the source code of this file.

Macros

#define AICE_CMD_BATCH_BUFFER_READ   0x60
 
#define AICE_CMD_BATCH_BUFFER_WRITE   0x68
 
#define AICE_CMD_READ_CTRL   0x50
 
#define AICE_CMD_READ_DTR_TO_BUFFER   0x61
 
#define AICE_CMD_SCAN_CHAIN   0x00
 
#define AICE_CMD_T_EXECUTE   0x3E
 
#define AICE_CMD_T_FASTREAD_MEM   0x27
 
#define AICE_CMD_T_FASTWRITE_MEM   0x2F
 
#define AICE_CMD_T_READ_DTR   0x22
 
#define AICE_CMD_T_READ_EDMSR   0x21
 
#define AICE_CMD_T_READ_MEM   0x26
 
#define AICE_CMD_T_READ_MEM_B   0x24
 
#define AICE_CMD_T_READ_MEM_H   0x25
 
#define AICE_CMD_T_READ_MISC   0x20
 
#define AICE_CMD_T_WRITE_DIM   0x2B
 
#define AICE_CMD_T_WRITE_DTR   0x2A
 
#define AICE_CMD_T_WRITE_EDMSR   0x29
 
#define AICE_CMD_T_WRITE_MEM   0x2E
 
#define AICE_CMD_T_WRITE_MEM_B   0x2C
 
#define AICE_CMD_T_WRITE_MEM_H   0x2D
 
#define AICE_CMD_T_WRITE_MISC   0x28
 
#define AICE_CMD_WRITE_CTRL   0x51
 
#define AICE_CMD_WRITE_DTR_FROM_BUFFER   0x69
 
#define AICE_FORMAT_DTHA   (6)
 
#define AICE_FORMAT_DTHB   (2)
 
#define AICE_FORMAT_DTHMA   (8)
 
#define AICE_FORMAT_DTHMB   (4)
 
#define AICE_FORMAT_HTDA   (3)
 
#define AICE_FORMAT_HTDC   (7)
 
#define AICE_FORMAT_HTDMA   (4)
 
#define AICE_FORMAT_HTDMB   (8)
 
#define AICE_FORMAT_HTDMC   (8)
 
#define AICE_FORMAT_HTDMD   (12)
 
#define LINE_BUFFER_SIZE   1024
 

Typedefs

typedef int(* read_mem_func_t) (uint32_t coreid, uint32_t address, uint32_t *data)
 
typedef int(* write_mem_func_t) (uint32_t coreid, uint32_t address, uint32_t data)
 

Functions

static int aice_backup_edm_registers (uint32_t coreid)
 EDM_CTL will be modified by OpenOCD as debugging. More...
 
static int aice_backup_tmp_registers (uint32_t coreid)
 
static int aice_batch_buffer_read (uint8_t buf_index, uint32_t *word, uint32_t num_of_words)
 
static int aice_batch_buffer_write (uint8_t buf_index, const uint8_t *word, uint32_t num_of_words)
 
static int aice_bulk_read_mem (uint32_t coreid, uint32_t addr, uint32_t count, uint8_t *buffer)
 
static int aice_bulk_write_mem (uint32_t coreid, uint32_t addr, uint32_t count, const uint8_t *buffer)
 
static int aice_check_dbger (uint32_t coreid, uint32_t expect_status)
 
static int aice_core_init (uint32_t coreid)
 
static int aice_do_execute (uint8_t target_id)
 
static int aice_edm_init (uint32_t coreid)
 
static int aice_execute_custom_script (const char *script)
 
static int aice_execute_dim (uint32_t coreid, uint32_t *insts, uint8_t n_inst)
 
static int aice_fastread_mem (uint8_t target_id, uint8_t *word, uint32_t num_of_words)
 
static int aice_fastwrite_mem (uint8_t target_id, const uint8_t *word, uint32_t num_of_words)
 
static int aice_get_version_info (void)
 
static int aice_init_edm_registers (uint32_t coreid, bool clear_dex_use_psw)
 
static int aice_issue_reset_hold (uint32_t coreid)
 
static int aice_issue_reset_hold_multi (void)
 
static int aice_issue_srst (uint32_t coreid)
 
static int aice_open_device (struct aice_port_param_s *param)
 
static void aice_pack_htda (uint8_t cmd_code, uint8_t extra_word_length, uint32_t address)
 
static void aice_pack_htdc (uint8_t cmd_code, uint8_t extra_word_length, uint32_t address, uint32_t word, enum aice_target_endian access_endian)
 
static void aice_pack_htdma (uint8_t cmd_code, uint8_t target_id, uint8_t extra_word_length, uint32_t address)
 
static void aice_pack_htdmb (uint8_t cmd_code, uint8_t target_id, uint8_t extra_word_length, uint32_t address)
 
static void aice_pack_htdmc (uint8_t cmd_code, uint8_t target_id, uint8_t extra_word_length, uint32_t address, uint32_t word, enum aice_target_endian access_endian)
 
static void aice_pack_htdmc_multiple_data (uint8_t cmd_code, uint8_t target_id, uint8_t extra_word_length, uint32_t address, uint32_t *word, uint8_t num_of_words, enum aice_target_endian access_endian)
 
static void aice_pack_htdmd (uint8_t cmd_code, uint8_t target_id, uint8_t extra_word_length, uint32_t address, uint32_t word, enum aice_target_endian access_endian)
 
static void aice_pack_htdmd_multiple_data (uint8_t cmd_code, uint8_t target_id, uint8_t extra_word_length, uint32_t address, const uint8_t *word, enum aice_target_endian access_endian)
 
int aice_read_ctrl (uint32_t address, uint32_t *data)
 
static int aice_read_dtr (uint8_t target_id, uint32_t *data)
 
static int aice_read_dtr_to_buffer (uint8_t target_id, uint32_t buffer_idx)
 
static int aice_read_edmsr (uint8_t target_id, uint32_t address, uint32_t *data)
 
static int aice_read_mem (uint8_t target_id, uint32_t address, uint32_t *data)
 
static int aice_read_mem_b (uint8_t target_id, uint32_t address, uint32_t *data)
 
static int aice_read_mem_h (uint8_t target_id, uint32_t address, uint32_t *data)
 
static int aice_read_misc (uint8_t target_id, uint32_t address, uint32_t *data)
 
static int aice_read_reg (uint32_t coreid, uint32_t num, uint32_t *val)
 
static int aice_reset_box (void)
 
static int aice_restore_edm_registers (uint32_t coreid)
 
static int aice_restore_tmp_registers (uint32_t coreid)
 
static int aice_scan_chain (uint32_t *id_codes, uint8_t *num_of_ids)
 
static int aice_switch_to_big_endian (uint32_t *word, uint8_t num_of_words)
 
static void aice_unpack_dtha (uint8_t *cmd_ack_code, uint8_t *extra_word_length, uint32_t *word, enum aice_target_endian access_endian)
 
static void aice_unpack_dtha_multiple_data (uint8_t *cmd_ack_code, uint8_t *extra_word_length, uint32_t *word, uint8_t num_of_words, enum aice_target_endian access_endian)
 
static void aice_unpack_dthb (uint8_t *cmd_ack_code, uint8_t *extra_word_length)
 
static void aice_unpack_dthma (uint8_t *cmd_ack_code, uint8_t *target_id, uint8_t *extra_word_length, uint32_t *word, enum aice_target_endian access_endian)
 
static void aice_unpack_dthma_multiple_data (uint8_t *cmd_ack_code, uint8_t *target_id, uint8_t *extra_word_length, uint8_t *word, enum aice_target_endian access_endian)
 
static void aice_unpack_dthmb (uint8_t *cmd_ack_code, uint8_t *target_id, uint8_t *extra_word_length)
 
static int aice_usb_assert_srst (uint32_t coreid, enum aice_srst_type_s srst)
 
static int aice_usb_bulk_read_mem (uint32_t coreid, uint32_t addr, uint32_t length, uint8_t *buffer)
 
static int aice_usb_bulk_write_mem (uint32_t coreid, uint32_t addr, uint32_t length, const uint8_t *buffer)
 
static int aice_usb_cache_ctl (uint32_t coreid, uint32_t subtype, uint32_t address)
 
static int aice_usb_close (void)
 
static int aice_usb_dcache_inval_all (uint32_t coreid)
 
static int aice_usb_dcache_va_inval (uint32_t coreid, uint32_t address)
 
static int aice_usb_dcache_va_wb (uint32_t coreid, uint32_t address)
 
static int aice_usb_dcache_wb_all (uint32_t coreid)
 
static int aice_usb_execute (uint32_t coreid, uint32_t *instructions, uint32_t instruction_num)
 
static int aice_usb_halt (uint32_t coreid)
 
static int aice_usb_icache_inval_all (uint32_t coreid)
 
static int aice_usb_icache_va_inval (uint32_t coreid, uint32_t address)
 
static int aice_usb_idcode (uint32_t *idcode, uint8_t *num_of_idcode)
 
static int aice_usb_init_cache (uint32_t coreid)
 
static int aice_usb_memory_access (uint32_t coreid, enum nds_memory_access channel)
 
static int aice_usb_memory_mode (uint32_t coreid, enum nds_memory_select mem_select)
 
static int aice_usb_open (struct aice_port_param_s *param)
 
static int aice_usb_packet_append (uint8_t *out_buffer, int out_length, int in_length)
 
static int aice_usb_packet_flush (void)
 
static int aice_usb_profiling (uint32_t coreid, uint32_t interval, uint32_t iteration, uint32_t reg_no, uint32_t *samples, uint32_t *num_samples)
 
static int aice_usb_program_edm (uint32_t coreid, char *command_sequence)
 
static int aice_usb_read (uint8_t *in_buffer, int expected_size)
 
static int aice_usb_read_debug_reg (uint32_t coreid, uint32_t addr, uint32_t *val)
 
static int aice_usb_read_mem_b_bus (uint32_t coreid, uint32_t address, uint32_t *data)
 
static int aice_usb_read_mem_b_dim (uint32_t coreid, uint32_t address, uint32_t *data)
 
static int aice_usb_read_mem_h_bus (uint32_t coreid, uint32_t address, uint32_t *data)
 
static int aice_usb_read_mem_h_dim (uint32_t coreid, uint32_t address, uint32_t *data)
 
static int aice_usb_read_mem_w_bus (uint32_t coreid, uint32_t address, uint32_t *data)
 
static int aice_usb_read_mem_w_dim (uint32_t coreid, uint32_t address, uint32_t *data)
 
static int aice_usb_read_memory_unit (uint32_t coreid, uint32_t addr, uint32_t size, uint32_t count, uint8_t *buffer)
 
static int aice_usb_read_reg (uint32_t coreid, uint32_t num, uint32_t *val)
 
static int aice_usb_read_reg_64 (uint32_t coreid, uint32_t num, uint64_t *val)
 
static int aice_usb_read_tlb (uint32_t coreid, target_addr_t virtual_address, target_addr_t *physical_address)
 
static int aice_usb_reset (void)
 
static int aice_usb_run (uint32_t coreid)
 
static int aice_usb_set_address_dim (uint32_t coreid, uint32_t address)
 
static int aice_usb_set_clock (int set_clock)
 
static int aice_usb_set_command_mode (enum aice_command_mode command_mode)
 
static int aice_usb_set_count_to_check_dbger (uint32_t count_to_check)
 
static int aice_usb_set_custom_restart_script (const char *script)
 
static int aice_usb_set_custom_srst_script (const char *script)
 
static int aice_usb_set_custom_trst_script (const char *script)
 
static int aice_usb_set_data_endian (uint32_t coreid, enum aice_target_endian target_data_endian)
 
static int aice_usb_set_jtag_clock (uint32_t a_clock)
 
static int aice_usb_set_retry_times (uint32_t a_retry_times)
 
static int aice_usb_state (uint32_t coreid, enum aice_target_state_s *state)
 
static int aice_usb_step (uint32_t coreid)
 
static int aice_usb_write (uint8_t *out_buffer, int out_length)
 
static int aice_usb_write_debug_reg (uint32_t coreid, uint32_t addr, const uint32_t val)
 
static int aice_usb_write_mem_b_bus (uint32_t coreid, uint32_t address, uint32_t data)
 
static int aice_usb_write_mem_b_dim (uint32_t coreid, uint32_t address, uint32_t data)
 
static int aice_usb_write_mem_h_bus (uint32_t coreid, uint32_t address, uint32_t data)
 
static int aice_usb_write_mem_h_dim (uint32_t coreid, uint32_t address, uint32_t data)
 
static int aice_usb_write_mem_w_bus (uint32_t coreid, uint32_t address, uint32_t data)
 
static int aice_usb_write_mem_w_dim (uint32_t coreid, uint32_t address, uint32_t data)
 
static int aice_usb_write_memory_unit (uint32_t coreid, uint32_t addr, uint32_t size, uint32_t count, const uint8_t *buffer)
 
static int aice_usb_write_reg (uint32_t coreid, uint32_t num, uint32_t val)
 
static int aice_usb_write_reg_64 (uint32_t coreid, uint32_t num, uint64_t val)
 
int aice_write_ctrl (uint32_t address, uint32_t data)
 
static int aice_write_dim (uint8_t target_id, uint32_t *word, uint8_t num_of_words)
 
static int aice_write_dtr (uint8_t target_id, uint32_t data)
 
static int aice_write_dtr_from_buffer (uint8_t target_id, uint32_t buffer_idx)
 
static int aice_write_edmsr (uint8_t target_id, uint32_t address, uint32_t data)
 
static int aice_write_mem (uint8_t target_id, uint32_t address, uint32_t data)
 
static int aice_write_mem_b (uint8_t target_id, uint32_t address, uint32_t data)
 
static int aice_write_mem_h (uint8_t target_id, uint32_t address, uint32_t data)
 
static int aice_write_misc (uint8_t target_id, uint32_t address, uint32_t data)
 
static int aice_write_reg (uint32_t coreid, uint32_t num, uint32_t val)
 
static int check_privilege (uint32_t coreid, uint32_t dbger_value)
 
static int check_suppressed_exception (uint32_t coreid, uint32_t dbger_value)
 
static int fill_profiling_batch_commands (uint32_t coreid, uint32_t reg_no)
 
static bool is_v2_edm (uint32_t coreid)
 
static int usb_bulk_read_ex (struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout)
 
static int usb_bulk_with_retries (int(*f)(struct libusb_device_handle *, int, char *, int, int, int *), struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
 
static int usb_bulk_write_ex (struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout)
 
static int wrap_usb_bulk_write (struct libusb_device_handle *dev, int ep, char *buff, int size, int timeout, int *transferred)
 

Variables

static enum aice_command_mode aice_command_mode
 
static uint32_t aice_count_to_check_dbger = 30
 
static struct aice_usb_handler_s aice_handler
 
static int aice_max_retry_times = 50
 
struct aice_port_api_s aice_usb_api
 
static struct aice_nds32_info core_info [AICE_MAX_NUM_CORE]
 
static char * custom_restart_script
 
static char * custom_srst_script
 
static char * custom_trst_script
 
static enum aice_target_endian data_endian
 
static uint32_t jtag_clock
 
static uint8_t total_num_of_core
 
static uint8_t usb_in_buffer [AICE_IN_BUFFER_SIZE]
 
static uint8_t usb_in_packets_buffer [AICE_IN_PACKETS_BUFFER_SIZE]
 
static uint32_t usb_in_packets_buffer_length
 
static uint8_t usb_out_buffer [AICE_OUT_BUFFER_SIZE]
 
static uint8_t usb_out_packets_buffer [AICE_OUT_PACKETS_BUFFER_SIZE]
 
static uint32_t usb_out_packets_buffer_length
 

Macro Definition Documentation

◆ AICE_CMD_BATCH_BUFFER_READ

#define AICE_CMD_BATCH_BUFFER_READ   0x60

Definition at line 64 of file aice_usb.c.

◆ AICE_CMD_BATCH_BUFFER_WRITE

#define AICE_CMD_BATCH_BUFFER_WRITE   0x68

Definition at line 66 of file aice_usb.c.

◆ AICE_CMD_READ_CTRL

#define AICE_CMD_READ_CTRL   0x50

Definition at line 62 of file aice_usb.c.

◆ AICE_CMD_READ_DTR_TO_BUFFER

#define AICE_CMD_READ_DTR_TO_BUFFER   0x61

Definition at line 65 of file aice_usb.c.

◆ AICE_CMD_SCAN_CHAIN

#define AICE_CMD_SCAN_CHAIN   0x00

Definition at line 45 of file aice_usb.c.

◆ AICE_CMD_T_EXECUTE

#define AICE_CMD_T_EXECUTE   0x3E

Definition at line 61 of file aice_usb.c.

◆ AICE_CMD_T_FASTREAD_MEM

#define AICE_CMD_T_FASTREAD_MEM   0x27

Definition at line 52 of file aice_usb.c.

◆ AICE_CMD_T_FASTWRITE_MEM

#define AICE_CMD_T_FASTWRITE_MEM   0x2F

Definition at line 60 of file aice_usb.c.

◆ AICE_CMD_T_READ_DTR

#define AICE_CMD_T_READ_DTR   0x22

Definition at line 48 of file aice_usb.c.

◆ AICE_CMD_T_READ_EDMSR

#define AICE_CMD_T_READ_EDMSR   0x21

Definition at line 47 of file aice_usb.c.

◆ AICE_CMD_T_READ_MEM

#define AICE_CMD_T_READ_MEM   0x26

Definition at line 51 of file aice_usb.c.

◆ AICE_CMD_T_READ_MEM_B

#define AICE_CMD_T_READ_MEM_B   0x24

Definition at line 49 of file aice_usb.c.

◆ AICE_CMD_T_READ_MEM_H

#define AICE_CMD_T_READ_MEM_H   0x25

Definition at line 50 of file aice_usb.c.

◆ AICE_CMD_T_READ_MISC

#define AICE_CMD_T_READ_MISC   0x20

Definition at line 46 of file aice_usb.c.

◆ AICE_CMD_T_WRITE_DIM

#define AICE_CMD_T_WRITE_DIM   0x2B

Definition at line 56 of file aice_usb.c.

◆ AICE_CMD_T_WRITE_DTR

#define AICE_CMD_T_WRITE_DTR   0x2A

Definition at line 55 of file aice_usb.c.

◆ AICE_CMD_T_WRITE_EDMSR

#define AICE_CMD_T_WRITE_EDMSR   0x29

Definition at line 54 of file aice_usb.c.

◆ AICE_CMD_T_WRITE_MEM

#define AICE_CMD_T_WRITE_MEM   0x2E

Definition at line 59 of file aice_usb.c.

◆ AICE_CMD_T_WRITE_MEM_B

#define AICE_CMD_T_WRITE_MEM_B   0x2C

Definition at line 57 of file aice_usb.c.

◆ AICE_CMD_T_WRITE_MEM_H

#define AICE_CMD_T_WRITE_MEM_H   0x2D

Definition at line 58 of file aice_usb.c.

◆ AICE_CMD_T_WRITE_MISC

#define AICE_CMD_T_WRITE_MISC   0x28

Definition at line 53 of file aice_usb.c.

◆ AICE_CMD_WRITE_CTRL

#define AICE_CMD_WRITE_CTRL   0x51

Definition at line 63 of file aice_usb.c.

◆ AICE_CMD_WRITE_DTR_FROM_BUFFER

#define AICE_CMD_WRITE_DTR_FROM_BUFFER   0x69

Definition at line 67 of file aice_usb.c.

◆ AICE_FORMAT_DTHA

#define AICE_FORMAT_DTHA   (6)

Definition at line 39 of file aice_usb.c.

◆ AICE_FORMAT_DTHB

#define AICE_FORMAT_DTHB   (2)

Definition at line 40 of file aice_usb.c.

◆ AICE_FORMAT_DTHMA

#define AICE_FORMAT_DTHMA   (8)

Definition at line 41 of file aice_usb.c.

◆ AICE_FORMAT_DTHMB

#define AICE_FORMAT_DTHMB   (4)

Definition at line 42 of file aice_usb.c.

◆ AICE_FORMAT_HTDA

#define AICE_FORMAT_HTDA   (3)

Definition at line 33 of file aice_usb.c.

◆ AICE_FORMAT_HTDC

#define AICE_FORMAT_HTDC   (7)

Definition at line 34 of file aice_usb.c.

◆ AICE_FORMAT_HTDMA

#define AICE_FORMAT_HTDMA   (4)

Definition at line 35 of file aice_usb.c.

◆ AICE_FORMAT_HTDMB

#define AICE_FORMAT_HTDMB   (8)

Definition at line 36 of file aice_usb.c.

◆ AICE_FORMAT_HTDMC

#define AICE_FORMAT_HTDMC   (8)

Definition at line 37 of file aice_usb.c.

◆ AICE_FORMAT_HTDMD

#define AICE_FORMAT_HTDMD   (12)

Definition at line 38 of file aice_usb.c.

◆ LINE_BUFFER_SIZE

#define LINE_BUFFER_SIZE   1024

Definition at line 2193 of file aice_usb.c.

Typedef Documentation

◆ read_mem_func_t

typedef int(* read_mem_func_t) (uint32_t coreid, uint32_t address, uint32_t *data)

Definition at line 1749 of file aice_usb.c.

◆ write_mem_func_t

typedef int(* write_mem_func_t) (uint32_t coreid, uint32_t address, uint32_t data)

Definition at line 1750 of file aice_usb.c.

Function Documentation

◆ aice_backup_edm_registers()

static int aice_backup_edm_registers ( uint32_t  coreid)
static

EDM_CTL will be modified by OpenOCD as debugging.

OpenOCD has the responsibility to keep EDM_CTL untouched after debugging.

There are two scenarios to consider:

  1. single step/running as debugging (running under debug session)
  2. detached from gdb (exit debug session)

So, we need to bakcup EDM_CTL before halted and restore it after running. The difference of these two scenarios is EDM_CTL.DEH_SEL is on for scenario 1, and off for scenario 2.

Definition at line 2376 of file aice_usb.c.

References aice_read_edmsr(), core_info, aice_nds32_info::dex_use_psw_on, LOG_DEBUG, and NDS_EDM_SR_EDM_CTL.

Referenced by aice_usb_halt(), and aice_usb_state().

◆ aice_backup_tmp_registers()

◆ aice_batch_buffer_read()

static int aice_batch_buffer_read ( uint8_t  buf_index,
uint32_t *  word,
uint32_t  num_of_words 
)
static

◆ aice_batch_buffer_write()

int aice_batch_buffer_write ( uint8_t  buf_index,
const uint8_t *  word,
uint32_t  num_of_words 
)
static

◆ aice_bulk_read_mem()

static int aice_bulk_read_mem ( uint32_t  coreid,
uint32_t  addr,
uint32_t  count,
uint8_t *  buffer 
)
static

set address

Definition at line 3256 of file aice_usb.c.

References addr, aice_fastread_mem(), aice_write_misc(), buffer, count, ERROR_FAIL, ERROR_OK, and NDS_EDM_MISC_SBAR.

Referenced by aice_usb_bulk_read_mem().

◆ aice_bulk_write_mem()

static int aice_bulk_write_mem ( uint32_t  coreid,
uint32_t  addr,
uint32_t  count,
const uint8_t *  buffer 
)
static

set address

Definition at line 3281 of file aice_usb.c.

References addr, aice_fastwrite_mem(), aice_write_misc(), buffer, count, ERROR_FAIL, ERROR_OK, and NDS_EDM_MISC_SBAR.

Referenced by aice_usb_bulk_write_mem().

◆ aice_check_dbger()

static int aice_check_dbger ( uint32_t  coreid,
uint32_t  expect_status 
)
static

◆ aice_core_init()

static int aice_core_init ( uint32_t  coreid)
static

◆ aice_do_execute()

◆ aice_edm_init()

◆ aice_execute_custom_script()

◆ aice_execute_dim()

◆ aice_fastread_mem()

◆ aice_fastwrite_mem()

◆ aice_get_version_info()

static int aice_get_version_info ( void  )
static

◆ aice_init_edm_registers()

static int aice_init_edm_registers ( uint32_t  coreid,
bool  clear_dex_use_psw 
)
static

◆ aice_issue_reset_hold()

◆ aice_issue_reset_hold_multi()

◆ aice_issue_srst()

◆ aice_open_device()

static int aice_open_device ( struct aice_port_param_s param)
static

◆ aice_pack_htda()

static void aice_pack_htda ( uint8_t  cmd_code,
uint8_t  extra_word_length,
uint32_t  address 
)
static

Definition at line 71 of file aice_usb.c.

References usb_out_buffer.

Referenced by aice_read_ctrl(), and aice_scan_chain().

◆ aice_pack_htdc()

static void aice_pack_htdc ( uint8_t  cmd_code,
uint8_t  extra_word_length,
uint32_t  address,
uint32_t  word,
enum aice_target_endian  access_endian 
)
static

Definition at line 79 of file aice_usb.c.

References AICE_BIG_ENDIAN, and usb_out_buffer.

Referenced by aice_write_ctrl().

◆ aice_pack_htdma()

static void aice_pack_htdma ( uint8_t  cmd_code,
uint8_t  target_id,
uint8_t  extra_word_length,
uint32_t  address 
)
static

◆ aice_pack_htdmb()

static void aice_pack_htdmb ( uint8_t  cmd_code,
uint8_t  target_id,
uint8_t  extra_word_length,
uint32_t  address 
)
static

Definition at line 107 of file aice_usb.c.

References usb_out_buffer.

Referenced by aice_fastread_mem(), aice_read_mem(), aice_read_mem_b(), and aice_read_mem_h().

◆ aice_pack_htdmc()

static void aice_pack_htdmc ( uint8_t  cmd_code,
uint8_t  target_id,
uint8_t  extra_word_length,
uint32_t  address,
uint32_t  word,
enum aice_target_endian  access_endian 
)
static

◆ aice_pack_htdmc_multiple_data()

static void aice_pack_htdmc_multiple_data ( uint8_t  cmd_code,
uint8_t  target_id,
uint8_t  extra_word_length,
uint32_t  address,
uint32_t *  word,
uint8_t  num_of_words,
enum aice_target_endian  access_endian 
)
static

Definition at line 141 of file aice_usb.c.

References AICE_BIG_ENDIAN, and usb_out_buffer.

Referenced by aice_write_dim().

◆ aice_pack_htdmd()

static void aice_pack_htdmd ( uint8_t  cmd_code,
uint8_t  target_id,
uint8_t  extra_word_length,
uint32_t  address,
uint32_t  word,
enum aice_target_endian  access_endian 
)
static

Definition at line 166 of file aice_usb.c.

References AICE_BIG_ENDIAN, and usb_out_buffer.

Referenced by aice_write_mem(), aice_write_mem_b(), and aice_write_mem_h().

◆ aice_pack_htdmd_multiple_data()

static void aice_pack_htdmd_multiple_data ( uint8_t  cmd_code,
uint8_t  target_id,
uint8_t  extra_word_length,
uint32_t  address,
const uint8_t *  word,
enum aice_target_endian  access_endian 
)
static

Definition at line 191 of file aice_usb.c.

References AICE_BIG_ENDIAN, and usb_out_buffer.

Referenced by aice_fastwrite_mem().

◆ aice_read_ctrl()

◆ aice_read_dtr()

◆ aice_read_dtr_to_buffer()

◆ aice_read_edmsr()

◆ aice_read_mem()

◆ aice_read_mem_b()

◆ aice_read_mem_h()

◆ aice_read_misc()

◆ aice_read_reg()

◆ aice_reset_box()

◆ aice_restore_edm_registers()

static int aice_restore_edm_registers ( uint32_t  coreid)
static

Definition at line 2399 of file aice_usb.c.

References aice_write_edmsr(), core_info, LOG_DEBUG, and NDS_EDM_SR_EDM_CTL.

Referenced by aice_issue_srst(), and aice_usb_run().

◆ aice_restore_tmp_registers()

static int aice_restore_tmp_registers ( uint32_t  coreid)
static

◆ aice_scan_chain()

◆ aice_switch_to_big_endian()

static int aice_switch_to_big_endian ( uint32_t *  word,
uint8_t  num_of_words 
)
static

Definition at line 1091 of file aice_usb.c.

References ERROR_OK.

Referenced by aice_write_dim().

◆ aice_unpack_dtha()

static void aice_unpack_dtha ( uint8_t *  cmd_ack_code,
uint8_t *  extra_word_length,
uint32_t *  word,
enum aice_target_endian  access_endian 
)
static

Definition at line 223 of file aice_usb.c.

References AICE_BIG_ENDIAN, and usb_in_buffer.

Referenced by aice_read_ctrl().

◆ aice_unpack_dtha_multiple_data()

static void aice_unpack_dtha_multiple_data ( uint8_t *  cmd_ack_code,
uint8_t *  extra_word_length,
uint32_t *  word,
uint8_t  num_of_words,
enum aice_target_endian  access_endian 
)
static

Definition at line 242 of file aice_usb.c.

References AICE_BIG_ENDIAN, and usb_in_buffer.

Referenced by aice_scan_chain().

◆ aice_unpack_dthb()

static void aice_unpack_dthb ( uint8_t *  cmd_ack_code,
uint8_t *  extra_word_length 
)
static

Definition at line 265 of file aice_usb.c.

References usb_in_buffer.

Referenced by aice_write_ctrl().

◆ aice_unpack_dthma()

static void aice_unpack_dthma ( uint8_t *  cmd_ack_code,
uint8_t *  target_id,
uint8_t *  extra_word_length,
uint32_t *  word,
enum aice_target_endian  access_endian 
)
static

◆ aice_unpack_dthma_multiple_data()

static void aice_unpack_dthma_multiple_data ( uint8_t *  cmd_ack_code,
uint8_t *  target_id,
uint8_t *  extra_word_length,
uint8_t *  word,
enum aice_target_endian  access_endian 
)
static

Definition at line 291 of file aice_usb.c.

References AICE_BIG_ENDIAN, and usb_in_buffer.

Referenced by aice_batch_buffer_read(), and aice_fastread_mem().

◆ aice_unpack_dthmb()

static void aice_unpack_dthmb ( uint8_t *  cmd_ack_code,
uint8_t *  target_id,
uint8_t *  extra_word_length 
)
static

◆ aice_usb_assert_srst()

◆ aice_usb_bulk_read_mem()

static int aice_usb_bulk_read_mem ( uint32_t  coreid,
uint32_t  addr,
uint32_t  length,
uint8_t *  buffer 
)
static

◆ aice_usb_bulk_write_mem()

static int aice_usb_bulk_write_mem ( uint32_t  coreid,
uint32_t  addr,
uint32_t  length,
const uint8_t *  buffer 
)
static

◆ aice_usb_cache_ctl()

◆ aice_usb_close()

static int aice_usb_close ( void  )
static

◆ aice_usb_dcache_inval_all()

◆ aice_usb_dcache_va_inval()

static int aice_usb_dcache_va_inval ( uint32_t  coreid,
uint32_t  address 
)
static

◆ aice_usb_dcache_va_wb()

static int aice_usb_dcache_va_wb ( uint32_t  coreid,
uint32_t  address 
)
static

◆ aice_usb_dcache_wb_all()

◆ aice_usb_execute()

static int aice_usb_execute ( uint32_t  coreid,
uint32_t *  instructions,
uint32_t  instruction_num 
)
static

fill DIM

clear DBGER.DPED

execute DIM

check DBGER.DPED

Definition at line 3777 of file aice_usb.c.

References aice_check_dbger(), aice_do_execute(), aice_execute_dim(), aice_write_dim(), aice_write_misc(), BEQ_MINUS_12, ERROR_FAIL, ERROR_OK, instructions, LOG_ERROR, NDS_DBGER_DPED, NDS_EDM_MISC_DBGER, and NOP.

◆ aice_usb_halt()

static int aice_usb_halt ( uint32_t  coreid)
static

backup EDM registers

init EDM for host debugging

no need to clear dex_use_psw, because dbgi will clear it

Clear EDM_CTL.DBGIM & EDM_CTL.DBGACKM

debug 'debug mode'. use force_debug to issue dbgi

Issue DBGI normally

set EDM_CTL.DBGIM & EDM_CTL.DBGACKM after halt

Definition at line 2560 of file aice_usb.c.

References aice_backup_edm_registers(), aice_backup_tmp_registers(), aice_check_dbger(), aice_init_edm_registers(), aice_read_edmsr(), aice_read_misc(), aice_read_reg(), AICE_TARGET_HALTED, aice_write_edmsr(), aice_write_misc(), aice_write_reg(), core_info, aice_nds32_info::core_state, aice_nds32_info::debug_under_dex_on, ERROR_FAIL, ERROR_OK, IR0, is_v2_edm(), LOG_DEBUG, LOG_ERROR, NDS_DBGER_AT_MAX, NDS_DBGER_DEX, NDS_EDM_MISC_ACC_CTL, NDS_EDM_MISC_DBGER, NDS_EDM_MISC_EDM_CMDR, and NDS_EDM_SR_EDM_CTL.

Referenced by aice_issue_reset_hold(), and aice_usb_state().

◆ aice_usb_icache_inval_all()

◆ aice_usb_icache_va_inval()

static int aice_usb_icache_va_inval ( uint32_t  coreid,
uint32_t  address 
)
static

◆ aice_usb_idcode()

static int aice_usb_idcode ( uint32_t *  idcode,
uint8_t *  num_of_idcode 
)
static

◆ aice_usb_init_cache()

◆ aice_usb_memory_access()

static int aice_usb_memory_access ( uint32_t  coreid,
enum nds_memory_access  channel 
)
static

Definition at line 3375 of file aice_usb.c.

References aice_nds32_info::access_channel, core_info, ERROR_OK, and LOG_DEBUG.

◆ aice_usb_memory_mode()

static int aice_usb_memory_mode ( uint32_t  coreid,
enum nds_memory_select  mem_select 
)
static

◆ aice_usb_open()

◆ aice_usb_packet_append()

◆ aice_usb_packet_flush()

◆ aice_usb_profiling()

static int aice_usb_profiling ( uint32_t  coreid,
uint32_t  interval,
uint32_t  iteration,
uint32_t  reg_no,
uint32_t *  samples,
uint32_t *  num_samples 
)
static

Definition at line 3932 of file aice_usb.c.

◆ aice_usb_program_edm()

static int aice_usb_program_edm ( uint32_t  coreid,
char *  command_sequence 
)
static

◆ aice_usb_read()

◆ aice_usb_read_debug_reg()

static int aice_usb_read_debug_reg ( uint32_t  coreid,
uint32_t  addr,
uint32_t *  val 
)
static

◆ aice_usb_read_mem_b_bus()

static int aice_usb_read_mem_b_bus ( uint32_t  coreid,
uint32_t  address,
uint32_t *  data 
)
static

Definition at line 2997 of file aice_usb.c.

References aice_read_mem_b().

Referenced by aice_usb_read_memory_unit().

◆ aice_usb_read_mem_b_dim()

static int aice_usb_read_mem_b_dim ( uint32_t  coreid,
uint32_t  address,
uint32_t *  data 
)
static

◆ aice_usb_read_mem_h_bus()

static int aice_usb_read_mem_h_bus ( uint32_t  coreid,
uint32_t  address,
uint32_t *  data 
)
static

Definition at line 3002 of file aice_usb.c.

References aice_read_mem_h().

Referenced by aice_usb_read_memory_unit().

◆ aice_usb_read_mem_h_dim()

static int aice_usb_read_mem_h_dim ( uint32_t  coreid,
uint32_t  address,
uint32_t *  data 
)
static

◆ aice_usb_read_mem_w_bus()

static int aice_usb_read_mem_w_bus ( uint32_t  coreid,
uint32_t  address,
uint32_t *  data 
)
static

Definition at line 3007 of file aice_usb.c.

References aice_read_mem().

Referenced by aice_usb_read_memory_unit().

◆ aice_usb_read_mem_w_dim()

static int aice_usb_read_mem_w_dim ( uint32_t  coreid,
uint32_t  address,
uint32_t *  data 
)
static

◆ aice_usb_read_memory_unit()

static int aice_usb_read_memory_unit ( uint32_t  coreid,
uint32_t  addr,
uint32_t  size,
uint32_t  count,
uint8_t *  buffer 
)
static

◆ aice_usb_read_reg()

static int aice_usb_read_reg ( uint32_t  coreid,
uint32_t  num,
uint32_t *  val 
)
static

◆ aice_usb_read_reg_64()

static int aice_usb_read_reg_64 ( uint32_t  coreid,
uint32_t  num,
uint64_t *  val 
)
static

◆ aice_usb_read_tlb()

static int aice_usb_read_tlb ( uint32_t  coreid,
target_addr_t  virtual_address,
target_addr_t physical_address 
)
static

◆ aice_usb_reset()

◆ aice_usb_run()

static int aice_usb_run ( uint32_t  coreid)
static

restore EDM registers

OpenOCD should restore EDM_CTL before to exit debug state. Otherwise, following instruction will read wrong EDM_CTL value.

pc -> mfsr $p0, EDM_CTL (single step) slli $p0, $p0, 1 slri $p0, $p0, 31

execute instructions in DIM

Definition at line 2897 of file aice_usb.c.

References aice_execute_dim(), aice_read_misc(), aice_restore_edm_registers(), aice_restore_tmp_registers(), AICE_TARGET_RUNNING, aice_write_misc(), core_info, aice_nds32_info::core_state, ERROR_FAIL, ERROR_OK, instructions, IRET, LOG_DEBUG, LOG_WARNING, NDS_DBGER_CLEAR_ALL, NDS_DBGER_DEX, NDS_EDM_MISC_DBGER, and NOP.

Referenced by aice_usb_step().

◆ aice_usb_set_address_dim()

static int aice_usb_set_address_dim ( uint32_t  coreid,
uint32_t  address 
)
static

◆ aice_usb_set_clock()

static int aice_usb_set_clock ( int  set_clock)
static

◆ aice_usb_set_command_mode()

static int aice_usb_set_command_mode ( enum aice_command_mode  command_mode)
static

◆ aice_usb_set_count_to_check_dbger()

static int aice_usb_set_count_to_check_dbger ( uint32_t  count_to_check)
static

Definition at line 3852 of file aice_usb.c.

References aice_count_to_check_dbger, and ERROR_OK.

◆ aice_usb_set_custom_restart_script()

static int aice_usb_set_custom_restart_script ( const char *  script)
static

Definition at line 3845 of file aice_usb.c.

References custom_restart_script, and ERROR_OK.

◆ aice_usb_set_custom_srst_script()

static int aice_usb_set_custom_srst_script ( const char *  script)
static

Definition at line 3831 of file aice_usb.c.

References custom_srst_script, and ERROR_OK.

◆ aice_usb_set_custom_trst_script()

static int aice_usb_set_custom_trst_script ( const char *  script)
static

Definition at line 3838 of file aice_usb.c.

References custom_trst_script, and ERROR_OK.

◆ aice_usb_set_data_endian()

static int aice_usb_set_data_endian ( uint32_t  coreid,
enum aice_target_endian  target_data_endian 
)
static

Definition at line 3859 of file aice_usb.c.

References data_endian, and ERROR_OK.

◆ aice_usb_set_jtag_clock()

static int aice_usb_set_jtag_clock ( uint32_t  a_clock)
static

Definition at line 2513 of file aice_usb.c.

References aice_usb_set_clock(), ERROR_FAIL, ERROR_OK, jtag_clock, and LOG_ERROR.

◆ aice_usb_set_retry_times()

static int aice_usb_set_retry_times ( uint32_t  a_retry_times)
static

Definition at line 3696 of file aice_usb.c.

References aice_max_retry_times, and ERROR_OK.

◆ aice_usb_state()

◆ aice_usb_step()

static int aice_usb_step ( uint32_t  coreid)
static

◆ aice_usb_write()

◆ aice_usb_write_debug_reg()

static int aice_usb_write_debug_reg ( uint32_t  coreid,
uint32_t  addr,
const uint32_t  val 
)
static

◆ aice_usb_write_mem_b_bus()

static int aice_usb_write_mem_b_bus ( uint32_t  coreid,
uint32_t  address,
uint32_t  data 
)
static

Definition at line 3135 of file aice_usb.c.

References aice_write_mem_b().

Referenced by aice_usb_write_memory_unit().

◆ aice_usb_write_mem_b_dim()

static int aice_usb_write_mem_b_dim ( uint32_t  coreid,
uint32_t  address,
uint32_t  data 
)
static

◆ aice_usb_write_mem_h_bus()

static int aice_usb_write_mem_h_bus ( uint32_t  coreid,
uint32_t  address,
uint32_t  data 
)
static

Definition at line 3140 of file aice_usb.c.

References aice_write_mem_h().

Referenced by aice_usb_write_memory_unit().

◆ aice_usb_write_mem_h_dim()

static int aice_usb_write_mem_h_dim ( uint32_t  coreid,
uint32_t  address,
uint32_t  data 
)
static

◆ aice_usb_write_mem_w_bus()

static int aice_usb_write_mem_w_bus ( uint32_t  coreid,
uint32_t  address,
uint32_t  data 
)
static

Definition at line 3145 of file aice_usb.c.

References aice_write_mem().

Referenced by aice_usb_write_memory_unit().

◆ aice_usb_write_mem_w_dim()

static int aice_usb_write_mem_w_dim ( uint32_t  coreid,
uint32_t  address,
uint32_t  data 
)
static

◆ aice_usb_write_memory_unit()

static int aice_usb_write_memory_unit ( uint32_t  coreid,
uint32_t  addr,
uint32_t  size,
uint32_t  count,
const uint8_t *  buffer 
)
static

◆ aice_usb_write_reg()

static int aice_usb_write_reg ( uint32_t  coreid,
uint32_t  num,
uint32_t  val 
)
static

◆ aice_usb_write_reg_64()

static int aice_usb_write_reg_64 ( uint32_t  coreid,
uint32_t  num,
uint64_t  val 
)
static

◆ aice_write_ctrl()

◆ aice_write_dim()

◆ aice_write_dtr()

◆ aice_write_dtr_from_buffer()

◆ aice_write_edmsr()

◆ aice_write_mem()

◆ aice_write_mem_b()

◆ aice_write_mem_h()

◆ aice_write_misc()

◆ aice_write_reg()

◆ check_privilege()

static int check_privilege ( uint32_t  coreid,
uint32_t  dbger_value 
)
static

◆ check_suppressed_exception()

static int check_suppressed_exception ( uint32_t  coreid,
uint32_t  dbger_value 
)
static

Definition at line 1763 of file aice_usb.c.

References aice_read_reg(), aice_write_reg(), ERROR_OK, IR4, IR6, LOG_ERROR, LOG_INFO, and NDS_DBGER_ALL_SUPRS_EX.

Referenced by aice_check_dbger().

◆ fill_profiling_batch_commands()

◆ is_v2_edm()

static bool is_v2_edm ( uint32_t  coreid)
static

Definition at line 2338 of file aice_usb.c.

References core_info.

Referenced by aice_usb_halt(), and aice_usb_step().

◆ usb_bulk_read_ex()

static int usb_bulk_read_ex ( struct libusb_device_handle *  dev,
int  ep,
char *  bytes,
int  size,
int  timeout 
)
inlinestatic

Definition at line 382 of file aice_usb.c.

References jtag_libusb_bulk_read(), size, and usb_bulk_with_retries().

Referenced by aice_usb_read().

◆ usb_bulk_with_retries()

static int usb_bulk_with_retries ( int(*)(struct libusb_device_handle *, int, char *, int, int, int *)  f,
struct libusb_device_handle *  dev,
int  ep,
char *  bytes,
int  size,
int  timeout,
int *  transferred 
)
static

Definition at line 341 of file aice_usb.c.

References count, ERROR_OK, ERROR_TIMEOUT_REACHED, and size.

Referenced by usb_bulk_read_ex(), and usb_bulk_write_ex().

◆ usb_bulk_write_ex()

static int usb_bulk_write_ex ( struct libusb_device_handle *  dev,
int  ep,
char *  bytes,
int  size,
int  timeout 
)
inlinestatic

Definition at line 372 of file aice_usb.c.

References size, usb_bulk_with_retries(), and wrap_usb_bulk_write().

Referenced by aice_usb_write().

◆ wrap_usb_bulk_write()

static int wrap_usb_bulk_write ( struct libusb_device_handle *  dev,
int  ep,
char *  buff,
int  size,
int  timeout,
int *  transferred 
)
static

Definition at line 362 of file aice_usb.c.

References jtag_libusb_bulk_write(), and size.

Referenced by usb_bulk_write_ex().

Variable Documentation

◆ aice_command_mode

Definition at line 425 of file aice_usb.c.

◆ aice_count_to_check_dbger

uint32_t aice_count_to_check_dbger = 30
static

Definition at line 1758 of file aice_usb.c.

Referenced by aice_check_dbger(), and aice_usb_set_count_to_check_dbger().

◆ aice_handler

struct aice_usb_handler_s aice_handler
static

Definition at line 25 of file aice_usb.c.

Referenced by aice_usb_close(), aice_usb_open(), aice_usb_read(), and aice_usb_write().

◆ aice_max_retry_times

◆ aice_usb_api

struct aice_port_api_s aice_usb_api

Definition at line 3932 of file aice_usb.c.

◆ core_info

◆ custom_restart_script

char* custom_restart_script
static

◆ custom_srst_script

char* custom_srst_script
static

Definition at line 1755 of file aice_usb.c.

Referenced by aice_issue_srst(), aice_usb_close(), and aice_usb_set_custom_srst_script().

◆ custom_trst_script

char* custom_trst_script
static

Definition at line 1756 of file aice_usb.c.

Referenced by aice_usb_close(), aice_usb_reset(), and aice_usb_set_custom_trst_script().

◆ data_endian

◆ jtag_clock

uint32_t jtag_clock
static

Definition at line 25 of file aice_usb.c.

Referenced by aice_usb_reset(), and aice_usb_set_jtag_clock().

◆ total_num_of_core

uint8_t total_num_of_core
static

Definition at line 1753 of file aice_usb.c.

Referenced by aice_issue_reset_hold_multi(), aice_usb_assert_srst(), and aice_usb_idcode().

◆ usb_in_buffer

◆ usb_in_packets_buffer

uint8_t usb_in_packets_buffer[AICE_IN_PACKETS_BUFFER_SIZE]
static

Definition at line 423 of file aice_usb.c.

Referenced by aice_usb_packet_flush().

◆ usb_in_packets_buffer_length

uint32_t usb_in_packets_buffer_length
static

◆ usb_out_buffer

◆ usb_out_packets_buffer

uint8_t usb_out_packets_buffer[AICE_OUT_PACKETS_BUFFER_SIZE]
static

◆ usb_out_packets_buffer_length

uint32_t usb_out_packets_buffer_length
static