2011-03-04 09:34:44 +01:00
|
|
|
|
2011-01-13 09:45:18 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file main.c
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @brief Main modem functions
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
#define USE_WATCHDOG // comment this out if you don't want to use the watchdog
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// OpenPilot Includes
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "crc.h"
|
|
|
|
#include "aes.h"
|
|
|
|
#include "rfm22b.h"
|
|
|
|
#include "packet_handler.h"
|
2011-02-05 14:45:16 +01:00
|
|
|
#include "stream.h"
|
|
|
|
#include "ppm.h"
|
2011-01-13 09:45:18 +01:00
|
|
|
#include "transparent_comms.h"
|
2011-02-02 00:40:40 +01:00
|
|
|
//#include "api_comms.h"
|
|
|
|
#include "api_config.h"
|
2011-01-13 09:45:18 +01:00
|
|
|
#include "gpio_in.h"
|
|
|
|
#include "stopwatch.h"
|
2011-01-13 20:15:12 +01:00
|
|
|
#include "watchdog.h"
|
2011-01-13 09:45:18 +01:00
|
|
|
#include "saved_settings.h"
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
2011-02-12 23:19:43 +01:00
|
|
|
/* Prototype of PIOS_Board_Init() function */
|
|
|
|
extern void PIOS_Board_Init(void);
|
|
|
|
|
2011-01-13 09:45:18 +01:00
|
|
|
// *****************************************************************************
|
|
|
|
// ADC data
|
|
|
|
|
|
|
|
#define ADC_REF 3.3f // ADC reference voltage
|
|
|
|
#define ADC_FULL_RANGE 4096 // 12 bit ADC
|
|
|
|
|
|
|
|
#define ADC_PSU_RESISTOR_TOP 10000.0f // 10k upper resistor
|
|
|
|
#define ADC_PSU_RESISTOR_BOTTOM 2700.0f // 2k7 lower resistor
|
|
|
|
#define ADC_PSU_RATIO (ADC_PSU_RESISTOR_BOTTOM / (ADC_PSU_RESISTOR_TOP + ADC_PSU_RESISTOR_BOTTOM))
|
|
|
|
#define ADC_PSU_mV_SCALE ((ADC_REF * 1000) / (ADC_FULL_RANGE * ADC_PSU_RATIO))
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// Global Variables
|
|
|
|
|
|
|
|
uint32_t flash_size;
|
|
|
|
|
|
|
|
char serial_number_str[25];
|
|
|
|
uint32_t serial_number_crc32;
|
|
|
|
|
|
|
|
uint32_t reset_addr;
|
|
|
|
|
|
|
|
bool API_Mode;
|
|
|
|
|
|
|
|
bool booting;
|
|
|
|
|
|
|
|
volatile uint32_t random32;
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// Local Variables
|
|
|
|
|
|
|
|
#if defined(USE_WATCHDOG)
|
|
|
|
volatile uint16_t watchdog_timer;
|
|
|
|
uint16_t watchdog_delay;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
volatile bool inside_timer_int;
|
|
|
|
volatile uint32_t uptime_ms;
|
|
|
|
|
|
|
|
volatile uint16_t second_tick_timer;
|
|
|
|
volatile bool second_tick;
|
|
|
|
|
2011-02-15 14:10:18 +01:00
|
|
|
//volatile int32_t temp_adc;
|
|
|
|
//volatile int32_t psu_adc;
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
#if defined(USE_WATCHDOG)
|
|
|
|
|
|
|
|
void processWatchdog(void)
|
|
|
|
{
|
|
|
|
// random32 = UpdateCRC32(random32, IWDG->SR);
|
|
|
|
|
|
|
|
if (watchdog_timer < watchdog_delay)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// the watchdog needs resetting
|
|
|
|
|
|
|
|
watchdog_timer = 0;
|
|
|
|
|
2011-01-13 20:15:12 +01:00
|
|
|
watchdog_Clear();
|
2011-01-13 09:45:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void enableWatchdog(void)
|
|
|
|
{ // enable a watchdog
|
|
|
|
watchdog_timer = 0;
|
2011-01-13 20:15:12 +01:00
|
|
|
watchdog_delay = watchdog_Init(1000); // 1 second watchdog timeout
|
2011-01-13 09:45:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
void sequenceLEDs(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
USB_LED_ON;
|
|
|
|
PIOS_DELAY_WaitmS(80);
|
|
|
|
USB_LED_OFF;
|
|
|
|
|
|
|
|
LINK_LED_ON;
|
|
|
|
PIOS_DELAY_WaitmS(80);
|
|
|
|
LINK_LED_OFF;
|
|
|
|
|
|
|
|
RX_LED_ON;
|
|
|
|
PIOS_DELAY_WaitmS(80);
|
|
|
|
RX_LED_OFF;
|
|
|
|
|
|
|
|
TX_LED_ON;
|
|
|
|
PIOS_DELAY_WaitmS(80);
|
|
|
|
TX_LED_OFF;
|
|
|
|
|
|
|
|
#if defined(USE_WATCHDOG)
|
|
|
|
processWatchdog(); // process the watchdog
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// timer interrupt
|
|
|
|
|
|
|
|
void TIMER_INT_FUNC(void)
|
|
|
|
{
|
|
|
|
inside_timer_int = TRUE;
|
|
|
|
|
|
|
|
if (TIM_GetITStatus(TIMER_INT_TIMER, TIM_IT_Update) != RESET)
|
|
|
|
{
|
|
|
|
// Clear timer interrupt pending bit
|
|
|
|
TIM_ClearITPendingBit(TIMER_INT_TIMER, TIM_IT_Update);
|
|
|
|
|
|
|
|
// random32 = UpdateCRC32(random32, PIOS_DELAY_TIMER->CNT >> 8);
|
|
|
|
// random32 = UpdateCRC32(random32, PIOS_DELAY_TIMER->CNT);
|
|
|
|
|
|
|
|
uptime_ms++;
|
|
|
|
|
|
|
|
#if defined(USE_WATCHDOG)
|
|
|
|
watchdog_timer++;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ***********
|
|
|
|
|
|
|
|
if (!booting)
|
|
|
|
{
|
|
|
|
// ***********
|
|
|
|
|
|
|
|
if (++second_tick_timer >= 1000)
|
|
|
|
{
|
|
|
|
second_tick_timer -= 1000;
|
|
|
|
second_tick = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ***********
|
|
|
|
|
|
|
|
// read the chip temperature
|
2011-01-16 20:32:53 +01:00
|
|
|
// temp_adc = PIOS_ADC_PinGet(0);
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// read the psu voltage
|
2011-01-16 20:32:53 +01:00
|
|
|
// psu_adc = PIOS_ADC_PinGet(1);
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// ***********
|
|
|
|
|
2011-02-05 14:45:16 +01:00
|
|
|
uint8_t mode = saved_settings.mode;
|
|
|
|
// modeTxBlankCarrierTest, // blank carrier Tx mode (for calibrating the carrier frequency say)
|
|
|
|
// modeTxSpectrumTest // pseudo random Tx data mode (for checking the Tx carrier spectrum)
|
|
|
|
|
2011-01-13 09:45:18 +01:00
|
|
|
rfm22_1ms_tick(); // rf module tick
|
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
if (mode == MODE_NORMAL)
|
2011-02-05 14:45:16 +01:00
|
|
|
ph_1ms_tick(); // packet handler tick
|
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
if (mode == MODE_STREAM_TX || mode == MODE_STREAM_RX)
|
2011-02-05 14:45:16 +01:00
|
|
|
stream_1ms_tick(); // continuous data stream tick
|
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
if (mode == MODE_PPM_TX || mode == MODE_PPM_RX)
|
2011-02-05 14:45:16 +01:00
|
|
|
ppm_1ms_tick(); // ppm tick
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
if (!API_Mode)
|
|
|
|
trans_1ms_tick(); // transparent communications tick
|
|
|
|
else
|
2011-02-02 00:40:40 +01:00
|
|
|
// api_1ms_tick(); // api communications tick
|
|
|
|
apiconfig_1ms_tick(); // api communications tick
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// ***********
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inside_timer_int = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_TimerInt(uint16_t Hz)
|
|
|
|
{ // setup the timer interrupt
|
|
|
|
|
|
|
|
// enable timer clock
|
|
|
|
switch ((uint32_t)TIMER_INT_TIMER)
|
|
|
|
{
|
|
|
|
case (uint32_t)TIM1: RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); break;
|
|
|
|
case (uint32_t)TIM2: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); break;
|
|
|
|
case (uint32_t)TIM3: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); break;
|
|
|
|
case (uint32_t)TIM4: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); break;
|
|
|
|
#ifdef STM32F10X_HD
|
|
|
|
case (uint32_t)TIM5: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE); break;
|
|
|
|
case (uint32_t)TIM6: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); break;
|
|
|
|
case (uint32_t)TIM7: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE); break;
|
|
|
|
case (uint32_t)TIM8: RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable timer interrupt
|
|
|
|
NVIC_InitTypeDef NVIC_InitStructure;
|
|
|
|
switch ((uint32_t)TIMER_INT_TIMER)
|
|
|
|
{
|
|
|
|
// case (uint32_t)TIM1: NVIC_InitStructure.NVIC_IRQChannel = TIM1_IRQn; break;
|
|
|
|
case (uint32_t)TIM2: NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; break;
|
|
|
|
case (uint32_t)TIM3: NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; break;
|
|
|
|
case (uint32_t)TIM4: NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; break;
|
|
|
|
#ifdef STM32F10X_HD
|
|
|
|
case (uint32_t)TIM5: NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn; break;
|
|
|
|
case (uint32_t)TIM6: NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn; break;
|
|
|
|
case (uint32_t)TIM7: NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn; break;
|
|
|
|
// case (uint32_t)TIM8: NVIC_InitStructure.NVIC_IRQChannel = TIM8_IRQn; break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = TIMER_INT_PRIORITY;
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
|
|
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
|
|
NVIC_Init(&NVIC_InitStructure);
|
|
|
|
|
|
|
|
// Time base configuration
|
|
|
|
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
|
|
|
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
|
|
|
TIM_TimeBaseStructure.TIM_Period = ((1000000 / Hz) - 1);
|
|
|
|
TIM_TimeBaseStructure.TIM_Prescaler = (PIOS_MASTER_CLOCK / 1000000) - 1; // For 1 uS accuracy
|
|
|
|
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
|
|
|
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
|
|
|
TIM_TimeBaseInit(TIMER_INT_TIMER, &TIM_TimeBaseStructure);
|
|
|
|
|
|
|
|
// Enable the CC2 Interrupt Request
|
|
|
|
TIM_ITConfig(TIMER_INT_TIMER, TIM_IT_Update, ENABLE);
|
|
|
|
|
|
|
|
// Clear update pending flag
|
|
|
|
TIM_ClearFlag(TIMER_INT_TIMER, TIM_FLAG_Update);
|
|
|
|
|
|
|
|
// Enable counter
|
|
|
|
TIM_Cmd(TIMER_INT_TIMER, ENABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// read the CPU's flash and ram sizes
|
|
|
|
|
|
|
|
void get_CPUDetails(void)
|
|
|
|
{
|
|
|
|
// read the flash size
|
|
|
|
flash_size = (uint32_t)mem16(0x1FFFF7E0) * 1024;
|
|
|
|
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
// read the CPU electronic signature (12-bytes)
|
|
|
|
serial_number_str[j] = 0;
|
|
|
|
for (int i = 0; i < 12; i++)
|
|
|
|
{
|
|
|
|
uint8_t ms_nibble = mem8(0x1ffff7e8 + i) >> 4;
|
|
|
|
uint8_t ls_nibble = mem8(0x1ffff7e8 + i) & 0x0f;
|
|
|
|
if (j > sizeof(serial_number_str) - 3) break;
|
|
|
|
serial_number_str[j++] = ((ms_nibble > 9) ? ('A' - 10) : '0') + ms_nibble;
|
|
|
|
serial_number_str[j++] = ((ls_nibble > 9) ? ('A' - 10) : '0') + ls_nibble;
|
|
|
|
serial_number_str[j] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a 32-bit crc from the serial number hex string
|
2011-02-02 00:40:40 +01:00
|
|
|
serial_number_crc32 = updateCRC32Data(0xffffffff, serial_number_str, j);
|
|
|
|
serial_number_crc32 = updateCRC32(serial_number_crc32, j);
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// reset_addr = (uint32_t)&Reset_Handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
|
|
|
|
void init_RF_module(void)
|
|
|
|
{
|
|
|
|
int i = -100;
|
|
|
|
|
|
|
|
switch (saved_settings.frequency_band)
|
|
|
|
{
|
2011-02-06 11:55:08 +01:00
|
|
|
case FREQBAND_434MHz:
|
|
|
|
case FREQBAND_868MHz:
|
|
|
|
case FREQBAND_915MHz:
|
2011-02-23 10:30:06 +01:00
|
|
|
i = rfm22_init_normal(saved_settings.min_frequency_Hz, saved_settings.max_frequency_Hz, 50000);
|
2011-01-13 09:45:18 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
#if defined(PIOS_COM_DEBUG)
|
2011-02-27 14:13:10 +01:00
|
|
|
DEBUG_PRINTF("UNKNOWN BAND ERROR\r\n\r\n", i);
|
2011-01-13 09:45:18 +01:00
|
|
|
#endif
|
|
|
|
|
2011-02-27 14:13:10 +01:00
|
|
|
for (int j = 0; j < 16; j++)
|
2011-01-13 09:45:18 +01:00
|
|
|
{
|
|
|
|
USB_LED_ON;
|
|
|
|
LINK_LED_OFF;
|
|
|
|
RX_LED_ON;
|
|
|
|
TX_LED_OFF;
|
|
|
|
|
|
|
|
PIOS_DELAY_WaitmS(200);
|
|
|
|
|
|
|
|
USB_LED_OFF;
|
|
|
|
LINK_LED_ON;
|
|
|
|
RX_LED_OFF;
|
|
|
|
TX_LED_ON;
|
|
|
|
|
|
|
|
PIOS_DELAY_WaitmS(200);
|
|
|
|
|
|
|
|
#if defined(USE_WATCHDOG)
|
|
|
|
processWatchdog();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
PIOS_DELAY_WaitmS(1000);
|
|
|
|
|
|
|
|
PIOS_SYS_Reset();
|
|
|
|
|
|
|
|
while (1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < 0)
|
|
|
|
{ // RF module error .. flash the LED's
|
|
|
|
|
|
|
|
#if defined(PIOS_COM_DEBUG)
|
2011-02-27 14:13:10 +01:00
|
|
|
DEBUG_PRINTF("RF ERROR res: %d\r\n\r\n", i);
|
2011-01-13 09:45:18 +01:00
|
|
|
#endif
|
|
|
|
|
2011-02-27 14:13:10 +01:00
|
|
|
for (int j = 0; j < 16; j++)
|
2011-01-13 09:45:18 +01:00
|
|
|
{
|
|
|
|
USB_LED_ON;
|
|
|
|
LINK_LED_ON;
|
|
|
|
RX_LED_OFF;
|
|
|
|
TX_LED_OFF;
|
|
|
|
|
|
|
|
PIOS_DELAY_WaitmS(200);
|
|
|
|
|
|
|
|
USB_LED_OFF;
|
|
|
|
LINK_LED_OFF;
|
|
|
|
RX_LED_ON;
|
|
|
|
TX_LED_ON;
|
|
|
|
|
|
|
|
PIOS_DELAY_WaitmS(200);
|
|
|
|
|
|
|
|
#if defined(USE_WATCHDOG)
|
|
|
|
processWatchdog();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
PIOS_DELAY_WaitmS(1000);
|
|
|
|
|
|
|
|
PIOS_SYS_Reset();
|
|
|
|
|
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
|
2011-02-02 12:44:23 +01:00
|
|
|
rfm22_setFreqCalibration(saved_settings.rf_xtal_cap);
|
2011-03-04 09:34:44 +01:00
|
|
|
rfm22_setNominalCarrierFrequency(saved_settings.frequency_Hz);
|
|
|
|
rfm22_setDatarate(saved_settings.max_rf_bandwidth, TRUE);
|
|
|
|
rfm22_setTxPower(saved_settings.max_tx_power);
|
2011-01-13 09:45:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// find out what caused our reset and act on it
|
|
|
|
|
|
|
|
void processReset(void)
|
|
|
|
{
|
|
|
|
if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
|
|
|
|
{ // Independant Watchdog Reset
|
|
|
|
|
|
|
|
#if defined(PIOS_COM_DEBUG)
|
|
|
|
DEBUG_PRINTF("\r\nINDEPENDANT WATCHDOG CAUSED A RESET\r\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// all led's ON
|
|
|
|
USB_LED_ON;
|
|
|
|
LINK_LED_ON;
|
|
|
|
RX_LED_ON;
|
|
|
|
TX_LED_ON;
|
|
|
|
|
|
|
|
PIOS_DELAY_WaitmS(500); // delay a bit
|
|
|
|
|
|
|
|
// all led's OFF
|
|
|
|
USB_LED_OFF;
|
|
|
|
LINK_LED_OFF;
|
|
|
|
RX_LED_OFF;
|
|
|
|
TX_LED_OFF;
|
|
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
|
|
|
|
{ // Window Watchdog Reset
|
|
|
|
|
|
|
|
DEBUG_PRINTF("\r\nWINDOW WATCHDOG CAUSED A REBOOT\r\n");
|
|
|
|
|
|
|
|
// all led's ON
|
|
|
|
USB_LED_ON;
|
|
|
|
LINK_LED_ON;
|
|
|
|
RX_LED_ON;
|
|
|
|
TX_LED_ON;
|
|
|
|
|
|
|
|
PIOS_DELAY_WaitmS(500); // delay a bit
|
|
|
|
|
|
|
|
// all led's OFF
|
|
|
|
USB_LED_OFF;
|
|
|
|
LINK_LED_OFF;
|
|
|
|
RX_LED_OFF;
|
|
|
|
TX_LED_OFF;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
|
|
|
|
{ // Power-On Reset
|
|
|
|
#if defined(PIOS_COM_DEBUG)
|
|
|
|
DEBUG_PRINTF("\r\nPOWER-ON-RESET\r\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RCC_GetFlagStatus(RCC_FLAG_SFTRST) != RESET)
|
|
|
|
{ // Software Reset
|
|
|
|
#if defined(PIOS_COM_DEBUG)
|
|
|
|
DEBUG_PRINTF("\r\nSOFTWARE RESET\r\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RCC_GetFlagStatus(RCC_FLAG_LPWRRST) != RESET)
|
|
|
|
{ // Low-Power Reset
|
|
|
|
#if defined(PIOS_COM_DEBUG)
|
|
|
|
DEBUG_PRINTF("\r\nLOW POWER RESET\r\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
|
|
|
|
{ // Pin Reset
|
|
|
|
#if defined(PIOS_COM_DEBUG)
|
|
|
|
DEBUG_PRINTF("\r\nPIN RESET\r\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear reset flags
|
|
|
|
RCC_ClearFlag();
|
|
|
|
}
|
|
|
|
|
|
|
|
// *****************************************************************************
|
|
|
|
// Main function
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// *************
|
|
|
|
// init various variables
|
|
|
|
|
|
|
|
booting = TRUE;
|
|
|
|
|
|
|
|
inside_timer_int = FALSE;
|
|
|
|
|
|
|
|
uptime_ms = 0;
|
|
|
|
|
|
|
|
flash_size = 0;
|
|
|
|
|
|
|
|
serial_number_str[0] = 0;
|
|
|
|
serial_number_crc32 = 0;
|
|
|
|
|
|
|
|
reset_addr = 0;
|
|
|
|
|
2011-01-16 20:32:53 +01:00
|
|
|
// temp_adc = -1;
|
|
|
|
// psu_adc = -1;
|
2011-01-13 09:45:18 +01:00
|
|
|
|
2011-02-02 00:40:40 +01:00
|
|
|
// API_Mode = FALSE;
|
|
|
|
API_Mode = TRUE; // TEST ONLY
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
second_tick_timer = 0;
|
|
|
|
second_tick = FALSE;
|
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
saved_settings.frequency_band = FREQBAND_UNKNOWN;
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// *************
|
2011-02-15 14:10:18 +01:00
|
|
|
|
2011-02-12 23:19:43 +01:00
|
|
|
PIOS_Board_Init();
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
CRC_init();
|
|
|
|
|
|
|
|
// read the CPU details
|
|
|
|
get_CPUDetails();
|
|
|
|
|
|
|
|
// setup the GPIO input pins
|
|
|
|
GPIO_IN_Init();
|
|
|
|
|
|
|
|
// *************
|
|
|
|
// set various GPIO pin states
|
|
|
|
|
|
|
|
// uart serial RTS line high
|
|
|
|
SERIAL_RTS_ENABLE;
|
|
|
|
SERIAL_RTS_SET;
|
|
|
|
|
|
|
|
// RF module chip-select line high
|
|
|
|
RF_CS_ENABLE;
|
|
|
|
RF_CS_HIGH;
|
|
|
|
|
2011-02-24 18:31:24 +01:00
|
|
|
// pin high
|
|
|
|
SPARE1_ENABLE;
|
|
|
|
SPARE1_HIGH;
|
|
|
|
|
|
|
|
// pin high
|
|
|
|
SPARE2_ENABLE;
|
|
|
|
SPARE2_HIGH;
|
|
|
|
|
|
|
|
// pin high
|
|
|
|
SPARE3_ENABLE;
|
|
|
|
SPARE3_HIGH;
|
|
|
|
|
|
|
|
// pin high
|
|
|
|
SPARE4_ENABLE;
|
|
|
|
SPARE4_HIGH;
|
|
|
|
|
|
|
|
// pin high
|
|
|
|
SPARE5_ENABLE;
|
|
|
|
SPARE5_HIGH;
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// *************
|
|
|
|
|
2011-03-04 09:34:44 +01:00
|
|
|
random32 ^= serial_number_crc32; // try to randomise the random number
|
|
|
|
// random32 ^= serial_number_crc32 ^ CRC_IDR; // try to randomise the random number
|
2011-01-13 09:45:18 +01:00
|
|
|
|
2011-03-04 09:34:44 +01:00
|
|
|
trans_init(); // initialise the transparent communications module
|
2011-01-13 09:45:18 +01:00
|
|
|
|
2011-02-02 00:40:40 +01:00
|
|
|
// api_init(); // initialise the API communications module
|
|
|
|
apiconfig_init(); // initialise the API communications module
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
setup_TimerInt(1000); // setup a 1kHz timer interrupt
|
|
|
|
|
2011-02-15 14:10:18 +01:00
|
|
|
#if defined(USE_WATCHDOG)
|
|
|
|
enableWatchdog(); // enable the watchdog
|
|
|
|
#endif
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// *************
|
|
|
|
// do a simple LED flash test sequence so the user knows all the led's are working and that we have booted
|
|
|
|
|
|
|
|
PIOS_DELAY_WaitmS(100);
|
|
|
|
|
|
|
|
// turn all the leds off
|
|
|
|
USB_LED_OFF;
|
|
|
|
LINK_LED_OFF;
|
|
|
|
RX_LED_OFF;
|
|
|
|
TX_LED_OFF;
|
|
|
|
|
|
|
|
PIOS_DELAY_WaitmS(200);
|
|
|
|
|
|
|
|
sequenceLEDs();
|
|
|
|
|
|
|
|
// turn all the leds off
|
|
|
|
USB_LED_OFF;
|
|
|
|
LINK_LED_OFF;
|
|
|
|
RX_LED_OFF;
|
|
|
|
TX_LED_OFF;
|
|
|
|
|
|
|
|
// *************
|
|
|
|
|
|
|
|
#if defined(PIOS_COM_DEBUG)
|
|
|
|
DEBUG_PRINTF("\r\n");
|
2011-02-06 22:21:50 +01:00
|
|
|
DEBUG_PRINTF("PipXtreme v%u.%u rebooted\r\n", VERSION_MAJOR, VERSION_MINOR);
|
2011-02-15 14:10:18 +01:00
|
|
|
DEBUG_PRINTF("\r\n");
|
|
|
|
DEBUG_PRINTF("CPU flash size: %u\r\n", flash_size);
|
|
|
|
DEBUG_PRINTF("CPU serial number: %s %08X\r\n", serial_number_str, serial_number_crc32);
|
|
|
|
// DEBUG_PRINTF("Reset address: %08X\r\n", reset_addr);
|
2011-01-13 09:45:18 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// *************
|
2011-02-15 14:10:18 +01:00
|
|
|
// initialise the saved settings module
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
saved_settings_init();
|
|
|
|
|
2011-02-15 13:57:46 +01:00
|
|
|
if (saved_settings.mode == 0xff ||
|
|
|
|
saved_settings.mode == MODE_TX_BLANK_CARRIER_TEST ||
|
|
|
|
saved_settings.mode == MODE_TX_SPECTRUM_TEST ||
|
|
|
|
saved_settings.mode == MODE_SCAN_SPECTRUM)
|
2011-02-15 14:10:18 +01:00
|
|
|
saved_settings.mode = MODE_NORMAL; // go back to NORMAL mode
|
2011-02-15 13:57:46 +01:00
|
|
|
|
|
|
|
if (saved_settings.rts_time == 0xff || saved_settings.rts_time > 100)
|
2011-02-15 14:10:18 +01:00
|
|
|
saved_settings.rts_time = 10; // default to 10ms
|
2011-02-15 13:57:46 +01:00
|
|
|
|
2011-02-02 12:44:23 +01:00
|
|
|
#if !defined(PIOS_COM_DEBUG)
|
|
|
|
if (saved_settings.serial_baudrate != 0xffffffff)
|
|
|
|
PIOS_COM_ChangeBaud(PIOS_COM_SERIAL, saved_settings.serial_baudrate);
|
|
|
|
#endif
|
|
|
|
|
2011-01-13 09:45:18 +01:00
|
|
|
// *************
|
|
|
|
// read the API mode pin
|
|
|
|
|
|
|
|
if (!GPIO_IN(API_MODE_PIN))
|
|
|
|
API_Mode = TRUE;
|
|
|
|
|
2011-02-15 14:10:18 +01:00
|
|
|
#if defined(PIOS_COM_DEBUG)
|
|
|
|
if (!API_Mode)
|
|
|
|
DEBUG_PRINTF("TRANSPARENT mode\r\n");
|
|
|
|
else
|
|
|
|
DEBUG_PRINTF("API mode\r\n");
|
|
|
|
#endif
|
|
|
|
|
2011-01-13 09:45:18 +01:00
|
|
|
// *************
|
|
|
|
// read the 434/868/915 jumper options
|
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
if (!GPIO_IN(_868MHz_PIN) && !GPIO_IN(_915MHz_PIN)) saved_settings.frequency_band = FREQBAND_434MHz; // 434MHz band
|
2011-01-13 09:45:18 +01:00
|
|
|
else
|
2011-02-06 11:55:08 +01:00
|
|
|
if (!GPIO_IN(_868MHz_PIN) && GPIO_IN(_915MHz_PIN)) saved_settings.frequency_band = FREQBAND_868MHz; // 868MHz band
|
2011-01-13 09:45:18 +01:00
|
|
|
else
|
2011-02-06 11:55:08 +01:00
|
|
|
if ( GPIO_IN(_868MHz_PIN) && !GPIO_IN(_915MHz_PIN)) saved_settings.frequency_band = FREQBAND_915MHz; // 915MHz band
|
2011-01-13 09:45:18 +01:00
|
|
|
|
2011-02-02 12:44:23 +01:00
|
|
|
// set some defaults if they are not set
|
2011-01-13 09:45:18 +01:00
|
|
|
switch (saved_settings.frequency_band)
|
|
|
|
{
|
2011-02-06 11:55:08 +01:00
|
|
|
case FREQBAND_434MHz:
|
2011-02-05 00:00:48 +01:00
|
|
|
|
2011-02-02 00:40:40 +01:00
|
|
|
if (saved_settings.min_frequency_Hz == 0xffffffff)
|
2011-01-13 09:45:18 +01:00
|
|
|
{
|
|
|
|
saved_settings.frequency_Hz = 434000000;
|
2011-02-02 00:40:40 +01:00
|
|
|
saved_settings.min_frequency_Hz = saved_settings.frequency_Hz - 2000000;
|
|
|
|
saved_settings.max_frequency_Hz = saved_settings.frequency_Hz + 2000000;
|
2011-01-13 09:45:18 +01:00
|
|
|
}
|
2011-02-02 00:40:40 +01:00
|
|
|
if (saved_settings.max_rf_bandwidth == 0xffffffff)
|
2011-01-13 09:45:18 +01:00
|
|
|
{
|
|
|
|
// saved_settings.max_rf_bandwidth = 500;
|
|
|
|
// saved_settings.max_rf_bandwidth = 1000;
|
|
|
|
// saved_settings.max_rf_bandwidth = 2000;
|
|
|
|
// saved_settings.max_rf_bandwidth = 4000;
|
|
|
|
// saved_settings.max_rf_bandwidth = 8000;
|
|
|
|
// saved_settings.max_rf_bandwidth = 9600;
|
|
|
|
// saved_settings.max_rf_bandwidth = 16000;
|
|
|
|
// saved_settings.max_rf_bandwidth = 19200;
|
|
|
|
// saved_settings.max_rf_bandwidth = 24000;
|
|
|
|
// saved_settings.max_rf_bandwidth = 32000;
|
|
|
|
// saved_settings.max_rf_bandwidth = 64000;
|
|
|
|
saved_settings.max_rf_bandwidth = 128000;
|
|
|
|
// saved_settings.max_rf_bandwidth = 192000;
|
|
|
|
}
|
2011-02-02 00:40:40 +01:00
|
|
|
if (saved_settings.max_tx_power == 0xff)
|
2011-01-13 09:45:18 +01:00
|
|
|
{
|
2011-02-06 22:21:50 +01:00
|
|
|
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_0; // +1dBm ... 1.25mW
|
|
|
|
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_1; // +2dBm ... 1.6mW
|
|
|
|
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_2; // +5dBm ... 3.16mW
|
|
|
|
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_3; // +8dBm ... 6.3mW
|
|
|
|
saved_settings.max_tx_power = RFM22_tx_pwr_txpow_4; // +11dBm .. 12.6mW
|
|
|
|
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_5; // +14dBm .. 25mW
|
|
|
|
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_6; // +17dBm .. 50mW
|
|
|
|
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_7; // +20dBm .. 100mW
|
2011-01-13 09:45:18 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
case FREQBAND_868MHz:
|
2011-02-02 00:40:40 +01:00
|
|
|
if (saved_settings.min_frequency_Hz == 0xffffffff)
|
2011-01-13 09:45:18 +01:00
|
|
|
{
|
|
|
|
saved_settings.frequency_Hz = 868000000;
|
2011-02-02 00:40:40 +01:00
|
|
|
saved_settings.min_frequency_Hz = saved_settings.frequency_Hz - 10000000;
|
|
|
|
saved_settings.max_frequency_Hz = saved_settings.frequency_Hz + 10000000;
|
2011-01-13 09:45:18 +01:00
|
|
|
}
|
2011-02-02 00:40:40 +01:00
|
|
|
if (saved_settings.max_rf_bandwidth == 0xffffffff)
|
2011-01-13 09:45:18 +01:00
|
|
|
saved_settings.max_rf_bandwidth = 128000;
|
2011-02-02 00:40:40 +01:00
|
|
|
if (saved_settings.max_tx_power == 0xff)
|
2011-02-06 22:21:50 +01:00
|
|
|
saved_settings.max_tx_power = RFM22_tx_pwr_txpow_4; // +11dBm .. 12.6mW
|
2011-01-13 09:45:18 +01:00
|
|
|
break;
|
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
case FREQBAND_915MHz:
|
2011-02-02 00:40:40 +01:00
|
|
|
if (saved_settings.min_frequency_Hz == 0xffffffff)
|
2011-01-13 09:45:18 +01:00
|
|
|
{
|
|
|
|
saved_settings.frequency_Hz = 915000000;
|
2011-02-02 00:40:40 +01:00
|
|
|
saved_settings.min_frequency_Hz = saved_settings.frequency_Hz - 13000000;
|
|
|
|
saved_settings.max_frequency_Hz = saved_settings.frequency_Hz + 13000000;
|
2011-01-13 09:45:18 +01:00
|
|
|
}
|
2011-02-02 00:40:40 +01:00
|
|
|
if (saved_settings.max_rf_bandwidth == 0xffffffff)
|
2011-01-13 09:45:18 +01:00
|
|
|
saved_settings.max_rf_bandwidth = 128000;
|
2011-02-02 00:40:40 +01:00
|
|
|
if (saved_settings.max_tx_power == 0xff)
|
2011-02-06 22:21:50 +01:00
|
|
|
saved_settings.max_tx_power = RFM22_tx_pwr_txpow_4; // +11dBm .. 12.6mW
|
2011-01-13 09:45:18 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-15 14:10:18 +01:00
|
|
|
#if defined(PIOS_COM_DEBUG)
|
|
|
|
switch (saved_settings.frequency_band)
|
|
|
|
{
|
|
|
|
case FREQBAND_UNKNOWN: DEBUG_PRINTF("UNKNOWN band\r\n"); break;
|
|
|
|
case FREQBAND_434MHz: DEBUG_PRINTF("434MHz band\r\n"); break;
|
|
|
|
case FREQBAND_868MHz: DEBUG_PRINTF("868MHz band\r\n"); break;
|
|
|
|
case FREQBAND_915MHz: DEBUG_PRINTF("915MHz band\r\n"); break;
|
|
|
|
}
|
|
|
|
#endif
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// *************
|
|
|
|
|
2011-02-15 14:10:18 +01:00
|
|
|
processReset(); // Determine what caused the reset/reboot
|
2011-01-13 09:45:18 +01:00
|
|
|
|
2011-02-05 14:45:16 +01:00
|
|
|
init_RF_module(); // initialise the RF module
|
|
|
|
|
2011-03-04 09:34:44 +01:00
|
|
|
// *************
|
2011-02-05 14:45:16 +01:00
|
|
|
|
2011-03-04 09:34:44 +01:00
|
|
|
#if defined(PIOS_COM_DEBUG)
|
|
|
|
DEBUG_PRINTF("\r\n");
|
|
|
|
DEBUG_PRINTF("RF datarate: %dbps\r\n", ph_getDatarate());
|
|
|
|
DEBUG_PRINTF("RF frequency: %dHz\r\n", rfm22_getNominalCarrierFrequency());
|
|
|
|
DEBUG_PRINTF("RF TX power: %d\r\n", ph_getTxPower());
|
2011-02-05 14:45:16 +01:00
|
|
|
|
2011-03-04 09:34:44 +01:00
|
|
|
DEBUG_PRINTF("\r\nUnit mode: ");
|
|
|
|
switch (saved_settings.mode)
|
|
|
|
{
|
|
|
|
case MODE_NORMAL: DEBUG_PRINTF("NORMAL\r\n"); break;
|
|
|
|
case MODE_STREAM_TX: DEBUG_PRINTF("STREAM-TX\r\n"); break;
|
|
|
|
case MODE_STREAM_RX: DEBUG_PRINTF("STREAM-RX\r\n"); break;
|
|
|
|
case MODE_PPM_TX: DEBUG_PRINTF("PPM-TX\r\n"); break;
|
|
|
|
case MODE_PPM_RX: DEBUG_PRINTF("PPM-RX\r\n"); break;
|
|
|
|
case MODE_SCAN_SPECTRUM: DEBUG_PRINTF("SCAN-SPECTRUM\r\n"); break;
|
|
|
|
case MODE_TX_BLANK_CARRIER_TEST: DEBUG_PRINTF("TX-BLANK-CARRIER\r\n"); break;
|
|
|
|
case MODE_TX_SPECTRUM_TEST: DEBUG_PRINTF("TX_SPECTRUM\r\n"); break;
|
|
|
|
default: DEBUG_PRINTF("UNKNOWN [%u]\r\n", saved_settings.mode); break;
|
|
|
|
}
|
|
|
|
#endif
|
2011-01-13 09:45:18 +01:00
|
|
|
|
2011-03-04 09:34:44 +01:00
|
|
|
switch (saved_settings.mode)
|
|
|
|
{
|
|
|
|
case MODE_NORMAL:
|
|
|
|
ph_init(serial_number_crc32); // initialise the packet handler
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_STREAM_TX:
|
|
|
|
case MODE_STREAM_RX:
|
|
|
|
stream_init(serial_number_crc32); // initialise the continuous packet stream module
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_PPM_TX:
|
|
|
|
case MODE_PPM_RX:
|
|
|
|
ppm_init(serial_number_crc32); // initialise the ppm module
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_SCAN_SPECTRUM:
|
|
|
|
case MODE_TX_BLANK_CARRIER_TEST:
|
|
|
|
case MODE_TX_SPECTRUM_TEST:
|
|
|
|
break;
|
|
|
|
}
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// *************
|
2011-02-02 12:44:23 +01:00
|
|
|
// Main executive loop
|
2011-01-13 09:45:18 +01:00
|
|
|
|
2011-03-04 09:34:44 +01:00
|
|
|
saved_settings_save();
|
2011-01-13 09:45:18 +01:00
|
|
|
|
2011-03-04 09:34:44 +01:00
|
|
|
booting = FALSE;
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
2011-02-02 00:40:40 +01:00
|
|
|
random32 = updateCRC32(random32, PIOS_DELAY_TIMER->CNT >> 8);
|
|
|
|
random32 = updateCRC32(random32, PIOS_DELAY_TIMER->CNT);
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
if (second_tick)
|
|
|
|
{
|
|
|
|
second_tick = FALSE;
|
|
|
|
|
|
|
|
// *************************
|
|
|
|
// display the up-time .. HH:MM:SS
|
|
|
|
|
2011-02-15 14:10:18 +01:00
|
|
|
// #if defined(PIOS_COM_DEBUG)
|
|
|
|
// uint32_t _uptime_ms = uptime_ms;
|
|
|
|
// uint32_t _uptime_sec = _uptime_ms / 1000;
|
|
|
|
// DEBUG_PRINTF("Uptime: %02d:%02d:%02d.%03d\r\n", _uptime_sec / 3600, (_uptime_sec / 60) % 60, _uptime_sec % 60, _uptime_ms % 1000);
|
|
|
|
// #endif
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// *************************
|
|
|
|
// process the Temperature
|
|
|
|
|
2011-02-15 14:10:18 +01:00
|
|
|
// if (temp_adc >= 0)
|
|
|
|
// {
|
2011-01-13 09:45:18 +01:00
|
|
|
// int32_t degress_C = temp_adc;
|
|
|
|
//
|
|
|
|
// #if defined(PIOS_COM_DEBUG)
|
|
|
|
// DEBUG_PRINTF("TEMP: %d %d\r\n", temp_adc, degress_C);
|
|
|
|
// #endif
|
2011-02-15 14:10:18 +01:00
|
|
|
// }
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
// *************************
|
|
|
|
// process the PSU voltage level
|
|
|
|
|
|
|
|
// if (psu_adc >= 0)
|
|
|
|
// {
|
|
|
|
// int32_t psu_mV = psu_adc * ADC_PSU_mV_SCALE;
|
|
|
|
//
|
|
|
|
// #if defined(PIOS_COM_DEBUG)
|
|
|
|
// DEBUG_PRINTF("PSU: %d, %dmV\r\n", psu_adc, psu_mV);
|
|
|
|
// #endif
|
|
|
|
// }
|
|
|
|
|
|
|
|
// *************************
|
|
|
|
}
|
|
|
|
|
|
|
|
rfm22_process(); // rf hardware layer processing
|
|
|
|
|
2011-02-05 14:45:16 +01:00
|
|
|
uint8_t mode = saved_settings.mode;
|
|
|
|
// modeTxBlankCarrierTest, // blank carrier Tx mode (for calibrating the carrier frequency say)
|
|
|
|
// modeTxSpectrumTest // pseudo random Tx data mode (for checking the Tx carrier spectrum)
|
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
if (mode == MODE_NORMAL)
|
2011-02-05 14:45:16 +01:00
|
|
|
ph_process(); // packet handler processing
|
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
if (mode == MODE_STREAM_TX || mode == MODE_STREAM_RX)
|
2011-02-05 14:45:16 +01:00
|
|
|
stream_process(); // continuous data stream processing
|
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
if (mode == MODE_PPM_TX || mode == MODE_PPM_RX)
|
2011-02-05 14:45:16 +01:00
|
|
|
ppm_process(); // ppm processing
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
if (!API_Mode)
|
2011-02-02 00:40:40 +01:00
|
|
|
trans_process(); // tranparent local communication processing (serial port and usb port)
|
2011-01-13 09:45:18 +01:00
|
|
|
else
|
2011-02-02 00:40:40 +01:00
|
|
|
// api_process(); // API local communication processing (serial port and usb port)
|
|
|
|
apiconfig_process(); // API local communication processing (serial port and usb port)
|
2011-01-13 09:45:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ******************
|
2011-01-31 16:44:39 +01:00
|
|
|
// TEST ONLY ... get/put data over the radio link .. speed testing .. comment out trans_process() and api_process() if testing with this
|
2011-01-13 09:45:18 +01:00
|
|
|
/*
|
|
|
|
int connection_index = 0;
|
|
|
|
|
|
|
|
if (ph_connected(connection_index))
|
|
|
|
{ // we have a connection to a remote modem
|
|
|
|
|
|
|
|
uint8_t buffer[128];
|
|
|
|
|
|
|
|
uint16_t num = ph_getData_used(connection_index); // number of bytes waiting for us to get
|
|
|
|
if (num > 0)
|
|
|
|
{ // their is data in the received buffer - fetch it
|
|
|
|
if (num > sizeof(buffer)) num = sizeof(buffer);
|
|
|
|
num = ph_getData(connection_index, buffer, num); // fetch the received data
|
|
|
|
}
|
|
|
|
|
|
|
|
// keep the tx buffer topped up
|
|
|
|
num = ph_putData_free(connection_index);
|
|
|
|
if (num > 0)
|
|
|
|
{ // their is space available in the transmit buffer - top it up
|
|
|
|
if (num > sizeof(buffer)) num = sizeof(buffer);
|
|
|
|
for (int16_t i = 0; i < num; i++) buffer[i] = i;
|
|
|
|
num = ph_putData(connection_index, buffer, num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// ******************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(USE_WATCHDOG)
|
|
|
|
processWatchdog(); // process the watchdog
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// *************
|
|
|
|
// we should never arrive here
|
|
|
|
|
|
|
|
// disable all interrupts
|
|
|
|
PIOS_IRQ_Disable();
|
|
|
|
|
|
|
|
// turn off all leds
|
|
|
|
USB_LED_OFF;
|
|
|
|
LINK_LED_OFF;
|
|
|
|
RX_LED_OFF;
|
|
|
|
TX_LED_OFF;
|
|
|
|
|
|
|
|
PIOS_SYS_Reset();
|
|
|
|
|
|
|
|
while (1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// *****************************************************************************
|