Zasadniczo działający APRS

aprs_test
Łukasz Nidecki 2017-01-10 21:21:44 +01:00
rodzic be555b2ee0
commit 65dbcc36e3
6 zmienionych plików z 94 dodań i 57 usunięć

Wyświetl plik

@ -82,7 +82,7 @@ private:
#elif F_CPU == 8000000UL
static const uint16_t toneSendTime1200 = 785;
#else
static const uint16_t toneSendTime1200 = 766;
static const uint16_t toneSendTime1200 = 717;
#endif
/**
* @brief Czas wysyłania podedynczego tonu. W ms.
@ -94,11 +94,11 @@ private:
* @brief Czas oczekiwania na zwolnienie kanału.
* @details Co 100ms sprawdzamy czy można już nadawać @see canTransmit
*/
static const uint16_t channelFreeWaitingMS = 2000; // 2000 ms
static const uint16_t channelFreeWaitingMS = 1; // 2000 ms
/**
* @brief Domylslny czas pomiędzy włączeniem nadawania a rozpoczęciem generowania AFSK
*/
static const uint16_t defaultTxDelay = 50; // 300 ms
static const uint16_t defaultTxDelay = 1; // 300 ms
/**
* @brief Pin Arduino na którym ustawiamy logiczną 1 w momencie nadawania
*/
@ -182,8 +182,8 @@ public:
private:
static const uint16_t toneSendTime = 833;
static const uint16_t MarkTimerValue = (uint16_t) ((1000000 / ((1338)*2)) - 1);
static const uint16_t SpaceTimerValue = (uint16_t) ((1000000 / ((-20+2670)*2)) - 1);
static const uint16_t MarkTimerValue = (uint16_t) ((1000000 / ((1245)*2)) - 1);
static const uint16_t SpaceTimerValue = (uint16_t) ((1000000 / ((2750)*2)) - 1);
void togglePin();
uint8_t pin;
public:

Wyświetl plik

@ -10,7 +10,8 @@
QAPRSBase qaprs;
void aprs_init(){
qaprs.init(0, 0, (char *) "SQ5RWU", '0', (char *) "APZQAP", '0', (char *) "WIDE1-1");
qaprs.init(0, 0, (char *) "SQ5RWU", '7', (char *) "URQU70", '0', (char *) "WIDE1-1,WIDE2-1");
}
void aprs_timer_handler() {

47
delay.c
Wyświetl plik

@ -2,18 +2,45 @@
#include <core_cm3.h>
#include <stm32f10x_rcc.h>
#include <misc.h>
#include <stm32f10x_tim.h>
#include "delay.h"
volatile uint8_t done;
void delay_init() {
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
TIM_TimeBaseInitTypeDef ts;
// TIM3 @ APB1 -> 6MHz WTF?!
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, DISABLE);
ts.TIM_Prescaler = 6 - 1;
ts.TIM_CounterMode = TIM_CounterMode_Up;
ts.TIM_Period = 0;
ts.TIM_ClockDivision = TIM_CKD_DIV1;
ts.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM3,&ts);
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
TIM_ITConfig(TIM3,TIM_IT_Update, ENABLE);
NVIC_InitTypeDef NVIC_InitStructure; //create NVIC structure
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM3, DISABLE);
}
void _delay_us(uint32_t us, uint8_t precise) {
SysTick->CTRL &= ~(SysTick_CTRL_ENABLE_Msk);
SysTick->VAL = us * 6;
SysTick->LOAD = us * 6;
SysTick->CTRL |= (SysTick_CTRL_ENABLE_Msk);
while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0) {}
void _delay_us(uint16_t us, uint8_t precise) {
TIM_Cmd(TIM3, DISABLE);
TIM_SetAutoreload(TIM3, us);
TIM_SetCounter(TIM3, 0);
TIM_Cmd(TIM3, ENABLE);
done = 0;
while(!done){
}
TIM_Cmd(TIM3, DISABLE);
}
inline void _delay_ms(uint32_t ms) {
@ -22,4 +49,10 @@ inline void _delay_ms(uint32_t ms) {
}
}
void TIM3_IRQHandler(void) {
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) {
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
done = 1;
}
}

Wyświetl plik

