LED driver implemented

This commit is contained in:
Mark Qvist 2019-01-12 16:30:26 +01:00
parent fa1d89d0e3
commit 6258e1e62e
7 changed files with 53 additions and 49 deletions

View File

@ -16,7 +16,8 @@
// TODO: Change this back to default
#define CONFIG_LED_INTENSITY 35
//#define CONFIG_LED_INTENSITY 192
#define COM_LED_TIMEOUT_MS 40
#define CONFIG_COM_LED_TIMEOUT_MS 40
#define CONFIG_LED_UPDATE_INTERVAL_MS 40
// Demodulator settings
#define OPEN_SQUELCH true
@ -29,6 +30,7 @@
#define CONFIG_QUEUE_MAX_LENGTH 15
#define CONFIG_SERIAL_BUFFER_SIZE 1532 // TODO: Tune this, what is actually required?
#define CONFIG_SERIAL_TIMEOUT_MS 10
#define CONFIG_BENCHMARK_MODE false
// CSMA Settings
#define CONFIG_FULL_DUPLEX false // TODO: Actually implement fdx

View File

@ -6,11 +6,11 @@
// TODO: Remove testing vars ////
#define SAMPLES_TO_CAPTURE 128
uint32_t capturedsamples = 0;
ticks_t capturedsamples = 0;
uint8_t samplebuf[SAMPLES_TO_CAPTURE];
/////////////////////////////////
extern volatile uint32_t _clock;
extern volatile ticks_t _clock;
extern unsigned long custom_preamble;
extern unsigned long custom_tail;
@ -24,6 +24,8 @@ int afsk_putchar(char c, FILE *stream);
// ADC and clock setup
void AFSK_hw_init(void) {
_clock = 0;
// Run ADC initialisation
AFSK_adc_init();
@ -613,5 +615,7 @@ ISR(ADC_vect) {
AFSK_adc_isr(AFSK_modem, (ADCH - 128));
}
update_led_status();
++_clock;
}

View File

@ -2,9 +2,13 @@
#include "util/time.h"
uint8_t ledIntensity = CONFIG_LED_INTENSITY;
uint32_t com_led_timeout = 0;
ticks_t led_status_ticks_top = 0;
ticks_t led_status_ticks = 0;
ticks_t com_led_timeout = 0;
void LED_init(void) {
led_status_ticks_top = ms_to_ticks(CONFIG_LED_UPDATE_INTERVAL_MS);
// Enable output for LED pins and drain pin
LED_DDR |= _BV(0) | // RX
_BV(1) | // TX
@ -32,26 +36,20 @@ void LED_setIntensity(uint8_t value) {
void LED_COM_ON(void) {
LED_PORT |= _BV(4);
int32_t xa = timer_clock();
com_led_timeout = xa + ms_to_ticks(COM_LED_TIMEOUT_MS);
if (xa > com_led_timeout) {
while(true) {
LED_COM_ON();
LED_RX_ON();
LED_TX_ON();
}
}
com_led_timeout = timer_clock() + ms_to_ticks(CONFIG_COM_LED_TIMEOUT_MS);
}
void LED_COM_OFF(void) {
LED_PORT &= ~_BV(4);
}
void led_status(void) {
if (timer_clock() > com_led_timeout) {
if (LED_PORT & _BV(4)) {
printf("%d\r\n", timer_clock());
void update_led_status(void) {
if (led_status_ticks >= led_status_ticks_top) {
if (timer_clock() > com_led_timeout) {
LED_COM_OFF();
}
led_status_ticks = 0;
} else {
led_status_ticks++;
}
}

View File

@ -16,6 +16,6 @@ void LED_setIntensity(uint8_t value);
void LED_COM_ON(void);
void LED_COM_OFF(void);
void led_status(void);
void update_led_status(void);
#endif

2
main.c
View File

@ -40,6 +40,7 @@ void init(void) {
system_check();
}
int main (void) {
init();
@ -47,7 +48,6 @@ int main (void) {
ax25_poll(&AX25);
kiss_poll();
kiss_csma();
led_status();
}
return(0);

View File

@ -24,7 +24,7 @@ size_t packet_lengths_buf[CONFIG_QUEUE_MAX_LENGTH+1];
AX25Ctx *ax25ctx;
Afsk *channel;
Serial *serial;
volatile uint32_t last_serial_read = 0;
volatile ticks_t last_serial_read = 0;
size_t frame_len;
bool IN_FRAME;
bool ESCAPE;
@ -57,28 +57,30 @@ void kiss_poll(void) {
}
}
// TODO: Remove debug functions
//size_t decodes = 0;
#if CONFIG_BENCHMARK_MODE
size_t decodes = 0;
#endif
void kiss_messageCallback(AX25Ctx *ctx) {
//decodes++;
//printf("%d\r\n", decodes);
fputc(FEND, &serial->uart0);
fputc(0x00, &serial->uart0);
for (unsigned i = 0; i < ctx->frame_len-2; i++) {
uint8_t b = ctx->buf[i];
if (b == FEND) {
fputc(FESC, &serial->uart0);
fputc(TFEND, &serial->uart0);
} else if (b == FESC) {
fputc(FESC, &serial->uart0);
fputc(TFESC, &serial->uart0);
} else {
fputc(b, &serial->uart0);
#if CONFIG_BENCHMARK_MODE
decodes++;
printf("%d\r\n", decodes);
#else
fputc(FEND, &serial->uart0);
fputc(0x00, &serial->uart0);
for (unsigned i = 0; i < ctx->frame_len-2; i++) {
uint8_t b = ctx->buf[i];
if (b == FEND) {
fputc(FESC, &serial->uart0);
fputc(TFEND, &serial->uart0);
} else if (b == FESC) {
fputc(FESC, &serial->uart0);
fputc(TFESC, &serial->uart0);
} else {
fputc(b, &serial->uart0);
}
}
}
fputc(FEND, &serial->uart0);
fputc(FEND, &serial->uart0);
#endif
}
void kiss_csma(void) {

View File

@ -6,13 +6,12 @@
#define DIV_ROUND(dividend, divisor) (((dividend) + (divisor) / 2) / (divisor))
//typedef int32_t ticks_t;
//typedef int32_t mtime_t;
typedef int32_t ticks_t;
typedef int32_t mtime_t;
volatile ticks_t _clock;
volatile uint32_t _clock;
static inline uint32_t timer_clock(void) {
uint32_t result;
static inline ticks_t timer_clock(void) {
ticks_t result;
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
result = _clock;
@ -22,7 +21,7 @@ static inline uint32_t timer_clock(void) {
}
inline uint32_t ms_to_ticks(mtime_t ms) {
inline ticks_t ms_to_ticks(mtime_t ms) {
return ms * DIV_ROUND(CLOCK_TICKS_PER_SEC, 1000);
}
@ -38,5 +37,4 @@ static inline void delay_ms(unsigned long ms) {
}
}
#endif