cmsisDAP: send disconnect after use
This commit is contained in:
parent
dd4e3e40df
commit
6a4d24cf7a
|
|
@ -32,6 +32,7 @@ enum datalink_cmd {
|
||||||
DAP_HOSTSTATUS = 0x01,
|
DAP_HOSTSTATUS = 0x01,
|
||||||
DAP_CONNECT = 0x02, // Connect to device and select mode
|
DAP_CONNECT = 0x02, // Connect to device and select mode
|
||||||
DAP_DISCONNECT = 0x03, // Disconnect to device
|
DAP_DISCONNECT = 0x03, // Disconnect to device
|
||||||
|
DAP_RESETTARGET = 0x0A, // reset the target
|
||||||
DAP_SWJ_CLK = 0x11, // Select maximum frequency
|
DAP_SWJ_CLK = 0x11, // Select maximum frequency
|
||||||
DAP_SWJ_SEQUENCE = 0x12, // Generate TMS sequence
|
DAP_SWJ_SEQUENCE = 0x12, // Generate TMS sequence
|
||||||
DAP_JTAG_SEQUENCE = 0x14 // Generate TMS, TDI and capture TDO Sequence
|
DAP_JTAG_SEQUENCE = 0x14 // Generate TMS, TDI and capture TDO Sequence
|
||||||
|
|
@ -89,7 +90,7 @@ enum cmsisdap_status {
|
||||||
|
|
||||||
CmsisDAP::CmsisDAP(int vid, int pid, bool verbose):_verbose(verbose),
|
CmsisDAP::CmsisDAP(int vid, int pid, bool verbose):_verbose(verbose),
|
||||||
_device_idx(0), _vid(vid), _pid(pid),
|
_device_idx(0), _vid(vid), _pid(pid),
|
||||||
_serial_number(L""), _dev(NULL), _num_tms(0)
|
_serial_number(L""), _dev(NULL), _num_tms(0), _is_connect(false)
|
||||||
{
|
{
|
||||||
std::vector<struct hid_device_info *> dev_found;
|
std::vector<struct hid_device_info *> dev_found;
|
||||||
_ll_buffer = (unsigned char *)malloc(sizeof(unsigned char) * 65);
|
_ll_buffer = (unsigned char *)malloc(sizeof(unsigned char) * 65);
|
||||||
|
|
@ -200,6 +201,8 @@ CmsisDAP::~CmsisDAP()
|
||||||
/* TODO: disconnect device
|
/* TODO: disconnect device
|
||||||
* close device
|
* close device
|
||||||
*/
|
*/
|
||||||
|
if (_is_connect)
|
||||||
|
dapDisconnect();
|
||||||
if (_ll_buffer)
|
if (_ll_buffer)
|
||||||
free(_ll_buffer);
|
free(_ll_buffer);
|
||||||
}
|
}
|
||||||
|
|
@ -209,6 +212,8 @@ CmsisDAP::~CmsisDAP()
|
||||||
*/
|
*/
|
||||||
int CmsisDAP::dapConnect()
|
int CmsisDAP::dapConnect()
|
||||||
{
|
{
|
||||||
|
if (_is_connect)
|
||||||
|
return 1;
|
||||||
_ll_buffer[1] = DAP_CONNECT;
|
_ll_buffer[1] = DAP_CONNECT;
|
||||||
_ll_buffer[2] = DAP_CONNECT_JTAG;
|
_ll_buffer[2] = DAP_CONNECT_JTAG;
|
||||||
uint8_t response[2];
|
uint8_t response[2];
|
||||||
|
|
@ -217,6 +222,30 @@ int CmsisDAP::dapConnect()
|
||||||
return ret;
|
return ret;
|
||||||
if (response[0] != DAP_CONNECT || response[1] != DAP_CONNECT_JTAG)
|
if (response[0] != DAP_CONNECT || response[1] != DAP_CONNECT_JTAG)
|
||||||
return 0;
|
return 0;
|
||||||
|
_is_connect = true;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send disconnect instruction (0x03)
|
||||||
|
*/
|
||||||
|
int CmsisDAP::dapDisconnect()
|
||||||
|
{
|
||||||
|
if (!_is_connect)
|
||||||
|
return 1;
|
||||||
|
int ret = xfer(DAP_DISCONNECT, NULL, 0);
|
||||||
|
if (ret <= 0)
|
||||||
|
return ret;
|
||||||
|
_is_connect = false;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* send resetTarget instruction (0x0A)
|
||||||
|
*/
|
||||||
|
int CmsisDAP::dapResetTarget()
|
||||||
|
{
|
||||||
|
int ret = xfer(DAP_RESETTARGET, NULL, 0);
|
||||||
|
if (ret <= 0)
|
||||||
|
return ret;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,13 @@ class CmsisDAP: public JtagInterface {
|
||||||
* \return 1 if success <= 0 otherwhise
|
* \return 1 if success <= 0 otherwhise
|
||||||
*/
|
*/
|
||||||
int dapConnect();
|
int dapConnect();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief disconnect device
|
||||||
|
* \return 1 if success <= 0 otherwhise
|
||||||
|
*/
|
||||||
|
int dapDisconnect();
|
||||||
|
int dapResetTarget();
|
||||||
int read_info(uint8_t info, uint8_t *rd_info, int max_len);
|
int read_info(uint8_t info, uint8_t *rd_info, int max_len);
|
||||||
int xfer(int tx_len, uint8_t *rx_buff, int rx_len);
|
int xfer(int tx_len, uint8_t *rx_buff, int rx_len);
|
||||||
int xfer(uint8_t instruction, int tx_len,
|
int xfer(uint8_t instruction, int tx_len,
|
||||||
|
|
@ -100,6 +107,7 @@ class CmsisDAP: public JtagInterface {
|
||||||
unsigned char *_ll_buffer; /**< message buffer */
|
unsigned char *_ll_buffer; /**< message buffer */
|
||||||
unsigned char *_buffer; /**< subset of _ll_buffer */
|
unsigned char *_buffer; /**< subset of _ll_buffer */
|
||||||
int _num_tms; /**< current tms length */
|
int _num_tms; /**< current tms length */
|
||||||
|
int _is_connect; /**< device status ((dis)connected) */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SRC_CMSISDAP_HPP_
|
#endif // SRC_CMSISDAP_HPP_
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue