KISS/AX.25 working

This commit is contained in:
Mark Qvist 2014-12-04 15:22:25 +01:00
parent 2da266e994
commit 4119591f88
4 changed files with 27 additions and 25 deletions

View File

@ -9,12 +9,14 @@
#define CONFIG_AFSK_DAC_SAMPLERATE 9600
// Serial settings
#define BAUD 9600
#define BAUD 115200
// Port settings
#define DAC_PORT PORTB
#define DAC_DDR DDRB
#define DAC_PORT PORTD
#define DAC_DDR DDRD
#define LED_PORT PORTB
#define LED_DDR DDRB
#define ADC_PORT PORTC
#define ADC_DDR DDRC
#define ADC_DDR DDRC
#endif

View File

@ -14,9 +14,6 @@ int afsk_getchar(void);
void afsk_putchar(char c);
void AFSK_hw_init(void) {
// Disable interrupts while we set up everything
cli();
// Set up ADC
TCCR1A = 0;
TCCR1B = _BV(CS10) | _BV(WGM13) | _BV(WGM12);
@ -36,8 +33,6 @@ void AFSK_hw_init(void) {
_BV(ADIE) |
_BV(ADPS2);
// Enable interrupts - starts DAC/ADC
sei();
AFSK_DAC_INIT();
LED_TX_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->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
FILE afsk_fd = FDEV_SETUP_STREAM(afsk_putchar, afsk_getchar, _FDEV_SETUP_RW);
afsk->fd = afsk_fd;
AFSK_hw_init();
}
static void AFSK_txStart(Afsk *afsk) {
@ -187,9 +187,9 @@ static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
LED_RX_ON();
} else {
// 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.
ret = false;
hdlc->receiving = false;
LED_RX_OFF();
@ -440,12 +440,12 @@ void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) {
ISR(ADC_vect) {
++_clock;
TIFR1 = _BV(ICF1);
AFSK_adc_isr(AFSK_modem, ((int16_t)((ADC) >> 2) - 128));
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 {
DAC_PORT = 128 | (DAC_PORT & 0x0F);
DAC_PORT = 128;
}
++_clock;
}

View File

@ -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_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
// THE _INIT() functions writes to the DDRB register
// to configure the pins as output pins, and the _ON()
// and _OFF() functions writes to the PORT registers
// to turn the pins on or off.
#define LED_TX_INIT() do { DAC_DDR |= _BV(1); } while (0)
#define LED_TX_ON() do { DAC_PORT |= _BV(1); } while (0)
#define LED_TX_OFF() do { DAC_PORT &= ~_BV(1); } while (0)
#define LED_TX_INIT() do { LED_DDR |= _BV(1); } while (0)
#define LED_TX_ON() do { LED_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_ON() do { DAC_PORT |= _BV(2); } while (0)
#define LED_RX_OFF() do { DAC_PORT &= ~_BV(2); } while (0)
#define LED_RX_INIT() do { LED_DDR |= _BV(2); } while (0)
#define LED_RX_ON() do { LED_PORT |= _BV(2); } while (0)
#define LED_RX_OFF() do { LED_PORT &= ~_BV(2); } while (0)
void AFSK_init(Afsk *afsk);
void AFSK_transmit(char *buffer, size_t size);

4
main.c
View File

@ -22,6 +22,7 @@ static void ax25_callback(struct AX25Ctx *ctx) {
}
void init(void) {
sei();
AFSK_init(&modem);
serial_init(&serial);
ax25_init(&AX25, &modem.fd, ax25_callback);
@ -40,8 +41,7 @@ int main (void) {
if (serial_available(0)) {
char sbyte = uart0_getchar_nowait();
kiss_serialCallback(sbyte);
}
}
}
return(0);