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 // TODO: Change this back to default
#define CONFIG_LED_INTENSITY 35 #define CONFIG_LED_INTENSITY 35
//#define CONFIG_LED_INTENSITY 192 //#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 // Demodulator settings
#define OPEN_SQUELCH true #define OPEN_SQUELCH true
@ -29,6 +30,7 @@
#define CONFIG_QUEUE_MAX_LENGTH 15 #define CONFIG_QUEUE_MAX_LENGTH 15
#define CONFIG_SERIAL_BUFFER_SIZE 1532 // TODO: Tune this, what is actually required? #define CONFIG_SERIAL_BUFFER_SIZE 1532 // TODO: Tune this, what is actually required?
#define CONFIG_SERIAL_TIMEOUT_MS 10 #define CONFIG_SERIAL_TIMEOUT_MS 10
#define CONFIG_BENCHMARK_MODE false
// CSMA Settings // CSMA Settings
#define CONFIG_FULL_DUPLEX false // TODO: Actually implement fdx #define CONFIG_FULL_DUPLEX false // TODO: Actually implement fdx

View File

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

View File

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

2
main.c
View File

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

View File

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

View File

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