From ea2f7b5c27b51ffcf472f0d117ff67de92c4d128 Mon Sep 17 00:00:00 2001 From: Richard Meadows Date: Tue, 14 Jul 2015 20:46:03 +0000 Subject: [PATCH] Moved gps usart over to glck1 (txco). Should be more stable. Added (untested) test case to check baud rate accuaracy --- firmware/Peripherals.md | 4 +-- firmware/inc/hw_config.h | 3 +- firmware/src/gps.c | 3 +- firmware/test/Makefile | 8 +++-- firmware/test/tc/gps_baud_error.h | 55 ++++++++++++++++++++++++++++++ firmware/test/tc/gps_baud_error.py | 47 +++++++++++++++++++++++++ firmware/test/tmain.c | 1 + 7 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 firmware/test/tc/gps_baud_error.h create mode 100644 firmware/test/tc/gps_baud_error.py diff --git a/firmware/Peripherals.md b/firmware/Peripherals.md index e82c871..6d4b4d3 100644 --- a/firmware/Peripherals.md +++ b/firmware/Peripherals.md @@ -43,7 +43,7 @@ ## Clock Layout ``` -[osc8m] --> [glck0] +--> [gps usart] +[osc8m] --> [glck0] + |--> [tc5] |--> [adc] |--> [extint] @@ -55,7 +55,7 @@ | | --> [glck1] +--> [tc0, telemetry tick] tcxo --> [xosc] --> 1| | |--> [tc2, count tcxo] <-- gps timepulse |/ |--> [glck7] --> [tc5] --> si_gpio1 - | + | |--> [gps usart] *USE_XOSC* diff --git a/firmware/inc/hw_config.h b/firmware/inc/hw_config.h index 6ef8195..2a6004d 100644 --- a/firmware/inc/hw_config.h +++ b/firmware/inc/hw_config.h @@ -66,6 +66,7 @@ #define GPS_SERCOM_MIGO_PIN PIN_PA07 #define GPS_SERCOM_MIGO_PINMUX PINMUX_PA07D_SERCOM0_PAD3 #define GPS_SERCOM_MUX USART_RX_3_TX_2_XCK_3 +#define GPS_GCLK GCLK_GENERATOR_1 #define GPS_BAUD_RATE 9600 #define GPS_PLATFORM_MODEL UBX_PLATFORM_MODEL_AIRBORNE_1G #define GPS_TIMEPULSE_PIN PIN_PA05 @@ -163,7 +164,7 @@ * APRS */ #define APRS_ENABLE 1 -#define APRS_USE_GEOFENCE 1 +#define APRS_USE_GEOFENCE 0 #define APRS_POWER RF_POWER_14dBm /** diff --git a/firmware/src/gps.c b/firmware/src/gps.c index 71f3d6b..0103d87 100644 --- a/firmware/src/gps.c +++ b/firmware/src/gps.c @@ -474,10 +474,9 @@ void gps_usart_init_enable(uint32_t baud_rate) true, /** Enable transmitter */ false, /** Sample on the rising edge of XLCK */ false, /** Use the external clock applied to the XCK pin. */ - 0, /** External clock frequency in synchronous mode. */ true, /** Run in standby */ - GCLK_GENERATOR_0, /** GCLK generator source */ + GPS_GCLK, /** GCLK generator source */ GPS_SERCOM_MOGI_PINMUX, /** PAD0 pinmux */ GPS_SERCOM_MIGO_PINMUX, /** PAD1 pinmux */ PINMUX_UNUSED, /** PAD2 pinmux */ diff --git a/firmware/test/Makefile b/firmware/test/Makefile index d2f9747..3f33b8c 100644 --- a/firmware/test/Makefile +++ b/firmware/test/Makefile @@ -16,7 +16,11 @@ ifdef name @$(SED) "s/\[template\]/$(name)/g" template/template.h > tc/$(name).h @$(SED) "s/\[template\]/$(name)/g" template/template.py > tc/$(name).py @$(SED) -i "s/\/\* \[new_tc\] \*\//\#include \"$(name).h\"\n\/\* \[new_tc\] \*\//" tmain.c - @$(ECHO) "Done" + @$(ECHO) "Done!" + @$(ECHO) + @$(ECHO) "Your testcase is at tc/$(name)_tc.{py,h}" + @$(ECHO) else - @$(ECHO) "Please specify a name for the test case!! Like 'make name=my_tc'" + @$(ECHO) "Please specify a name for the test case!! Like 'make name=new'" + @$(ECHO) "(Note the '_tc' will be appended automatically)" endif diff --git a/firmware/test/tc/gps_baud_error.h b/firmware/test/tc/gps_baud_error.h new file mode 100644 index 0000000..fe11af1 --- /dev/null +++ b/firmware/test/tc/gps_baud_error.h @@ -0,0 +1,55 @@ +#ifndef __verification__ +#define __verification__ +#endif + +/****************************//* gps_baud_error_tc *//****************************/ +/** + * Calculates the real hardware baud rate for gps serial + */ +#include "hw_config.h" +#include "sercom/sercom.h" +#include "sercom/usart.h" + +/* Parameters in */ +struct gps_baud_error_tc_params { + + /* Input paramters to your test case go here */ + uint32_t dummy; + +} gps_baud_error_tc_params; +/* Results out */ +struct gps_baud_error_tc_results { + + /* Result values should be populated here */ + uint32_t intended_baud; + uint32_t peripheral_clock; + uint16_t calculated_baud; + +} gps_baud_error_tc_results; +/* Function */ +__verification__ void gps_baud_error_tc(void) { + + /** + * The main body of the test case goes here. + * + * Use the input parameters to run the test case. Populate the + * results structure at the end + */ + + uint32_t sercom_index = _sercom_get_sercom_inst_index((Sercom*)GPS_SERCOM); + uint32_t gclk_index = sercom_index + SERCOM0_GCLK_ID_CORE; + uint32_t baudrate = GPS_BAUD_RATE; + uint16_t baud; /* The actual register value */ + + enum sercom_asynchronous_operation_mode mode = SERCOM_ASYNC_OPERATION_MODE_ARITHMETIC; + enum sercom_asynchronous_sample_num sample_num = SERCOM_ASYNC_SAMPLE_NUM_16; + + uint32_t peripheral_clock = system_gclk_chan_get_hz(gclk_index); + + _sercom_get_async_baud_val(baudrate, + peripheral_clock, &baud, mode, sample_num); + + gps_baud_error_tc_results.intended_baud = baudrate; + gps_baud_error_tc_results.peripheral_clock = peripheral_clock; + gps_baud_error_tc_results.calculated_baud = baud; +} diff --git a/firmware/test/tc/gps_baud_error.py b/firmware/test/tc/gps_baud_error.py new file mode 100644 index 0000000..85a4d66 --- /dev/null +++ b/firmware/test/tc/gps_baud_error.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +# ------------------------------------------------------------------------------ +# Imports +# ------------------------------------------------------------------------------ + +import sys +sys.path.append("./test") +import main + +from random import randint + +# ------------------------------------------------------------------------------ +# Test Script +# ------------------------------------------------------------------------------ + +class gps_baud_error_tc: + def __init__(self): + self.name = self.__class__.__name__ + self.iterations = 20 + + + def get_test(self): + """Returns some suitable test parameters""" + params = main.struct_gps_baud_error_tc_params() + + """ + Assign input parameters here + """ + + return params + + def is_correct(self, params, result, print_info): + """Returns if a result is correct for the given parameters""" + + """ + Compare result and params here, decide sth. + Can use print_info + """ + + print_info("{} Hz on a {} MHz clock (Intended {} Hz)".format( + result["calculated_baud"], + result["peripheral_clock"], + result["intended_baud"] + ) + + return True diff --git a/firmware/test/tmain.c b/firmware/test/tmain.c index 444a726..8b22d18 100644 --- a/firmware/test/tmain.c +++ b/firmware/test/tmain.c @@ -45,6 +45,7 @@ #include "backlog_write_read.h" #include "mem_erase_all.h" #include "adc_battery_solar_read.h" +#include "gps_baud_error.h" /* [new_tc] */