mirror of
https://github.com/markqvist/OpenModem.git
synced 2024-12-29 01:16:17 -05:00
Phase sync experiments
This commit is contained in:
parent
13873775e8
commit
f42f6d8bae
16
Modem/afsk.c
16
Modem/afsk.c
@ -83,7 +83,7 @@ INLINE uint8_t sinSample(uint16_t i) {
|
||||
#define PHASE_BITS 8
|
||||
#define PHASE_INC 1 // FIXME: originally 1
|
||||
#define PHASE_MAX (SAMPLESPERBIT * PHASE_BITS)
|
||||
#define PHASE_THRESHOLD (PHASE_MAX / 2) + (PHASE_MAX / 8) // FIXME: originally /2
|
||||
#define PHASE_THRESHOLD (PHASE_MAX / 4) + (PHASE_MAX / 8) // FIXME: originally /2
|
||||
|
||||
// Modulation constants
|
||||
#define MARK_FREQ 1200
|
||||
@ -111,6 +111,7 @@ STATIC_ASSERT(!(CONFIG_AFSK_DAC_SAMPLERATE % BITRATE));
|
||||
// Link Layer Control and Demodulation //
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
static int adjustCount; // FIXME: Debug
|
||||
// hdlcParse /////////////////////////////////////////
|
||||
// This function looks at the raw bits demodulated from
|
||||
// the physical medium and tries to parse actual data
|
||||
@ -157,6 +158,7 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
|
||||
// false and stopping the here.
|
||||
ret = false;
|
||||
hdlc->receiving = false;
|
||||
kprintf("RX overrun 1!"); // FIXME: remove these
|
||||
LED_RX_OFF();
|
||||
}
|
||||
|
||||
@ -167,10 +169,18 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
|
||||
// of the received bytes.
|
||||
hdlc->currentByte = 0;
|
||||
hdlc->bitIndex = 0;
|
||||
//if (adjustCount > 25) kprintf("[AC%d]", adjustCount); // this slows down stuff and makes it work. wtf?!
|
||||
adjustCount = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Check if we have received a RESET flag (01111111)
|
||||
// In this comparison we also detect when no transmission
|
||||
// (or silence) is taking place, and the demodulator
|
||||
// returns an endless stream of zeroes. Due to the NRZ
|
||||
// coding, the actual bits send to this function will
|
||||
// be an endless stream of ones, which this AND operation
|
||||
// will also detect.
|
||||
if ((hdlc->demodulatedBits & HDLC_RESET) == HDLC_RESET) {
|
||||
// If we have, something probably went wrong at the
|
||||
// transmitting end, and we abort the reception.
|
||||
@ -232,6 +242,7 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
|
||||
// If it is, abort and return false
|
||||
hdlc->receiving = false;
|
||||
LED_RX_OFF();
|
||||
kprintf("RX overrun 3!");
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
@ -244,6 +255,7 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
|
||||
// If it is, well, you know by now!
|
||||
hdlc->receiving = false;
|
||||
LED_RX_OFF();
|
||||
kprintf("RX overrun 4!");
|
||||
ret = false;
|
||||
}
|
||||
|
||||
@ -328,6 +340,7 @@ void afsk_adc_isr(Afsk *afsk, int8_t currentSample) {
|
||||
// our timing to the transmitter, even if it's timing is
|
||||
// a little off compared to our own.
|
||||
if (TRANSITION_FOUND(afsk->sampledBits)) {
|
||||
adjustCount++;
|
||||
if (afsk->currentPhase < PHASE_THRESHOLD) {
|
||||
afsk->currentPhase += PHASE_INC;
|
||||
} else {
|
||||
@ -391,6 +404,7 @@ void afsk_adc_isr(Afsk *afsk, int8_t currentSample) {
|
||||
//
|
||||
// We also check the return of the Link Control parser
|
||||
// to check if an error occured.
|
||||
|
||||
if (!hdlcParse(&afsk->hdlc, !TRANSITION_FOUND(afsk->actualBits), &afsk->rxFifo)) {
|
||||
afsk->status |= RX_OVERRUN;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ static bool sertx = false; // Flag signifying whether it's time to send da
|
||||
// Right now it just prints the packet to the serial port.
|
||||
static void mp1Callback(struct MP1Packet *packet) {
|
||||
//kfile_printf(&ser.fd, "%.*s\r\n", packet->dataLength, packet->data);
|
||||
kprintf("%.*s\r\n", packet->dataLength, packet->data);
|
||||
kprintf("%.*s\n", packet->dataLength, packet->data);
|
||||
}
|
||||
|
||||
// Simple initialization function.
|
||||
@ -90,6 +90,7 @@ int main(void)
|
||||
// incoming data
|
||||
mp1Poll(&mp1);
|
||||
|
||||
|
||||
// We then read a byte from the serial port.
|
||||
// Notice that we use "_nowait" since we can't
|
||||
// have this blocking execution until a byte
|
||||
|
@ -1,7 +1,11 @@
|
||||
#include "mp1.h"
|
||||
#include "hardware.h"
|
||||
#include <string.h>
|
||||
#include <drv/ser.h>
|
||||
|
||||
static int okC; // FIXME: remove
|
||||
static int erC;
|
||||
|
||||
static void mp1Decode(MP1 *mp1) {
|
||||
// This decode function is basic and bare minimum.
|
||||
// It does nothing more than extract the data
|
||||
@ -41,9 +45,11 @@ void mp1Poll(MP1 *mp1) {
|
||||
// kprintf("Got checksum: %d.\n", mp1->buffer[mp1->packetLength-1]);
|
||||
if ((mp1->checksum_in & 0xff) == 0x00) {
|
||||
//kprintf("Correct checksum. Found %d.\n", mp1->buffer[mp1->packetLength-1]);
|
||||
kprintf("[OK%d] ", okC++);
|
||||
mp1Decode(mp1);
|
||||
} else {
|
||||
// Checksum was incorrect
|
||||
kprintf("[ER%d] ", erC++);
|
||||
mp1Decode(mp1);
|
||||
//kprintf("Incorrect checksum. Found %d, ", mp1->buffer[mp1->packetLength]);
|
||||
//kprintf("should be %d\n", mp1->checksum_in);
|
||||
|
@ -1,2 +1,2 @@
|
||||
#define VERS_BUILD 448
|
||||
#define VERS_BUILD 477
|
||||
#define VERS_HOST "vixen"
|
||||
|
Loading…
Reference in New Issue
Block a user