mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-22 06:40:58 +00:00
Add trigger test code.
This commit is contained in:
parent
0548f97d33
commit
0f1435177b
@ -65,6 +65,12 @@ usbtmcd_app_capabilities =
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define IEEE4882_STB_QUESTIONABLE (0x08u)
|
||||||
|
#define IEEE4882_STB_MAV (0x10u)
|
||||||
|
#define IEEE4882_STB_SER (0x20u)
|
||||||
|
#define IEEE4882_STB_SRQ (0x40u)
|
||||||
|
|
||||||
static const char idn[] = "TinyUSB,ModelNumber,SerialNumber,FirmwareVer123456\r\n";
|
static const char idn[] = "TinyUSB,ModelNumber,SerialNumber,FirmwareVer123456\r\n";
|
||||||
//static const char idn[] = "TinyUSB,ModelNumber,SerialNumber,FirmwareVer and a bunch of other text to make it longer than a packet, perhaps? lets make it three transfers...\n";
|
//static const char idn[] = "TinyUSB,ModelNumber,SerialNumber,FirmwareVer and a bunch of other text to make it longer than a packet, perhaps? lets make it three transfers...\n";
|
||||||
static volatile uint8_t status;
|
static volatile uint8_t status;
|
||||||
@ -92,6 +98,8 @@ static usbtmc_msg_dev_dep_msg_in_header_t rspMsg = {
|
|||||||
bool usbtmcd_app_msg_trigger(uint8_t rhport, usbtmc_msg_generic_t* msg) {
|
bool usbtmcd_app_msg_trigger(uint8_t rhport, usbtmc_msg_generic_t* msg) {
|
||||||
(void)rhport;
|
(void)rhport;
|
||||||
(void)msg;
|
(void)msg;
|
||||||
|
// Let trigger set the SRQ
|
||||||
|
status |= IEEE4882_STB_SRQ;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,9 +132,12 @@ bool usbtmcd_app_msg_data(uint8_t rhport, void *data, size_t len, bool transfer_
|
|||||||
if(transfer_complete && !strncasecmp("delay ",data,5))
|
if(transfer_complete && !strncasecmp("delay ",data,5))
|
||||||
{
|
{
|
||||||
queryState = 0;
|
queryState = 0;
|
||||||
resp_delay = atoi((char*)data + 5);
|
int d = atoi((char*)data + 5);
|
||||||
if(resp_delay > 10000u)
|
if(d > 10000)
|
||||||
resp_delay = 10000u;
|
d = 10000;
|
||||||
|
if(d<0)
|
||||||
|
d=0;
|
||||||
|
resp_delay = (uint32_t)d;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -135,7 +146,7 @@ bool usbtmcd_app_msgBulkIn_complete(uint8_t rhport)
|
|||||||
{
|
{
|
||||||
(void)rhport;
|
(void)rhport;
|
||||||
|
|
||||||
status &= (uint8_t)~(0x50u); // clear MAV and SRQ
|
status &= (uint8_t)~(IEEE4882_STB_MAV); // clear MAV
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -237,6 +248,7 @@ bool usbtmcd_app_initiate_abort_bulk_in(uint8_t rhport, uint8_t *tmcResult)
|
|||||||
bool usbtmcd_app_check_abort_bulk_in(uint8_t rhport, usbtmc_check_abort_bulk_rsp_t *rsp)
|
bool usbtmcd_app_check_abort_bulk_in(uint8_t rhport, usbtmc_check_abort_bulk_rsp_t *rsp)
|
||||||
{
|
{
|
||||||
(void)rhport;
|
(void)rhport;
|
||||||
|
(void)rsp;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,6 +261,8 @@ bool usbtmcd_app_initiate_abort_bulk_out(uint8_t rhport, uint8_t *tmcResult)
|
|||||||
}
|
}
|
||||||
bool usbtmcd_app_check_abort_bulk_out(uint8_t rhport, usbtmc_check_abort_bulk_rsp_t *rsp)
|
bool usbtmcd_app_check_abort_bulk_out(uint8_t rhport, usbtmc_check_abort_bulk_rsp_t *rsp)
|
||||||
{
|
{
|
||||||
|
(void)rhport;
|
||||||
|
(void)rsp;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +280,7 @@ uint8_t usbtmcd_app_get_stb(uint8_t rhport, uint8_t *tmcResult)
|
|||||||
{
|
{
|
||||||
(void)rhport;
|
(void)rhport;
|
||||||
uint8_t old_status = status;
|
uint8_t old_status = status;
|
||||||
status = status & ~(0x40u); // clear SRQ
|
status = (uint8_t)(status & ~(IEEE4882_STB_SRQ)); // clear SRQ
|
||||||
|
|
||||||
*tmcResult = USBTMC_STATUS_SUCCESS;
|
*tmcResult = USBTMC_STATUS_SUCCESS;
|
||||||
// Increment status so that we see different results on each read...
|
// Increment status so that we see different results on each read...
|
||||||
|
@ -22,6 +22,16 @@ def test_echo(m,n):
|
|||||||
assert(xt == y), f"failed i={i}"
|
assert(xt == y), f"failed i={i}"
|
||||||
inst.read_stb();# Just to make USB logging easier by sending a control query
|
inst.read_stb();# Just to make USB logging easier by sending a control query
|
||||||
|
|
||||||
|
def test_trig():
|
||||||
|
# clear SRQ
|
||||||
|
inst.read_stb()
|
||||||
|
assert (inst.read_stb() == 0)
|
||||||
|
inst.assert_trigger()
|
||||||
|
time.sleep(0.3) # SRQ may have some delay
|
||||||
|
assert (inst.read_stb() & 0x40), "SRQ not set after 0.3 seconds"
|
||||||
|
assert (inst.read_stb() == 0)
|
||||||
|
|
||||||
|
|
||||||
def test_mav():
|
def test_mav():
|
||||||
assert (inst.read_stb() == 0)
|
assert (inst.read_stb() == 0)
|
||||||
inst.write("123")
|
inst.write("123")
|
||||||
@ -65,9 +75,6 @@ inst.clear()
|
|||||||
#print("+ IDN")
|
#print("+ IDN")
|
||||||
#test_idn()
|
#test_idn()
|
||||||
|
|
||||||
print("+ random trigger")
|
|
||||||
#inst.assert_trigger();
|
|
||||||
|
|
||||||
print("+ echo delay=0")
|
print("+ echo delay=0")
|
||||||
inst.write("delay 0")
|
inst.write("delay 0")
|
||||||
test_echo(1,175)
|
test_echo(1,175)
|
||||||
@ -76,15 +83,19 @@ print("+ echo delay=2")
|
|||||||
inst.write("delay 2")
|
inst.write("delay 2")
|
||||||
test_echo(1,175)
|
test_echo(1,175)
|
||||||
|
|
||||||
print("+ echo delay=200")
|
print("+ echo delay=150")
|
||||||
inst.write("delay 200")
|
inst.write("delay 150")
|
||||||
test_echo(50,90)
|
test_echo(53,76)
|
||||||
test_echo(165,170)
|
test_echo(165,170)
|
||||||
|
|
||||||
print("+ MAV")
|
print("+ MAV")
|
||||||
test_mav()
|
test_mav()
|
||||||
|
|
||||||
print("+ SRQ")
|
print("+ SRQ")
|
||||||
test_srq()
|
test_srq()
|
||||||
|
|
||||||
|
print("+ TRIG")
|
||||||
|
test_trig()
|
||||||
|
|
||||||
inst.close()
|
inst.close()
|
||||||
print("Test complete")
|
print("Test complete")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user