Add support for preamble/trailer before starting real data transmission: this give...
authorbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 9 Oct 2009 21:48:32 +0000 (21:48 +0000)
committerbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 9 Oct 2009 21:48:32 +0000 (21:48 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3053 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/cfg/cfg_afsk.h
bertos/net/afsk.c

index 791916d2c017eaef226d1a16a777dd419238d6a5..f5a27e428944bffb9885fc087405e83f975a08f6 100644 (file)
@@ -62,7 +62,7 @@
  * $WIZ$ type = "int"
  * $WIZ$ min = 2
  */
-#define CONFIG_AFSK_TX_BUFLEN 256
+#define CONFIG_AFSK_TX_BUFLEN 32
 
 /**
  * AFSK DAC sample rate for modem outout.
  */
 #define CONFIG_AFSK_RXTIMEOUT 0
 
+
+/**
+ * AFSK Preamble length in [ms], before starting transmissions.
+ * $WIZ$ type = "int"
+ * $WIZ$ min = 1
+ */
+#define CONFIG_AFSK_PREAMBLE_LEN 300UL
+
+
+
+/**
+ * AFSK Trailer length in [ms], before stopping transmissions.
+ * $WIZ$ type = "int"
+ * $WIZ$ min = 1
+ */
+#define CONFIG_AFSK_TRAILER_LEN 50UL
+
 #endif /* CFG_AFSK_H */
index d2291262858cefe7d7d68f3a395ac01b8a85792d..e516a3f32b854bf23d813ebcc70600afd1eca34d 100644 (file)
@@ -164,6 +164,9 @@ static uint8_t hdlc_bit_idx;
 #define BIT_DIFFER(bitline1, bitline2) (((bitline1) ^ (bitline2)) & 0x01)
 #define EDGE_FOUND(bitline)            BIT_DIFFER((bitline), (bitline) >> 1)
 
+static uint16_t preamble_len;
+static uint16_t trailer_len;
+
 static void hdlc_parse(bool bit)
 {
        demod_bits <<= 1;
@@ -342,8 +345,10 @@ static void afsk_txStart(void)
                phase_acc = 0;
                stuff_cnt = 0;
                sending = true;
+               preamble_len = DIV_ROUND(CONFIG_AFSK_PREAMBLE_LEN * BITRATE, 8000);
                AFSK_DAC_IRQ_START();
        }
+       ATOMIC(trailer_len  = DIV_ROUND(CONFIG_AFSK_TRAILER_LEN  * BITRATE, 8000));
 }
 
 #define BIT_STUFF_LEN 5
@@ -358,7 +363,7 @@ DEFINE_AFSK_DAC_ISR()
                if (tx_bit == 0)
                {
                        /* We have just finished transimitting a char, get a new one. */
-                       if (fifo_isempty(&tx_fifo))
+                       if (fifo_isempty(&tx_fifo) && trailer_len == 0)
                        {
                                AFSK_DAC_IRQ_STOP();
                                sending = false;
@@ -375,7 +380,25 @@ DEFINE_AFSK_DAC_ISR()
                                        stuff_cnt = 0;
 
                                bit_stuff = true;
-                               curr_out = fifo_pop(&tx_fifo);
+
+                               /*
+                                * Handle preamble and trailer
+                                */
+                               if (preamble_len == 0)
+                               {
+                                       if (fifo_isempty(&tx_fifo))
+                                       {
+                                               trailer_len--;
+                                               curr_out = HDLC_FLAG;
+                                       }
+                                       else
+                                               curr_out = fifo_pop(&tx_fifo);
+                               }
+                               else
+                               {
+                                       preamble_len--;
+                                       curr_out = HDLC_FLAG;
+                               }
 
                                /* Handle char escape */
                                if (curr_out == AX25_ESC)