From: batt Date: Sat, 10 Oct 2009 10:02:07 +0000 (+0000) Subject: Refactor afsk IRQ macros in order to handle multiple modems. X-Git-Tag: 2.3.0~25 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=80d83c6b228d01d19f4c97650c4d88456b909637;p=bertos.git Refactor afsk IRQ macros in order to handle multiple modems. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3058 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/hw/hw_afsk.h b/bertos/hw/hw_afsk.h index b562c18c..74ebfcd5 100644 --- a/bertos/hw/hw_afsk.h +++ b/bertos/hw/hw_afsk.h @@ -44,24 +44,17 @@ #if !(ARCH & ARCH_UNITTEST) #warning TODO:This is an example implementation, you must implement it! - #define AFSK_ADC_INIT() do { /* Implement me */ } while (0) + + #define AFSK_ADC_INIT(ch, ctx) do { (void)ch, (void)ctx; } while (0) #define AFSK_STROBE_INIT() do { /* Implement me */ } while (0) #define AFSK_STROBE_ON() do { /* Implement me */ } while (0) #define AFSK_STROBE_OFF() do { /* Implement me */ } while (0) - void afsk_adc_isr(void); - #define DEFINE_AFSK_ADC_ISR() void afsk_adc_isr(void) - #define AFSK_ADC_IRQ_END() do { /* Implement me */ } while (0) - - #define AFSK_READ_ADC() (0) - - void afsk_dac_isr(void); - #define DEFINE_AFSK_DAC_ISR() void afsk_dac_isr(void) - #define AFSK_DAC_IRQ_END() do { /* Implement me */ } while (0) - #define AFSK_DAC_IRQ_START() do { /* Implement me */ } while (0) - #define AFSK_DAC_IRQ_STOP() do { /* Implement me */ } while (0) - #define AFSK_SET_DAC(val) do { (void)val; } while (0) + #define AFSK_DAC_INIT(ch, ctx) do { (void)ch, (void)ctx; } while (0) + #define AFSK_DAC_IRQ_START(ch) do { (void)ch; /* Implement me */ } while (0) + #define AFSK_DAC_IRQ_STOP(ch) do { (void)ch; /* Implement me */ } while (0) + #define AFSK_DAC_SET(ch, val) do { (void)ch; (void)val; } while (0) #else /* (ARCH & ARCH_UNITTEST) */ #include @@ -72,19 +65,18 @@ extern FILE *fp_dac; extern bool afsk_tx_test; - #define AFSK_ADC_INIT() do { } while (0) + #define AFSK_ADC_INIT(ch, ctx) do { (void)ch, (void)ctx; } while (0) #define AFSK_STROBE_INIT() /* Implement me */ #define AFSK_STROBE_ON() /* Implement me */ #define AFSK_STROBE_OFF() /* Implement me */ - #define AFSK_ADC_IRQ_END() do { /* Implement me */ } while (0) - - #define AFSK_DAC_IRQ_END() do { /* Implement me */ } while (0) - #define AFSK_DAC_IRQ_START() do { afsk_tx_test = true; } while (0) - #define AFSK_DAC_IRQ_STOP() do { afsk_tx_test = false; } while (0) - #define AFSK_SET_DAC(_val) \ + #define AFSK_DAC_INIT(ch, ctx) do { (void)ch, (void)ctx; } while (0) + #define AFSK_DAC_IRQ_START(ch) do { (void)ch; afsk_tx_test = true; } while (0) + #define AFSK_DAC_IRQ_STOP(ch) do { (void)ch; afsk_tx_test = false; } while (0) + #define AFSK_DAC_SET(ch, _val) \ do { \ + (void)ch; \ int8_t val = (_val) - 128; \ ASSERT(fwrite(&val, 1, sizeof(val), fp_dac) == sizeof(val)); \ data_written++; \ diff --git a/bertos/net/afsk.c b/bertos/net/afsk.c index 6fea471b..a7273bdf 100644 --- a/bertos/net/afsk.c +++ b/bertos/net/afsk.c @@ -272,7 +272,6 @@ void afsk_adc_isr(Afsk *af, int8_t curr_sample) AFSK_STROBE_OFF(); - AFSK_ADC_IRQ_END(); } static void afsk_txStart(Afsk *af) @@ -284,7 +283,7 @@ static void afsk_txStart(Afsk *af) af->stuff_cnt = 0; af->sending = true; af->preamble_len = DIV_ROUND(CONFIG_AFSK_PREAMBLE_LEN * BITRATE, 8000); - AFSK_DAC_IRQ_START(); + AFSK_DAC_IRQ_START(af->dac_ch); } ATOMIC(af->trailer_len = DIV_ROUND(CONFIG_AFSK_TRAILER_LEN * BITRATE, 8000)); } @@ -303,9 +302,8 @@ void afsk_dac_isr(Afsk *af) /* We have just finished transimitting a char, get a new one. */ if (fifo_isempty(&af->tx_fifo) && af->trailer_len == 0) { - AFSK_DAC_IRQ_STOP(); + AFSK_DAC_IRQ_STOP(af->dac_ch); af->sending = false; - AFSK_DAC_IRQ_END(); return; } else @@ -343,9 +341,8 @@ void afsk_dac_isr(Afsk *af) { if (fifo_isempty(&af->tx_fifo)) { - AFSK_DAC_IRQ_STOP(); + AFSK_DAC_IRQ_STOP(af->dac_ch); af->sending = false; - AFSK_DAC_IRQ_END(); return; } else @@ -403,9 +400,8 @@ void afsk_dac_isr(Afsk *af) af->phase_acc += af->phase_inc; af->phase_acc %= SIN_LEN; - AFSK_SET_DAC(sin_sample(af->phase_acc)); + AFSK_DAC_SET(af->dac_ch, sin_sample(af->phase_acc)); af->sample_count--; - AFSK_DAC_IRQ_END(); } @@ -465,12 +461,14 @@ static int afsk_flush(KFile *fd) } -void afsk_init(Afsk *af) +void afsk_init(Afsk *af, int adc_ch, int dac_ch) { #if CONFIG_AFSK_RXTIMEOUT != -1 MOD_CHECK(timer); #endif memset(af, 0, sizeof(*af)); + af->adc_ch = adc_ch; + af->dac_ch = dac_ch; fifo_init(&af->delay_fifo, (uint8_t *)af->delay_buf, sizeof(af->delay_buf)); fifo_init(&af->rx_fifo, af->rx_buf, sizeof(af->rx_buf)); @@ -481,7 +479,8 @@ void afsk_init(Afsk *af) fifo_init(&af->tx_fifo, af->tx_buf, sizeof(af->tx_buf)); - AFSK_ADC_INIT(); + AFSK_ADC_INIT(adc_ch, af); + AFSK_DAC_INIT(dac_ch, af); AFSK_STROBE_INIT(); kprintf("MARK_INC %d, SPACE_INC %d\n", MARK_INC, SPACE_INC); diff --git a/bertos/net/afsk.h b/bertos/net/afsk.h index 2f1a2e08..4ab20c50 100644 --- a/bertos/net/afsk.h +++ b/bertos/net/afsk.h @@ -63,6 +63,9 @@ typedef struct Afsk { KFile fd; + int adc_ch; + int dac_ch; + /** Current sample of bit for output data. */ uint8_t sample_count; @@ -131,7 +134,7 @@ INLINE Afsk *AFSK_CAST(KFile *fd) void afsk_adc_isr(Afsk *af, int8_t curr_sample); void afsk_dac_isr(Afsk *af); -void afsk_init(Afsk *af); +void afsk_init(Afsk *af, int adc_ch, int dac_ch); /** diff --git a/bertos/net/afsk_test.c b/bertos/net/afsk_test.c index e3006c16..54e22fd0 100644 --- a/bertos/net/afsk_test.c +++ b/bertos/net/afsk_test.c @@ -146,7 +146,7 @@ int afsk_testSetup(void) ASSERT(fwrite(snd_header, 1, sizeof(snd_header), fp_dac) == sizeof(snd_header)); timer_init(); - afsk_init(&afsk_fd); + afsk_init(&afsk_fd, 0 ,0); afsk_fd.fd.error = kfile_genericClose; ax25_init(&ax25, &afsk_fd.fd, message_hook); return 0;