kopia lustrzana https://github.com/bristol-seds/pico-tracker
Don't use rtc for timing, use eic from gps timepulse instead
rodzic
e6f5d0ba61
commit
cf0e3824fd
|
@ -15,8 +15,8 @@
|
|||
||tc4|osc8m event source
|
||||
||tc5|telemetry pwm 8-bit
|
||||
|
||||
|*RTC*|
|
||||
||rtc|telemetry timings
|
||||
|*EXTINT*|
|
||||
||extint[5]|gps timepulse
|
||||
|
||||
|*event channels*|
|
||||
||0|event source for timer 2 xosc measurement
|
||||
|
@ -32,6 +32,7 @@
|
|||
|
||||
| Name | Function | Priority H(0-3)L | Notes
|
||||
| --- | --- | --- | ---
|
||||
|TC0_IRQn||0
|
||||
|TC0_IRQn|telemetry tick timer|0
|
||||
|TC2_IRQn|xosc measurement done|2
|
||||
|[GPS_SERCOM]_IRQn|gps usart rx|0
|
||||
|EIC_IRQn|timer|1
|
||||
|
|
|
@ -124,6 +124,11 @@
|
|||
#define XOSC_FREQUENCY 16369000
|
||||
#define XOSC_COUNT_RESOLUTION 4
|
||||
|
||||
/**
|
||||
* Timings
|
||||
*/
|
||||
#define TELEMETRY_INTERVAL 30
|
||||
|
||||
/**
|
||||
* Watchdog Timer
|
||||
*/
|
||||
|
@ -149,5 +154,17 @@
|
|||
#define NC3_PIN PIN_PA04
|
||||
#define NC4_PIN PIN_PA14
|
||||
|
||||
/**
|
||||
* Interrupt Priority
|
||||
*/
|
||||
/* Telemetry Tick Timer */
|
||||
#define TC0_INT_PRIO 0
|
||||
/* XOSC Measure Timer */
|
||||
#define TC2_INT_PRIO 2
|
||||
/* GPS USART Rx */
|
||||
#define GPS_SERCOM_INT_PRIO 0
|
||||
/* Timepulse, telemetry */
|
||||
#define EIC_INT_PRIO 0
|
||||
|
||||
|
||||
#endif /* HW_CONFIG_H */
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Functions for running system timings
|
||||
* Copyright (C) 2015 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 TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
typedef void (*timepulse_callback_t)(uint32_t sequence);
|
||||
|
||||
void timepulse_extint_init(void);
|
||||
void timepulse_set_callback(timepulse_callback_t callback);
|
||||
|
||||
#endif /* TIMER_H */
|
|
@ -449,7 +449,7 @@ void gps_init(void)
|
|||
gps_disable_nmea();
|
||||
|
||||
/* Incoming ubx messages are handled in an irq */
|
||||
usart_register_rx_callback(GPS_SERCOM, gps_rx_callback, 0);
|
||||
usart_register_rx_callback(GPS_SERCOM, gps_rx_callback, GPS_SERCOM_INT_PRIO);
|
||||
|
||||
/* Set the platform model */
|
||||
gps_set_platform_model();
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "system/wdt.h"
|
||||
#include "xosc.h"
|
||||
#include "telemetry.h"
|
||||
#include "timer.h"
|
||||
#include "contestia.h"
|
||||
#include "rsid.h"
|
||||
#include "si_trx.h"
|
||||
|
@ -51,6 +52,9 @@
|
|||
|
||||
#define CALLSIGN "UBSEDSx"
|
||||
|
||||
void xosc_measure_callback(uint32_t result);
|
||||
void timepulse_callback(uint32_t sequence);
|
||||
|
||||
/**
|
||||
* Initialises the status LED
|
||||
*/
|
||||
|
@ -225,11 +229,6 @@ void output_telemetry_string(enum telemetry_t type)
|
|||
|
||||
/* Main telemetry */
|
||||
telemetry_start(type, len);
|
||||
|
||||
/* Sleep Wait */
|
||||
while (telemetry_active()) {
|
||||
system_sleep();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -275,11 +274,16 @@ void init(void)
|
|||
//wdt_init();
|
||||
//wdt_reset_count();
|
||||
|
||||
/* Enables the xosc on gclk1 */
|
||||
xosc_init();
|
||||
|
||||
led_init();
|
||||
gps_init();
|
||||
|
||||
/* Enable timer interrupt and event channel */
|
||||
timepulse_extint_init();
|
||||
timepulse_set_callback(timepulse_callback);
|
||||
|
||||
/* Initialise Si4060 interface */
|
||||
si_trx_init();
|
||||
}
|
||||
|
@ -287,7 +291,13 @@ void init(void)
|
|||
|
||||
void xosc_measure_callback(uint32_t result)
|
||||
{
|
||||
result++;
|
||||
}
|
||||
|
||||
uint8_t telemetry_trigger_flag = 0;
|
||||
void timepulse_callback(uint32_t sequence)
|
||||
{
|
||||
telemetry_trigger_flag = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -300,35 +310,21 @@ int main(void)
|
|||
|
||||
measure_xosc(XOSC_MEASURE_TIMEPULSE, xosc_measure_callback);
|
||||
|
||||
while (1) {
|
||||
system_sleep();
|
||||
}
|
||||
|
||||
|
||||
led_on();
|
||||
|
||||
while (1) {
|
||||
/* Sleep wait for next telemetry */
|
||||
while (telemetry_trigger_flag == 0 || telemetry_active()) {
|
||||
system_sleep();
|
||||
}
|
||||
telemetry_trigger_flag = 0;
|
||||
|
||||
/* Watchdog */
|
||||
//wdt_reset_count();
|
||||
|
||||
/* Send the next packet */
|
||||
output_telemetry_string(TELEMETRY_RTTY);
|
||||
|
||||
telemetry_start(TELEMETRY_PIPS, 5);
|
||||
|
||||
/* Sleep Wait */
|
||||
while (telemetry_active()) {
|
||||
system_sleep();
|
||||
}
|
||||
|
||||
/* Send the next packet */
|
||||
output_telemetry_string(TELEMETRY_CONTESTIA);
|
||||
|
||||
telemetry_start(TELEMETRY_PIPS, 5);
|
||||
|
||||
/* Sleep Wait */
|
||||
while (telemetry_active()) {
|
||||
system_sleep();
|
||||
}
|
||||
//telemetry_start(TELEMETRY_PIPS, 5);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -332,7 +332,7 @@ float timer0_tick_init(float frequency)
|
|||
|
||||
/* Enable Interrupt */
|
||||
TC0->COUNT32.INTENSET.reg = (1 << 4);
|
||||
irq_register_handler(TC0_IRQn, 0); /* Highest Priority */
|
||||
irq_register_handler(TC0_IRQn, TC0_INT_PRIO); /* Highest Priority */
|
||||
|
||||
/* Enable Timer */
|
||||
tc_enable(TC0);
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Functions for running system timings
|
||||
* Copyright (C) 2015 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 <string.h>
|
||||
|
||||
#include "samd20.h"
|
||||
#include "hw_config.h"
|
||||
#include "timer.h"
|
||||
#include "system/extint.h"
|
||||
#include "system/events.h"
|
||||
#include "system/interrupt.h"
|
||||
|
||||
uint32_t gps_timepulse_count = 0;
|
||||
uint32_t telemetry_interval_count = TELEMETRY_INTERVAL;
|
||||
uint32_t timepulse_sequence = 0;
|
||||
|
||||
timepulse_callback_t _timer_callback;
|
||||
|
||||
/**
|
||||
* Enables an interrupt on the GPS_TIMEPULSE and routes it to event channel 0
|
||||
*/
|
||||
void timepulse_extint_init(void) {
|
||||
|
||||
/* Enable extint events for gps timepulse */
|
||||
struct extint_events events;
|
||||
memset(&events, 0, sizeof(struct extint_events));
|
||||
events.generate_event_on_detect[GPS_TIMEPULSE_EXTINT] = true;
|
||||
extint_enable_events(&events);
|
||||
|
||||
/* Configure extinit channel */
|
||||
struct extint_chan_conf config;
|
||||
config.gpio_pin = GPS_TIMEPULSE_PIN;
|
||||
config.gpio_pin_mux = GPS_TIMEPULSE_PINMUX;
|
||||
config.gpio_pin_pull = EXTINT_PULL_NONE; // ???
|
||||
config.wake_if_sleeping = false; // ???
|
||||
config.filter_input_signal = false;
|
||||
config.detection_criteria = EXTINT_DETECT_RISING;
|
||||
extint_chan_set_config(GPS_TIMEPULSE_EXTINT, &config);
|
||||
|
||||
/* We route this event to event channel 0 */
|
||||
events_allocate(0,
|
||||
EVENTS_EDGE_DETECT_NONE,
|
||||
EVENTS_PATH_ASYNCHRONOUS,
|
||||
0xC + GPS_TIMEPULSE_EXTINT, /* External Interrupt Number */
|
||||
0);
|
||||
|
||||
/* Interrupt handler below */
|
||||
EIC->INTENSET.reg = (1 << GPS_TIMEPULSE_EXTINT);
|
||||
irq_register_handler(EIC_IRQn, EIC_INT_PRIO);
|
||||
|
||||
extint_enable();
|
||||
}
|
||||
|
||||
void timepulse_set_callback(timepulse_callback_t callback) {
|
||||
_timer_callback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* EIC Handler, triggered by the GPS at GPS_TIMEPULSE_FREQ Hz
|
||||
*/
|
||||
void EIC_Handler(void) {
|
||||
|
||||
if (EIC->INTFLAG.reg & (1 << GPS_TIMEPULSE_EXTINT)) {
|
||||
EIC->INTFLAG.reg = (1 << GPS_TIMEPULSE_EXTINT);
|
||||
|
||||
gps_timepulse_count++;
|
||||
/* Runs at 1Hz */
|
||||
if (gps_timepulse_count >= GPS_TIMEPULSE_FREQ) {
|
||||
gps_timepulse_count = 0;
|
||||
|
||||
telemetry_interval_count++;
|
||||
/* Runs at the rate of telemetry packets */
|
||||
if (telemetry_interval_count >= TELEMETRY_INTERVAL) {
|
||||
telemetry_interval_count = 0;
|
||||
|
||||
/* Make the callback if we have one */
|
||||
if (_timer_callback) {
|
||||
_timer_callback(timepulse_sequence++);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,7 +44,8 @@ enum xosc_measurement_t _measurement_t;
|
|||
measurement_result_t _callback;
|
||||
|
||||
/**
|
||||
* Configures external oscillator, waits for it to stabilise
|
||||
* Configures external oscillator, waits for it to stabilise, and
|
||||
* connects it to GLCK1.
|
||||
*/
|
||||
void xosc_init(void) {
|
||||
system_clock_source_xosc_set_config(SYSTEM_CLOCK_EXTERNAL_CLOCK,
|
||||
|
@ -56,6 +57,18 @@ void xosc_init(void) {
|
|||
system_clock_source_enable(SYSTEM_CLOCK_SOURCE_XOSC);
|
||||
|
||||
while (!system_clock_source_is_ready(SYSTEM_CLOCK_SOURCE_XOSC));
|
||||
|
||||
/* Configure GCLK1 to XOSC */
|
||||
system_gclk_gen_set_config(GCLK_GENERATOR_1,
|
||||
GCLK_SOURCE_XOSC, /* Source */
|
||||
false, /* High When Disabled */
|
||||
XOSC_COUNT_RESOLUTION,/* Division Factor */
|
||||
false, /* Run in standby */
|
||||
false); /* Output Pin Enable */
|
||||
|
||||
|
||||
/* Enable GCLK1 */
|
||||
system_gclk_gen_enable(GCLK_GENERATOR_1);
|
||||
}
|
||||
|
||||
struct osc8m_calibration_t osc8m_get_calibration(void) {
|
||||
|
@ -136,34 +149,10 @@ void osc8m_event_source_disable(void) {
|
|||
* Configure the timepulse extint to generate events
|
||||
*/
|
||||
void timepulse_extint_event_source(void) {
|
||||
|
||||
/* Enable extint events for gps timepulse */
|
||||
struct extint_events events;
|
||||
memset(&events, 0, sizeof(struct extint_events));
|
||||
events.generate_event_on_detect[GPS_TIMEPULSE_EXTINT] = true;
|
||||
extint_enable_events(&events);
|
||||
|
||||
/* Configure extinit channel */
|
||||
struct extint_chan_conf config;
|
||||
config.gpio_pin = GPS_TIMEPULSE_PIN;
|
||||
config.gpio_pin_mux = GPS_TIMEPULSE_PINMUX;
|
||||
config.gpio_pin_pull = EXTINT_PULL_NONE; // ???
|
||||
config.wake_if_sleeping = false; // ???
|
||||
config.filter_input_signal = false;
|
||||
config.detection_criteria = EXTINT_DETECT_RISING;
|
||||
extint_chan_set_config(GPS_TIMEPULSE_EXTINT, &config);
|
||||
|
||||
/* We route this event to event channel 0 */
|
||||
events_allocate(0,
|
||||
EVENTS_EDGE_DETECT_NONE,
|
||||
EVENTS_PATH_ASYNCHRONOUS,
|
||||
0x11, /* External Interrupt 5 */
|
||||
0);
|
||||
|
||||
extint_enable();
|
||||
/* Nothing to do: event should be already in place */
|
||||
}
|
||||
void timepulse_extint_event_source_disable(void) {
|
||||
// Oh I don't know
|
||||
/* Nothing to do here */
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -178,19 +167,7 @@ void measure_xosc(enum xosc_measurement_t measurement_t,
|
|||
_measurement_t = measurement_t;
|
||||
_callback = callback;
|
||||
|
||||
/* Configure GCLK1 to XOSC */
|
||||
system_gclk_gen_set_config(GCLK_GENERATOR_1,
|
||||
GCLK_SOURCE_XOSC, /* Source */
|
||||
false, /* High When Disabled */
|
||||
XOSC_COUNT_RESOLUTION,/* Division Factor */
|
||||
false, /* Run in standby */
|
||||
false); /* Output Pin Enable */
|
||||
|
||||
|
||||
/* Enable GCLK1 */
|
||||
system_gclk_gen_enable(GCLK_GENERATOR_1);
|
||||
|
||||
/* Timer 2 runs on GLCK1 */
|
||||
/* Timer 2 runs on GLCK1: XOSC */
|
||||
bool t2_capture_channel_enables[] = {true, true};
|
||||
uint32_t t2_compare_channel_values[] = {0x0000, 0x0000};
|
||||
|
||||
|
@ -221,7 +198,7 @@ void measure_xosc(enum xosc_measurement_t measurement_t,
|
|||
|
||||
/* Enable Interrupt */
|
||||
TC2->COUNT32.INTENSET.reg = (1 << 4); // MC0
|
||||
irq_register_handler(TC2_IRQn, 2); /* Lowish Priority */
|
||||
irq_register_handler(TC2_IRQn, TC2_INT_PRIO); /* Lowish Priority */
|
||||
|
||||
/* Timer 2 is event user on channel 0 */
|
||||
events_attach_user(0, 2);
|
||||
|
|
Ładowanie…
Reference in New Issue