|
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 void | ch347_configure_activity_led (const struct adapter_gpio_config *led_config) |
| Configure which GPIO pin is used as the activity LED. More... | |
| static void | ch347_configure_srst_gpio (const struct adapter_gpio_config *srst_config) |
| Configure which GPIO pin drives SRST in SWD mode. 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_cmd (unsigned int gpio, uint8_t value, uint8_t *state) |
| Sends a GPIO command for a single pin and returns the pin state that the device reports back. More... | |
| static uint8_t | ch347_gpio_drive_value (bool level, enum adapter_gpio_drive_mode drive) |
| Translates an output level into a GPIO command byte for a drive mode. More... | |
| 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 int | 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 int | ch347_swd_write_reg (uint8_t cmd, uint32_t value, uint32_t ap_delay_clk) |
| static uint8_t | ch347_usable_gpios (void) |
| Mask of the GPIO's that don't collide with an interface signal. More... | |
| 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) |
| 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 struct libusb_device_handle * | ch347_handle |
| static struct jtag_interface | ch347_interface |
| static const int | ch347_larger_pack_clock_speeds [] |
| static bool | ch347_srst_active_high |
| static uint8_t | ch347_srst_gpio_pin = 0xFF |
| static const int | ch347_standard_pack_clock_speeds [] |
| static const struct swd_driver | ch347_swd |
| static struct ch347_swd_context | ch347_swd_context |
| 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 1369 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 1671 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 1720 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 1708 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 2122 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 459 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 499 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 804 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_cmd(), 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 672 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 |
Configure which GPIO pin is used as the activity LED.
Updates the global activity LED GPIO pin and polarity settings based on the provided configuration. If the given GPIO is not usable, the function returns without making changes.
| led_config | Pointer to the GPIO configuration structure for the LED pin |
Definition at line 1901 of file ch347.c.
References adapter_gpio_config::active_low, BIT, ch347_activity_led_active_high, ch347_activity_led_gpio_pin, ch347_usable_gpios(), GPIO_CNT, and adapter_gpio_config::gpio_num.
Referenced by ch347_init().
|
static |
Configure which GPIO pin drives SRST in SWD mode.
Defaults to the TRST pin, which is unused in SWD mode. A different pin can be selected with 'adapter gpio srst'. If the configured GPIO is not usable or is already taken by the activity LED, SRST gets disabled.
Must be called after ch347_configure_activity_led().
| srst_config | Pointer to the GPIO configuration structure for the SRST pin |
Definition at line 1922 of file ch347.c.
References adapter_gpio_config::active_low, ADAPTER_GPIO_NOT_SET, BIT, ch347, ch347_activity_led_gpio_pin, ch347_srst_active_high, ch347_srst_gpio_pin, ch347_usable_gpios(), CH347F, CH347F_TRST_GPIO, CH347T_TRST_GPIO, ch347_info::chip_variant, GPIO_CNT, adapter_gpio_config::gpio_num, and LOG_ERROR.
Referenced by ch347_init().
|
static |
Executes the command queue.
Definition at line 1460 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 2019 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 |
Sends a GPIO command for a single pin and returns the pin state that the device reports back.
Only the byte of the addressed pin is filled in, all other bytes stay zero. A zero byte means "not enabled" for the device, so the other pins keep their configuration.
| gpio | GPIO bit number 0-7 |
| value | byte for this pin, one of GPIO_SET_L, GPIO_SET_H, GPIO_SET_INPUT |
| state | returns the byte the device reports for this pin; BIT(6) is the pin level |
Definition at line 1291 of file ch347.c.
References CH347_CMD_GPIO, ch347_cmd_start_next(), ch347_scratchpad_add_bytes(), ch347_single_read_get_byte(), ERROR_FAIL, ERROR_OK, GPIO_CNT, gpios, LOG_ERROR, and state.
Referenced by ch347_gpio_set(), and ch347_reset().
|
static |
Translates an output level into a GPIO command byte for a drive mode.
The CH347 has no open drain output driver, so it gets emulated by switching the pin to input instead of driving the inactive level. The line then relies on an external pull resistor or on the target driving it.
| level | true to output a high level, false for a low level |
| drive | output drive mode to emulate |
Definition at line 1323 of file ch347.c.
References ADAPTER_GPIO_DRIVE_MODE_OPEN_DRAIN, ADAPTER_GPIO_DRIVE_MODE_OPEN_SOURCE, ADAPTER_GPIO_DRIVE_MODE_PUSH_PULL, GPIO_SET_H, GPIO_SET_INPUT, and GPIO_SET_L.
Referenced by ch347_reset().
|
static |
Sets a GPIO bit.
| gpio | GPIO bit number 0-7 |
| data | true for high; false for low |
Definition at line 1344 of file ch347.c.
References BIT, ch347_gpio_cmd(), ERROR_FAIL, ERROR_OK, GPIO_SET_H, GPIO_SET_L, LOG_ERROR, and state.
Referenced by ch347_activity_led_set().
|
static |
CH347 Initialization function.
Definition at line 1955 of file ch347.c.
References adapter_gpio_get_config(), ADAPTER_GPIO_IDX_LED, ADAPTER_GPIO_IDX_SRST, ch347, ch347_configure_activity_led(), ch347_configure_srst_gpio(), 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 1779 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(), and ch347_speed_get().
|
inlinestatic |
Definition at line 279 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 1515 of file ch347.c.
References adapter_usb_get_pids(), adapter_usb_get_product_name(), adapter_usb_get_vids(), BYTEWISE_MODE_VERSION, ch347, ch347_handle, CH347F, CH347F_MPHSI_INTERFACE, CH347T, CH347T_MPHSI_INTERFACE, ch347_info::chip_variant, 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 1650 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 423 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 537 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 2093 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.
In SWD mode TRST is not used as a JTAG signal, so the pin is driven as a GPIO to provide SRST. In JTAG mode the pin is TRST and SRST is unavailable.
The SRST GPIO follows the drive mode configured with 'reset_config'.
| trst | 1 to assert TRST, 0 to deassert TRST. |
| srst | 1 to assert SRST, 0 to deassert SRST. |
Definition at line 1391 of file ch347.c.
References adapter_gpio_get_config(), ADAPTER_GPIO_IDX_SRST, ch347, CH347_CMD_JTAG_BIT_OP, ch347_cmd_start_next(), ch347_cmd_transmit_queue(), ch347_gpio_cmd(), ch347_gpio_drive_value(), ch347_scratchpad_add_idle_clock(), ch347_scratchpad_add_pin_byte(), ch347_srst_active_high, ch347_srst_gpio_pin, ERROR_FAIL, ERROR_OK, LOG_DEBUG_IO, LOG_ERROR, LOG_WARNING, state, 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 610 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 846 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 906 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 940 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_cmd(), 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 974 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 1015 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 1052 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 1086 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 925 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 1207 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 1230 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 992 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 1029 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 1112 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 888 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 869 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_cmd(), and ch347_swd_init_cmd().
|
static |
Flushes the command buffer and sleeps for a specific timespan.
| us | Sleep time in microseconds |
Definition at line 1447 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 1805 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 |
|
static |
Initializes the JTAG interface and set CH347 TCK frequency.
| speed_index | speed index for JTAG_INIT command |
Definition at line 1760 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 1997 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 1732 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 2403 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 2034 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 2493 of file ch347.c.
References ch347_swd_queue_cmd(), cmd, SWD_CMD_RNW, and ch347_swd_io::value.
|
static |
Definition at line 2392 of file ch347.c.
References ch347_swd_run_queue_inner(), ch347_swd_send_idle(), and ERROR_OK.
|
static |
Definition at line 2249 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 2169 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 2104 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 2463 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 |
Mask of the GPIO's that don't collide with an interface signal.
Definition at line 1273 of file ch347.c.
References ch347, CH347F, CH347F_USABLE_GPIOS, CH347T_USABLE_GPIOS, and ch347_info::chip_variant.
Referenced by ch347_configure_activity_led(), and ch347_configure_srst_gpio().
|
static |
writes data to the CH347 via libusb driver
| data | Point to the data buffer |
| length | Data length in and out |
Definition at line 387 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 2081 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 2066 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().
|
static |
Definition at line 284 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 273 of file ch347.c.
Referenced by ch347_cmd_from_scratchpad(), ch347_cmd_start_next(), ch347_cmd_transmit_queue(), ch347_configure_srst_gpio(), 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_usable_gpios().
|
static |
Definition at line 270 of file ch347.c.
Referenced by ch347_activity_led_set(), and ch347_configure_activity_led().
|
static |
Definition at line 269 of file ch347.c.
Referenced by ch347_activity_led_set(), ch347_configure_activity_led(), and ch347_configure_srst_gpio().
| struct adapter_driver ch347_adapter_driver |
|
static |
|
static |
Definition at line 275 of file ch347.c.
Referenced by ch347_open_device(), ch347_quit(), ch347_read_data(), and ch347_write_data().
|
static |
|
static |
Definition at line 187 of file ch347.c.
Referenced by ch347_speed_get().
|
static |
Definition at line 273 of file ch347.c.
Referenced by ch347_configure_srst_gpio(), and ch347_reset().
|
static |
Definition at line 272 of file ch347.c.
Referenced by ch347_configure_srst_gpio(), and ch347_reset().
|
static |
Definition at line 177 of file ch347.c.
Referenced by ch347_speed_get().
|
static |
|
static |
|
static |
|
static |
Definition at line 266 of file ch347.c.
Referenced by ch347_open_device().
|
static |
Definition at line 265 of file ch347.c.
Referenced by ch347_init(), ch347_open_device(), ch347_reset(), ch347_speed_get(), ch347_speed_set(), and ch347_swd_init().