RS41ng/src/hal/millis.c

66 wiersze
1.7 KiB
C
Czysty Zwykły widok Historia

Graw DFM-17 radiosonde support (#61) * Initial plumbing for DFM17 (#54) * Implementing Si4063 radio chip support for DFM17 sonde. Work in progress. * Add an error to indicate that the code does not work yet * Removed copyrighted docs from documentation and provided links instead (#55) * Fix SPI bus initialization for DFM17. Trying to make Si4063 SPI communication work (in progress). Fix LED bit polarity. * Set DFM17 clocks correctly to 24 MHz * Still trying to fix Si4063 SPI communication, no luck * Add clearing of SPI overrun status flag to make Si4063 comm work properly in DFM17. Not sure about the reason this is required. * Fix bug when setting Si4063 frequency. Remove unnecessary GPS debug and delays. Add Si4063 debug printout. Find a suitable frequency offset multiplier to achieve 270 Hz tone spacing for Horus 4FSK. * Add some known good Si4063 configuration values. Implement direct GPIO-based modulation for Si4063 that allows support for CW now. * DFM-17 APRS work (#60) * Modify for APRS on DFM17 * Clean up Si4063 APRS work and make APRS deviation configurable * Add documentation for DFM-17 * Add a note about the DFM-17 connector * More work on docs and config for DFM-17 * Docs * Mor work on config * Fix RS41 URL * Added info about high-altitude balloon flights * Fix typo * More code cleanup * Update authors * Improve DFM-17 docs * Added a timepulse routine for DFM17 and also a millis() routine. Working toward clock calibration. * More refinements to the HCI calibration * Cleaned up clock calibration code and integrated into the main radio loop. Also added APRS telemetry for calibration. * Added logic to (hopefully) avoid over-calibration if there is an errant timepulse. * Clean up DFM-17 clock calibration implementation and make RS41 compile properly * Adjust README * Add notes about DFM-17 clock calibration * Fix typo * Add DFM-17 note about clock calibration to the top of the README * Text style * Working on README * Working on README * Move datasheet links to main README * Markdown styling * Improve config file structure * Remove unnecessary comments --------- Co-authored-by: Mike Hojnowski <kd2eat@gmail.com>
2023-10-15 09:38:05 +00:00
#include <stm32f10x_rcc.h>
#include <stm32f10x_tim.h>
#include <misc.h>
#include "src/hal/millis.h"
static uint32_t millis_counter;
void millis_timer_init(void)
{
TIM_DeInit(TIM7);
TIM_TimeBaseInitTypeDef tim_init;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB1Periph_TIM7, DISABLE);
// The data timer assumes a 24 MHz clock source
tim_init.TIM_Prescaler = 24 - 1; // tick every 1/1000000 s
tim_init.TIM_CounterMode = TIM_CounterMode_Up;
tim_init.TIM_Period = (uint16_t) (1000 - 1); // set up period of 1 millisecond
tim_init.TIM_ClockDivision = TIM_CKD_DIV1;
tim_init.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM7, &tim_init);
TIM_ClearITPendingBit(TIM7, TIM_IT_Update);
TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE);
NVIC_InitTypeDef nvic_init;
nvic_init.NVIC_IRQChannel = TIM7_IRQn;
nvic_init.NVIC_IRQChannelPreemptionPriority = 0;
nvic_init.NVIC_IRQChannelSubPriority = 1;
nvic_init.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic_init);
TIM_Cmd(TIM7, ENABLE);
}
void millis_timer_uninit()
{
TIM_Cmd(TIM7, DISABLE);
NVIC_InitTypeDef nvic_init;
nvic_init.NVIC_IRQChannel = TIM7_IRQn;
nvic_init.NVIC_IRQChannelPreemptionPriority = 0;
nvic_init.NVIC_IRQChannelSubPriority = 1;
nvic_init.NVIC_IRQChannelCmd = DISABLE;
NVIC_Init(&nvic_init);
TIM_ITConfig(TIM7, TIM_IT_Update, DISABLE);
TIM_ClearITPendingBit(TIM7, TIM_IT_Update);
}
void TIM7_IRQHandler(void)
{
if (TIM_GetITStatus(TIM7, TIM_IT_Update) != RESET) {
TIM_ClearITPendingBit(TIM7, TIM_IT_Update);
millis_counter++;
}
}
uint32_t millis(void)
{
return millis_counter;
}