mirror of
https://github.com/markqvist/OpenModem.git
synced 2024-10-01 03:15:46 -04:00
KISS/AX.25 working
This commit is contained in:
parent
2da266e994
commit
4119591f88
8
device.h
8
device.h
@ -9,11 +9,13 @@
|
|||||||
#define CONFIG_AFSK_DAC_SAMPLERATE 9600
|
#define CONFIG_AFSK_DAC_SAMPLERATE 9600
|
||||||
|
|
||||||
// Serial settings
|
// Serial settings
|
||||||
#define BAUD 9600
|
#define BAUD 115200
|
||||||
|
|
||||||
// Port settings
|
// Port settings
|
||||||
#define DAC_PORT PORTB
|
#define DAC_PORT PORTD
|
||||||
#define DAC_DDR DDRB
|
#define DAC_DDR DDRD
|
||||||
|
#define LED_PORT PORTB
|
||||||
|
#define LED_DDR DDRB
|
||||||
#define ADC_PORT PORTC
|
#define ADC_PORT PORTC
|
||||||
#define ADC_DDR DDRC
|
#define ADC_DDR DDRC
|
||||||
|
|
||||||
|
@ -14,9 +14,6 @@ int afsk_getchar(void);
|
|||||||
void afsk_putchar(char c);
|
void afsk_putchar(char c);
|
||||||
|
|
||||||
void AFSK_hw_init(void) {
|
void AFSK_hw_init(void) {
|
||||||
// Disable interrupts while we set up everything
|
|
||||||
cli();
|
|
||||||
|
|
||||||
// Set up ADC
|
// Set up ADC
|
||||||
TCCR1A = 0;
|
TCCR1A = 0;
|
||||||
TCCR1B = _BV(CS10) | _BV(WGM13) | _BV(WGM12);
|
TCCR1B = _BV(CS10) | _BV(WGM13) | _BV(WGM12);
|
||||||
@ -36,8 +33,6 @@ void AFSK_hw_init(void) {
|
|||||||
_BV(ADIE) |
|
_BV(ADIE) |
|
||||||
_BV(ADPS2);
|
_BV(ADPS2);
|
||||||
|
|
||||||
// Enable interrupts - starts DAC/ADC
|
|
||||||
sei();
|
|
||||||
AFSK_DAC_INIT();
|
AFSK_DAC_INIT();
|
||||||
LED_TX_INIT();
|
LED_TX_INIT();
|
||||||
LED_RX_INIT();
|
LED_RX_INIT();
|
||||||
@ -54,11 +49,16 @@ void AFSK_init(Afsk *afsk) {
|
|||||||
fifo_init(&afsk->rxFifo, afsk->rxBuf, sizeof(afsk->rxBuf));
|
fifo_init(&afsk->rxFifo, afsk->rxBuf, sizeof(afsk->rxBuf));
|
||||||
fifo_init(&afsk->txFifo, afsk->txBuf, sizeof(afsk->txBuf));
|
fifo_init(&afsk->txFifo, afsk->txBuf, sizeof(afsk->txBuf));
|
||||||
|
|
||||||
|
// Fill delay FIFO with zeroes
|
||||||
|
for (int i = 0; i<SAMPLESPERBIT / 2; i++) {
|
||||||
|
fifo_push(&afsk->delayFifo, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
AFSK_hw_init();
|
||||||
|
|
||||||
// Set up streams
|
// Set up streams
|
||||||
FILE afsk_fd = FDEV_SETUP_STREAM(afsk_putchar, afsk_getchar, _FDEV_SETUP_RW);
|
FILE afsk_fd = FDEV_SETUP_STREAM(afsk_putchar, afsk_getchar, _FDEV_SETUP_RW);
|
||||||
afsk->fd = afsk_fd;
|
afsk->fd = afsk_fd;
|
||||||
|
|
||||||
AFSK_hw_init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AFSK_txStart(Afsk *afsk) {
|
static void AFSK_txStart(Afsk *afsk) {
|
||||||
@ -187,9 +187,9 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
|
|||||||
LED_RX_ON();
|
LED_RX_ON();
|
||||||
} else {
|
} else {
|
||||||
// If the buffer is full, we have a problem
|
// If the buffer is full, we have a problem
|
||||||
// and abort by setting the return value to msg.len = ctx->frm_len - 2 - (buf - ctx->buf);
|
// and abort by setting the return value to
|
||||||
|
|
||||||
// false and stopping the here.
|
// false and stopping the here.
|
||||||
|
|
||||||
ret = false;
|
ret = false;
|
||||||
hdlc->receiving = false;
|
hdlc->receiving = false;
|
||||||
LED_RX_OFF();
|
LED_RX_OFF();
|
||||||
@ -440,12 +440,12 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) {
|
|||||||
|
|
||||||
|
|
||||||
ISR(ADC_vect) {
|
ISR(ADC_vect) {
|
||||||
++_clock;
|
|
||||||
TIFR1 = _BV(ICF1);
|
TIFR1 = _BV(ICF1);
|
||||||
AFSK_adc_isr(AFSK_modem, ((int16_t)((ADC) >> 2) - 128));
|
AFSK_adc_isr(AFSK_modem, ((int16_t)((ADC) >> 2) - 128));
|
||||||
if (hw_afsk_dac_isr) {
|
if (hw_afsk_dac_isr) {
|
||||||
DAC_PORT = (AFSK_dac_isr(AFSK_modem) & 0xF0) | (DAC_PORT & 0x0F);
|
DAC_PORT = (AFSK_dac_isr(AFSK_modem) & 0xF0) | _BV(3);
|
||||||
} else {
|
} else {
|
||||||
DAC_PORT = 128 | (DAC_PORT & 0x0F);
|
DAC_PORT = 128;
|
||||||
}
|
}
|
||||||
|
++_clock;
|
||||||
}
|
}
|
@ -114,20 +114,20 @@ typedef struct Afsk
|
|||||||
|
|
||||||
#define AFSK_DAC_IRQ_START() do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = true; } while (0)
|
#define AFSK_DAC_IRQ_START() do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = true; } while (0)
|
||||||
#define AFSK_DAC_IRQ_STOP() do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = false; } while (0)
|
#define AFSK_DAC_IRQ_STOP() do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = false; } while (0)
|
||||||
#define AFSK_DAC_INIT() do { DAC_DDR |= 0xF0; } while (0)
|
#define AFSK_DAC_INIT() do { DAC_DDR |= 0xF8; } while (0)
|
||||||
|
|
||||||
// Here's some macros for controlling the RX/TX LEDs
|
// Here's some macros for controlling the RX/TX LEDs
|
||||||
// THE _INIT() functions writes to the DDRB register
|
// THE _INIT() functions writes to the DDRB register
|
||||||
// to configure the pins as output pins, and the _ON()
|
// to configure the pins as output pins, and the _ON()
|
||||||
// and _OFF() functions writes to the PORT registers
|
// and _OFF() functions writes to the PORT registers
|
||||||
// to turn the pins on or off.
|
// to turn the pins on or off.
|
||||||
#define LED_TX_INIT() do { DAC_DDR |= _BV(1); } while (0)
|
#define LED_TX_INIT() do { LED_DDR |= _BV(1); } while (0)
|
||||||
#define LED_TX_ON() do { DAC_PORT |= _BV(1); } while (0)
|
#define LED_TX_ON() do { LED_PORT |= _BV(1); } while (0)
|
||||||
#define LED_TX_OFF() do { DAC_PORT &= ~_BV(1); } while (0)
|
#define LED_TX_OFF() do { LED_PORT &= ~_BV(1); } while (0)
|
||||||
|
|
||||||
#define LED_RX_INIT() do { DAC_DDR |= _BV(2); } while (0)
|
#define LED_RX_INIT() do { LED_DDR |= _BV(2); } while (0)
|
||||||
#define LED_RX_ON() do { DAC_PORT |= _BV(2); } while (0)
|
#define LED_RX_ON() do { LED_PORT |= _BV(2); } while (0)
|
||||||
#define LED_RX_OFF() do { DAC_PORT &= ~_BV(2); } while (0)
|
#define LED_RX_OFF() do { LED_PORT &= ~_BV(2); } while (0)
|
||||||
|
|
||||||
void AFSK_init(Afsk *afsk);
|
void AFSK_init(Afsk *afsk);
|
||||||
void AFSK_transmit(char *buffer, size_t size);
|
void AFSK_transmit(char *buffer, size_t size);
|
||||||
|
2
main.c
2
main.c
@ -22,6 +22,7 @@ static void ax25_callback(struct AX25Ctx *ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init(void) {
|
void init(void) {
|
||||||
|
sei();
|
||||||
AFSK_init(&modem);
|
AFSK_init(&modem);
|
||||||
serial_init(&serial);
|
serial_init(&serial);
|
||||||
ax25_init(&AX25, &modem.fd, ax25_callback);
|
ax25_init(&AX25, &modem.fd, ax25_callback);
|
||||||
@ -41,7 +42,6 @@ int main (void) {
|
|||||||
char sbyte = uart0_getchar_nowait();
|
char sbyte = uart0_getchar_nowait();
|
||||||
kiss_serialCallback(sbyte);
|
kiss_serialCallback(sbyte);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user