Reworked KFile read
This commit is contained in:
parent
d35f134128
commit
50f11f6645
26
Modem/afsk.c
26
Modem/afsk.c
|
@ -313,18 +313,19 @@ uint8_t afsk_dac_isr(Afsk *afsk) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////
|
||||||
// File operation overwrites for read/write //
|
// 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)
|
static size_t afsk_read(KFile *fd, void *_buf, size_t size) {
|
||||||
{
|
Afsk *afsk = AFSK_CAST(fd);
|
||||||
Afsk *af = AFSK_CAST(fd);
|
uint8_t *buffer = (uint8_t *)_buf;
|
||||||
uint8_t *buf = (uint8_t *)_buf;
|
|
||||||
|
|
||||||
#if CONFIG_AFSK_RXTIMEOUT == 0
|
#if CONFIG_AFSK_RXTIMEOUT == 0
|
||||||
while (size-- && !fifo_isempty_locked(&af->rxFifo))
|
while (size-- && !fifo_isempty_locked(&afsk->rxFifo))
|
||||||
#else
|
#else
|
||||||
while (size--)
|
while (size--)
|
||||||
#endif
|
#endif
|
||||||
|
@ -333,19 +334,18 @@ static size_t afsk_read(KFile *fd, void *_buf, size_t size)
|
||||||
ticks_t start = timer_clock();
|
ticks_t start = timer_clock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (fifo_isempty_locked(&af->rxFifo))
|
while (fifo_isempty_locked(&afsk->rxFifo)) {
|
||||||
{
|
|
||||||
cpu_relax();
|
cpu_relax();
|
||||||
#if CONFIG_AFSK_RXTIMEOUT != -1
|
#if CONFIG_AFSK_RXTIMEOUT != -1
|
||||||
if (timer_clock() - start > ms_to_ticks(CONFIG_AFSK_RXTIMEOUT))
|
if (timer_clock() - start > ms_to_ticks(CONFIG_AFSK_RXTIMEOUT)) {
|
||||||
return buf - (uint8_t *)_buf;
|
return buffer - (uint8_t *)_buf;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
*buffer++ = fifo_pop_locked(&afsk->rxFifo);
|
||||||
*buf++ = fifo_pop_locked(&af->rxFifo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf - (uint8_t *)_buf;
|
return buffer - (uint8_t *)_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t afsk_write(KFile *fd, const void *_buf, size_t size)
|
static size_t afsk_write(KFile *fd, const void *_buf, size_t size)
|
||||||
|
|
27
Modem/afsk.h
27
Modem/afsk.h
|
@ -71,21 +71,36 @@ typedef struct Afsk
|
||||||
|
|
||||||
} 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')
|
#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);
|
ASSERT(fd->_type == KFT_AFSK);
|
||||||
return (Afsk *)fd;
|
return (Afsk *)fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Declare ISRs and initialization functions
|
||||||
void afsk_adc_isr(Afsk *af, int8_t sample);
|
void afsk_adc_isr(Afsk *af, int8_t sample);
|
||||||
uint8_t afsk_dac_isr(Afsk *af);
|
uint8_t afsk_dac_isr(Afsk *af);
|
||||||
void afsk_init(Afsk *af, int adc_ch, int dac_ch);
|
void afsk_init(Afsk *af, int adc_ch, int dac_ch);
|
||||||
|
|
||||||
int afsk_testSetup(void);
|
//int afsk_testSetup(void);
|
||||||
int afsk_testRun(void);
|
//int afsk_testRun(void);
|
||||||
int afsk_testTearDown(void);
|
//int afsk_testTearDown(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#define VERS_BUILD 113
|
#define VERS_BUILD 117
|
||||||
#define VERS_HOST "vixen"
|
#define VERS_HOST "vixen"
|
||||||
|
|
Loading…
Reference in New Issue