Added XOSC clock measurement. Requires hardware modifications

geofence_dev
Richard Meadows 2015-03-13 09:58:22 +00:00
rodzic ecf9c7b546
commit 9c581b5a05
6 zmienionych plików z 51 dodań i 280 usunięć

Wyświetl plik

@ -3,14 +3,30 @@
| Type | Peripheral | Function | Notes
| --- | --- | --- | ---
|*GLCK*|
||gclk0|main|2MHz??
||gclk0|main clock, internal osc8m|4 MHz
||gclk1|tcxo clock, fed from xosc
|*TC*||
||tc0|
||tc1|
||tc3|there was the txco on glck_io[3], but the pin voltages didn't work
||tc5|pwm
||tc0|telemetry tick timer (has timepulse input)
||tc1|^^^^^
||tc2|counts cycles of tcxo. 32-bit
||tc3|^^^^^
||tc4|osc8m event source
||tc5|pwm 8-bit
|*event channels*|
||0|event source for timer 2 xosc measurement
||1|tc4 retrigger
|*SERCOM*||
||sercom0|spi flash
||sercom1|ublox gps
||sercom2|
||sercom3|radio|currently bitbanged as required pin layout broken in sercom
## SAM D20 Interrupts usage
| Name | Function | Notes
| --- | --- | --- | ---
|TC0_IRQn|
|TC2_IRQn|xosc measurement done|

Wyświetl plik

@ -70,8 +70,9 @@
#define GPS_SERCOM_MUX USART_RX_1_TX_0_XCK_1
#define GPS_PLATFORM_MODEL UBX_PLATFORM_MODEL_AIRBORNE_1G
#define GPS_TIMEPULSE_PIN PIN_PA05
#define GPS_TIMEPULSE_PINMUX PINMUX_PA05F_TC0_WO1
#define GPS_TIMEPULSE_FREQ 10
#define GPS_TIMEPULSE_PINMUX PINMUX_PA05A_EIC_EXTINT5
#define GPS_TIMEPULSE_FREQ 2
#define GPS_TIMEPULSE_EXTINT 5
/**
* USART Loopback Testing
@ -115,12 +116,14 @@
#define SI406X_GPIO0_PIN PIN_PA27
#define SI406X_GPIO1_PIN PIN_PA25
#define SI406X_GPIO1_PINMUX PINMUX_PA25F_TC5_WO1
#define SI406X_TCXO_PIN PIN_PA17
#define SI406X_TCXO_PINMUX PINMUX_PA17H_GCLK_IO3
#define SI406X_TCXO_GCLK GCLK_GENERATOR_3
#define SI406X_TCXO_FREQUENCY 16369000
/**
* XOSC
*/
#define XOSC_FREQUENCY 16369000
#define XOSC_COUNT_RESOLUTION 4
/**
* Watchdog Timer
*/

Wyświetl plik

@ -1,31 +0,0 @@
/*
* Functions for turning the GPS timepulse into a HF Clock
* Copyright (C) 2014 Richard Meadows <richardeoin>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef TIMEPULSE_H
#define TIMEPULSE_H
void timepulse_init(void);
void switch_gclk_main_to_timepulse(void);
#endif /* TIMEPULSE_H */

Wyświetl plik

