mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-19 04:52:12 +01:00
Merged in mindnever/librepilot/LP-484-refactoring_oplink_and_openlrs_rcvr_ppm_callbacks (pull request #392)
LP-484 refactoring oplink and openlrs rcvr ppm callbacks Approved-by: Philippe Renon <philippe_renon@yahoo.fr> Approved-by: Lalanne Laurent <f5soh@free.fr> Approved-by: Vladimir Zidar <mr_w@mindnever.org> Approved-by: Alessio Morale <alessiomorale@gmail.com> Approved-by: Brian Webb <webbbn@gmail.com>
This commit is contained in:
commit
a1e84d5483
@ -870,13 +870,8 @@ static void pios_openlrs_rx_loop(struct pios_openlrs_dev *openlrs_dev)
|
||||
rescaleChannels(openlrs_dev->ppm);
|
||||
|
||||
// Call the PPM received callback if it's available.
|
||||
if (openlrs_dev->openlrs_rcvr_id) {
|
||||
#if defined(PIOS_INCLUDE_OPENLRS_RCVR)
|
||||
PIOS_OpenLRS_Rcvr_UpdateChannels(openlrs_dev->openlrs_rcvr_id, openlrs_dev->ppm);
|
||||
#endif
|
||||
}
|
||||
if (openlrs_dev->ppm_callback) {
|
||||
openlrs_dev->ppm_callback(openlrs_dev->ppm);
|
||||
openlrs_dev->ppm_callback(openlrs_dev->ppm_context, openlrs_dev->ppm);
|
||||
}
|
||||
} else {
|
||||
// Not PPM data. Push into serial RX buffer.
|
||||
@ -1084,31 +1079,13 @@ uint8_t PIOS_OpenLRS_RSSI_Get(void)
|
||||
* PPM Code
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Register a OpenLRS_Rcvr interface to inform of PPM packets
|
||||
*
|
||||
* @param[in] rfm22b_dev The RFM22B device ID.
|
||||
* @param[in] rfm22b_rcvr_id The receiver device to inform of PPM packets
|
||||
*/
|
||||
void PIOS_OpenLRS_RegisterRcvr(uint32_t openlrs_id, uint32_t openlrs_rcvr_id)
|
||||
{
|
||||
struct pios_openlrs_dev *openlrs_dev =
|
||||
(struct pios_openlrs_dev *)openlrs_id;
|
||||
|
||||
if (!pios_openlrs_validate(openlrs_dev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
openlrs_dev->openlrs_rcvr_id = openlrs_rcvr_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a OpenLRS_Rcvr interface to inform of PPM packets using a generic callback.
|
||||
*
|
||||
* @param[in] openlrs_id The OpenLRS device ID.
|
||||
* @param[in] callback The callback function.
|
||||
*/
|
||||
void PIOS_OpenLRS_RegisterPPMCallback(uint32_t openlrs_id, PIOS_OpenLRS_PPMReceivedCallback callback)
|
||||
void PIOS_OpenLRS_RegisterPPMCallback(uint32_t openlrs_id, PIOS_OpenLRS_PPMReceivedCallback callback, uint32_t context)
|
||||
{
|
||||
struct pios_openlrs_dev *openlrs_dev =
|
||||
(struct pios_openlrs_dev *)openlrs_id;
|
||||
@ -1117,6 +1094,11 @@ void PIOS_OpenLRS_RegisterPPMCallback(uint32_t openlrs_id, PIOS_OpenLRS_PPMRecei
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Order is important in these assignments since openlrs_task uses ppm_callback
|
||||
* field to determine if it's ok to dereference ppm_callback and ppm_context
|
||||
*/
|
||||
openlrs_dev->ppm_context = context;
|
||||
openlrs_dev->ppm_callback = callback;
|
||||
}
|
||||
|
||||
@ -1166,12 +1148,13 @@ int32_t PIOS_OpenLRS_Init(uint32_t *openlrs_id, uint32_t spi_id,
|
||||
}
|
||||
|
||||
// Initialize the com callbacks.
|
||||
openlrs_dev->rx_in_cb = NULL;
|
||||
openlrs_dev->tx_out_cb = NULL;
|
||||
openlrs_dev->rx_in_cb = NULL;
|
||||
openlrs_dev->tx_out_cb = NULL;
|
||||
|
||||
// Initialize the "PPM" callback.
|
||||
openlrs_dev->openlrs_rcvr_id = 0;
|
||||
openlrs_dev->ppm_callback = 0;
|
||||
openlrs_dev->ppm_context = 0;
|
||||
openlrs_dev->ppm_callback = 0;
|
||||
|
||||
|
||||
OPLinkSettingsInitialize();
|
||||
OPLinkStatusInitialize();
|
||||
|
@ -44,6 +44,7 @@
|
||||
/* Provide a RCVR driver */
|
||||
static int32_t PIOS_OpenLRS_Rcvr_Get(uint32_t rcvr_id, uint8_t channel);
|
||||
static void PIOS_OpenLRS_Rcvr_Supervisor(uint32_t ppm_id);
|
||||
static void PIOS_OpenLRS_Rcvr_ppm_callback(uint32_t openlrs_rcvr_id, const int16_t *channels);
|
||||
|
||||
const struct pios_rcvr_driver pios_openlrs_rcvr_driver = {
|
||||
.read = PIOS_OpenLRS_Rcvr_Get,
|
||||
@ -102,7 +103,7 @@ extern int32_t PIOS_OpenLRS_Rcvr_Init(uint32_t *openlrs_rcvr_id, uintptr_t openl
|
||||
OPLinkReceiverInitialize();
|
||||
|
||||
*openlrs_rcvr_id = (uintptr_t)openlrs_rcvr_dev;
|
||||
PIOS_OpenLRS_RegisterRcvr(openlrs_id, *openlrs_rcvr_id);
|
||||
PIOS_OpenLRS_RegisterPPMCallback(openlrs_id, PIOS_OpenLRS_Rcvr_ppm_callback, *openlrs_rcvr_id);
|
||||
|
||||
/* Register the failsafe timer callback. */
|
||||
if (!PIOS_RTC_RegisterTickCallback
|
||||
@ -118,7 +119,7 @@ extern int32_t PIOS_OpenLRS_Rcvr_Init(uint32_t *openlrs_rcvr_id, uintptr_t openl
|
||||
* PPM packet is received. This method stores the data locally as well
|
||||
* as sets the data into the OPLinkReceiver UAVO for visibility
|
||||
*/
|
||||
int32_t PIOS_OpenLRS_Rcvr_UpdateChannels(uint32_t openlrs_rcvr_id, int16_t *channels)
|
||||
static void PIOS_OpenLRS_Rcvr_ppm_callback(uint32_t openlrs_rcvr_id, const int16_t *channels)
|
||||
{
|
||||
/* Recover our device context */
|
||||
struct pios_openlrs_rcvr_dev *openlrs_rcvr_dev =
|
||||
@ -126,7 +127,7 @@ int32_t PIOS_OpenLRS_Rcvr_UpdateChannels(uint32_t openlrs_rcvr_id, int16_t *chan
|
||||
|
||||
if (!PIOS_OpenLRS_Rcvr_Validate(openlrs_rcvr_dev)) {
|
||||
/* Invalid device specified */
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < OPENLRS_PPM_NUM_CHANNELS; i++) {
|
||||
@ -137,8 +138,6 @@ int32_t PIOS_OpenLRS_Rcvr_UpdateChannels(uint32_t openlrs_rcvr_id, int16_t *chan
|
||||
|
||||
// let supervisor know we have new data
|
||||
openlrs_rcvr_dev->fresh = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include <oplinkstatus.h>
|
||||
#include <pios_oplinkrcvr_priv.h>
|
||||
|
||||
static OPLinkReceiverData oplinkreceiverdata;
|
||||
|
||||
/* Provide a RCVR driver */
|
||||
static int32_t PIOS_OPLinkRCVR_Get(uint32_t rcvr_id, uint8_t channel);
|
||||
@ -56,18 +55,34 @@ enum pios_oplinkrcvr_dev_magic {
|
||||
|
||||
struct pios_oplinkrcvr_dev {
|
||||
enum pios_oplinkrcvr_dev_magic magic;
|
||||
|
||||
uint8_t supv_timer;
|
||||
OPLinkReceiverData oplinkreceiverdata;
|
||||
bool Fresh;
|
||||
};
|
||||
|
||||
static struct pios_oplinkrcvr_dev *global_oplinkrcvr_dev;
|
||||
|
||||
static bool PIOS_oplinkrcvr_validate(struct pios_oplinkrcvr_dev *oplinkrcvr_dev)
|
||||
{
|
||||
return oplinkrcvr_dev->magic == PIOS_OPLINKRCVR_DEV_MAGIC;
|
||||
}
|
||||
|
||||
static void PIOS_oplinkrcvr_ppm_callback(uint32_t oplinkrcvr_id, const int16_t *channels)
|
||||
{
|
||||
/* Recover our device context */
|
||||
struct pios_oplinkrcvr_dev *oplinkrcvr_dev = (struct pios_oplinkrcvr_dev *)oplinkrcvr_id;
|
||||
|
||||
if (!PIOS_oplinkrcvr_validate(oplinkrcvr_dev)) {
|
||||
/* Invalid device specified */
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < OPLINKRECEIVER_CHANNEL_NUMELEM; ++i) {
|
||||
oplinkrcvr_dev->oplinkreceiverdata.Channel[i] = (i < RFM22B_PPM_NUM_CHANNELS) ? channels[i] : PIOS_RCVR_TIMEOUT;
|
||||
}
|
||||
OPLinkReceiverSet(&oplinkrcvr_dev->oplinkreceiverdata);
|
||||
|
||||
oplinkrcvr_dev->Fresh = true;
|
||||
}
|
||||
|
||||
#if defined(PIOS_INCLUDE_FREERTOS)
|
||||
static struct pios_oplinkrcvr_dev *PIOS_oplinkrcvr_alloc(void)
|
||||
{
|
||||
@ -82,9 +97,6 @@ static struct pios_oplinkrcvr_dev *PIOS_oplinkrcvr_alloc(void)
|
||||
oplinkrcvr_dev->Fresh = false;
|
||||
oplinkrcvr_dev->supv_timer = 0;
|
||||
|
||||
/* The update callback cannot receive the device pointer, so set it in a global */
|
||||
global_oplinkrcvr_dev = oplinkrcvr_dev;
|
||||
|
||||
return oplinkrcvr_dev;
|
||||
}
|
||||
#else
|
||||
@ -103,23 +115,11 @@ static struct pios_oplinkrcvr_dev *PIOS_oplinkrcvr_alloc(void)
|
||||
oplinkrcvr_dev->Fresh = false;
|
||||
oplinkrcvr_dev->supv_timer = 0;
|
||||
|
||||
global_oplinkrcvr_dev = oplinkrcvr_dev;
|
||||
|
||||
return oplinkrcvr_dev;
|
||||
}
|
||||
#endif /* if defined(PIOS_INCLUDE_FREERTOS) */
|
||||
|
||||
static void oplinkreceiver_updated(UAVObjEvent *ev)
|
||||
{
|
||||
struct pios_oplinkrcvr_dev *oplinkrcvr_dev = global_oplinkrcvr_dev;
|
||||
|
||||
if (ev->obj == OPLinkReceiverHandle()) {
|
||||
OPLinkReceiverGet(&oplinkreceiverdata);
|
||||
oplinkrcvr_dev->Fresh = true;
|
||||
}
|
||||
}
|
||||
|
||||
extern int32_t PIOS_OPLinkRCVR_Init(__attribute__((unused)) uint32_t *oplinkrcvr_id)
|
||||
extern int32_t PIOS_OPLinkRCVR_Init(uint32_t *oplinkrcvr_id, uint32_t rfm22b_id)
|
||||
{
|
||||
struct pios_oplinkrcvr_dev *oplinkrcvr_dev;
|
||||
|
||||
@ -131,17 +131,19 @@ extern int32_t PIOS_OPLinkRCVR_Init(__attribute__((unused)) uint32_t *oplinkrcvr
|
||||
|
||||
for (uint8_t i = 0; i < OPLINKRECEIVER_CHANNEL_NUMELEM; i++) {
|
||||
/* Flush channels */
|
||||
oplinkreceiverdata.Channel[i] = PIOS_RCVR_TIMEOUT;
|
||||
oplinkrcvr_dev->oplinkreceiverdata.Channel[i] = PIOS_RCVR_TIMEOUT;
|
||||
}
|
||||
|
||||
/* Register uavobj callback */
|
||||
OPLinkReceiverConnectCallback(oplinkreceiver_updated);
|
||||
/* Register ppm callback */
|
||||
PIOS_RFM22B_SetPPMCallback(rfm22b_id, PIOS_oplinkrcvr_ppm_callback, (uint32_t)oplinkrcvr_dev);
|
||||
|
||||
/* Register the failsafe timer callback. */
|
||||
if (!PIOS_RTC_RegisterTickCallback(PIOS_oplinkrcvr_Supervisor, (uint32_t)oplinkrcvr_dev)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
|
||||
*oplinkrcvr_id = (uint32_t)oplinkrcvr_dev;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -152,14 +154,22 @@ extern int32_t PIOS_OPLinkRCVR_Init(__attribute__((unused)) uint32_t *oplinkrcvr
|
||||
* \output PIOS_RCVR_TIMEOUT failsafe condition or missing receiver
|
||||
* \output >=0 channel value
|
||||
*/
|
||||
static int32_t PIOS_OPLinkRCVR_Get(__attribute__((unused)) uint32_t rcvr_id, uint8_t channel)
|
||||
static int32_t PIOS_OPLinkRCVR_Get(uint32_t oplinkrcvr_id, uint8_t channel)
|
||||
{
|
||||
/* Recover our device context */
|
||||
struct pios_oplinkrcvr_dev *oplinkrcvr_dev = (struct pios_oplinkrcvr_dev *)oplinkrcvr_id;
|
||||
|
||||
if (!PIOS_oplinkrcvr_validate(oplinkrcvr_dev)) {
|
||||
/* Invalid device specified */
|
||||
return PIOS_RCVR_INVALID;
|
||||
}
|
||||
|
||||
if (channel >= OPLINKRECEIVER_CHANNEL_NUMELEM) {
|
||||
/* channel is out of range */
|
||||
return PIOS_RCVR_INVALID;
|
||||
}
|
||||
|
||||
return oplinkreceiverdata.Channel[channel];
|
||||
return oplinkrcvr_dev->oplinkreceiverdata.Channel[channel];
|
||||
}
|
||||
|
||||
static void PIOS_oplinkrcvr_Supervisor(uint32_t oplinkrcvr_id)
|
||||
@ -182,7 +192,7 @@ static void PIOS_oplinkrcvr_Supervisor(uint32_t oplinkrcvr_id)
|
||||
|
||||
if (!oplinkrcvr_dev->Fresh) {
|
||||
for (int32_t i = 0; i < OPLINKRECEIVER_CHANNEL_NUMELEM; i++) {
|
||||
oplinkreceiverdata.Channel[i] = PIOS_RCVR_TIMEOUT;
|
||||
oplinkrcvr_dev->oplinkreceiverdata.Channel[i] = PIOS_RCVR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -407,39 +407,12 @@ int32_t PIOS_RFM22B_Init(uint32_t *rfm22b_id, uint32_t spi_id, uint32_t slave_nu
|
||||
g_rfm22b_dev = rfm22b_dev;
|
||||
|
||||
// Store the SPI handle
|
||||
rfm22b_dev->slave_num = slave_num;
|
||||
rfm22b_dev->spi_id = spi_id;
|
||||
rfm22b_dev->slave_num = slave_num;
|
||||
rfm22b_dev->spi_id = spi_id;
|
||||
|
||||
// Initialize our configuration parameters
|
||||
rfm22b_dev->datarate = RFM22B_DEFAULT_RX_DATARATE;
|
||||
rfm22b_dev->tx_power = RFM22B_DEFAULT_TX_POWER;
|
||||
rfm22b_dev->coordinator = false;
|
||||
rfm22b_dev->coordinatorID = 0;
|
||||
|
||||
// Initialize the com callbacks.
|
||||
rfm22b_dev->rx_in_cb = NULL;
|
||||
rfm22b_dev->tx_out_cb = NULL;
|
||||
|
||||
rfm22b_dev->aux_rx_in_cb = NULL;
|
||||
rfm22b_dev->aux_tx_out_cb = NULL;
|
||||
// Initialize the PPM callback.
|
||||
rfm22b_dev->ppm_callback = NULL;
|
||||
|
||||
// Initialize the stats.
|
||||
rfm22b_dev->stats.packets_per_sec = 0;
|
||||
rfm22b_dev->stats.rx_good = 0;
|
||||
rfm22b_dev->stats.rx_corrected = 0;
|
||||
rfm22b_dev->stats.rx_error = 0;
|
||||
rfm22b_dev->stats.rx_missed = 0;
|
||||
rfm22b_dev->stats.tx_dropped = 0;
|
||||
rfm22b_dev->stats.resets = 0;
|
||||
rfm22b_dev->stats.timeouts = 0;
|
||||
rfm22b_dev->stats.link_quality = 0;
|
||||
rfm22b_dev->stats.rssi = 0;
|
||||
rfm22b_dev->stats.afc_correction = 0;
|
||||
rfm22b_dev->stats.tx_seq = 0;
|
||||
rfm22b_dev->stats.rx_seq = 0;
|
||||
rfm22b_dev->stats.tx_failure = 0;
|
||||
rfm22b_dev->datarate = RFM22B_DEFAULT_RX_DATARATE;
|
||||
rfm22b_dev->tx_power = RFM22B_DEFAULT_TX_POWER;
|
||||
|
||||
// Set the frequency band
|
||||
switch (band) {
|
||||
@ -1123,7 +1096,7 @@ pios_rfm22b_int_result PIOS_RFM22B_ProcessRx(uint32_t rfm22b_id)
|
||||
* @param[in] rfm22b_dev The RFM22B device ID.
|
||||
* @param[in] cb The callback function pointer.
|
||||
*/
|
||||
void PIOS_RFM22B_SetPPMCallback(uint32_t rfm22b_id, PPMReceivedCallback cb)
|
||||
void PIOS_RFM22B_SetPPMCallback(uint32_t rfm22b_id, PPMReceivedCallback cb, uint32_t cb_context)
|
||||
{
|
||||
struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rfm22b_id;
|
||||
|
||||
@ -1131,6 +1104,11 @@ void PIOS_RFM22B_SetPPMCallback(uint32_t rfm22b_id, PPMReceivedCallback cb)
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Order is important in these assignments since rfm22_task uses ppm_callback
|
||||
* field to determine if it's ok to dereference ppm_callback and ppm_context
|
||||
*/
|
||||
rfm22b_dev->ppm_context = cb_context;
|
||||
rfm22b_dev->ppm_callback = cb;
|
||||
}
|
||||
|
||||
@ -2071,7 +2049,7 @@ static enum pios_radio_event radio_receivePacket(struct pios_rfm22b_dev *radio_d
|
||||
|
||||
// Call the PPM received callback if it's available.
|
||||
if (radio_dev->ppm_callback) {
|
||||
radio_dev->ppm_callback(radio_dev->ppm);
|
||||
radio_dev->ppm_callback(radio_dev->ppm_context, radio_dev->ppm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2572,12 +2550,13 @@ static struct pios_rfm22b_dev *pios_rfm22_alloc(void)
|
||||
struct pios_rfm22b_dev *rfm22b_dev;
|
||||
|
||||
rfm22b_dev = (struct pios_rfm22b_dev *)pios_malloc(sizeof(*rfm22b_dev));
|
||||
rfm22b_dev->spi_id = 0;
|
||||
if (!rfm22b_dev) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(rfm22b_dev, 0, sizeof(*rfm22b_dev));
|
||||
rfm22b_dev->magic = PIOS_RFM22B_DEV_MAGIC;
|
||||
|
||||
return rfm22b_dev;
|
||||
}
|
||||
#else
|
||||
@ -2592,6 +2571,8 @@ static struct pios_rfm22b_dev *pios_rfm22_alloc(void)
|
||||
}
|
||||
|
||||
rfm22b_dev = &pios_rfm22b_devs[pios_rfm22b_num_devs++];
|
||||
|
||||
memset(rfm22b_dev, 0, sizeof(*rfm22b_dev));
|
||||
rfm22b_dev->magic = PIOS_RFM22B_DEV_MAGIC;
|
||||
|
||||
return rfm22b_dev;
|
||||
|
@ -39,13 +39,12 @@ struct pios_openlrs_cfg {
|
||||
enum gpio_direction gpio_direction; /* Definition comes from pios_rfm22b.h */
|
||||
};
|
||||
|
||||
typedef void (*PIOS_OpenLRS_PPMReceivedCallback)(const int16_t *channels);
|
||||
typedef void (*PIOS_OpenLRS_PPMReceivedCallback)(uint32_t context, const int16_t *channels);
|
||||
|
||||
extern int32_t PIOS_OpenLRS_Init(uint32_t *openlrs_id, uint32_t spi_id,
|
||||
uint32_t slave_num, const struct pios_openlrs_cfg *cfg);
|
||||
|
||||
extern void PIOS_OpenLRS_RegisterRcvr(uint32_t openlrs_id, uint32_t rfm22b_rcvr_id);
|
||||
extern void PIOS_OpenLRS_RegisterPPMCallback(uint32_t openlrs_id, PIOS_OpenLRS_PPMReceivedCallback callback);
|
||||
extern void PIOS_OpenLRS_RegisterPPMCallback(uint32_t openlrs_id, PIOS_OpenLRS_PPMReceivedCallback callback, uint32_t context);
|
||||
extern uint8_t PIOS_OpenLRS_RSSI_Get(void);
|
||||
#endif /* PIOS_OPENLRS_H */
|
||||
/**
|
||||
|
@ -155,16 +155,15 @@ struct pios_openlrs_dev {
|
||||
struct pios_semaphore *sema_isr;
|
||||
|
||||
// The PPM buffer
|
||||
int16_t ppm[OPENLRS_PPM_NUM_CHANNELS];
|
||||
|
||||
// RFM22B RCVR interface
|
||||
uintptr_t openlrs_rcvr_id;
|
||||
int16_t ppm[OPENLRS_PPM_NUM_CHANNELS];
|
||||
|
||||
// PPM callback.
|
||||
PIOS_OpenLRS_PPMReceivedCallback ppm_callback;
|
||||
// PPM context
|
||||
uint32_t ppm_context;
|
||||
|
||||
// Flag to indicate if link every acquired
|
||||
bool link_acquired;
|
||||
bool link_acquired;
|
||||
|
||||
// Active bound information data
|
||||
struct bind_data bind_data;
|
||||
|
@ -37,7 +37,6 @@
|
||||
extern const struct pios_rcvr_driver pios_openlrs_rcvr_driver;
|
||||
|
||||
extern int32_t PIOS_OpenLRS_Rcvr_Init(uint32_t *openlrs_rcvr_id, uintptr_t openlrs_id);
|
||||
extern int32_t PIOS_OpenLRS_Rcvr_UpdateChannels(uint32_t openlrs_rcvr_id, int16_t *channels);
|
||||
|
||||
#endif /* PIOS_OPENLRS_RCVR_PRIV_H */
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
extern const struct pios_rcvr_driver pios_oplinkrcvr_rcvr_driver;
|
||||
|
||||
extern int32_t PIOS_OPLinkRCVR_Init(uint32_t *oplinkrcvr_id);
|
||||
extern int32_t PIOS_OPLinkRCVR_Init(uint32_t *oplinkrcvr_id, uint32_t rfm22b_id);
|
||||
|
||||
#endif /* PIOS_OPLINKRCVR_PRIV_H */
|
||||
|
||||
|
@ -47,7 +47,7 @@ struct pios_rfm22b_cfg {
|
||||
uint8_t slave_num;
|
||||
enum gpio_direction gpio_direction;
|
||||
};
|
||||
typedef void (*PPMReceivedCallback)(const int16_t *channels);
|
||||
typedef void (*PPMReceivedCallback)(uint32_t context, const int16_t *channels);
|
||||
|
||||
enum rfm22b_tx_power {
|
||||
RFM22_tx_pwr_txpow_0 = 0x00, // +1dBm .. 1.25mW
|
||||
@ -117,7 +117,7 @@ extern bool PIOS_RFM22B_ReceivePacket(uint32_t rfm22b_id, uint8_t *p);
|
||||
extern bool PIOS_RFM22B_TransmitPacket(uint32_t rfm22b_id, uint8_t *p, uint8_t len);
|
||||
extern pios_rfm22b_int_result PIOS_RFM22B_ProcessTx(uint32_t rfm22b_id);
|
||||
extern pios_rfm22b_int_result PIOS_RFM22B_ProcessRx(uint32_t rfm22b_id);
|
||||
extern void PIOS_RFM22B_SetPPMCallback(uint32_t rfm22b_id, PPMReceivedCallback cb);
|
||||
extern void PIOS_RFM22B_SetPPMCallback(uint32_t rfm22b_id, PPMReceivedCallback cb, uint32_t cb_context);
|
||||
extern void PIOS_RFM22B_PPMSet(uint32_t rfm22b_id, int16_t *channels, uint8_t nchan);
|
||||
extern void PIOS_RFM22B_PPMGet(uint32_t rfm22b_id, int16_t *channels, uint8_t nchan);
|
||||
|
||||
|
@ -273,6 +273,8 @@ struct pios_rfm22b_dev {
|
||||
int16_t ppm[RFM22B_PPM_NUM_CHANNELS];
|
||||
// The PPM packet received callback.
|
||||
PPMReceivedCallback ppm_callback;
|
||||
// The PPM callback context
|
||||
uint32_t ppm_context;
|
||||
|
||||
// The id that the packet was received from
|
||||
uint32_t rx_destination_id;
|
||||
|
@ -103,6 +103,13 @@ int32_t PIOS_TIM_InitClock(const struct pios_tim_clock_cfg *cfg)
|
||||
/* Enable Interrupts */
|
||||
NVIC_Init(&cfg->irq.init);
|
||||
|
||||
/* Advanced TIM1 has additional IRQ */
|
||||
if (cfg->timer == TIM1) {
|
||||
NVIC_InitTypeDef init = cfg->irq.init;
|
||||
init.NVIC_IRQChannel = TIM1_UP_IRQn;
|
||||
NVIC_Init(&init);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -780,7 +780,6 @@ void PIOS_Board_Init(void)
|
||||
bool is_coordinator = (oplinkSettings.Coordinator == OPLINKSETTINGS_COORDINATOR_TRUE);
|
||||
bool is_oneway = (oplinkSettings.OneWay == OPLINKSETTINGS_ONEWAY_TRUE);
|
||||
bool ppm_mode = (oplinkSettings.PPM == OPLINKSETTINGS_PPM_TRUE);
|
||||
bool ppm_only = (oplinkSettings.PPMOnly == OPLINKSETTINGS_PPMONLY_TRUE);
|
||||
if (oplinkSettings.MaxRFPower != OPLINKSETTINGS_MAXRFPOWER_0) {
|
||||
/* Configure the RFM22B device. */
|
||||
const struct pios_rfm22b_cfg *rfm22b_cfg = PIOS_BOARD_HW_DEFS_GetRfm22Cfg(bdinfo->board_rev);
|
||||
@ -829,11 +828,6 @@ void PIOS_Board_Init(void)
|
||||
PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, oplinkSettings.RFXtalCap);
|
||||
PIOS_RFM22B_SetChannelConfig(pios_rfm22b_id, datarate, oplinkSettings.MinChannel, oplinkSettings.MaxChannel, is_coordinator, data_mode, ppm_mode);
|
||||
|
||||
/* Set the PPM callback if we should be receiving PPM. */
|
||||
if (ppm_mode || (ppm_only && !is_coordinator)) {
|
||||
PIOS_RFM22B_SetPPMCallback(pios_rfm22b_id, PIOS_Board_PPM_callback);
|
||||
}
|
||||
|
||||
/* Set the modem Tx power level */
|
||||
switch (oplinkSettings.MaxRFPower) {
|
||||
case OPLINKSETTINGS_MAXRFPOWER_125:
|
||||
@ -969,7 +963,7 @@ void PIOS_Board_Init(void)
|
||||
{
|
||||
OPLinkReceiverInitialize();
|
||||
uint32_t pios_oplinkrcvr_id;
|
||||
PIOS_OPLinkRCVR_Init(&pios_oplinkrcvr_id);
|
||||
PIOS_OPLinkRCVR_Init(&pios_oplinkrcvr_id, pios_rfm22b_id);
|
||||
uint32_t pios_oplinkrcvr_rcvr_id;
|
||||
if (PIOS_RCVR_Init(&pios_oplinkrcvr_rcvr_id, &pios_oplinkrcvr_rcvr_driver, pios_oplinkrcvr_id)) {
|
||||
PIOS_Assert(0);
|
||||
|
@ -29,10 +29,9 @@ override USE_DSP_LIB := NO
|
||||
|
||||
# List of mandatory modules to include
|
||||
MODULES += RadioComBridge
|
||||
MODULES += ComUsbBridge
|
||||
|
||||
# List of optional modules to include
|
||||
OPTMODULES =
|
||||
OPTMODULES = ComUsbBridge
|
||||
|
||||
# List C source files here (C dependencies are automatically generated).
|
||||
# Use file-extension c for "c-only"-files
|
||||
|
@ -122,7 +122,7 @@ static void PIOS_Board_configure_com(const struct pios_usart_cfg *usart_port_cfg
|
||||
|
||||
|
||||
// Forward definitions
|
||||
static void PIOS_Board_PPM_callback(const int16_t *channels);
|
||||
static void PIOS_Board_PPM_callback(uint32_t context, const int16_t *channels);
|
||||
|
||||
/**
|
||||
* PIOS_Board_Init()
|
||||
@ -384,6 +384,10 @@ void PIOS_Board_Init(void)
|
||||
servo_count = 2;
|
||||
PIOS_Servo_Init(&pios_servo_flexi_cfg);
|
||||
}
|
||||
|
||||
// Set bank modes
|
||||
PIOS_Servo_SetBankMode(0, PIOS_SERVO_BANK_MODE_PWM);
|
||||
PIOS_Servo_SetBankMode(1, PIOS_SERVO_BANK_MODE_PWM);
|
||||
#endif
|
||||
|
||||
// Initialize out status object.
|
||||
@ -408,7 +412,7 @@ void PIOS_Board_Init(void)
|
||||
oplinkStatus.LinkState = OPLINKSTATUS_LINKSTATE_ENABLED;
|
||||
|
||||
PIOS_OpenLRS_Init(&openlrs_id, PIOS_RFM22_SPI_PORT, 0, openlrs_cfg);
|
||||
PIOS_OpenLRS_RegisterPPMCallback(openlrs_id, PIOS_Board_PPM_callback);
|
||||
PIOS_OpenLRS_RegisterPPMCallback(openlrs_id, PIOS_Board_PPM_callback, 0);
|
||||
#endif /* PIOS_INCLUDE_OPENLRS */
|
||||
} else {
|
||||
oplinkStatus.LinkState = OPLINKSTATUS_LINKSTATE_ENABLED;
|
||||
@ -493,7 +497,7 @@ void PIOS_Board_Init(void)
|
||||
|
||||
/* Set the PPM callback if we should be receiving PPM. */
|
||||
if (ppm_mode || (ppm_only && !is_coordinator)) {
|
||||
PIOS_RFM22B_SetPPMCallback(pios_rfm22b_id, PIOS_Board_PPM_callback);
|
||||
PIOS_RFM22B_SetPPMCallback(pios_rfm22b_id, PIOS_Board_PPM_callback, 0);
|
||||
}
|
||||
|
||||
// Reinitialize the modem to affect the changes.
|
||||
@ -558,7 +562,7 @@ void PIOS_Board_Init(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void PIOS_Board_PPM_callback(const int16_t *channels)
|
||||
static void PIOS_Board_PPM_callback(__attribute__((unused)) uint32_t context, const int16_t *channels)
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_PPM) && defined(PIOS_INCLUDE_PPM_OUT)
|
||||
if (pios_ppm_out_id) {
|
||||
|
@ -391,16 +391,6 @@ static void PIOS_Board_configure_ppm(const struct pios_ppm_cfg *ppm_cfg)
|
||||
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_PPM] = pios_ppm_rcvr_id;
|
||||
}
|
||||
|
||||
static void PIOS_Board_PPM_callback(const int16_t *channels)
|
||||
{
|
||||
OPLinkReceiverData opl_rcvr;
|
||||
|
||||
for (uint8_t i = 0; i < OPLINKRECEIVER_CHANNEL_NUMELEM; ++i) {
|
||||
opl_rcvr.Channel[i] = (i < RFM22B_PPM_NUM_CHANNELS) ? channels[i] : PIOS_RCVR_TIMEOUT;
|
||||
}
|
||||
OPLinkReceiverSet(&opl_rcvr);
|
||||
}
|
||||
|
||||
/**
|
||||
* PIOS_Board_Init()
|
||||
* initializes all the core subsystems on this specific hardware
|
||||
@ -891,7 +881,6 @@ void PIOS_Board_Init(void)
|
||||
(oplinkSettings.LinkType == OPLINKSETTINGS_LINKTYPE_DATAANDCONTROL));
|
||||
bool ppm_mode = ((oplinkSettings.LinkType == OPLINKSETTINGS_LINKTYPE_CONTROL) ||
|
||||
(oplinkSettings.LinkType == OPLINKSETTINGS_LINKTYPE_DATAANDCONTROL));
|
||||
bool ppm_only = (oplinkSettings.LinkType == OPLINKSETTINGS_LINKTYPE_CONTROL);
|
||||
bool is_enabled = ((oplinkSettings.Protocol != OPLINKSETTINGS_PROTOCOL_DISABLED) &&
|
||||
((oplinkSettings.MaxRFPower != OPLINKSETTINGS_MAXRFPOWER_0) || openlrs));
|
||||
if (is_enabled) {
|
||||
@ -961,11 +950,6 @@ void PIOS_Board_Init(void)
|
||||
PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, oplinkSettings.RFXtalCap);
|
||||
PIOS_RFM22B_SetChannelConfig(pios_rfm22b_id, datarate, oplinkSettings.MinChannel, oplinkSettings.MaxChannel, is_coordinator, data_mode, ppm_mode);
|
||||
|
||||
/* Set the PPM callback if we should be receiving PPM. */
|
||||
if (ppm_mode || (ppm_only && !is_coordinator)) {
|
||||
PIOS_RFM22B_SetPPMCallback(pios_rfm22b_id, PIOS_Board_PPM_callback);
|
||||
}
|
||||
|
||||
/* Set the modem Tx power level */
|
||||
switch (oplinkSettings.MaxRFPower) {
|
||||
case OPLINKSETTINGS_MAXRFPOWER_125:
|
||||
@ -1131,7 +1115,7 @@ void PIOS_Board_Init(void)
|
||||
{
|
||||
OPLinkReceiverInitialize();
|
||||
uint32_t pios_oplinkrcvr_id;
|
||||
PIOS_OPLinkRCVR_Init(&pios_oplinkrcvr_id);
|
||||
PIOS_OPLinkRCVR_Init(&pios_oplinkrcvr_id, pios_rfm22b_id);
|
||||
uint32_t pios_oplinkrcvr_rcvr_id;
|
||||
if (PIOS_RCVR_Init(&pios_oplinkrcvr_rcvr_id, &pios_oplinkrcvr_rcvr_driver, pios_oplinkrcvr_id)) {
|
||||
PIOS_Assert(0);
|
||||
|
@ -391,16 +391,6 @@ static void PIOS_Board_configure_hott(const struct pios_usart_cfg *usart_cfg, en
|
||||
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_HOTT] = pios_hott_rcvr_id;
|
||||
}
|
||||
|
||||
static void PIOS_Board_PPM_callback(const int16_t *channels)
|
||||
{
|
||||
OPLinkReceiverData opl_rcvr;
|
||||
|
||||
for (uint8_t i = 0; i < OPLINKRECEIVER_CHANNEL_NUMELEM; ++i) {
|
||||
opl_rcvr.Channel[i] = (i < RFM22B_PPM_NUM_CHANNELS) ? channels[i] : PIOS_RCVR_TIMEOUT;
|
||||
}
|
||||
OPLinkReceiverSet(&opl_rcvr);
|
||||
}
|
||||
|
||||
/**
|
||||
* PIOS_Board_Init()
|
||||
* initializes all the core subsystems on this specific hardware
|
||||
@ -831,7 +821,6 @@ void PIOS_Board_Init(void)
|
||||
(oplinkSettings.LinkType == OPLINKSETTINGS_LINKTYPE_DATAANDCONTROL));
|
||||
bool ppm_mode = ((oplinkSettings.LinkType == OPLINKSETTINGS_LINKTYPE_CONTROL) ||
|
||||
(oplinkSettings.LinkType == OPLINKSETTINGS_LINKTYPE_DATAANDCONTROL));
|
||||
bool ppm_only = (oplinkSettings.LinkType == OPLINKSETTINGS_LINKTYPE_CONTROL);
|
||||
bool is_enabled = ((oplinkSettings.Protocol != OPLINKSETTINGS_PROTOCOL_DISABLED) &&
|
||||
((oplinkSettings.MaxRFPower != OPLINKSETTINGS_MAXRFPOWER_0) || openlrs));
|
||||
if (is_enabled) {
|
||||
@ -901,11 +890,6 @@ void PIOS_Board_Init(void)
|
||||
PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, oplinkSettings.RFXtalCap);
|
||||
PIOS_RFM22B_SetChannelConfig(pios_rfm22b_id, datarate, oplinkSettings.MinChannel, oplinkSettings.MaxChannel, is_coordinator, data_mode, ppm_mode);
|
||||
|
||||
/* Set the PPM callback if we should be receiving PPM. */
|
||||
if (ppm_mode || (ppm_only && !is_coordinator)) {
|
||||
PIOS_RFM22B_SetPPMCallback(pios_rfm22b_id, PIOS_Board_PPM_callback);
|
||||
}
|
||||
|
||||
/* Set the modem Tx poer level */
|
||||
switch (oplinkSettings.MaxRFPower) {
|
||||
case OPLINKSETTINGS_MAXRFPOWER_125:
|
||||
@ -1066,7 +1050,7 @@ void PIOS_Board_Init(void)
|
||||
{
|
||||
OPLinkReceiverInitialize();
|
||||
uint32_t pios_oplinkrcvr_id;
|
||||
PIOS_OPLinkRCVR_Init(&pios_oplinkrcvr_id);
|
||||
PIOS_OPLinkRCVR_Init(&pios_oplinkrcvr_id, pios_rfm22b_id);
|
||||
uint32_t pios_oplinkrcvr_rcvr_id;
|
||||
if (PIOS_RCVR_Init(&pios_oplinkrcvr_rcvr_id, &pios_oplinkrcvr_rcvr_driver, pios_oplinkrcvr_id)) {
|
||||
PIOS_Assert(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user