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

Go to the source code of this file.

Data Structures

struct  kitprog
 
struct  pending_transfer_result
 

Macros

#define ACQUIRE_MODE_POWER_CYCLE   0x01
 
#define ACQUIRE_MODE_RESET   0x00
 
#define BULK_EP_IN   1
 
#define BULK_EP_OUT   2
 
#define CONTROL_COMMAND_PROGRAM   0x07
 
#define CONTROL_MODE_ACQUIRE_SWD_TARGET   0x42
 
#define CONTROL_MODE_POLL_PROGRAMMER_STATUS   0x01
 
#define CONTROL_MODE_RESET_TARGET   0x04
 
#define CONTROL_MODE_SEND_SWD_SEQUENCE   0x43
 
#define CONTROL_MODE_SET_PROGRAMMER_PROTOCOL   0x40
 
#define CONTROL_MODE_SYNCHRONIZE_TRANSFER   0x41
 
#define CONTROL_TYPE_READ   0x01
 
#define CONTROL_TYPE_WRITE   0x02
 
#define DEVICE_PSOC3   0x01
 
#define DEVICE_PSOC4   0x00
 
#define DEVICE_PSOC5   0x03
 
#define DEVICE_UNKNOWN   0x02
 
#define HID_COMMAND_BOOTLOADER   0xa0
 
#define HID_COMMAND_CONFIGURE   0x8f
 
#define HID_COMMAND_POWER   0x80
 
#define HID_COMMAND_RESET   0x82
 
#define HID_COMMAND_VERSION   0x81
 
#define HID_TYPE_READ   0x01
 
#define HID_TYPE_START   0x02
 
#define HID_TYPE_WRITE   0x00
 
#define PID   0xf139
 
#define PROGRAMMER_NOK_NACK   0x00
 
#define PROGRAMMER_OK_ACK   0x01
 
#define PROTOCOL_JTAG   0x00
 
#define PROTOCOL_SWD   0x01
 
#define SEQUENCE_JTAG_TO_SWD   0x01
 
#define SEQUENCE_LINE_RESET   0x00
 
#define SWD_MAX_BUFFER_LENGTH   300
 
#define VID   0x04b4
 

Functions

 COMMAND_HANDLER (kitprog_handle_acquire_psoc_command)
 
 COMMAND_HANDLER (kitprog_handle_info_command)
 
 COMMAND_HANDLER (kitprog_handle_init_acquire_psoc_command)
 
static int kitprog_acquire_psoc (uint8_t psoc_type, uint8_t acquire_mode, uint8_t max_attempts)
 
static int kitprog_generic_acquire (void)
 
static int kitprog_get_info (void)
 
static int kitprog_get_millivolts (void)
 
static int kitprog_get_status (void)
 
static int kitprog_get_usb_serial (void)
 
static int kitprog_get_version (void)
 
static int kitprog_hid_command (uint8_t *command, size_t command_length, uint8_t *data, size_t data_length)
 
static int kitprog_init (void)
 
static int kitprog_quit (void)
 
static int kitprog_reset (int trst, int srst)
 
static int kitprog_reset_target (void)
 
static int kitprog_set_protocol (uint8_t protocol)
 
static int kitprog_set_unknown (void)
 
static int kitprog_swd_init (void)
 
static void kitprog_swd_queue_cmd (uint8_t cmd, uint32_t *dst, uint32_t data)
 
