From 50f11f6645072e2cf321641dbae42c356c1a4422 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 4 Apr 2014 08:45:27 +0200 Subject: [PATCH] Reworked KFile read --- Modem/afsk.c | 26 +++++++++++++------------- Modem/afsk.h | 27 +++++++++++++++++++++------ buildrev.h | 2 +- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/Modem/afsk.c b/Modem/afsk.c index 8656c86..f8a71bc 100644 --- a/Modem/afsk.c +++ b/Modem/afsk.c @@ -313,18 +313,19 @@ uint8_t afsk_dac_isr(Afsk *afsk) { } - ////////////////////////////////////////////////////// // File operation overwrites for read/write // +// These functions make the "class" act like a file // +// pointer, which can be read from or written to. // +// Handy for sending and receiving data :) // ////////////////////////////////////////////////////// -static size_t afsk_read(KFile *fd, void *_buf, size_t size) -{ - Afsk *af = AFSK_CAST(fd); - uint8_t *buf = (uint8_t *)_buf; +static size_t afsk_read(KFile *fd, void *_buf, size_t size) { + Afsk *afsk = AFSK_CAST(fd); + uint8_t *buffer = (uint8_t *)_buf; #if CONFIG_AFSK_RXTIMEOUT == 0 - while (size-- && !fifo_isempty_locked(&af->rxFifo)) + while (size-- && !fifo_isempty_locked(&afsk->rxFifo)) #else while (size--) #endif @@ -333,19 +334,18 @@ static size_t afsk_read(KFile *fd, void *_buf, size_t size) ticks_t start = timer_clock(); #endif - while (fifo_isempty_locked(&af->rxFifo)) - { + while (fifo_isempty_locked(&afsk->rxFifo)) { cpu_relax(); #if CONFIG_AFSK_RXTIMEOUT != -1 - if (timer_clock() - start > ms_to_ticks(CONFIG_AFSK_RXTIMEOUT)) - return buf - (uint8_t *)_buf; + if (timer_clock() - start > ms_to_ticks(CONFIG_AFSK_RXTIMEOUT)) { + return buffer - (uint8_t *)_buf; + } #endif } - - *buf++ = fifo_pop_locked(&af->rxFifo); + *buffer++ = fifo_pop_locked(&afsk->rxFifo); } - return buf - (uint8_t *)_buf; + return buffer - (uint8_t *)_buf; } static size_t afsk_write(KFile *fd, const void *_buf, size_t size) diff --git a/Modem/afsk.h b/Modem/afsk.h index 2f8acd0..9801d51 100644 --- a/Modem/afsk.h +++ b/Modem/afsk.h @@ -71,21 +71,36 @@ typedef struct Afsk } Afsk; +// Explanation nessecary for this. BertOS uses an +// object-oriented approach for handling "file-like" +// transactions (yes, we are using C :P). What we are +// doing here is defining a specific "file type" for +// the standard KFile to identify the modem as a "file" +// that can be read from and written to. #define KFT_AFSK MAKE_ID('F', 'S', 'K', 'M') -INLINE Afsk *AFSK_CAST(KFile *fd) -{ +// We then make a macro that can "typecast" a generic +// KFile file-pointer to an Afsk "object". This lets +// other pieces of code read from and write to the AFSK +// "objects" buffers with the standard KFile operations. +// If this seems weird and confusing, check out the +// BertOS KFile explanation at: +// http://www.bertos.org/use/tutorial-front-page/drivers-kfile-interface +INLINE Afsk *AFSK_CAST(KFile *fd) { + // We need to assert that the what we are trying + // to read/write is actually an AFSK "object", + // identified by the KFT_AFSK constant ASSERT(fd->_type == KFT_AFSK); return (Afsk *)fd; } - +// Declare ISRs and initialization functions void afsk_adc_isr(Afsk *af, int8_t sample); uint8_t afsk_dac_isr(Afsk *af); void afsk_init(Afsk *af, int adc_ch, int dac_ch); -int afsk_testSetup(void); -int afsk_testRun(void); -int afsk_testTearDown(void); +//int afsk_testSetup(void); +//int afsk_testRun(void); +//int afsk_testTearDown(void); #endif diff --git a/buildrev.h b/buildrev.h index 9cce0fd..3a49074 100644 --- a/buildrev.h +++ b/buildrev.h @@ -1,2 +1,2 @@ -#define VERS_BUILD 113 +#define VERS_BUILD 117 #define VERS_HOST "vixen"