2010-09-27 09:28:45 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
|
|
|
* @{
|
|
|
|
* @addtogroup PIOS_SPEKTRUM Spektrum receiver functions
|
|
|
|
* @brief Code to read Spektrum input
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file pios_spektrum.c
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @brief USART commands. Inits USARTs, controls USARTs & Interrupt handlers. (STM32 dependent)
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Project Includes */
|
|
|
|
#include "pios.h"
|
|
|
|
|
|
|
|
#if defined(PIOS_INCLUDE_SPEKTRUM)
|
|
|
|
|
2011-07-30 21:04:24 +02:00
|
|
|
#include "pios_spektrum_priv.h"
|
|
|
|
|
2011-03-07 22:29:41 +01:00
|
|
|
/**
|
|
|
|
* @Note Framesyncing:
|
|
|
|
* The code resets the watchdog timer whenever a single byte is received, so what watchdog code
|
2011-05-29 13:52:22 +02:00
|
|
|
* is never called if regularly getting bytes.
|
|
|
|
* RTC timer is running @625Hz, supervisor timer has divider 5 so frame sync comes every 1/125Hz=8ms.
|
|
|
|
* Good for both 11ms and 22ms framecycles
|
2011-03-07 22:29:41 +01:00
|
|
|
*/
|
|
|
|
|
2010-09-27 09:28:45 +02:00
|
|
|
/* Global Variables */
|
|
|
|
|
2011-06-25 15:27:28 +02:00
|
|
|
/* Provide a RCVR driver */
|
2011-07-15 03:52:07 +02:00
|
|
|
static int32_t PIOS_SPEKTRUM_Get(uint32_t rcvr_id, uint8_t channel);
|
2011-06-25 15:27:28 +02:00
|
|
|
|
|
|
|
const struct pios_rcvr_driver pios_spektrum_rcvr_driver = {
|
|
|
|
.read = PIOS_SPEKTRUM_Get,
|
|
|
|
};
|
|
|
|
|
2011-07-30 21:04:24 +02:00
|
|
|
enum pios_spektrum_dev_magic {
|
|
|
|
PIOS_SPEKTRUM_DEV_MAGIC = 0xa9b9c9d9,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pios_spektrum_fsm {
|
|
|
|
uint16_t channel;
|
|
|
|
uint16_t CaptureValue[PIOS_SPEKTRUM_NUM_INPUTS];
|
|
|
|
uint16_t CaptureValueTemp[PIOS_SPEKTRUM_NUM_INPUTS];
|
|
|
|
uint8_t prev_byte;
|
|
|
|
uint8_t sync;
|
|
|
|
uint8_t bytecount;
|
|
|
|
uint8_t datalength;
|
|
|
|
uint8_t frame_error;
|
|
|
|
uint8_t sync_of;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pios_spektrum_dev {
|
|
|
|
enum pios_spektrum_dev_magic magic;
|
|
|
|
const struct pios_spektrum_cfg * cfg;
|
|
|
|
|
|
|
|
struct pios_spektrum_fsm fsm;
|
|
|
|
|
|
|
|
uint16_t supv_timer;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool PIOS_SPEKTRUM_validate(struct pios_spektrum_dev * spektrum_dev)
|
|
|
|
{
|
|
|
|
return (spektrum_dev->magic == PIOS_SPEKTRUM_DEV_MAGIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(PIOS_INCLUDE_FREERTOS) && 0
|
|
|
|
static struct pios_spektrum_dev * PIOS_SPEKTRUM_alloc(void)
|
|
|
|
{
|
|
|
|
struct pios_spektrum_dev * spektrum_dev;
|
|
|
|
|
|
|
|
spektrum_dev = (struct pios_spektrum_dev *)malloc(sizeof(*spektrum_dev));
|
|
|
|
if (!spektrum_dev) return(NULL);
|
|
|
|
|
|
|
|
spektrum_dev->magic = PIOS_SPEKTRUM_DEV_MAGIC;
|
|
|
|
return(spektrum_dev);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static struct pios_spektrum_dev pios_spektrum_devs[PIOS_SPEKTRUM_MAX_DEVS];
|
|
|
|
static uint8_t pios_spektrum_num_devs;
|
|
|
|
static struct pios_spektrum_dev * PIOS_SPEKTRUM_alloc(void)
|
|
|
|
{
|
|
|
|
struct pios_spektrum_dev * spektrum_dev;
|
|
|
|
|
|
|
|
if (pios_spektrum_num_devs >= PIOS_SPEKTRUM_MAX_DEVS) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
spektrum_dev = &pios_spektrum_devs[pios_spektrum_num_devs++];
|
|
|
|
spektrum_dev->magic = PIOS_SPEKTRUM_DEV_MAGIC;
|
|
|
|
|
|
|
|
return (spektrum_dev);
|
|
|
|
}
|
|
|
|
#endif
|
2010-09-27 09:28:45 +02:00
|
|
|
|
2011-07-03 01:25:35 +02:00
|
|
|
static void PIOS_SPEKTRUM_Supervisor(uint32_t spektrum_id);
|
2011-08-06 21:16:47 +02:00
|
|
|
static bool PIOS_SPEKTRUM_Bind(const struct pios_spektrum_cfg * cfg, uint8_t bind);
|
2011-07-30 21:04:24 +02:00
|
|
|
static int32_t PIOS_SPEKTRUM_UpdateFSM(struct pios_spektrum_fsm * fsm, uint8_t b);
|
2011-07-26 06:27:03 +02:00
|
|
|
|
|
|
|
static uint16_t PIOS_SPEKTRUM_RxInCallback(uint32_t context, uint8_t * buf, uint16_t buf_len, uint16_t * headroom, bool * need_yield)
|
|
|
|
{
|
2011-07-30 21:04:24 +02:00
|
|
|
struct pios_spektrum_dev * spektrum_dev = (struct pios_spektrum_dev *)context;
|
|
|
|
|
|
|
|
bool valid = PIOS_SPEKTRUM_validate(spektrum_dev);
|
|
|
|
PIOS_Assert(valid);
|
|
|
|
|
2011-07-26 06:27:03 +02:00
|
|
|
/* process byte(s) and clear receive timer */
|
|
|
|
for (uint8_t i = 0; i < buf_len; i++) {
|
2011-07-30 21:04:24 +02:00
|
|
|
PIOS_SPEKTRUM_UpdateFSM(&(spektrum_dev->fsm), buf[i]);
|
|
|
|
spektrum_dev->supv_timer = 0;
|
2011-07-26 06:27:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Always signal that we can accept another byte */
|
|
|
|
if (headroom) {
|
|
|
|
*headroom = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We never need a yield */
|
|
|
|
*need_yield = false;
|
|
|
|
|
|
|
|
/* Always indicate that all bytes were consumed */
|
|
|
|
return (buf_len);
|
|
|
|
}
|
2011-07-03 01:25:35 +02:00
|
|
|
|
2011-07-30 21:04:24 +02:00
|
|
|
static void PIOS_SPEKTRUM_ResetFSM(struct pios_spektrum_fsm * fsm)
|
|
|
|
{
|
|
|
|
fsm->channel = 0;
|
|
|
|
fsm->prev_byte = 0xFF;
|
|
|
|
fsm->sync = 0;
|
|
|
|
fsm->bytecount = 0;
|
|
|
|
fsm->datalength = 0;
|
|
|
|
fsm->frame_error = 0;
|
|
|
|
fsm->sync_of = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decodes a byte
|
|
|
|
* \param[in] b byte which should be spektrum decoded
|
|
|
|
* \return 0 if no error
|
|
|
|
* \return -1 if USART not available
|
|
|
|
* \return -2 if buffer full (retry)
|
|
|
|
*/
|
|
|
|
static int32_t PIOS_SPEKTRUM_UpdateFSM(struct pios_spektrum_fsm * fsm, uint8_t b)
|
|
|
|
{
|
|
|
|
fsm->bytecount++;
|
|
|
|
if (fsm->sync == 0) {
|
|
|
|
/* Known sync bytes, 0x01, 0x02, 0x12 */
|
|
|
|
if (fsm->bytecount == 2) {
|
|
|
|
if (b == 0x01) {
|
|
|
|
fsm->datalength=0; // 10bit
|
|
|
|
fsm->sync = 1;
|
|
|
|
fsm->bytecount = 2;
|
|
|
|
}
|
|
|
|
else if(b == 0x02) {
|
|
|
|
fsm->datalength=0; // 10bit
|
|
|
|
fsm->sync = 1;
|
|
|
|
fsm->bytecount = 2;
|
|
|
|
}
|
|
|
|
else if(b == 0x12) {
|
|
|
|
fsm->datalength=1; // 11bit
|
|
|
|
fsm->sync = 1;
|
|
|
|
fsm->bytecount = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fsm->bytecount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((fsm->bytecount % 2) == 0) {
|
|
|
|
uint16_t data;
|
|
|
|
uint8_t channeln;
|
|
|
|
|
|
|
|
fsm->channel = (fsm->prev_byte << 8) + b;
|
|
|
|
channeln = (fsm->channel >> (10+fsm->datalength)) & 0x0F;
|
|
|
|
data = fsm->channel & (0x03FF+(0x0400*fsm->datalength));
|
|
|
|
if(channeln==0 && data<10) // discard frame if throttle misbehaves
|
|
|
|
{
|
|
|
|
fsm->frame_error=1;
|
|
|
|
}
|
|
|
|
if (channeln < PIOS_SPEKTRUM_NUM_INPUTS && !fsm->frame_error)
|
|
|
|
fsm->CaptureValueTemp[channeln] = data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fsm->bytecount == 16) {
|
|
|
|
fsm->bytecount = 0;
|
|
|
|
fsm->sync = 0;
|
|
|
|
fsm->sync_of = 0;
|
|
|
|
if (!fsm->frame_error)
|
|
|
|
{
|
|
|
|
for(int i=0;i<PIOS_SPEKTRUM_NUM_INPUTS;i++)
|
|
|
|
{
|
|
|
|
fsm->CaptureValue[i] = fsm->CaptureValueTemp[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fsm->frame_error=0;
|
|
|
|
}
|
|
|
|
fsm->prev_byte = b;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-27 09:28:45 +02:00
|
|
|
/**
|
2011-05-29 13:52:22 +02:00
|
|
|
* Bind and Initialise Spektrum satellite receiver
|
2010-09-27 09:28:45 +02:00
|
|
|
*/
|
2011-08-06 21:16:47 +02:00
|
|
|
int32_t PIOS_SPEKTRUM_Init(uint32_t * spektrum_id, const struct pios_spektrum_cfg *cfg, const struct pios_com_driver * driver, uint32_t lower_id, uint8_t bind)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
2011-07-30 21:04:24 +02:00
|
|
|
PIOS_DEBUG_Assert(spektrum_id);
|
|
|
|
PIOS_DEBUG_Assert(cfg);
|
|
|
|
PIOS_DEBUG_Assert(driver);
|
|
|
|
|
|
|
|
struct pios_spektrum_dev * spektrum_dev;
|
|
|
|
|
|
|
|
spektrum_dev = (struct pios_spektrum_dev *) PIOS_SPEKTRUM_alloc();
|
|
|
|
if (!spektrum_dev) goto out_fail;
|
|
|
|
|
|
|
|
/* Bind the configuration to the device instance */
|
|
|
|
spektrum_dev->cfg = cfg;
|
|
|
|
|
bootcfg: use UAVobj to control boot-time HW config
This should mark an end to the compile-time selection of HW
configurations.
Minor changes in board initialization for all platforms:
- Most config structs are marked static to prevent badly written
drivers from directly referring to config data.
- Adapt to changes in .irq fields in config data.
- Adapt to changes in USART IRQ handling.
Major changes in board initialization for CC:
- Use HwSettings UAVObj to decide which drivers to attach to
the "main" port and the flexi port, and select the appropriate
device configuration data.
- HwSettings allows choosing between Disabled, Telemetry, SBUS,
Spektrum,GPS, and I2C for each of the two ports.
- Use ManualControlSettings.InputMode to init/configure the
appropriate receiver module, and register its available rx channels
with the PIOS_RCVR layer. Can choose between PWM, Spektrum and PPM
at board init time. PPM driver is broken, and SBUS will work once
it is added to this UAVObj as an option.
- CC build now includes code for SBUS, Spektrum and PWM receivers in
every firmware image.
PIOS_USART driver:
- Now handles its own low-level IRQs internally
- If NULL upper-level IRQ handler is bound in at board init time
then rx/tx is satisfied by internal PIOS_USART buffered IO routines
which are (typically) attached to the COM layer.
- If an alternate upper-level IRQ handler is bound in at board init
then that handler is called and expected to clear down the USART
IRQ sources. This is used by Spektrum and SBUS drivers.
PIOS_SBUS and PIOS_SPEKTRUM drivers:
- Improved data/API hiding
- No longer assume they know where their config data is stored which
allows for boot-time alternate configurations for the driver.
- Now registers an upper-level IRQ handlerwith the USART layer to
decouple the driver from which USART it is actually attached to.
2011-07-06 02:21:00 +02:00
|
|
|
if (bind) {
|
2011-08-06 21:16:47 +02:00
|
|
|
PIOS_SPEKTRUM_Bind(cfg,bind);
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
|
|
|
|
2011-07-30 21:04:24 +02:00
|
|
|
PIOS_SPEKTRUM_ResetFSM(&(spektrum_dev->fsm));
|
|
|
|
|
|
|
|
*spektrum_id = (uint32_t)spektrum_dev;
|
2011-07-26 06:27:03 +02:00
|
|
|
|
2011-07-30 21:04:24 +02:00
|
|
|
(driver->bind_rx_cb)(lower_id, PIOS_SPEKTRUM_RxInCallback, *spektrum_id);
|
|
|
|
|
|
|
|
if (!PIOS_RTC_RegisterTickCallback(PIOS_SPEKTRUM_Supervisor, *spektrum_id)) {
|
2011-07-03 01:25:35 +02:00
|
|
|
PIOS_DEBUG_Assert(0);
|
|
|
|
}
|
2011-07-26 06:27:03 +02:00
|
|
|
|
|
|
|
return (0);
|
2011-07-30 21:04:24 +02:00
|
|
|
|
|
|
|
out_fail:
|
|
|
|
return(-1);
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of an input channel
|
|
|
|
* \param[in] Channel Number of the channel desired
|
|
|
|
* \output -1 Channel not available
|
|
|
|
* \output >0 Channel value
|
|
|
|
*/
|
2011-07-15 03:52:07 +02:00
|
|
|
static int32_t PIOS_SPEKTRUM_Get(uint32_t rcvr_id, uint8_t channel)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
2011-07-30 21:04:24 +02:00
|
|
|
struct pios_spektrum_dev * spektrum_dev = (struct pios_spektrum_dev *)rcvr_id;
|
|
|
|
|
|
|
|
bool valid = PIOS_SPEKTRUM_validate(spektrum_dev);
|
|
|
|
PIOS_Assert(valid);
|
|
|
|
|
2010-09-27 09:28:45 +02:00
|
|
|
/* Return error if channel not available */
|
2011-07-15 03:52:07 +02:00
|
|
|
if (channel >= PIOS_SPEKTRUM_NUM_INPUTS) {
|
2010-09-27 09:28:45 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2011-07-30 21:04:24 +02:00
|
|
|
return spektrum_dev->fsm.CaptureValue[channel];
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Spektrum bind function
|
bootcfg: use UAVobj to control boot-time HW config
This should mark an end to the compile-time selection of HW
configurations.
Minor changes in board initialization for all platforms:
- Most config structs are marked static to prevent badly written
drivers from directly referring to config data.
- Adapt to changes in .irq fields in config data.
- Adapt to changes in USART IRQ handling.
Major changes in board initialization for CC:
- Use HwSettings UAVObj to decide which drivers to attach to
the "main" port and the flexi port, and select the appropriate
device configuration data.
- HwSettings allows choosing between Disabled, Telemetry, SBUS,
Spektrum,GPS, and I2C for each of the two ports.
- Use ManualControlSettings.InputMode to init/configure the
appropriate receiver module, and register its available rx channels
with the PIOS_RCVR layer. Can choose between PWM, Spektrum and PPM
at board init time. PPM driver is broken, and SBUS will work once
it is added to this UAVObj as an option.
- CC build now includes code for SBUS, Spektrum and PWM receivers in
every firmware image.
PIOS_USART driver:
- Now handles its own low-level IRQs internally
- If NULL upper-level IRQ handler is bound in at board init time
then rx/tx is satisfied by internal PIOS_USART buffered IO routines
which are (typically) attached to the COM layer.
- If an alternate upper-level IRQ handler is bound in at board init
then that handler is called and expected to clear down the USART
IRQ sources. This is used by Spektrum and SBUS drivers.
PIOS_SBUS and PIOS_SPEKTRUM drivers:
- Improved data/API hiding
- No longer assume they know where their config data is stored which
allows for boot-time alternate configurations for the driver.
- Now registers an upper-level IRQ handlerwith the USART layer to
decouple the driver from which USART it is actually attached to.
2011-07-06 02:21:00 +02:00
|
|
|
* \output true Successful bind
|
|
|
|
* \output false Bind failed
|
2010-09-27 09:28:45 +02:00
|
|
|
*/
|
2011-08-06 21:16:47 +02:00
|
|
|
static bool PIOS_SPEKTRUM_Bind(const struct pios_spektrum_cfg * cfg, uint8_t bind)
|
2010-09-27 09:28:45 +02:00
|
|
|
{
|
2011-08-07 09:10:52 +02:00
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
GPIO_InitStructure.GPIO_Pin = cfg->bind.init.GPIO_Pin;
|
|
|
|
GPIO_InitStructure.GPIO_Speed = cfg->bind.init.GPIO_Speed;
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
|
|
|
|
2011-08-06 21:16:47 +02:00
|
|
|
/* just to limit bind pulses */
|
|
|
|
bind=(bind<=10)?bind:10;
|
2011-01-28 10:25:30 +01:00
|
|
|
|
2011-07-14 13:43:26 +02:00
|
|
|
GPIO_Init(cfg->bind.gpio, &cfg->bind.init);
|
|
|
|
/* RX line, set high */
|
bootcfg: use UAVobj to control boot-time HW config
This should mark an end to the compile-time selection of HW
configurations.
Minor changes in board initialization for all platforms:
- Most config structs are marked static to prevent badly written
drivers from directly referring to config data.
- Adapt to changes in .irq fields in config data.
- Adapt to changes in USART IRQ handling.
Major changes in board initialization for CC:
- Use HwSettings UAVObj to decide which drivers to attach to
the "main" port and the flexi port, and select the appropriate
device configuration data.
- HwSettings allows choosing between Disabled, Telemetry, SBUS,
Spektrum,GPS, and I2C for each of the two ports.
- Use ManualControlSettings.InputMode to init/configure the
appropriate receiver module, and register its available rx channels
with the PIOS_RCVR layer. Can choose between PWM, Spektrum and PPM
at board init time. PPM driver is broken, and SBUS will work once
it is added to this UAVObj as an option.
- CC build now includes code for SBUS, Spektrum and PWM receivers in
every firmware image.
PIOS_USART driver:
- Now handles its own low-level IRQs internally
- If NULL upper-level IRQ handler is bound in at board init time
then rx/tx is satisfied by internal PIOS_USART buffered IO routines
which are (typically) attached to the COM layer.
- If an alternate upper-level IRQ handler is bound in at board init
then that handler is called and expected to clear down the USART
IRQ sources. This is used by Spektrum and SBUS drivers.
PIOS_SBUS and PIOS_SPEKTRUM drivers:
- Improved data/API hiding
- No longer assume they know where their config data is stored which
allows for boot-time alternate configurations for the driver.
- Now registers an upper-level IRQ handlerwith the USART layer to
decouple the driver from which USART it is actually attached to.
2011-07-06 02:21:00 +02:00
|
|
|
GPIO_SetBits(cfg->bind.gpio, cfg->bind.init.GPIO_Pin);
|
2011-07-14 13:43:26 +02:00
|
|
|
|
|
|
|
/* on CC works upto 140ms, I guess bind window is around 20-140ms after powerup */
|
|
|
|
PIOS_DELAY_WaitmS(60);
|
|
|
|
|
2011-08-06 21:16:47 +02:00
|
|
|
for (int i = 0; i < bind ; i++) {
|
2011-07-14 13:43:26 +02:00
|
|
|
/* RX line, drive low for 120us */
|
|
|
|
GPIO_ResetBits(cfg->bind.gpio, cfg->bind.init.GPIO_Pin);
|
|
|
|
PIOS_DELAY_WaituS(120);
|
|
|
|
/* RX line, drive high for 120us */
|
|
|
|
GPIO_SetBits(cfg->bind.gpio, cfg->bind.init.GPIO_Pin);
|
|
|
|
PIOS_DELAY_WaituS(120);
|
|
|
|
}
|
2011-01-28 10:25:30 +01:00
|
|
|
/* RX line, set input and wait for data, PIOS_SPEKTRUM_Init */
|
2011-08-07 09:10:52 +02:00
|
|
|
GPIO_Init(cfg->bind.gpio, &GPIO_InitStructure);
|
2011-01-28 10:25:30 +01:00
|
|
|
|
bootcfg: use UAVobj to control boot-time HW config
This should mark an end to the compile-time selection of HW
configurations.
Minor changes in board initialization for all platforms:
- Most config structs are marked static to prevent badly written
drivers from directly referring to config data.
- Adapt to changes in .irq fields in config data.
- Adapt to changes in USART IRQ handling.
Major changes in board initialization for CC:
- Use HwSettings UAVObj to decide which drivers to attach to
the "main" port and the flexi port, and select the appropriate
device configuration data.
- HwSettings allows choosing between Disabled, Telemetry, SBUS,
Spektrum,GPS, and I2C for each of the two ports.
- Use ManualControlSettings.InputMode to init/configure the
appropriate receiver module, and register its available rx channels
with the PIOS_RCVR layer. Can choose between PWM, Spektrum and PPM
at board init time. PPM driver is broken, and SBUS will work once
it is added to this UAVObj as an option.
- CC build now includes code for SBUS, Spektrum and PWM receivers in
every firmware image.
PIOS_USART driver:
- Now handles its own low-level IRQs internally
- If NULL upper-level IRQ handler is bound in at board init time
then rx/tx is satisfied by internal PIOS_USART buffered IO routines
which are (typically) attached to the COM layer.
- If an alternate upper-level IRQ handler is bound in at board init
then that handler is called and expected to clear down the USART
IRQ sources. This is used by Spektrum and SBUS drivers.
PIOS_SBUS and PIOS_SPEKTRUM drivers:
- Improved data/API hiding
- No longer assume they know where their config data is stored which
allows for boot-time alternate configurations for the driver.
- Now registers an upper-level IRQ handlerwith the USART layer to
decouple the driver from which USART it is actually attached to.
2011-07-06 02:21:00 +02:00
|
|
|
return true;
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-29 13:52:22 +02:00
|
|
|
*@brief This function is called between frames and when a spektrum word hasnt been decoded for too long
|
|
|
|
*@brief clears the channel values
|
2011-03-07 22:29:41 +01:00
|
|
|
*/
|
2011-07-30 21:04:24 +02:00
|
|
|
static void PIOS_SPEKTRUM_Supervisor(uint32_t spektrum_id)
|
|
|
|
{
|
|
|
|
struct pios_spektrum_dev * spektrum_dev = (struct pios_spektrum_dev *)spektrum_id;
|
|
|
|
|
|
|
|
bool valid = PIOS_SPEKTRUM_validate(spektrum_dev);
|
|
|
|
PIOS_Assert(valid);
|
|
|
|
|
2011-05-29 13:52:22 +02:00
|
|
|
/* 125hz */
|
2011-07-30 21:04:24 +02:00
|
|
|
spektrum_dev->supv_timer++;
|
|
|
|
if(spektrum_dev->supv_timer > 5) {
|
2011-05-29 13:52:22 +02:00
|
|
|
/* sync between frames */
|
2011-07-30 21:04:24 +02:00
|
|
|
struct pios_spektrum_fsm * fsm = &(spektrum_dev->fsm);
|
|
|
|
|
|
|
|
fsm->sync = 0;
|
|
|
|
fsm->bytecount = 0;
|
|
|
|
fsm->prev_byte = 0xFF;
|
|
|
|
fsm->frame_error = 0;
|
|
|
|
fsm->sync_of++;
|
2011-05-29 13:52:22 +02:00
|
|
|
/* watchdog activated after 100ms silence */
|
2011-07-30 21:04:24 +02:00
|
|
|
if (fsm->sync_of > 12) {
|
2011-08-27 07:44:58 +02:00
|
|
|
|
2011-05-29 13:52:22 +02:00
|
|
|
/* signal lost */
|
2011-07-30 21:04:24 +02:00
|
|
|
fsm->sync_of = 0;
|
2011-06-25 15:27:28 +02:00
|
|
|
for (int i = 0; i < PIOS_SPEKTRUM_NUM_INPUTS; i++) {
|
2011-07-30 21:04:24 +02:00
|
|
|
fsm->CaptureValue[i] = 0;
|
|
|
|
fsm->CaptureValueTemp[i] = 0;
|
2011-05-29 13:52:22 +02:00
|
|
|
}
|
2010-12-28 19:37:36 +01:00
|
|
|
}
|
2011-07-30 21:04:24 +02:00
|
|
|
spektrum_dev->supv_timer = 0;
|
2010-09-27 09:28:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
* @}
|
|
|
|
*/
|