static void kitprog_swd_read_reg (uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
 
static int kitprog_swd_run_queue (void)
 
static int kitprog_swd_seq (uint8_t seq_type)
 
static int kitprog_swd_switch_seq (enum swd_special_seq seq)
 
static int kitprog_swd_sync (void)
 
static void kitprog_swd_write_reg (uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
 
static void kitprog_usb_close (void)
 
static int kitprog_usb_open (void)
 
static int mm_to_version (uint8_t major, uint8_t minor)
 

Variables

struct adapter_driver kitprog_adapter_driver
 
static const struct command_registration kitprog_command_handlers []
 
static struct kitprogkitprog_handle
 
static bool kitprog_init_acquire_psoc
 
static const struct command_registration kitprog_subcommand_handlers []
 
static const struct swd_driver kitprog_swd
 
static const char *const kitprog_transports [] = { "swd", NULL }
 
static int pending_queue_len
 
static int pending_transfer_count
 
static struct pending_transfer_resultpending_transfers
 
static int queued_retval
 

Macro Definition Documentation

◆ ACQUIRE_MODE_POWER_CYCLE

#define ACQUIRE_MODE_POWER_CYCLE   0x01

Definition at line 64 of file kitprog.c.

◆ ACQUIRE_MODE_RESET

#define ACQUIRE_MODE_RESET   0x00

Definition at line 63 of file kitprog.c.

◆ BULK_EP_IN

#define BULK_EP_IN   1

Definition at line 40 of file kitprog.c.

◆ BULK_EP_OUT

#define BULK_EP_OUT   2

Definition at line 41 of file kitprog.c.

◆ CONTROL_COMMAND_PROGRAM

#define CONTROL_COMMAND_PROGRAM   0x07

Definition at line 46 of file kitprog.c.

◆ CONTROL_MODE_ACQUIRE_SWD_TARGET

#define CONTROL_MODE_ACQUIRE_SWD_TARGET   0x42

Definition at line 52 of file kitprog.c.

◆ CONTROL_MODE_POLL_PROGRAMMER_STATUS

#define CONTROL_MODE_POLL_PROGRAMMER_STATUS   0x01

Definition at line 48 of file kitprog.c.

◆ CONTROL_MODE_RESET_TARGET

#define CONTROL_MODE_RESET_TARGET   0x04

Definition at line 49 of file kitprog.c.

◆ CONTROL_MODE_SEND_SWD_SEQUENCE

#define CONTROL_MODE_SEND_SWD_SEQUENCE   0x43

Definition at line 53 of file kitprog.c.

◆ CONTROL_MODE_SET_PROGRAMMER_PROTOCOL

#define CONTROL_MODE_SET_PROGRAMMER_PROTOCOL   0x40

Definition at line 50 of file kitprog.c.

◆ CONTROL_MODE_SYNCHRONIZE_TRANSFER

#define CONTROL_MODE_SYNCHRONIZE_TRANSFER   0x41

Definition at line 51 of file kitprog.c.

◆ CONTROL_TYPE_READ

#define CONTROL_TYPE_READ   0x01

Definition at line 43 of file kitprog.c.

◆ CONTROL_TYPE_WRITE

#define CONTROL_TYPE_WRITE   0x02

Definition at line 44 of file kitprog.c.

◆ DEVICE_PSOC3

#define DEVICE_PSOC3   0x01

Definition at line 59 of file kitprog.c.

◆ DEVICE_PSOC4

#define DEVICE_PSOC4   0x00

Definition at line 58 of file kitprog.c.

◆ DEVICE_PSOC5

#define DEVICE_PSOC5   0x03

Definition at line 61 of file kitprog.c.

◆ DEVICE_UNKNOWN

#define DEVICE_UNKNOWN   0x02

Definition at line 60 of file kitprog.c.

◆ HID_COMMAND_BOOTLOADER

#define HID_COMMAND_BOOTLOADER   0xa0

Definition at line 80 of file kitprog.c.

◆ HID_COMMAND_CONFIGURE

#define HID_COMMAND_CONFIGURE   0x8f

Definition at line 79 of file kitprog.c.

◆ HID_COMMAND_POWER

#define HID_COMMAND_POWER   0x80

Definition at line 76 of file kitprog.c.

◆ HID_COMMAND_RESET

#define HID_COMMAND_RESET   0x82

Definition at line 78 of file kitprog.c.

◆ HID_COMMAND_VERSION

#define HID_COMMAND_VERSION   0x81

Definition at line 77 of file kitprog.c.

◆ HID_TYPE_READ

#define HID_TYPE_READ   0x01

Definition at line 73 of file kitprog.c.

◆ HID_TYPE_START

#define HID_TYPE_START   0x02

Definition at line 74 of file kitprog.c.

◆ HID_TYPE_WRITE

#define HID_TYPE_WRITE   0x00

Definition at line 72 of file kitprog.c.

◆ PID

#define PID   0xf139

Definition at line 38 of file kitprog.c.

◆ PROGRAMMER_NOK_NACK

#define PROGRAMMER_NOK_NACK   0x00

Definition at line 69 of file kitprog.c.

◆ PROGRAMMER_OK_ACK

#define PROGRAMMER_OK_ACK   0x01

Definition at line 70 of file kitprog.c.

◆ PROTOCOL_JTAG

#define PROTOCOL_JTAG   0x00

Definition at line 55 of file kitprog.c.

◆ PROTOCOL_SWD

#define PROTOCOL_SWD   0x01

Definition at line 56 of file kitprog.c.

◆ SEQUENCE_JTAG_TO_SWD

#define SEQUENCE_JTAG_TO_SWD   0x01

Definition at line 67 of file kitprog.c.

◆ SEQUENCE_LINE_RESET

#define SEQUENCE_LINE_RESET   0x00

Definition at line 66 of file kitprog.c.

◆ SWD_MAX_BUFFER_LENGTH

#define SWD_MAX_BUFFER_LENGTH   300

Definition at line 99 of file kitprog.c.

◆ VID

#define VID   0x04b4

Definition at line 37 of file kitprog.c.

Function Documentation

◆ COMMAND_HANDLER() [1/3]

COMMAND_HANDLER ( kitprog_handle_acquire_psoc_command  )

Definition at line 853 of file kitprog.c.

References kitprog_generic_acquire().

◆ COMMAND_HANDLER() [2/3]

COMMAND_HANDLER ( kitprog_handle_info_command  )

Definition at line 845 of file kitprog.c.

References kitprog_get_info().

◆ COMMAND_HANDLER() [3/3]

COMMAND_HANDLER ( kitprog_handle_init_acquire_psoc_command  )

Definition at line 860 of file kitprog.c.

References ERROR_OK, and kitprog_init_acquire_psoc.

◆ kitprog_acquire_psoc()

static int kitprog_acquire_psoc ( uint8_t  psoc_type,
uint8_t  acquire_mode,
uint8_t  max_attempts 
)
static

◆ kitprog_generic_acquire()

static int kitprog_generic_acquire ( void  )
static

◆ kitprog_get_info()

◆ kitprog_get_millivolts()

static int kitprog_get_millivolts ( void  )
static

◆ kitprog_get_status()

◆ kitprog_get_usb_serial()

static int kitprog_get_usb_serial ( void  )
static

Definition at line 244 of file kitprog.c.

References ERROR_FAIL, ERROR_OK, kitprog_handle, LOG_ERROR, kitprog::serial, and kitprog::usb_handle.

Referenced by kitprog_usb_open().

◆ kitprog_get_version()

static int kitprog_get_version ( void  )
static

◆ kitprog_hid_command()

static int kitprog_hid_command ( uint8_t *  command,
size_t  command_length,
uint8_t *  data,
size_t  data_length 
)
static

◆ kitprog_init()

◆ kitprog_quit()

static int kitprog_quit ( void  )
static

◆ kitprog_reset()

static int kitprog_reset ( int  trst,
int  srst 
)
static

Definition at line 820 of file kitprog.c.

References ERROR_FAIL, ERROR_OK, kitprog_reset_target(), and LOG_ERROR.

◆ kitprog_reset_target()

◆ kitprog_set_protocol()

◆ kitprog_set_unknown()

static int kitprog_set_unknown ( void  )
static

◆ kitprog_swd_init()

static int kitprog_swd_init ( void  )
static

Definition at line 627 of file kitprog.c.

References ERROR_OK.

◆ kitprog_swd_queue_cmd()

static void kitprog_swd_queue_cmd ( uint8_t  cmd,
uint32_t *  dst,
uint32_t  data 
)
static

◆ kitprog_swd_read_reg()

static void kitprog_swd_read_reg ( uint8_t  cmd,
uint32_t *  value,
uint32_t  ap_delay_clk 
)
static

Definition at line 638 of file kitprog.c.

References cmd, kitprog_swd_queue_cmd(), and SWD_CMD_RNW.

◆ kitprog_swd_run_queue()

◆ kitprog_swd_seq()

◆ kitprog_swd_switch_seq()

static int kitprog_swd_switch_seq ( enum swd_special_seq  seq)
static

◆ kitprog_swd_sync()

◆ kitprog_swd_write_reg()

static void kitprog_swd_write_reg ( uint8_t  cmd,
uint32_t  value,
uint32_t  ap_delay_clk 
)
static

Definition at line 632 of file kitprog.c.

References cmd, kitprog_swd_queue_cmd(), NULL, and SWD_CMD_RNW.

◆ kitprog_usb_close()

static void kitprog_usb_close ( void  )
static

Definition at line 317 of file kitprog.c.

References kitprog::hid_handle, jtag_libusb_close(), kitprog_handle, and kitprog::usb_handle.

Referenced by kitprog_quit().

◆ kitprog_usb_open()

static int kitprog_usb_open ( void  )
static

◆ mm_to_version()

static int mm_to_version ( uint8_t  major,
uint8_t  minor 
)
inlinestatic

Definition at line 155 of file kitprog.c.

Referenced by kitprog_init().

Variable Documentation

◆ kitprog_adapter_driver

struct adapter_driver kitprog_adapter_driver
Initial value:
= {
.name = "kitprog",
.transports = kitprog_transports,
.init = kitprog_init,
.quit = kitprog_quit,
.reset = kitprog_reset,
.swd_ops = &kitprog_swd,
}
static int kitprog_init(void)
Definition: kitprog.c:160
static const struct command_registration kitprog_command_handlers[]
Definition: kitprog.c:885
static const struct swd_driver kitprog_swd
Definition: kitprog.c:903
static const char *const kitprog_transports[]
Definition: kitprog.c:911
static int kitprog_reset(int trst, int srst)
Definition: kitprog.c:820
static int kitprog_quit(void)
Definition: kitprog.c:230

Definition at line 911 of file kitprog.c.

◆ kitprog_command_handlers

const struct command_registration kitprog_command_handlers[]
static
Initial value:
= {
{
.name = "kitprog",
.mode = COMMAND_ANY,
.help = "perform KitProg management",
.usage = "<cmd>",
},
{
.name = "kitprog_init_acquire_psoc",
.handler = &kitprog_handle_init_acquire_psoc_command,
.mode = COMMAND_CONFIG,
.help = "try to acquire a PSoC during init",
.usage = "",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
static const struct command_registration kitprog_subcommand_handlers[]
Definition: kitprog.c:867
const char * name
Definition: command.h:229

Definition at line 860 of file kitprog.c.

◆ kitprog_handle

◆ kitprog_init_acquire_psoc

bool kitprog_init_acquire_psoc
static

Definition at line 122 of file kitprog.c.

Referenced by COMMAND_HANDLER(), and kitprog_init().

◆ kitprog_subcommand_handlers

const struct command_registration kitprog_subcommand_handlers[]
static
Initial value:
= {
{
.name = "info",
.handler = &kitprog_handle_info_command,
.mode = COMMAND_EXEC,
.usage = "",
.help = "show KitProg info",
},
{
.name = "acquire_psoc",
.handler = &kitprog_handle_acquire_psoc_command,
.mode = COMMAND_EXEC,
.usage = "",
.help = "try to acquire a PSoC",
},
}
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 860 of file kitprog.c.

◆ kitprog_swd

const struct swd_driver kitprog_swd
static
Initial value:
= {
.switch_seq = kitprog_swd_switch_seq,
.read_reg = kitprog_swd_read_reg,
.write_reg = kitprog_swd_write_reg,
}
static int kitprog_swd_switch_seq(enum swd_special_seq seq)
Definition: kitprog.c:646
static void kitprog_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
Definition: kitprog.c:638
static void kitprog_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
Definition: kitprog.c:632
static int kitprog_swd_init(void)
Definition: kitprog.c:627
static int kitprog_swd_run_queue(void)
Definition: kitprog.c:673

Definition at line 860 of file kitprog.c.

◆ kitprog_transports

const char* const kitprog_transports[] = { "swd", NULL }
static

Definition at line 911 of file kitprog.c.

◆ pending_queue_len

int pending_queue_len
static

Definition at line 124 of file kitprog.c.

Referenced by kitprog_init(), and kitprog_swd_queue_cmd().

◆ pending_transfer_count

int pending_transfer_count
static

Definition at line 124 of file kitprog.c.

Referenced by kitprog_swd_queue_cmd(), and kitprog_swd_run_queue().

◆ pending_transfers

struct pending_transfer_result* pending_transfers
static

◆ queued_retval

int queued_retval
static

Definition at line 127 of file kitprog.c.

Referenced by kitprog_swd_queue_cmd(), and kitprog_swd_run_queue().