Async io work

This commit is contained in:
Mark Qvist 2019-01-08 20:56:58 +01:00
parent 42dcd121cc
commit 06d138d66c
11 changed files with 246 additions and 94 deletions

View file

@ -1,6 +1,7 @@
#include <string.h>
#include "AFSK.h"
#include "util/time.h"
#include "protocol/KISS.h"
// TODO: Remove testing vars ////
#define SAMPLES_TO_CAPTURE 128
@ -618,33 +619,10 @@ ISR(TIMER3_CAPT_vect) {
ISR(ADC_vect) {
TIFR1 = _BV(ICF1);
if (CONFIG_FULL_DUPLEX || !hw_afsk_dac_isr) {
AFSK_adc_isr(AFSK_modem, (ADCH - 128));
}
++_clock;
/*
// TODO: Remove these debug sample collection functions
//DAC_PORT ^= 0xFF;
//DAC_PORT = ADCH;
if (capturedsamples == SAMPLES_TO_CAPTURE) {
printf("--- Dumping samples ---");
for (ticks_t i = 0; i < SAMPLES_TO_CAPTURE; i++) {
uint8_t c = samplebuf[i];
printf("%d\r\n", c);
}
printf("-------- Done ---------");
}
DAC_PORT ^= 0xFF;
if (capturedsamples < SAMPLES_TO_CAPTURE) {
samplebuf[capturedsamples++] = ADCH;
// Clear Input Capture Flag from Timer1 Interrupt Flag Register
// to allow for next capture interrupt to occur
TIFR1 = _BV(ICF1);
}
*/
}

View file

@ -39,7 +39,7 @@ inline static uint8_t sinSample(uint16_t i) {
#define CPU_FREQ F_CPU
#define BITRATE 1200
#define BITRATE 2400
#if BITRATE == 300
#define CONFIG_ADC_SAMPLERATE 9600UL
@ -53,8 +53,8 @@ inline static uint8_t sinSample(uint16_t i) {
#endif
#define CONFIG_AFSK_RX_BUFLEN CONFIG_ADC_SAMPLERATE/75
#define CONFIG_AFSK_TX_BUFLEN CONFIG_ADC_SAMPLERATE/75
#define CONFIG_AFSK_RX_BUFLEN AX25_MAX_FRAME_LEN
#define CONFIG_AFSK_TX_BUFLEN AX25_MAX_FRAME_LEN
#define CONFIG_AFSK_RXTIMEOUT 0
#define CONFIG_AFSK_PREAMBLE_LEN 150UL

View file

@ -5,6 +5,8 @@
void serial_init(Serial *serial) {
memset(serial, 0, sizeof(*serial));
memset(serialBuf, 0, sizeof(serialBuf));
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
@ -14,13 +16,15 @@ void serial_init(Serial *serial) {
UCSR0A &= ~(_BV(U2X0));
#endif
// Set to 8-bit data, enable RX and TX
// Set to 8-bit data, enable RX and TX, enable receive interrupt
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
UCSR0B = _BV(RXEN0) | _BV(TXEN0);
UCSR0B = _BV(RXEN0) | _BV(TXEN0) | _BV(RXCIE0);
FILE uart0_fd = FDEV_SETUP_STREAM(uart0_putchar, uart0_getchar, _FDEV_SETUP_RW);
serial->uart0 = uart0_fd;
fifo_init(&serialFIFO, serialBuf, sizeof(serialBuf));
}
bool serial_available(uint8_t index) {
@ -45,4 +49,11 @@ int uart0_getchar(FILE *stream) {
char uart0_getchar_nowait(void) {
if (!(UCSR0A & _BV(RXC0))) return EOF;
return UDR0;
}
ISR(USART0_RX_vect) {
if (serial_available(0)) {
char c = uart0_getchar_nowait();
fifo_push(&serialFIFO, c);
}
}

View file

@ -6,11 +6,15 @@
#include <stdio.h>
#include <stdbool.h>
#include <avr/io.h>
#include "util/FIFO.h"
typedef struct Serial {
FILE uart0;
} Serial;
FIFOBuffer serialFIFO;
uint8_t serialBuf[CONFIG_SERIAL_BUFFER_SIZE];
void serial_init(Serial *serial);
bool serial_available(uint8_t index);
int uart0_putchar(char c, FILE *stream);