@ -7,7 +7,7 @@ extern "C" {
/** Initialize delay core - configure SysTick timer */
void delay_init();
void _delay_us(uint32_t us, uint8_t precise);
void _delay_us(uint16_t us, uint8_t precise);
void _delay_ms(uint32_t ms);

14
init.c
Wyświetl plik

@ -80,10 +80,10 @@ void RCC_Conf()
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
FLASH_SetLatency(FLASH_Latency_2);
RCC_HCLKConfig(RCC_SYSCLK_Div4); // 25 / 4 -> 6.25
RCC_PCLK2Config(RCC_HCLK_Div4); // 6.25 / 4
RCC_PCLK1Config(RCC_HCLK_Div2); // 6.25 / 2
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); // 25
RCC_HCLKConfig(RCC_SYSCLK_Div4); // 24 / 4 -> 6
RCC_PCLK2Config(RCC_HCLK_Div4); // 6 / 4 = 1,5 -> APB2
RCC_PCLK1Config(RCC_HCLK_Div2); // 6 / 2 = 3 -> APB1
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE); // 24
while(RCC_GetSYSCLKSource() != 0x04);
}
}
@ -217,10 +217,10 @@ void spi_deinit() {
void init_timer(const int rtty_speed) {
TIM_TimeBaseInitTypeDef TIM2_TimeBaseInitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2,DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2, DISABLE);
TIM2_TimeBaseInitStruct.TIM_Prescaler = 6/*0*/ - 1;// tick every 1/100000 s
TIM2_TimeBaseInitStruct.TIM_Prescaler = 6/*0*/ - 1;// tick every 1/1000000 s
TIM2_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM2_TimeBaseInitStruct.TIM_Period = (uint16_t) ((1000000 / rtty_speed) - 1);
TIM2_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;

75
main.c
Wyświetl plik

@ -65,44 +65,46 @@ void USART1_IRQHandler(void) {
void TIM2_IRQHandler(void) {
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) {
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}
if (aprs_is_active()){
aprs_timer_handler();
} else {
if (tx_on /*&& ++cun_rtty == 17*/) {
send_rtty_status = send_rtty((char *) rtty_buf);
if (send_rtty_status == rttyEnd) {
GPIO_SetBits(GPIOB, RED);
if (*(++rtty_buf) == 0) {
tx_on = 0;
tx_on_delay = tx_delay / (1000/RTTY_SPEED);//2500;
tx_enable = 0;
radio_disable_tx();
if (aprs_is_active()){
aprs_timer_handler();
} else {
if (tx_on /*&& ++cun_rtty == 17*/) {
send_rtty_status = send_rtty((char *) rtty_buf);
if (send_rtty_status == rttyEnd) {
GPIO_SetBits(GPIOB, RED);
if (*(++rtty_buf) == 0) {
tx_on = 0;
tx_on_delay = tx_delay / (1000/RTTY_SPEED);//2500;
tx_enable = 0;
radio_disable_tx();
}
} else if (send_rtty_status == rttyOne) {
radio_rw_register(0x73, 0x02, 1);
GPIO_SetBits(GPIOB, RED);
} else if (send_rtty_status == rttyZero) {
radio_rw_register(0x73, 0x00, 1);
GPIO_ResetBits(GPIOB, RED);
}
} else if (send_rtty_status == rttyOne) {
radio_rw_register(0x73, 0x02, 1);
GPIO_SetBits(GPIOB, RED);
} else if (send_rtty_status == rttyZero) {
radio_rw_register(0x73, 0x00, 1);
GPIO_ResetBits(GPIOB, RED);
}
if (!tx_on && --tx_on_delay == 0) {
tx_enable = 1;
tx_on_delay--;
}
if (--cun == 0) {
if (pun) {
GPIO_ResetBits(GPIOB, GREEN);
pun = 0;
} else {
if (flaga & 0x80) {
GPIO_SetBits(GPIOB, GREEN);
}
pun = 1;
}
cun = 200;
}
}
if (!tx_on && --tx_on_delay == 0) {
tx_enable = 1;
tx_on_delay--;
}
if (--cun == 0) {
if (pun) {
GPIO_ResetBits(GPIOB, GREEN);
pun = 0;
} else {
if (flaga & 0x80) {
GPIO_SetBits(GPIOB, GREEN);
}
pun = 1;
}
cun = 200;
}
}
}
@ -151,7 +153,8 @@ int main(void) {
//Button = ADCVal[1];
aprs_init();
radio_enable_tx();
uint16_t x = 760;
uint16_t x = 710;
while (1){
radio_enable_tx();
USART_Cmd(USART1, DISABLE);