summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorNathan Conrad <[email protected]>2019-09-19 16:43:59 -0400
committerNathan Conrad <[email protected]>2019-09-19 19:00:02 -0400
commit0f1435177b15b739188d08d08563e02e1bf2edde (patch)
tree6d7f44b5a4bb8965c1e45b519a9d76dea7189bda /examples
parent0548f97d3300edb4d57f6920f6307211833917f2 (diff)
Add trigger test code.
Diffstat (limited to 'examples')
-rw-r--r--examples/device/usbtmc/src/usbtmc_app.c24
-rw-r--r--examples/device/usbtmc/visaQuery.py23
2 files changed, 36 insertions, 11 deletions
diff --git a/examples/device/usbtmc/src/usbtmc_app.c b/examples/device/usbtmc/src/usbtmc_app.c
index 8ce468561..ea6e6aa6f 100644
--- a/examples/device/usbtmc/src/usbtmc_app.c
+++ b/examples/device/usbtmc/src/usbtmc_app.c
@@ -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...
diff --git a/examples/device/usbtmc/visaQuery.py b/examples/device/usbtmc/visaQuery.py
index 2034e6ff7..9610cbc8f 100644
--- a/examples/device/usbtmc/visaQuery.py
+++ b/examples/device/usbtmc/visaQuery.py
@@ -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")