From 150732ee3c59385ca0ff0a8aa564936b587a1df9 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Wed, 12 Jun 2013 18:43:35 -0400 Subject: [PATCH] Cleanups for thesis inclusion --- firmware/adc.c | 2 +- firmware/adcext.c | 6 +++--- firmware/calibrate.c | 5 +++-- firmware/config.c | 4 ++-- firmware/led.c | 2 +- firmware/mode_debug.c | 7 +++---- firmware/mode_normal.c | 17 ++++++++++------- firmware/packet.c | 9 +++++---- firmware/timer.c | 4 ++-- firmware/uart.c | 6 +++--- firmware/zoom.c | 3 +-- firmware/zoom.h | 2 -- 12 files changed, 34 insertions(+), 33 deletions(-) diff --git a/firmware/adc.c b/firmware/adc.c index ead9e22..4bd0509 100644 --- a/firmware/adc.c +++ b/firmware/adc.c @@ -38,7 +38,7 @@ int16_t adc_get(void) LAT_CS = IO_HIGH; /* Sign-extend the 12-bit value */ - if (v & 0x0800) + if (v & 0x0800) v |= 0xF000; else v &= ~0xF000; diff --git a/firmware/adcext.c b/firmware/adcext.c index 1793e7b..bc8f1b9 100644 --- a/firmware/adcext.c +++ b/firmware/adcext.c @@ -8,7 +8,7 @@ This means we can't have the hardware do SPI for us. */ /* External serial clock, 2-wire I/O -- tie /EXT low, - tie ADC SDI for rate selection, tie /CS low, use BUSY for + tie ADC SDI for rate selection, tie /CS low, use BUSY for interrupt notification if desired */ #define TRIS_SDO TRISBbits.TRISB5 @@ -34,13 +34,13 @@ void adcext_init(void) TRIS_SCK = 0; LAT_SCS = IO_LOW; TRIS_SCS = 0; - + /* Startup delay CS down to SCK high t4 = 5000ns */ for (i = 0; i < 5000 / 25; i++) wait_25ns(); /* We need to monitor BUSY, I think. With the 2-wire - interface, we never know if we start in the middle of + interface, we never know if we start in the middle of a data output phase. For now, consider reading broken.. just return early. XXXX */ return; diff --git a/firmware/calibrate.c b/firmware/calibrate.c index f85fa59..f530c38 100644 --- a/firmware/calibrate.c +++ b/firmware/calibrate.c @@ -14,7 +14,8 @@ float g_scale; /* delta(DAC) / delta(ADC) */ /* Initialize. Assume some relatively-safe scaling if no calibration is run */ void calibrate_init(void) { - g_scale = (DAC_RANGE / 65536.0); /* 1 count at 16-bit DAC means 1 counts at ADC */ + g_scale = (DAC_RANGE / 65536.0); /* 1 count at 16-bit DAC + * means 1 counts at ADC */ } /* Given the current DAC and ADC values d1 and a1, @@ -34,7 +35,7 @@ float calculate_scale(uint16_t d1, float a1, uint16_t d2, float a2) { float scale; float a = a2 - a1; - + /* Correct for known errors */ d1 = dac_get_actual_float(d1); d2 = dac_get_actual_float(d2); diff --git a/firmware/config.c b/firmware/config.c index bd9002e..3287da4 100644 --- a/firmware/config.c +++ b/firmware/config.c @@ -11,12 +11,12 @@ void config_init(void) AD1PCFGL = 0xffff; AD1PCFGH = 0xffff; AD2PCFGL = 0xffff; - + /* Configure PLL to multiply from 8 -> 40 MHz */ PLLFBD = 38; CLKDIVbits.PLLPRE = 0; CLKDIVbits.PLLPOST = 0; - + /* Switch to XTPLL clock */ __builtin_write_OSCCONH(0x03); __builtin_write_OSCCONL(0x01); diff --git a/firmware/led.c b/firmware/led.c index 03022ae..9aae06e 100644 --- a/firmware/led.c +++ b/firmware/led.c @@ -6,7 +6,7 @@ int16_t __led_pattern; /* Debug LED */ void TISR_HANDLER(6) -{ +{ timer_clear_txif(6); if (__led_pattern == -1) diff --git a/firmware/mode_debug.c b/firmware/mode_debug.c index e29c091..d40138e 100644 --- a/firmware/mode_debug.c +++ b/firmware/mode_debug.c @@ -9,14 +9,13 @@ #include "util.h" #include "led.h" #include "mode.h" -#include "zoom.h" static uint16_t dac = DAC_MID; void sweep(void) { int32_t d; - int16_t a; + int16_t a; #define SWEEP ((DAC_HIGH - DAC_LOW) * (int32_t)2000 / 65535) @@ -47,7 +46,7 @@ void run_debug(void) int16_t adc; int32_t v; char buf[4]; - uart1_init(115200); + uart1_init(115200); led_pattern(0b10101010); @@ -122,7 +121,7 @@ void run_debug(void) dac = seek(dac, 1024); uart1_get(); break; - + // test seeking case '1': uart1_put_string("seek 512\r\n"); diff --git a/firmware/mode_normal.c b/firmware/mode_normal.c index afd8945..ec82263 100644 --- a/firmware/mode_normal.c +++ b/firmware/mode_normal.c @@ -10,7 +10,6 @@ #include "util.h" #include "mode.h" #include "led.h" -#include "zoom.h" #include "packet.h" int send_data = 0; @@ -41,7 +40,7 @@ void TISR_HANDLER(5) LATAbits.LATA9 = 1; #endif timer_clear_txif(5); - + /* Get most recent sample from 12-bit ADC. */ v = adc_get(); @@ -51,20 +50,22 @@ void TISR_HANDLER(5) /* Send data to PC */ if (++count >= (TIMER_RATE / PC_RATE)) { count = 0; - + /* Send most recent sample and old DAC value */ send_adc = v; send_dac = dac_cmd; send_data = 1; } -#define WINDOW +#define WINDOW #ifdef WINDOW /* If ADC value is outside the window, step DAC */ if (v < ADC_WINDOW_MIN) - dac_cmd = adc_to_dac(dac_cmd, v, ADC_WINDOW_MIN_STEPTO, g_scale); + dac_cmd = adc_to_dac(dac_cmd, v, ADC_WINDOW_MIN_STEPTO, + g_scale); else if (v > ADC_WINDOW_MAX) - dac_cmd = adc_to_dac(dac_cmd, v, ADC_WINDOW_MAX_STEPTO, g_scale); + dac_cmd = adc_to_dac(dac_cmd, v, ADC_WINDOW_MAX_STEPTO, + g_scale); #else dac_cmd = adc_to_dac(dac_cmd, v, 1024, g_scale); #endif @@ -113,7 +114,9 @@ void run_normal(void) uint16_t a, d, o; disable_int({ if (possibly_clamped) { - /* Mark a possible overflow in the output */ + /* Mark a possible + * overflow in the + * output */ o = 1; possibly_clamped = 0; } else o = 0; diff --git a/firmware/packet.c b/firmware/packet.c index a9b64f7..7df840f 100644 --- a/firmware/packet.c +++ b/firmware/packet.c @@ -7,13 +7,13 @@ void packet_send_adc_dac(int16_t adc, uint16_t dac, int overflow) { char b[4]; /* Packet format for DAC/ADC values: - 10100000 ffffAaaa aaaaaaaa Dddddddd dddddddd + 10100000 ffffAaaa aaaaaaaa Dddddddd dddddddd ffff = flags, default 0000 ...1 = possible overflow Aaaaaaaaaaaa = 12-bit ADC value (2s compliment signed) Dddddddddddddddd = 16-bit DAC command (unsigned) - */ + */ uart1_put(PACKET_ADC_DAC); @@ -34,10 +34,11 @@ void packet_send_calibration(float scale) /* Packet format for calibration data: A1 xx xx xx xx - where xx xx xx xx = 32-bit floating point value, little endian IEEE 754 */ + where xx xx xx xx = 32-bit floating point value, little + endian IEEE 754 */ uint8_t *b = (uint8_t *)&scale; - + uart1_put(PACKET_CALIBRATION); uart1_put(b[0]); uart1_put(b[1]); diff --git a/firmware/timer.c b/firmware/timer.c index 3c14bf4..9570909 100644 --- a/firmware/timer.c +++ b/firmware/timer.c @@ -10,7 +10,7 @@ int timer_setup_16bit(int timer, uint32_t freq, int ie) { uint32_t period; uint16_t prescale; - + if (timer < 1 || timer > 9) return -1; @@ -63,7 +63,7 @@ case x: \ __timer_setup_case(9); #undef __timer_setup_case } - + /* Enable interrupt if requested */ timer_clear_txif(timer); switch (timer) { diff --git a/firmware/uart.c b/firmware/uart.c index 1c05cbb..aee65e5 100644 --- a/firmware/uart.c +++ b/firmware/uart.c @@ -5,7 +5,7 @@ void uart_init(int uart, int32_t rate) { int32_t brg; - + brg = ((FCY + (8 * rate - 1)) / (16 * rate)) - 1; if (brg < 1) brg = 1; if (brg > 65535) brg = 65535; @@ -54,12 +54,12 @@ uint8_t uart_get(int uart) if (uart == 1) { while (!U1STAbits.URXDA) continue; data = U1RXREG; - if (U1STAbits.OERR) + if (U1STAbits.OERR) U1STAbits.OERR = 0; } else if (uart == 2) { while (!U2STAbits.URXDA) continue; data = U2RXREG; - if (U2STAbits.OERR) + if (U2STAbits.OERR) U2STAbits.OERR = 0; } return data; diff --git a/firmware/zoom.c b/firmware/zoom.c index 1fd0e9a..0d17ad5 100644 --- a/firmware/zoom.c +++ b/firmware/zoom.c @@ -7,7 +7,6 @@ #include "util.h" #include "led.h" #include "mode.h" -#include "zoom.h" #include "calibrate.h" int main(void) @@ -16,7 +15,7 @@ int main(void) config_init(); led_init(); - led_on(); + led_on(); calibrate_init(); /* debug output */ diff --git a/firmware/zoom.h b/firmware/zoom.h index a8359ef..b85eab3 100644 --- a/firmware/zoom.h +++ b/firmware/zoom.h @@ -1,6 +1,4 @@ #ifndef ZOOM_H #define ZOOM_H -void degauss(void); - #endif