OpenOCD
|
Go to the source code of this file.
Data Structures | |
struct | ch347_cmd |
struct | ch347_info |
struct | ch347_scan |
struct | ch347_swd_context |
struct | ch347_swd_io |
Enumerations | |
enum | ch347_variant { CH347T = 0 , CH347F = 1 , OTHER_PRODUCT_ID = 2 } |
enum | pack_size { UNSET = -1 , STANDARD_PACK = 0 , LARGER_PACK = 1 } |
Functions | |
static int | ch347_activity_led_set (int led_state) |
Turn the activity LED on or off. More... | |
static int | ch347_adapter_init (uint8_t clock_index, bool *supports_larger_pack_mode) |
Sends the CH347_CMD_JTAG_INIT (D0) command to get the JTAG interface initialized with the speed index or asking with special clock index 9 for the LARGER_PACK mode support. More... | |
static int | ch347_adapter_set_speed (uint8_t clock_index) |
Sends the CH347_CMD_JTAG_INIT (D0) command to get the JTAG interface initialized with the speed index. More... | |
static int | ch347_adapter_supports_larger_pack_mode (bool *supports_larger_pack_mode) |
Sends the CH347_CMD_JTAG_INIT (D0) command to ask the JTAG interface with special clock index 9 for the LARGER_PACK mode support. More... | |
static bool | ch347_chk_buf_size (uint8_t cmd, uint32_t ap_delay_clk) |
static void | ch347_cmd_calc_reads (struct ch347_cmd *cmd) |
calculates the amount of bits and bytes that should be read for this command More... | |
static int | ch347_cmd_from_scratchpad (void) |
copy the scratchpad content into a new command in the command queue More... | |
static int | ch347_cmd_start_next (uint8_t type) |
starts the next command in the scratchpad. More... | |
static int | ch347_cmd_transmit_queue (void) |
Sends the write buffer via libusb and if LARGER_PACK mode is active read also data back. More... | |
static int | ch347_execute_queue (struct jtag_command *cmd_queue) |
Executes the command queue. More... | |
static struct ch347_swd_io * | ch347_get_one_swd_io (void) |
static int | ch347_gpio_set (int gpio, bool data) |
Sets a GPIO bit. More... | |
static int | ch347_init (void) |
CH347 Initialization function. More... | |
static int | ch347_init_pack_size (void) |
inits ch347.pack_size and ch347.max_len More... | |
static bool | ch347_is_single_cmd_type (uint8_t type) |
static int | ch347_open_device (void) |
opens the CH347 device via libusb driver More... | |
static int | ch347_quit (void) |
CH347 Device Release Function. More... | |
static int | ch347_read_data (uint8_t *data, int *length) |
reads data from the CH347 via libusb driver More... | |
static int | ch347_read_scan (uint8_t *decoded_buf, int decoded_buf_len, int raw_read_len) |
Reads data back from CH347 and decode it byte- and bitwise into the buffer. More... | |
static void | ch347_read_swd_reg (uint8_t cmd) |
static int | ch347_reset (int trst, int srst) |
Control (assert/deassert) the signals SRST and TRST on the interface. More... | |
static int | ch347_scan_data_to_fields (uint8_t *decoded_buf, int decoded_buf_len) |
Used to put the data from the decoded buffer into the scan command fields. More... | |
static int | ch347_scan_queue_fields (struct scan_field *scan_fields, int scan_fields_len) |
queue the scan fields into the scan queue More... | |
static int | ch347_scratchpad_add_byte (uint8_t byte) |
adds one byte to the scratchpad if scratchpad is full after this byte the command will be created from the scratchpad and the scratchpad is cleared for the next command More... | |
static int | ch347_scratchpad_add_bytes (uint8_t *bytes, int count) |
adds bytes from a buffer to the scratchpad if scratchpad is full after this byte the command will be created from the scratchpad and the scratchpad is cleared for the next command More... | |
static int | ch347_scratchpad_add_clock_tms (bool tms) |
Function used to change the TMS value at the rising edge of TCK to switch its TAP state. More... | |
static int | ch347_scratchpad_add_idle_clock (void) |
Function to ensure that the clock is in a low state. More... | |
static int | ch347_scratchpad_add_move_path (struct pathmove_command *cmd) |
Obtain the current Tap status and switch to the status TMS value passed down by cmd. More... | |
static int | ch347_scratchpad_add_move_state (enum tap_state state, int skip) |
Toggle the tap state to the target state. More... | |
static int | ch347_scratchpad_add_pin_byte (void) |
adds the output pin byte to the scratchpad if scratchpad is full after this byte the command will be created from the scratchpad and the scratchpad is cleared for the next command More... | |
static int | ch347_scratchpad_add_run_test (int cycles, enum tap_state state) |
Toggle the Tap state to run test/idle. More... | |
static int | ch347_scratchpad_add_scan (struct scan_command *cmd) |
Switch to SHIFT-DR or SHIFT-IR status for scanning. More... | |
static int | ch347_scratchpad_add_stableclocks (int count) |
Function adds a certain amount of TCK pulses without changing the TMS pin. More... | |
static int | ch347_scratchpad_add_tms_change (const uint8_t *tms_value, int step, int skip) |
Function that performs state switching by changing the value of TMS. More... | |
static int | ch347_scratchpad_add_write_read (struct scan_command *cmd, uint8_t *bits, int bits_len, enum scan_type scan) |
CH347 Batch read/write function. More... | |
static void | ch347_scratchpad_check_full (void) |
checks if the scratchpad is full. More... | |
static int | ch347_single_read_get_byte (int read_buf_idx, uint8_t *byte) |
Function executes the single command and deliver one byte from the buffer that's read back from USB. More... | |
static int | ch347_sleep (int us) |
Flushes the command buffer and sleeps for a specific timespan. More... | |
static int | ch347_speed_get (int speed_idx, int *khz) |
returns the speed in kHz by the give speed index More... | |
static int | ch347_speed_get_index (int khz, int *speed_idx) |
multiplies the input speed by 1000 More... | |
static int | ch347_speed_set (int speed_index) |
Initializes the JTAG interface and set CH347 TCK frequency. More... | |
static int | ch347_swd_init (void) |
Initialization for the swd mode. More... | |
static int | ch347_swd_init_cmd (uint8_t clock_divisor) |
swd init function More... | |
static int | ch347_swd_queue_cmd (uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk) |
static int | ch347_swd_queue_flush (void) |
static void | ch347_swd_read_reg (uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk) |
static int | ch347_swd_run_queue (void) |
static int | ch347_swd_run_queue_inner (void) |
static int | ch347_swd_send_idle (uint32_t ap_delay_clk) |
static int | ch347_swd_switch_out (enum swd_special_seq seq, const uint8_t *out, unsigned int out_len) |
static int | ch347_swd_switch_seq (enum swd_special_seq seq) |
static void | ch347_swd_write_reg (uint8_t cmd, uint32_t value, uint32_t ap_delay_clk) |
static int | ch347_write_data (uint8_t *data, int *length) |
writes data to the CH347 via libusb driver More... | |
static void | ch347_write_spec_seq (const uint8_t *out, uint8_t out_len) |
static void | ch347_write_swd_reg (uint8_t cmd, const uint32_t out) |
COMMAND_HANDLER (ch347_handle_activity_led_command) | |
The command handler for configuring which GPIO pin is used as activity LED. More... | |
COMMAND_HANDLER (ch347_handle_device_desc_command) | |
The command handler for setting the device description that should be found. More... | |
COMMAND_HANDLER (ch347_handle_vid_pid_command) | |
The command handler for setting the device usb vid/pid. More... | |
static void | log_buf_dump (const uint8_t *data, unsigned int size, bool recv) |
Variables | |
static struct ch347_info | ch347 |
static bool | ch347_activity_led_active_high |
static uint8_t | ch347_activity_led_gpio_pin = 0xFF |
struct adapter_driver | ch347_adapter_driver |
static const struct command_registration | ch347_command_handlers [] |
static char * | ch347_device_desc |
static struct libusb_device_handle * | ch347_handle |
static struct jtag_interface | ch347_interface |
static const int | ch347_larger_pack_clock_speeds [] |
static const int | ch347_standard_pack_clock_speeds [] |
static const struct command_registration | ch347_subcommand_handlers [] |
static const struct swd_driver | ch347_swd |
static struct ch347_swd_context | ch347_swd_context |
static uint16_t | custom_ch347_pids [] = {0, 0, 0, 0} |
static uint16_t | custom_ch347_vids [] = {0, 0, 0, 0} |
static uint16_t | default_ch347_pids [] |
static uint16_t | default_ch347_vids [] = {DEFAULT_VENDOR_ID, DEFAULT_VENDOR_ID, DEFAULT_VENDOR_ID, 0} |
static bool | swd_mode |
#define CH347_MAX_RECV_BUF USBC_PACKET_USBHS |
#define CH347_MAX_SEND_BUF USBC_PACKET_USBHS |
#define CH347_SINGLE_CMD_MAX_READ MAX(GPIO_CNT, CH347_CMD_INIT_READ_LEN) |
#define CH347_SWD_CLOCK_MAX_DIVISOR (CH347_MAX_PROCESSING_US / swd_seq_dormant_to_swd_len) |
enum ch347_variant |
|
static |
Turn the activity LED on or off.
led_state | LED_ON or LED_OFF |
Definition at line 1303 of file ch347.c.
References ch347_activity_led_active_high, ch347_activity_led_gpio_pin, ch347_gpio_set(), and ERROR_OK.
Referenced by ch347_execute_queue(), and ch347_quit().
|
static |
Sends the CH347_CMD_JTAG_INIT (D0) command to get the JTAG interface initialized with the speed index or asking with special clock index 9 for the LARGER_PACK mode support.
clock_index | Clock index; special clock index 9 is used for checking if the device supports the LARGER_PACK mode |
supports_larger_pack_mode | returns true if the device supports the LARGER_PACK mode for newer CH347 devices; false if the device supports only the older STANDARD_PACK mode |
Definition at line 1568 of file ch347.c.
References CH347_CMD_JTAG_INIT, ch347_cmd_start_next(), ch347_scratchpad_add_byte(), ch347_scratchpad_add_pin_byte(), ch347_single_read_get_byte(), ERROR_OK, and mode.
Referenced by ch347_adapter_set_speed(), and ch347_adapter_supports_larger_pack_mode().
|
static |
Sends the CH347_CMD_JTAG_INIT (D0) command to get the JTAG interface initialized with the speed index.
clock_index | Clock index |
Definition at line 1617 of file ch347.c.
References ch347_adapter_init().
Referenced by ch347_speed_set().
|
static |
Sends the CH347_CMD_JTAG_INIT (D0) command to ask the JTAG interface with special clock index 9 for the LARGER_PACK mode support.
supports_larger_pack_mode | returns true if the device supports the LARGER_PACK mode for newer CH347 devices; false if the device supports only the older STANDARD_PACK mode |
Definition at line 1605 of file ch347.c.
References ch347_adapter_init(), and CH347_CMD_INIT_GET_MODE_CLOCK_INDEX_VALUE.
Referenced by ch347_init_pack_size().
|
static |
Definition at line 2042 of file ch347.c.
References CH347_MAX_RECV_BUF, CH347_MAX_SEND_BUF, cmd, DIV_ROUND_UP, ch347_swd_context::need_recv_len, ch347_swd_context::send_len, SWD_CMD_APNDP, and SWD_CMD_RNW.
Referenced by ch347_swd_queue_cmd().
|
static |
calculates the amount of bits and bytes that should be read for this command
cmd | command for the calculation |
Definition at line 447 of file ch347.c.
References CH347_CMD_GPIO, CH347_CMD_INIT_READ_LEN, CH347_CMD_JTAG_BIT_OP_RD, CH347_CMD_JTAG_DATA_SHIFT_RD, CH347_CMD_JTAG_INIT, CH347_CMD_SWD_INIT, cmd, and TCK_H.
Referenced by ch347_cmd_from_scratchpad().
|
static |
copy the scratchpad content into a new command in the command queue
scan_fields | array of scan_field's for data from the device |
scan_fields_len | array length |
Definition at line 487 of file ch347.c.
References ch347, ch347_cmd_calc_reads(), cmd, ch347_info::cmd_queue, ERROR_FAIL, ERROR_OK, list_add_tail(), LOG_ERROR, ch347_info::scratchpad, ch347_info::scratchpad_cmd_type, and ch347_info::scratchpad_idx.
Referenced by ch347_cmd_start_next(), ch347_cmd_transmit_queue(), ch347_scratchpad_add_write_read(), and ch347_scratchpad_check_full().
|
static |
starts the next command in the scratchpad.
If it's the same command type it can concat the data bytes. no need to make a new command for this case
type | command type |
Definition at line 792 of file ch347.c.
References ch347, ch347_cmd_from_scratchpad(), ch347_cmd_transmit_queue(), ch347_is_single_cmd_type(), ERROR_OK, ch347_info::scratchpad_cmd_type, ch347_info::scratchpad_idx, and type.
Referenced by ch347_adapter_init(), ch347_gpio_set(), ch347_reset(), ch347_scratchpad_add_move_path(), ch347_scratchpad_add_stableclocks(), ch347_scratchpad_add_tms_change(), ch347_scratchpad_add_write_read(), and ch347_swd_init_cmd().
|
static |
Sends the write buffer via libusb and if LARGER_PACK mode is active read also data back.
Definition at line 660 of file ch347.c.
References ch347, ch347_cmd_from_scratchpad(), CH347_CMD_HEADER, ch347_is_single_cmd_type(), ch347_read_scan(), ch347_scan_data_to_fields(), ch347_write_data(), cmd, ch347_info::cmd_queue, DIV_ROUND_UP, ERROR_FAIL, ERROR_OK, h_u16_to_le(), HW_TDO_BUF_SIZE, list_del(), list_empty(), list_for_each_entry, list_for_each_entry_safe, LOG_ERROR, ch347_info::max_len, and NULL.
Referenced by ch347_cmd_start_next(), ch347_execute_queue(), ch347_quit(), ch347_reset(), ch347_single_read_get_byte(), and ch347_sleep().
|
static |
Executes the command queue.
Definition at line 1369 of file ch347.c.
References ch347_activity_led_set(), ch347_cmd_transmit_queue(), ch347_scratchpad_add_move_path(), ch347_scratchpad_add_move_state(), ch347_scratchpad_add_run_test(), ch347_scratchpad_add_scan(), ch347_scratchpad_add_stableclocks(), ch347_scratchpad_add_tms_change(), ch347_sleep(), cmd, ERROR_FAIL, ERROR_OK, JTAG_PATHMOVE, JTAG_RUNTEST, JTAG_SCAN, JTAG_SLEEP, JTAG_STABLECLOCKS, JTAG_TLR_RESET, JTAG_TMS, LED_OFF, LED_ON, and LOG_ERROR.
|
static |
Definition at line 1939 of file ch347.c.
References CH347_CMD_SWD_SEQ_W, ch347_swd_io::cmd, ch347_swd_io::dst, ch347_swd_context::free_cmd_head, list_del_init(), list_empty(), list_entry, ch347_swd_io::list_entry, list_first_entry, NULL, and ch347_swd_io::usb_cmd.
Referenced by ch347_swd_queue_cmd(), ch347_swd_send_idle(), and ch347_swd_switch_out().
|
static |
Sets a GPIO bit.
gpio | GPIO bit number 0-7 |
data | true for high; false for low |
Definition at line 1267 of file ch347.c.
References BIT, CH347_CMD_GPIO, ch347_cmd_start_next(), ch347_scratchpad_add_bytes(), ch347_single_read_get_byte(), ERROR_FAIL, ERROR_OK, GPIO_CNT, GPIO_SET_H, GPIO_SET_L, gpios, and LOG_ERROR.
Referenced by ch347_activity_led_set().
|
static |
CH347 Initialization function.
Definition at line 1879 of file ch347.c.
References ch347, ch347_init_pack_size(), ch347_open_device(), ch347_swd_init_cmd(), ch347_info::cmd_queue, ERROR_OK, INIT_LIST_HEAD(), LOG_DEBUG_IO, LOG_ERROR, ch347_info::pack_size, ch347_info::scan_queue, swd_mode, TAP_RESET, tap_set_state, TCK_L, ch347_info::tck_pin, TDI_L, ch347_info::tdi_pin, TMS_H, ch347_info::tms_pin, TRST_H, ch347_info::trst_pin, and UNSET.
|
static |
inits ch347.pack_size and ch347.max_len
Definition at line 1676 of file ch347.c.
References ch347, ch347_adapter_supports_larger_pack_mode(), ERROR_OK, LARGER_PACK, LARGER_PACK_MAX_SIZE, ch347_info::max_len, MIN, ch347_info::pack_size, STANDARD_PACK, UNSET, USBC_PACKET_USBHS, and ch347_info::use_bitwise_mode.
Referenced by ch347_init(), ch347_speed_get(), and ch347_speed_get_index().
|
inlinestatic |
Definition at line 267 of file ch347.c.
References CH347_CMD_GPIO, CH347_CMD_JTAG_INIT, CH347_CMD_SWD_INIT, and type.
Referenced by ch347_cmd_start_next(), and ch347_cmd_transmit_queue().
|
static |
opens the CH347 device via libusb driver
Definition at line 1424 of file ch347.c.
References BYTEWISE_MODE_VERSION, ch347, ch347_device_desc, ch347_handle, CH347F, CH347F_MPHSI_INTERFACE, CH347T, CH347T_MPHSI_INTERFACE, ch347_info::chip_variant, custom_ch347_pids, custom_ch347_vids, default_ch347_pids, default_ch347_vids, device, ERROR_FAIL, ERROR_OK, jtag_libusb_close(), jtag_libusb_control_transfer(), jtag_libusb_open(), LOG_ERROR, LOG_INFO, LOG_WARNING, NULL, ch347_info::swclk_5mhz_supported, swd_mode, USB_WRITE_TIMEOUT, ch347_info::use_bitwise_mode, and VENDOR_VERSION.
Referenced by ch347_init().
|
static |
CH347 Device Release Function.
Definition at line 1547 of file ch347.c.
References ch347_activity_led_set(), ch347_cmd_transmit_queue(), ch347_handle, jtag_libusb_close(), LED_ON, and LOG_DEBUG_IO.
|
static |
reads data from the CH347 via libusb driver
data | Point to the data buffer |
length | Data length in and out |
Definition at line 411 of file ch347.c.
References CH347_EPIN, ch347_handle, ERROR_OK, jtag_libusb_bulk_read(), length, log_buf_dump(), LOG_DEBUG_IO, LOG_ERROR, LOG_LEVEL_IS, LOG_LVL_DEBUG_IO, and USB_READ_TIMEOUT.
Referenced by ch347_read_scan(), and ch347_swd_queue_flush().
|
static |
Reads data back from CH347 and decode it byte- and bitwise into the buffer.
decoded_buf | Point to a buffer to place the data to be decoded; need to be sized to the decoded size length; not the raw_read_len |
decoded_buf_len | length of the decoded_buf |
raw_read_len | Data length in bytes that should be read via libusb; the decoded length can be shorter |
Definition at line 525 of file ch347.c.
References BIT, CH347_CMD_GPIO, CH347_CMD_JTAG_BIT_OP_RD, CH347_CMD_JTAG_DATA_SHIFT_RD, CH347_CMD_JTAG_INIT, CH347_CMD_SWD_INIT, ch347_read_data(), DIV_ROUND_UP, ERROR_FAIL, ERROR_OK, le_to_h_u16(), LOG_ERROR, ch347_cmd::read_len, and type.
Referenced by ch347_cmd_transmit_queue().
|
static |
Definition at line 2013 of file ch347.c.
References CH347_CMD_SWD_REG_R, cmd, ch347_swd_context::need_recv_len, ch347_swd_context::send_buf, ch347_swd_context::send_len, and ch347_swd_context::total_swd_clk.
Referenced by ch347_swd_queue_cmd().
|
static |
Control (assert/deassert) the signals SRST and TRST on the interface.
trst | 1 to assert TRST, 0 to deassert TRST. |
srst | 1 to assert SRST, 0 to deassert SRST. |
Definition at line 1320 of file ch347.c.
References ch347, CH347_CMD_JTAG_BIT_OP, ch347_cmd_start_next(), ch347_cmd_transmit_queue(), ch347_scratchpad_add_idle_clock(), ch347_scratchpad_add_pin_byte(), ERROR_FAIL, ERROR_OK, LOG_DEBUG_IO, LOG_ERROR, LOG_WARNING, swd_mode, TRST_H, TRST_L, and ch347_info::trst_pin.
|
static |
Used to put the data from the decoded buffer into the scan command fields.
decoded_buf | Point to a buffer for the decoded data |
decoded_buf_len | length of the decoded_buf |
Definition at line 598 of file ch347.c.
References bit_offset, buf_cpy(), buf_set_buf(), buf_to_hex_str(), ch347, CH347_SINGLE_CMD_MAX_READ, DIV_ROUND_UP, ERROR_FAIL, ERROR_OK, list_del(), list_for_each_entry_safe, LOG_DEBUG, LOG_DEBUG_IO, LOG_ERROR, LOG_LEVEL_IS, LOG_LVL_DEBUG_IO, scan, ch347_info::scan_queue, ch347_info::singe_read_len, and ch347_info::single_read.
Referenced by ch347_cmd_transmit_queue().
|
static |
queue the scan fields into the scan queue
scan_fields | array of scan field's for data from the device |
scan_fields_len | array length |
Definition at line 835 of file ch347.c.
References ch347, ERROR_FAIL, ERROR_OK, list_add_tail(), LOG_ERROR, scan, and ch347_info::scan_queue.
Referenced by ch347_scratchpad_add_write_read().
|
static |
adds one byte to the scratchpad if scratchpad is full after this byte the command will be created from the scratchpad and the scratchpad is cleared for the next command
byte | add this byte |
Definition at line 896 of file ch347.c.
References ch347, ch347_scratchpad_check_full(), ERROR_FAIL, ERROR_OK, LOG_ERROR, ch347_info::scratchpad, ch347_info::scratchpad_cmd_type, and ch347_info::scratchpad_idx.
Referenced by ch347_adapter_init(), and ch347_scratchpad_add_pin_byte().
|
static |
adds bytes from a buffer to the scratchpad if scratchpad is full after this byte the command will be created from the scratchpad and the scratchpad is cleared for the next command
bytes | add this bytes |
count | byte count |
Definition at line 930 of file ch347.c.
References ch347, ch347_scratchpad_check_full(), count, ERROR_FAIL, ERROR_OK, LOG_ERROR, ch347_info::scratchpad, ch347_info::scratchpad_cmd_type, ch347_info::scratchpad_idx, and UCMDPKT_DATA_MAX_BYTES_USBHS.
Referenced by ch347_gpio_set(), ch347_scratchpad_add_write_read(), and ch347_swd_init_cmd().
|
static |
Function used to change the TMS value at the rising edge of TCK to switch its TAP state.
tms | TMS value to be changed; true = output TMS high; false = output TMS low |
Definition at line 964 of file ch347.c.
References ch347, ch347_scratchpad_add_pin_byte(), ERROR_OK, TCK_H, TCK_L, ch347_info::tck_pin, TMS_H, TMS_L, and ch347_info::tms_pin.
Referenced by ch347_scratchpad_add_move_path(), ch347_scratchpad_add_stableclocks(), and ch347_scratchpad_add_tms_change().
|
static |
Function to ensure that the clock is in a low state.
Definition at line 1007 of file ch347.c.
References ch347, ch347_scratchpad_add_pin_byte(), TCK_L, and ch347_info::tck_pin.
Referenced by ch347_reset(), ch347_scratchpad_add_move_path(), ch347_scratchpad_add_tms_change(), and ch347_scratchpad_add_write_read().
|
static |
Obtain the current Tap status and switch to the status TMS value passed down by cmd.
cmd | Upper layer transfer command parameters |
Definition at line 1044 of file ch347.c.
References CH347_CMD_JTAG_BIT_OP, ch347_cmd_start_next(), ch347_scratchpad_add_clock_tms(), ch347_scratchpad_add_idle_clock(), cmd, ERROR_JTAG_TRANSITION_INVALID, ERROR_OK, LOG_DEBUG_IO, LOG_ERROR, tap_get_state(), tap_set_state, and tap_state_transition().
Referenced by ch347_execute_queue().
|
static |
Toggle the tap state to the target state.
state | Pre switch target path |
skip | Number of digits to skip |
Definition at line 1078 of file ch347.c.
References ch347_scratchpad_add_tms_change(), ERROR_OK, LOG_DEBUG_IO, state, tap_get_state(), tap_get_tms_path(), tap_get_tms_path_len(), TAP_RESET, tap_set_state, and tap_state_name().
Referenced by ch347_execute_queue(), ch347_scratchpad_add_run_test(), and ch347_scratchpad_add_scan().
|
static |
adds the output pin byte to the scratchpad if scratchpad is full after this byte the command will be created from the scratchpad and the scratchpad is cleared for the next command
Definition at line 915 of file ch347.c.
References ch347, ch347_scratchpad_add_byte(), ch347_info::tck_pin, ch347_info::tdi_pin, ch347_info::tms_pin, and ch347_info::trst_pin.
Referenced by ch347_adapter_init(), ch347_reset(), ch347_scratchpad_add_clock_tms(), ch347_scratchpad_add_idle_clock(), and ch347_scratchpad_add_write_read().
|
static |
Toggle the Tap state to run test/idle.
cycles | how many clock cycles for output |
state | JTAG end state |
Definition at line 1199 of file ch347.c.
References ch347_scratchpad_add_move_state(), ch347_scratchpad_add_stableclocks(), ERROR_OK, LOG_DEBUG_IO, state, tap_get_state(), and TAP_IDLE.
Referenced by ch347_execute_queue().
|
static |
Switch to SHIFT-DR or SHIFT-IR status for scanning.
cmd | Upper layer transfer command parameters |
Definition at line 1222 of file ch347.c.
References buf_to_hex_str(), ch347_scratchpad_add_move_state(), ch347_scratchpad_add_write_read(), cmd, ERROR_OK, jtag_build_buffer(), jtag_scan_type(), LOG_DEBUG_IO, LOG_LEVEL_IS, LOG_LVL_DEBUG_IO, NULL, TAP_DRSHIFT, TAP_IRSHIFT, and type.
Referenced by ch347_execute_queue().
|
static |
Function adds a certain amount of TCK pulses without changing the TMS pin.
count | Amount of L/H TCK pulses to add |
Definition at line 982 of file ch347.c.
References ch347, CH347_CMD_JTAG_BIT_OP, ch347_cmd_start_next(), ch347_scratchpad_add_clock_tms(), count, ERROR_OK, ch347_info::scratchpad_cmd_type, TMS_H, and ch347_info::tms_pin.
Referenced by ch347_execute_queue(), and ch347_scratchpad_add_run_test().
|
static |
Function that performs state switching by changing the value of TMS.
tms_value | The TMS values that need to be switched form one byte of data in the switching order |
step | The number of bit values that need to be read from the tms_value value |
skip | Count from the skip bit of tms_value to step |
Definition at line 1021 of file ch347.c.
References BIT, CH347_CMD_JTAG_BIT_OP, ch347_cmd_start_next(), ch347_scratchpad_add_clock_tms(), ch347_scratchpad_add_idle_clock(), ERROR_OK, LOG_DEBUG_IO, and step().
Referenced by ch347_execute_queue(), and ch347_scratchpad_add_move_state().
|
static |
CH347 Batch read/write function.
cmd | The scan command |
bits | Read and write data this time |
bits_len | Incoming data length in bits |
scan | The transmission method of incoming data to determine whether to perform data reading |
Definition at line 1104 of file ch347.c.
References BIT, bits, ch347, ch347_cmd_from_scratchpad(), CH347_CMD_JTAG_BIT_OP, CH347_CMD_JTAG_BIT_OP_RD, CH347_CMD_JTAG_DATA_SHIFT, CH347_CMD_JTAG_DATA_SHIFT_RD, ch347_cmd_start_next(), ch347_scan_queue_fields(), ch347_scratchpad_add_bytes(), ch347_scratchpad_add_idle_clock(), ch347_scratchpad_add_pin_byte(), cmd, ERROR_OK, MAX_BITS_PER_BIT_OP, NULL, scan, SCAN_IN, SCAN_IO, TCK_H, TCK_L, ch347_info::tck_pin, TDI_H, TDI_L, ch347_info::tdi_pin, TMS_H, TMS_L, ch347_info::tms_pin, and ch347_info::use_bitwise_mode.
Referenced by ch347_scratchpad_add_scan().
|
static |
checks if the scratchpad is full.
If it's full the function creates a command from it and puts it into the command queue
Definition at line 878 of file ch347.c.
References ch347, ch347_cmd_from_scratchpad(), ch347_info::scratchpad_cmd_type, ch347_info::scratchpad_idx, type, and UCMDPKT_DATA_MAX_BYTES_USBHS.
Referenced by ch347_scratchpad_add_byte(), and ch347_scratchpad_add_bytes().
|
static |
Function executes the single command and deliver one byte from the buffer that's read back from USB.
read_buf_idx | index of the byte that should be returned |
byte | returns byte at index or if index is out of range the first byte |
Definition at line 858 of file ch347.c.
References ch347, ch347_cmd_transmit_queue(), CH347_SINGLE_CMD_MAX_READ, ERROR_FAIL, ERROR_OK, LOG_ERROR, and ch347_info::single_read.
Referenced by ch347_adapter_init(), ch347_gpio_set(), and ch347_swd_init_cmd().
|
static |
Flushes the command buffer and sleeps for a specific timespan.
us | Sleep time in microseconds |
Definition at line 1356 of file ch347.c.
References ch347_cmd_transmit_queue(), jtag_sleep(), and LOG_DEBUG_IO.
Referenced by ch347_execute_queue().
|
static |
returns the speed in kHz by the give speed index
speed_idx | CH347 speed index |
khz | Output of the speed in kHz |
Definition at line 1702 of file ch347.c.
References ch347, ch347_init_pack_size(), ch347_larger_pack_clock_speeds, ch347_standard_pack_clock_speeds, CH347_SWD_CLOCK_BASE, CH347_SWD_CLOCK_MAX, DIV_ROUND_UP, ERROR_OK, ch347_info::pack_size, STANDARD_PACK, and swd_mode.
|
static |
multiplies the input speed by 1000
khz | Speed in kHz |
speed_idx | CH347 speed index |
Definition at line 1728 of file ch347.c.
References ARRAY_SIZE, ch347, ch347_init_pack_size(), ch347_larger_pack_clock_speeds, ch347_standard_pack_clock_speeds, CH347_SWD_CLOCK_BASE, CH347_SWD_CLOCK_MAX, CH347_SWD_CLOCK_MAX_DIVISOR, DIV_ROUND_UP, ERROR_FAIL, ERROR_OK, length, LOG_ERROR, LOG_INFO, MIN, ch347_info::pack_size, STANDARD_PACK, ch347_info::swclk_5mhz_supported, and swd_mode.
|
static |
Initializes the JTAG interface and set CH347 TCK frequency.
speed_index | speed index for JTAG_INIT command |
Definition at line 1657 of file ch347.c.
References ch347_adapter_set_speed(), ch347_swd_init_cmd(), ERROR_OK, LOG_ERROR, and swd_mode.
|
static |
Initialization for the swd mode.
Definition at line 1917 of file ch347.c.
References ch347_swd_context::ch347_cmd_buf, CH347_CMD_HEADER, CH347_MAX_CMD_BUF, ERROR_OK, ch347_swd_context::free_cmd_head, INIT_LIST_HEAD(), list_add_tail(), ch347_swd_io::list_entry, LOG_INFO, ch347_swd_context::need_recv_len, ch347_swd_context::queued_retval, ch347_swd_context::send_cmd_head, ch347_swd_context::send_len, and swd_mode.
|
static |
swd init function
clock_divisor | Divisor of base SWD frequency 1 MHz or 0 for fast 5 MHz clock |
Definition at line 1629 of file ch347.c.
References ARRAY_SIZE, ch347_cmd_start_next(), CH347_CMD_SWD_INIT, ch347_scratchpad_add_bytes(), ch347_single_read_get_byte(), ch347_swd_context::clk_divisor, ERROR_OK, and LOG_DEBUG.
Referenced by ch347_init(), and ch347_speed_set().
|
static |
Definition at line 2323 of file ch347.c.
References ch347_chk_buf_size(), CH347_CMD_SWD_REG_R, CH347_CMD_SWD_REG_W, ch347_get_one_swd_io(), CH347_MAX_PROCESSING_US, ch347_read_swd_reg(), ch347_swd_run_queue_inner(), ch347_swd_send_idle(), ch347_write_swd_reg(), ch347_swd_context::clk_divisor, ch347_swd_io::cmd, cmd, ch347_swd_io::dst, ERROR_FAIL, ERROR_OK, list_add_tail(), ch347_swd_io::list_entry, LOG_DEBUG_IO, LOG_ERROR, NULL, ch347_swd_context::queued_retval, ch347_swd_context::send_cmd_head, ch347_swd_context::sent_cmd_count, SWD_CMD_PARK, SWD_CMD_RNW, SWD_CMD_START, ch347_swd_context::total_swd_clk, ch347_swd_io::usb_cmd, and ch347_swd_io::value.
Referenced by ch347_swd_read_reg().
|
static |
Definition at line 1954 of file ch347.c.
References CH347_CMD_HEADER, CH347_CMD_SWD, ch347_read_data(), ch347_write_data(), ERROR_FAIL, ERROR_OK, h_u16_to_le(), length, LOG_DEBUG, LOG_ERROR, ch347_swd_context::need_recv_len, ch347_swd_context::queued_retval, ch347_swd_context::recv_buf, ch347_swd_context::recv_len, ch347_swd_context::send_buf, and ch347_swd_context::send_len.
Referenced by ch347_swd_run_queue_inner().
|
static |
Definition at line 2413 of file ch347.c.
References ch347_swd_queue_cmd(), cmd, ERROR_OK, ch347_swd_context::queued_retval, SWD_CMD_RNW, and ch347_swd_io::value.
|
static |
Definition at line 2312 of file ch347.c.
References ch347_swd_run_queue_inner(), ch347_swd_send_idle(), and ERROR_OK.
|
static |
Definition at line 2169 of file ch347.c.
References buf_get_u32(), CH347_CMD_HEADER, CH347_CMD_SWD, CH347_CMD_SWD_REG_R, CH347_CMD_SWD_REG_W, CH347_CMD_SWD_SEQ_W, ch347_swd_queue_flush(), ch347_swd_io::cmd, ch347_swd_io::dst, ERROR_FAIL, ERROR_OK, ch347_swd_context::free_cmd_head, le_to_h_u16(), list_add_tail(), list_del_init(), list_empty(), list_entry, ch347_swd_io::list_entry, list_for_each_safe, LOG_CUSTOM_LEVEL, LOG_DEBUG_IO, LOG_ERROR, LOG_LVL_DEBUG, LOG_LVL_DEBUG_IO, ch347_swd_context::need_recv_len, parity(), parity_u32(), ch347_swd_context::queued_retval, ch347_swd_context::recv_buf, ch347_swd_context::recv_len, ch347_swd_context::send_cmd_head, ch347_swd_context::send_len, ch347_swd_context::sent_cmd_count, SWD_ACK_FAULT, SWD_ACK_OK, swd_ack_to_error_code(), SWD_ACK_WAIT, SWD_CMD_A32, SWD_CMD_APNDP, swd_cmd_returns_ack(), SWD_CMD_RNW, ch347_swd_context::total_swd_clk, ch347_swd_io::usb_cmd, and ch347_swd_io::value.
Referenced by ch347_swd_queue_cmd(), ch347_swd_run_queue(), and ch347_swd_send_idle().
|
static |
Definition at line 2089 of file ch347.c.
References ch347_get_one_swd_io(), CH347_MAX_PROCESSING_US, CH347_MAX_RECV_BUF, CH347_MAX_SEND_BUF, ch347_swd_run_queue_inner(), ch347_write_spec_seq(), ch347_swd_context::clk_divisor, DIV_ROUND_UP, ERROR_FAIL, ERROR_OK, list_add_tail(), ch347_swd_io::list_entry, LOG_DEBUG_IO, LOG_ERROR, MIN, ch347_swd_context::need_recv_len, NULL, ch347_swd_context::queued_retval, ch347_swd_context::send_cmd_head, ch347_swd_context::send_len, ch347_swd_context::sent_cmd_count, and ch347_swd_context::total_swd_clk.
Referenced by ch347_swd_queue_cmd(), and ch347_swd_run_queue().
|
static |
Definition at line 2024 of file ch347.c.
References ch347_get_one_swd_io(), CH347_MAX_RECV_BUF, CH347_MAX_SEND_BUF, ch347_write_spec_seq(), DIV_ROUND_UP, ERROR_FAIL, ERROR_OK, list_add_tail(), ch347_swd_io::list_entry, ch347_swd_context::need_recv_len, ch347_swd_context::send_cmd_head, and ch347_swd_context::send_len.
Referenced by ch347_swd_switch_seq().
|
static |
Definition at line 2383 of file ch347.c.
References ch347_swd_switch_out(), DORMANT_TO_JTAG, DORMANT_TO_SWD, ERROR_FAIL, JTAG_TO_DORMANT, JTAG_TO_SWD, LINE_RESET, LOG_DEBUG, LOG_ERROR, swd_seq_dormant_to_jtag, swd_seq_dormant_to_jtag_len, swd_seq_dormant_to_swd, swd_seq_dormant_to_swd_len, swd_seq_jtag_to_dormant, swd_seq_jtag_to_dormant_len, swd_seq_jtag_to_swd, swd_seq_jtag_to_swd_len, swd_seq_line_reset, swd_seq_line_reset_len, swd_seq_swd_to_dormant, swd_seq_swd_to_dormant_len, swd_seq_swd_to_jtag, swd_seq_swd_to_jtag_len, SWD_TO_DORMANT, and SWD_TO_JTAG.
|
static |
|
static |
writes data to the CH347 via libusb driver
data | Point to the data buffer |
length | Data length in and out |
Definition at line 375 of file ch347.c.
References CH347_EPOUT, ch347_handle, ERROR_OK, jtag_libusb_bulk_write(), length, log_buf_dump(), LOG_DEBUG_IO, LOG_ERROR, LOG_LEVEL_IS, LOG_LVL_DEBUG_IO, and USB_WRITE_TIMEOUT.
Referenced by ch347_cmd_transmit_queue(), and ch347_swd_queue_flush().
|
static |
Definition at line 2001 of file ch347.c.
References CH347_CMD_SWD_SEQ_W, DIV_ROUND_UP, ch347_swd_context::need_recv_len, ch347_swd_context::send_buf, ch347_swd_context::send_len, and ch347_swd_context::total_swd_clk.
Referenced by ch347_swd_send_idle(), and ch347_swd_switch_out().
|
static |
Definition at line 1986 of file ch347.c.
References CH347_CMD_SWD_REG_W, cmd, h_u32_to_le(), ch347_swd_context::need_recv_len, parity_u32(), ch347_swd_context::send_buf, ch347_swd_context::send_len, and ch347_swd_context::total_swd_clk.
Referenced by ch347_swd_queue_cmd().
COMMAND_HANDLER | ( | ch347_handle_activity_led_command | ) |
COMMAND_HANDLER | ( | ch347_handle_device_desc_command | ) |
The command handler for setting the device description that should be found.
Definition at line 1802 of file ch347.c.
References ch347_device_desc, CMD_ARGC, CMD_ARGV, ERROR_COMMAND_SYNTAX_ERROR, and ERROR_OK.
COMMAND_HANDLER | ( | ch347_handle_vid_pid_command | ) |
The command handler for setting the device usb vid/pid.
Definition at line 1784 of file ch347.c.
References ARRAY_SIZE, CMD_ARGC, CMD_ARGV, COMMAND_PARSE_NUMBER, custom_ch347_pids, custom_ch347_vids, ERROR_COMMAND_SYNTAX_ERROR, ERROR_OK, and MIN.
|
static |
Definition at line 272 of file ch347.c.
References CH347_CMD_SWD, CH347_CMD_SWD_REG_R, CH347_CMD_SWD_REG_W, CH347_CMD_SWD_SEQ_W, cmd, DIV_ROUND_UP, hexify(), le_to_h_u16(), LOG_DEBUG_IO, MIN, size, and swd_cmd().
Referenced by ch347_read_data(), and ch347_write_data().
|
static |
Definition at line 261 of file ch347.c.
Referenced by ch347_cmd_from_scratchpad(), ch347_cmd_start_next(), ch347_cmd_transmit_queue(), ch347_init(), ch347_init_pack_size(), ch347_open_device(), ch347_reset(), ch347_scan_data_to_fields(), ch347_scan_queue_fields(), ch347_scratchpad_add_byte(), ch347_scratchpad_add_bytes(), ch347_scratchpad_add_clock_tms(), ch347_scratchpad_add_idle_clock(), ch347_scratchpad_add_pin_byte(), ch347_scratchpad_add_stableclocks(), ch347_scratchpad_add_write_read(), ch347_scratchpad_check_full(), ch347_single_read_get_byte(), ch347_speed_get(), and ch347_speed_get_index().
|
static |
Definition at line 261 of file ch347.c.
Referenced by ch347_activity_led_set().
|
static |
Definition at line 260 of file ch347.c.
Referenced by ch347_activity_led_set().
struct adapter_driver ch347_adapter_driver |
|
static |
|
static |
Definition at line 259 of file ch347.c.
Referenced by ch347_open_device(), and COMMAND_HANDLER().
|
static |
Definition at line 263 of file ch347.c.
Referenced by ch347_open_device(), ch347_quit(), ch347_read_data(), and ch347_write_data().
|
static |
|
static |
Definition at line 175 of file ch347.c.
Referenced by ch347_speed_get(), and ch347_speed_get_index().
|
static |
Definition at line 165 of file ch347.c.
Referenced by ch347_speed_get(), and ch347_speed_get_index().
|
static |
|
static |
|
static |
|
static |
Definition at line 258 of file ch347.c.
Referenced by ch347_open_device(), and COMMAND_HANDLER().
|
static |
Definition at line 257 of file ch347.c.
Referenced by ch347_open_device(), and COMMAND_HANDLER().
|
static |
|
static |
Definition at line 254 of file ch347.c.
Referenced by ch347_open_device().
|
static |
Definition at line 253 of file ch347.c.
Referenced by ch347_init(), ch347_open_device(), ch347_reset(), ch347_speed_get(), ch347_speed_get_index(), ch347_speed_set(), and ch347_swd_init().