src/hp34comm.cpp

changeset 8
55021f3f1929
parent 5
f1c85c2500f2
child 9
e5254c6aa0c8
--- a/src/hp34comm.cpp	Fri Sep 23 21:12:43 2016 +0200
+++ b/src/hp34comm.cpp	Tue Oct 11 00:14:20 2016 +0200
@@ -4,23 +4,22 @@
 
 /***** HP 34970A communication class ***/
 
-#define HP_SERIAL_TX PC_7 // serial6 RX
-#define HP_SERIAL_RX PA_1 // serial4 RX
-
-#ifdef DEBUG
+#ifdef DEBUG2
 
-DigitalOut inrx(PC_0);
-DigitalOut intx(PC_1);
-DigitalOut ack(PC_3);
-DigitalOut staterx(PC_2);
-DigitalOut statetx(PH_1);
+DigitalOut inrx(D9);
+DigitalOut intx(D5);
+DigitalOut ack(D6);
+DigitalOut staterx(D7);
+DigitalOut statetx(D8);
 
 #endif
 
+DigitalOut lled(LED1);
   
-HPSerial::HPSerial():
-  ncmd(0),
-  serial_tx(NC, HP_SERIAL_TX), serial_rx(NC, HP_SERIAL_RX) {
+HPSerial::HPSerial(PinName rx, PinName tx):
+  serial_tx(A7, tx),
+  serial_rx(NC, rx),
+  ncmd(0) {
   
   //pc.printf("HPSerial init\n");
 
@@ -84,7 +83,7 @@
 	if (val == 0x99)
 	  {
 	    tx_ack = true;
-#ifdef DEBUG
+#ifdef DEBUG2
 	    ack = 1;
 	    wait_us(2);
 	    ack = 0;
@@ -97,7 +96,7 @@
 	if (val == 0x00)
 	  {
 	    tx_ack = true;
-#ifdef DEBUG
+#ifdef DEBUG2
 	    ack = 1;
 	    wait_us(2);
 	    ack = 0;
@@ -150,7 +149,7 @@
     }
     else { // end of payload, manage sent content
       uint8_t cur_state = tx_state;
-      pushCmd(tx_state, tx_cmd, head, buf); 
+      pushCmd((TrState)tx_state, tx_cmd, head, (char*)buf); 
       
       switch(val) {
       case 0x66: // a new transmisson
@@ -171,24 +170,25 @@
 
 
 void HPSerial::setstatedbg(void) {
-  /*
+#ifdef DEBUG2
     if (tx_state == Rx)
-    staterx = 1;
+      staterx = 1;
     else
-    staterx = 0;
+      staterx = 0;
     if (tx_state == Tx)
-    statetx = 1;
+      statetx = 1;
     else
-    statetx = 0;
-  */
+      statetx = 0;
+#endif
 }
 
 void HPSerial::rxIrq(void) {
   uint8_t val;
   if(serial_rx.readable()) { // no reason why we would end here without this condition, but hey
-#ifdef DEBUG
+#ifdef DEBUG2
     inrx=1;
 #endif
+  lled = 1;
     val = serial_rx.getc();
     
     timeouter.attach(this, &HPSerial::timeout, 0.001); // if nothing else happen in the next ms, reset
@@ -200,15 +200,16 @@
 	tx_ack = false;
 	setstatedbg();
       }
-      else
+      else {
 	reset(4);
-    
+      }
     else if (tx_state == Tx)  // manage the acks
       handleAck(val);
     
     else 
       handleChar(val);
-#ifdef DEBUG
+  lled = 0;
+#ifdef DEBUG2
     inrx=0;
 #endif
   }
@@ -217,7 +218,7 @@
 void HPSerial::txIrq(void) {
   uint8_t val;
   if(serial_tx.readable()) { // no reason why we would end here without this condition, but hey
-#ifdef DEBUG
+#ifdef DEBUG2
     intx=1;
 #endif
     val = serial_tx.getc();
@@ -231,8 +232,9 @@
 	tx_ack = false;
 	setstatedbg();
       }
-      else
+      else {
 	reset(5);
+      }
     
     else if (tx_state == Rx)  // manage the acks
       handleAck(val);
@@ -240,7 +242,7 @@
     else 
       handleChar(val);
   }
-#ifdef DEBUG
+#ifdef DEBUG2
   intx=0;
 #endif
 }

mercurial