From 2a398044dd1d7b2af34a96c19ad378c25b546579 Mon Sep 17 00:00:00 2001 From: batt Date: Sat, 10 Oct 2009 12:33:12 +0000 Subject: [PATCH] Handle rx fifo overflow error. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3067 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/net/afsk.c | 46 ++++++++++++++++++++++++++++++++++-------- bertos/net/afsk.h | 10 +++++++++ bertos/net/afsk_test.c | 1 - 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/bertos/net/afsk.c b/bertos/net/afsk.c index 1c01c339..01b43474 100644 --- a/bertos/net/afsk.c +++ b/bertos/net/afsk.c @@ -120,8 +120,10 @@ INLINE uint8_t sin_sample(uint16_t idx) #define EDGE_FOUND(bitline) BIT_DIFFER((bitline), (bitline) >> 1) -static void hdlc_parse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) +static bool hdlc_parse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) { + bool ret = true; + hdlc->demod_bits <<= 1; hdlc->demod_bits |= bit ? 1 : 0; @@ -134,26 +136,29 @@ static void hdlc_parse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) hdlc->rxstart = true; } else + { + ret = false; hdlc->rxstart = false; + } hdlc->currchar = 0; hdlc->bit_idx = 0; - return; + return ret; } /* Reset */ if ((hdlc->demod_bits & HDLC_RESET) == HDLC_RESET) { hdlc->rxstart = false; - return; + return ret; } if (!hdlc->rxstart) - return; + return ret; /* Stuffed bit */ if ((hdlc->demod_bits & 0x3f) == 0x3e) - return; + return ret; if (hdlc->demod_bits & 0x01) hdlc->currchar |= 0x80; @@ -167,20 +172,27 @@ static void hdlc_parse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) if (!fifo_isfull(fifo)) fifo_push(fifo, AX25_ESC); else + { hdlc->rxstart = false; + ret = false; + } } if (!fifo_isfull(fifo)) fifo_push(fifo, hdlc->currchar); else + { hdlc->rxstart = false; + ret = false; + } hdlc->currchar = 0; hdlc->bit_idx = 0; - return; } + else + hdlc->currchar >>= 1; - hdlc->currchar >>= 1; + return ret; } @@ -288,7 +300,8 @@ void afsk_adc_isr(Afsk *af, int8_t curr_sample) * NRZI coding: if 2 consecutive bits have the same value * a 1 is received, otherwise it's a 0. */ - hdlc_parse(&af->hdlc, !EDGE_FOUND(af->found_bits), &af->rx_fifo); + if (!hdlc_parse(&af->hdlc, !EDGE_FOUND(af->found_bits), &af->rx_fifo)) + af->status |= AFSK_RXFIFO_OVERRUN; } @@ -491,6 +504,21 @@ static int afsk_flush(KFile *fd) return 0; } +static int afsk_error(KFile *fd) +{ + Afsk *af = AFSK_CAST(fd); + int err; + + ATOMIC(err = af->status); + return err; +} + +static void afsk_clearerr(KFile *fd) +{ + Afsk *af = AFSK_CAST(fd); + ATOMIC(af->status = 0); +} + /** * Initialize an AFSK1200 modem. @@ -525,5 +553,7 @@ void afsk_init(Afsk *af, int adc_ch, int dac_ch) af->fd.write = afsk_write; af->fd.read = afsk_read; af->fd.flush = afsk_flush; + af->fd.error = afsk_error; + af->fd.clearerr = afsk_clearerr; af->phase_inc = MARK_INC; } diff --git a/bertos/net/afsk.h b/bertos/net/afsk.h index 020b2f96..5f75b3e3 100644 --- a/bertos/net/afsk.h +++ b/bertos/net/afsk.h @@ -81,6 +81,10 @@ typedef struct Hdlc bool rxstart; ///< True if an HDLC_FLAG char has been found in the bitstream. } Hdlc; +/** + * RX FIFO buffer full error. + */ +#define AFSK_RXFIFO_OVERRUN BV(0) /** * AFSK1200 modem context. @@ -165,6 +169,12 @@ typedef struct Afsk /** True while modem sends data */ volatile bool sending; + /** + * AFSK modem status. + * If 0 all is ok, otherwise errors are present. + */ + volatile int status; + /** Hdlc context */ Hdlc hdlc; diff --git a/bertos/net/afsk_test.c b/bertos/net/afsk_test.c index 54e22fd0..7ce7b4c6 100644 --- a/bertos/net/afsk_test.c +++ b/bertos/net/afsk_test.c @@ -147,7 +147,6 @@ int afsk_testSetup(void) timer_init(); afsk_init(&afsk_fd, 0 ,0); - afsk_fd.fd.error = kfile_genericClose; ax25_init(&ax25, &afsk_fd.fd, message_hook); return 0; } -- 2.25.1