Add trigger test code.

This commit is contained in:
Nathan Conrad 2019-09-19 16:43:59 -04:00
parent 0548f97d33
commit 0f1435177b
2 changed files with 36 additions and 11 deletions

View File

@ -65,6 +65,12 @@ usbtmcd_app_capabilities =
}
#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,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;
@ -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) {
(void)rhport;
(void)msg;
// Let trigger set the SRQ
status |= IEEE4882_STB_SRQ;
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))
{
queryState = 0;
resp_delay = atoi((char*)data + 5);
if(resp_delay > 10000u)
resp_delay = 10000u;
int d = atoi((char*)data + 5);
if(d > 10000)
d = 10000;
if(d<0)
d=0;
resp_delay = (uint32_t)d;
}
return true;
}
@ -135,7 +146,7 @@ bool usbtmcd_app_msgBulkIn_complete(uint8_t rhport)
{
(void)rhport;
status &= (uint8_t)~(0x50u); // clear MAV and SRQ
status &= (uint8_t)~(IEEE4882_STB_MAV); // clear MAV
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)
{
(void)rhport;
(void)rsp;
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)
{
(void)rhport;
(void)rsp;
return true;
}
@ -266,7 +280,7 @@ uint8_t usbtmcd_app_get_stb(uint8_t rhport, uint8_t *tmcResult)
{
(void)rhport;
uint8_t old_status = status;
status = status & ~(0x40u); // clear SRQ
status = (uint8_t)(status & ~(IEEE4882_STB_SRQ)); // clear SRQ
*tmcResult = USBTMC_STATUS_SUCCESS;
// Increment status so that we see different results on each read...

View File

@ -22,6 +22,16 @@ def test_echo(m,n):
assert(xt == y), f"failed i={i}"
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():
assert (inst.read_stb() == 0)
inst.write("123")
@ -65,9 +75,6 @@ inst.clear()
#print("+ IDN")
#test_idn()
print("+ random trigger")
#inst.assert_trigger();
print("+ echo delay=0")
inst.write("delay 0")
test_echo(1,175)
@ -76,15 +83,19 @@ print("+ echo delay=2")
inst.write("delay 2")
test_echo(1,175)
print("+ echo delay=200")
inst.write("delay 200")
test_echo(50,90)
print("+ echo delay=150")
inst.write("delay 150")
test_echo(53,76)
test_echo(165,170)
print("+ MAV")
test_mav()
print("+ SRQ")
test_srq()
print("+ TRIG")
test_trig()
inst.close()
print("Test complete")