@ -32,12 +32,14 @@
#include "system/system.h"
#include "sercom/usart.h"
#include "system/port.h"
#include "system/events.h"
#include "system/extint.h"
#include "tc/tc_driver.h"
#include "gps.h"
#include "mfsk.h"
#include "ubx_messages.h"
#include "system/wdt.h"
#include "timepulse.h"
#include "xosc.h"
#include "telemetry.h"
#include "contestia.h"
#include "rsid.h"
@ -49,21 +51,16 @@
#define CALLSIGN "UBSEDSx"
/* Set the modulation mode */
//#define RTTY
#define CONTESTIA
/**
* Initialises the status LED
*/
static inline void led_init(void)
{
port_pin_set_config(LED0_PIN,
PORT_PIN_DIR_OUTPUT, /* Direction */
PORT_PIN_DIR_INPUT, /* Direction */
PORT_PIN_PULL_NONE, /* Pull */
false); /* Powersave */
port_pin_set_output_level(LED0_PIN, 1); /* LED is active low */
// port_pin_set_output_level(LED0_PIN, 1); /* LED is active low */
}
/**
* Turns the status LED on
@ -287,6 +284,8 @@ int main(void)
/* Restart the GCLK Module */
system_gclk_init();
system_events_init();
system_extint_init();
/* Get the current CPU Clock */
SystemCoreClock = system_cpu_clock_get_hz();
@ -298,8 +297,6 @@ int main(void)
/* Configure the Power Manager */
//powermananger_init();
/**
* System initialisation
* ---------------------------------------------------------------------------
@ -315,6 +312,20 @@ int main(void)
/* Initialise Si4060 interface */
si_trx_init();
xosc_init();
measure_xosc(XOSC_MEASURE_TIMEPULSE);
while (1) {
system_sleep();
}
led_on();
while (1) {

Wyświetl plik

@ -294,23 +294,6 @@ void telemetry_tick(void) {
* =============================================================================
*/
void si_gclk_setup(void)
{
system_pinmux_pin_set_config(SI406X_TCXO_PINMUX >> 16, /* GPIO Pin */
SI406X_TCXO_PINMUX & 0xFFFF, /* Mux Position */
SYSTEM_PINMUX_PIN_DIR_INPUT, /* Direction */
SYSTEM_PINMUX_PIN_PULL_NONE, /* Pull */
false); /* Powersave */
system_gclk_gen_set_config(SI406X_TCXO_GCLK,
GCLK_SOURCE_GCLKIN, /* Source */
false, /* High When Disabled */
1, /* Division Factor */
false, /* Run in standby */
false); /* Output Pin Enable */
system_gclk_gen_enable(SI406X_TCXO_GCLK);
}
/**
* Initialises a timer interupt at the given frequency
*
@ -318,10 +301,7 @@ void si_gclk_setup(void)
*/
float timer0_tick_init(float frequency)
{
//si_gclk_setup();
/* Calculate the wrap value for the given frequency */
//float gclk_frequency = SI406X_TCXO_FREQUENCY;
float gclk_frequency = (float)system_gclk_chan_get_hz(0);
uint32_t count = (uint32_t)(gclk_frequency / frequency);

Wyświetl plik

@ -1,208 +0,0 @@
/*
* Functions for turning the GPS timepulse into a HF Clock
* Copyright (C) 2014 Richard Meadows <richardeoin>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "samd20.h"
#include "system/clock.h"
#include "system/gclk.h"
#include "system/pinmux.h"
#include "tc/tc_driver.h"
#include "hw_config.h"
/* void timepulse_init(void) */
/* { */
/* /\* Set up the DFLL GCLK channel *\/ */
/* system_gclk_chan_set_config(SYSCTRL_GCLK_ID_DFLL48, DFLL48M_GCLK); */
/* system_gclk_chan_enable(SYSCTRL_GCLK_ID_DFLL48); */
/* /\* Configure DFLL48 *\/ */
/* system_clock_source_dfll_set_config( */
/* SYSTEM_CLOCK_DFLL_LOOP_MODE_CLOSED, /\* Loop Mode *\/ */
/* false, /\* On demand *\/ */
/* SYSTEM_CLOCK_DFLL_QUICK_LOCK_DISABLE, /\* Quick Lock *\/ */
/* SYSTEM_CLOCK_DFLL_CHILL_CYCLE_ENABLE, /\* Chill Cycle *\/ */
/* SYSTEM_CLOCK_DFLL_WAKEUP_LOCK_KEEP, /\* Lock during wakeup *\/ */
/* SYSTEM_CLOCK_DFLL_STABLE_TRACKING_TRACK_AFTER_LOCK, */
/* 0x1f / 4, /\* Open Loop - Coarse calibration value *\/ */
/* 0xff / 4, /\* Open Loop - Fine calibration value *\/ */
/* 1, /\* Closed Loop - Coarse Maximum step *\/ */
/* 1, /\* Closed Loop - Fine Maximum step *\/ */
/* DFLL48_MUL); /\* Frequency Multiplication Factor *\/ */
/* /\* Enable DFLL48 *\/ */
/* system_clock_source_enable(SYSTEM_CLOCK_SOURCE_DFLL); */
/* /\* Wait for it to be ready *\/ */
/* while(!system_clock_source_is_ready(SYSTEM_CLOCK_SOURCE_DFLL)); */
/* /\* system_clock_source_xosc_set_config(SYSTEM_CLOCK_EXTERNAL_CLOCK, *\/ */
/* /\* SYSTEM_XOSC_STARTUP_16384, *\/ */
/* /\* true, /\\* Auto gain control *\\/ *\/ */
/* /\* 16000000UL, /\\* Frequency *\\/ *\/ */
/* /\* true, /\\* Run in Standby *\\/ *\/ */
/* /\* false); /\\* Run on demand *\\/ *\/ */
/* /\* system_clock_source_enable(SYSTEM_CLOCK_SOURCE_XOSC); *\/ */
/* /\* Configure the HF GCLK *\/ */
/* system_gclk_gen_set_config(SI406X_HF_GCLK, */
/* GCLK_SOURCE_DFLL48M, /\* Source *\/ */
/* false, /\* High When Disabled *\/ */
/* 3, /\* Division Factor = 16MHz*\/ */
/* false, /\* Run in standby *\/ */
/* true); /\* Output Pin Enable *\/ */
/* /\* Configure the output pin *\/ */
/* system_pinmux_pin_set_config(SI406X_HF_CLK_PINMUX >> 16, /\* GPIO Pin *\/ */
/* SI406X_HF_CLK_PINMUX & 0xFFFF, /\* Mux Position *\/ */
/* SYSTEM_PINMUX_PIN_DIR_INPUT, /\* Direction *\/ */
/* SYSTEM_PINMUX_PIN_PULL_NONE, /\* Pull *\/ */
/* false); /\* Powersave *\/ */
/* /\* Enable the HF GCLK *\/ */
/* system_gclk_gen_enable(SI406X_HF_GCLK); */
/* } */
/* /\** */
/* * Switches GCLK_MAIN (a.k.a. GCLK0) to the gps timepulse */
/* *\/ */
/* void switch_gclk_main_to_timepulse(void) */
/* { */
/* /\* Enable GCLK_IO[0] *\/ */
/* system_pinmux_pin_set_config(GPS_TIME_PINMUX >> 16, /\* GPIO Pin *\/ */
/* GPS_TIME_PINMUX & 0xFFFF, /\* Mux Position *\/ */
/* SYSTEM_PINMUX_PIN_DIR_INPUT, /\* Direction *\/ */
/* SYSTEM_PINMUX_PIN_PULL_NONE, /\* Pull *\/ */
/* false); /\* Powersave *\/ */
/* /\* Switch GCLK_MAIN to GCLK_IO[0] *\/ */
/* system_gclk_gen_set_config(GCLK_GENERATOR_0, /\* GCLK 0 *\/ */
/* GCLK_SOURCE_GCLKIN,/\* Source from pin *\/ */
/* false, /\* High When Disabled *\/ */
/* 1, /\* Division Factor *\/ */
/* true, /\* Run in standby *\/ */
/* true); /\* Output Pin Enable *\/ */
/* /\* Wait for switch? *\/ */
/* } */
/* /\** */
/* * Outputs GCLK0 div 2 on the HF CLK pin */
/* *\/ */
/* void half_glck_main_on_hf_clk(void) */
/* { */
/* bool capture_channel_enables[] = {true, true}; */
/* uint32_t compare_channel_values[] = {0x0000, 0x0000}; */
/* tc_init(TC2, */
/* GCLK_GENERATOR_0, */
/* TC_COUNTER_SIZE_8BIT, */
/* TC_CLOCK_PRESCALER_DIV1, */
/* TC_WAVE_GENERATION_NORMAL_FREQ, */
/* TC_RELOAD_ACTION_GCLK, */
/* TC_COUNT_DIRECTION_UP, */
/* TC_WAVEFORM_INVERT_OUTPUT_NONE, */
/* false, /\* Oneshot = false *\/ */
/* false, /\* Run in standby = false *\/ */
/* 0x0000, /\* Initial value *\/ */
/* 0x0000, /\* Top value *\/ */
/* capture_channel_enables, /\* Capture Channel Enables *\/ */
/* compare_channel_values); /\* Compare Channels Values *\/ */
/* /\* Enable the output pin *\/ */
/* system_pinmux_pin_set_config(PINMUX_PA17F_TC2_WO1 >> 16, /\* GPIO Pin *\/ */
/* PINMUX_PA17F_TC2_WO1 & 0xFFFF, /\* Mux Position *\/ */
/* SYSTEM_PINMUX_PIN_DIR_INPUT, /\* Direction *\/ */
/* SYSTEM_PINMUX_PIN_PULL_NONE, /\* Pull *\/ */
/* false); /\* Powersave *\/ */
/* tc_enable(TC2); */
/* tc_start_counter(TC2); */
/* } */
/* /\** */
/* * Returns the current GCLK_MAIN frequency, as measured against OSC8M */
/* *\/ */
/* uint32_t gclk_main_frequency(void) */
/* { */
/* uint32_t osc8m_frequency = 8000000UL >> SYSCTRL->OSC8M.bit.PRESC; */
/* /\* Configure GCLK Gen 6 as reference *\/ */
/* system_gclk_gen_set_config(GCLK_GENERATOR_6, */
/* GCLK_SOURCE_OSC8M, /\* Source *\/ */
/* false, /\* High When Disabled *\/ */
/* 4, /\* Division Factor *\/ */
/* false, /\* Run in standby *\/ */
/* false); /\* Output Pin Enable *\/ */
/* /\* Enable GCLK 6 *\/ */
/* system_gclk_gen_enable(GCLK_GENERATOR_6); */
/* /\* Timer 0 free runs on GLCK 0 *\/ */
/* bool t0_capture_channel_enables[] = {false, false}; */
/* uint32_t t0_compare_channel_values[] = {0x0000, 0x0000}; */
/* tc_init(TC0, */
/* GCLK_GENERATOR_0, */
/* TC_COUNTER_SIZE_32BIT, */
/* TC_CLOCK_PRESCALER_DIV1, */
/* TC_WAVE_GENERATION_NORMAL_FREQ, */
/* TC_RELOAD_ACTION_GCLK, */
/* TC_COUNT_DIRECTION_UP, */
/* TC_WAVEFORM_INVERT_OUTPUT_NONE, */
/* false, /\* Oneshot *\/ */
/* false, /\* Run in standby *\/ */
/* 0x0000, /\* Initial value *\/ */
/* 0xFFFFFFFF, /\* Top value *\/ */
/* t0_capture_channel_enables, /\* Capture Channel Enables *\/ */
/* t0_compare_channel_values); /\* Compare Channels Values *\/ */
/* /\* Timer 3 counts 10000 cycles of GLCK 6 *\/ */
/* bool t1_capture_channel_enables[] = {false, false}; */
/* uint32_t t1_compare_channel_values[] = {10000, 0x0000}; */
/* tc_init(TC3, */
/* GCLK_GENERATOR_6, */
/* TC_COUNTER_SIZE_16BIT, */
/* TC_CLOCK_PRESCALER_DIV1, */
/* TC_WAVE_GENERATION_NORMAL_FREQ, */
/* TC_RELOAD_ACTION_GCLK, */
/* TC_COUNT_DIRECTION_UP, */
/* TC_WAVEFORM_INVERT_OUTPUT_NONE, */
/* false, /\* Oneshot *\/ */
/* false, /\* Run in standby *\/ */
/* 0x0000, /\* Initial value *\/ */
/* 0xFFFF, /\* Top value *\/ */
/* t1_capture_channel_enables, /\* Capture Channel Enables *\/ */
/* t1_compare_channel_values); /\* Compare Channels Values *\/ */
/* tc_enable(TC0); */
/* tc_enable(TC3); */
/* tc_start_counter(TC0); */
/* tc_start_counter(TC3); */
/* /\* Wait 10000 cycles of GCLK 6 *\/ */
/* while (!(tc_get_status(TC3) & TC_STATUS_CHANNEL_0_MATCH)); */
/* uint32_t gclk_main_count = tc_get_count_value(TC0) - 50; */
/* return gclk_main_count / 10; */
/* } */