Reworked KFile read

This commit is contained in:
Mark Qvist 2014-04-04 08:45:27 +02:00
parent d35f134128
commit 50f11f6645
3 changed files with 35 additions and 20 deletions

View File

@ -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)

View File

@ -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

View File

@ -1,2 +1,2 @@
#define VERS_BUILD 113
#define VERS_BUILD 117
#define VERS_HOST "vixen"