mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-18 08:54:15 +01:00
OP-1849 Initial commit
This commit is contained in:
parent
79339d677f
commit
7f93340f7f
@ -112,7 +112,7 @@ static inline void matrix_mult_3x3f(float a[3][3], float b[3][3], float result[3
|
|||||||
result[2][2] = a[0][2] * b[2][0] + a[1][2] * b[2][1] + a[2][2] * b[2][2];
|
result[2][2] = a[0][2] * b[2][0] + a[1][2] * b[2][1] + a[2][2] * b[2][2];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void matrix_inline_scale_3f(float a[3][3], float scale)
|
static inline void matrix_inline_scale_3f(float a[3][3], float scale)
|
||||||
{
|
{
|
||||||
a[0][0] *= scale;
|
a[0][0] *= scale;
|
||||||
a[0][1] *= scale;
|
a[0][1] *= scale;
|
||||||
@ -127,7 +127,7 @@ inline void matrix_inline_scale_3f(float a[3][3], float scale)
|
|||||||
a[2][2] *= scale;
|
a[2][2] *= scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void rot_about_axis_x(const float rotation, float R[3][3])
|
static inline void rot_about_axis_x(const float rotation, float R[3][3])
|
||||||
{
|
{
|
||||||
float s = sinf(rotation);
|
float s = sinf(rotation);
|
||||||
float c = cosf(rotation);
|
float c = cosf(rotation);
|
||||||
@ -145,7 +145,7 @@ inline void rot_about_axis_x(const float rotation, float R[3][3])
|
|||||||
R[2][2] = c;
|
R[2][2] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void rot_about_axis_y(const float rotation, float R[3][3])
|
static inline void rot_about_axis_y(const float rotation, float R[3][3])
|
||||||
{
|
{
|
||||||
float s = sinf(rotation);
|
float s = sinf(rotation);
|
||||||
float c = cosf(rotation);
|
float c = cosf(rotation);
|
||||||
@ -163,7 +163,7 @@ inline void rot_about_axis_y(const float rotation, float R[3][3])
|
|||||||
R[2][2] = c;
|
R[2][2] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void rot_about_axis_z(const float rotation, float R[3][3])
|
static inline void rot_about_axis_z(const float rotation, float R[3][3])
|
||||||
{
|
{
|
||||||
float s = sinf(rotation);
|
float s = sinf(rotation);
|
||||||
float c = cosf(rotation);
|
float c = cosf(rotation);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
*
|
*
|
||||||
* @file pios_com.h
|
* @file pios_com.h
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* Parts by Thorsten Klose (tk@midibox.org)
|
||||||
* @brief COM layer functions header
|
* @brief COM layer functions header
|
||||||
* @see The GNU Public License (GPL) Version 3
|
* @see The GNU Public License (GPL) Version 3
|
||||||
*
|
*
|
||||||
@ -35,19 +36,28 @@
|
|||||||
#include <stdbool.h> /* bool */
|
#include <stdbool.h> /* bool */
|
||||||
|
|
||||||
typedef uint16_t (*pios_com_callback)(uint32_t context, uint8_t *buf, uint16_t buf_len, uint16_t *headroom, bool *task_woken);
|
typedef uint16_t (*pios_com_callback)(uint32_t context, uint8_t *buf, uint16_t buf_len, uint16_t *headroom, bool *task_woken);
|
||||||
|
typedef void (*pios_com_callback_ctrl_line)(uint32_t context, uint32_t mask, uint32_t state);
|
||||||
|
|
||||||
struct pios_com_driver {
|
struct pios_com_driver {
|
||||||
void (*init)(uint32_t id);
|
void (*init)(uint32_t id);
|
||||||
void (*set_baud)(uint32_t id, uint32_t baud);
|
void (*set_baud)(uint32_t id, uint32_t baud);
|
||||||
|
void (*set_ctrl_line)(uint32_t id, uint32_t mask, uint32_t state);
|
||||||
void (*tx_start)(uint32_t id, uint16_t tx_bytes_avail);
|
void (*tx_start)(uint32_t id, uint16_t tx_bytes_avail);
|
||||||
void (*rx_start)(uint32_t id, uint16_t rx_bytes_avail);
|
void (*rx_start)(uint32_t id, uint16_t rx_bytes_avail);
|
||||||
void (*bind_rx_cb)(uint32_t id, pios_com_callback rx_in_cb, uint32_t context);
|
void (*bind_rx_cb)(uint32_t id, pios_com_callback rx_in_cb, uint32_t context);
|
||||||
void (*bind_tx_cb)(uint32_t id, pios_com_callback tx_out_cb, uint32_t context);
|
void (*bind_tx_cb)(uint32_t id, pios_com_callback tx_out_cb, uint32_t context);
|
||||||
|
void (*bind_ctrl_line_cb)(uint32_t id, pios_com_callback_ctrl_line ctrl_line_cb, uint32_t context);
|
||||||
bool (*available)(uint32_t id);
|
bool (*available)(uint32_t id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Control line definitions */
|
||||||
|
#define COM_CTRL_LINE_DTR_MASK 0x01
|
||||||
|
#define COM_CTRL_LINE_RTS_MASK 0x02
|
||||||
|
|
||||||
/* Public Functions */
|
/* Public Functions */
|
||||||
|
extern int32_t PIOS_COM_Init(uint32_t *com_id, const struct pios_com_driver *driver, uint32_t lower_id, uint8_t *rx_buffer, uint16_t rx_buffer_len, uint8_t *tx_buffer, uint16_t tx_buffer_len);
|
||||||
extern int32_t PIOS_COM_ChangeBaud(uint32_t com_id, uint32_t baud);
|
extern int32_t PIOS_COM_ChangeBaud(uint32_t com_id, uint32_t baud);
|
||||||
|
extern int32_t PIOS_COM_SetCtrlLine(uint32_t com_id, uint32_t mask, uint32_t state);
|
||||||
extern int32_t PIOS_COM_SendCharNonBlocking(uint32_t com_id, char c);
|
extern int32_t PIOS_COM_SendCharNonBlocking(uint32_t com_id, char c);
|
||||||
extern int32_t PIOS_COM_SendChar(uint32_t com_id, char c);
|
extern int32_t PIOS_COM_SendChar(uint32_t com_id, char c);
|
||||||
extern int32_t PIOS_COM_SendBufferNonBlocking(uint32_t com_id, const uint8_t *buffer, uint16_t len);
|
extern int32_t PIOS_COM_SendBufferNonBlocking(uint32_t com_id, const uint8_t *buffer, uint16_t len);
|
||||||
|
@ -47,7 +47,7 @@ extern int8_t pios_instrumentation_last_used_counter;
|
|||||||
* @param counter_handle handle of the counter to update @see PIOS_Instrumentation_SearchCounter @see PIOS_Instrumentation_CreateCounter
|
* @param counter_handle handle of the counter to update @see PIOS_Instrumentation_SearchCounter @see PIOS_Instrumentation_CreateCounter
|
||||||
* @param newValue the updated value.
|
* @param newValue the updated value.
|
||||||
*/
|
*/
|
||||||
inline void PIOS_Instrumentation_updateCounter(pios_counter_t counter_handle, int32_t newValue)
|
static inline void PIOS_Instrumentation_updateCounter(pios_counter_t counter_handle, int32_t newValue)
|
||||||
{
|
{
|
||||||
PIOS_Assert(pios_instrumentation_perf_counters && counter_handle);
|
PIOS_Assert(pios_instrumentation_perf_counters && counter_handle);
|
||||||
vPortEnterCritical();
|
vPortEnterCritical();
|
||||||
@ -69,7 +69,7 @@ inline void PIOS_Instrumentation_updateCounter(pios_counter_t counter_handle, in
|
|||||||
* Used to determine the time duration of a code block, mark the begin of the block. @see PIOS_Instrumentation_TimeEnd
|
* Used to determine the time duration of a code block, mark the begin of the block. @see PIOS_Instrumentation_TimeEnd
|
||||||
* @param counter_handle handle of the counter @see PIOS_Instrumentation_SearchCounter @see PIOS_Instrumentation_CreateCounter
|
* @param counter_handle handle of the counter @see PIOS_Instrumentation_SearchCounter @see PIOS_Instrumentation_CreateCounter
|
||||||
*/
|
*/
|
||||||
inline void PIOS_Instrumentation_TimeStart(pios_counter_t counter_handle)
|
static inline void PIOS_Instrumentation_TimeStart(pios_counter_t counter_handle)
|
||||||
{
|
{
|
||||||
PIOS_Assert(pios_instrumentation_perf_counters && counter_handle);
|
PIOS_Assert(pios_instrumentation_perf_counters && counter_handle);
|
||||||
vPortEnterCritical();
|
vPortEnterCritical();
|
||||||
@ -83,7 +83,7 @@ inline void PIOS_Instrumentation_TimeStart(pios_counter_t counter_handle)
|
|||||||
* Used to determine the time duration of a code block, mark the end of the block. @see PIOS_Instrumentation_TimeStart
|
* Used to determine the time duration of a code block, mark the end of the block. @see PIOS_Instrumentation_TimeStart
|
||||||
* @param counter_handle handle of the counter @see PIOS_Instrumentation_SearchCounter @see PIOS_Instrumentation_CreateCounter
|
* @param counter_handle handle of the counter @see PIOS_Instrumentation_SearchCounter @see PIOS_Instrumentation_CreateCounter
|
||||||
*/
|
*/
|
||||||
inline void PIOS_Instrumentation_TimeEnd(pios_counter_t counter_handle)
|
static inline void PIOS_Instrumentation_TimeEnd(pios_counter_t counter_handle)
|
||||||
{
|
{
|
||||||
PIOS_Assert(pios_instrumentation_perf_counters && counter_handle);
|
PIOS_Assert(pios_instrumentation_perf_counters && counter_handle);
|
||||||
vPortEnterCritical();
|
vPortEnterCritical();
|
||||||
@ -106,7 +106,7 @@ inline void PIOS_Instrumentation_TimeEnd(pios_counter_t counter_handle)
|
|||||||
* Used to determine the mean period between each call to the function
|
* Used to determine the mean period between each call to the function
|
||||||
* @param counter_handle handle of the counter @see PIOS_Instrumentation_SearchCounter @see PIOS_Instrumentation_CreateCounter
|
* @param counter_handle handle of the counter @see PIOS_Instrumentation_SearchCounter @see PIOS_Instrumentation_CreateCounter
|
||||||
*/
|
*/
|
||||||
inline void PIOS_Instrumentation_TrackPeriod(pios_counter_t counter_handle)
|
static inline void PIOS_Instrumentation_TrackPeriod(pios_counter_t counter_handle)
|
||||||
{
|
{
|
||||||
PIOS_Assert(pios_instrumentation_perf_counters && counter_handle);
|
PIOS_Assert(pios_instrumentation_perf_counters && counter_handle);
|
||||||
pios_perf_counter_t *counter = (pios_perf_counter_t *)counter_handle;
|
pios_perf_counter_t *counter = (pios_perf_counter_t *)counter_handle;
|
||||||
|
@ -40,17 +40,21 @@
|
|||||||
|
|
||||||
/* Provide a COM driver */
|
/* Provide a COM driver */
|
||||||
static void PIOS_USART_ChangeBaud(uint32_t usart_id, uint32_t baud);
|
static void PIOS_USART_ChangeBaud(uint32_t usart_id, uint32_t baud);
|
||||||
|
static void PIOS_USART_SetCtrlLine(uint32_t usart_id, uint32_t mask, uint32_t state);
|
||||||
static void PIOS_USART_RegisterRxCallback(uint32_t usart_id, pios_com_callback rx_in_cb, uint32_t context);
|
static void PIOS_USART_RegisterRxCallback(uint32_t usart_id, pios_com_callback rx_in_cb, uint32_t context);
|
||||||
static void PIOS_USART_RegisterTxCallback(uint32_t usart_id, pios_com_callback tx_out_cb, uint32_t context);
|
static void PIOS_USART_RegisterTxCallback(uint32_t usart_id, pios_com_callback tx_out_cb, uint32_t context);
|
||||||
|
static void PIOS_USART_RegisterCtrlLineCallback(uint32_t usart_id, pios_com_callback_ctrl_line ctrl_line_cb, uint32_t context);
|
||||||
static void PIOS_USART_TxStart(uint32_t usart_id, uint16_t tx_bytes_avail);
|
static void PIOS_USART_TxStart(uint32_t usart_id, uint16_t tx_bytes_avail);
|
||||||
static void PIOS_USART_RxStart(uint32_t usart_id, uint16_t rx_bytes_avail);
|
static void PIOS_USART_RxStart(uint32_t usart_id, uint16_t rx_bytes_avail);
|
||||||
|
|
||||||
const struct pios_com_driver pios_usart_com_driver = {
|
const struct pios_com_driver pios_usart_com_driver = {
|
||||||
.set_baud = PIOS_USART_ChangeBaud,
|
.set_baud = PIOS_USART_ChangeBaud,
|
||||||
.tx_start = PIOS_USART_TxStart,
|
.set_ctrl_line = PIOS_USART_SetCtrlLine,
|
||||||
.rx_start = PIOS_USART_RxStart,
|
.tx_start = PIOS_USART_TxStart,
|
||||||
.bind_tx_cb = PIOS_USART_RegisterTxCallback,
|
.rx_start = PIOS_USART_RxStart,
|
||||||
.bind_rx_cb = PIOS_USART_RegisterRxCallback,
|
.bind_tx_cb = PIOS_USART_RegisterTxCallback,
|
||||||
|
.bind_rx_cb = PIOS_USART_RegisterRxCallback,
|
||||||
|
.bind_ctrl_line_cb = PIOS_USART_RegisterCtrlLineCallback,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum pios_usart_dev_magic {
|
enum pios_usart_dev_magic {
|
||||||
@ -65,6 +69,8 @@ struct pios_usart_dev {
|
|||||||
uint32_t rx_in_context;
|
uint32_t rx_in_context;
|
||||||
pios_com_callback tx_out_cb;
|
pios_com_callback tx_out_cb;
|
||||||
uint32_t tx_out_context;
|
uint32_t tx_out_context;
|
||||||
|
pios_com_callback_ctrl_line ctrl_line_cb;
|
||||||
|
uint32_t ctrl_line_context;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool PIOS_USART_validate(struct pios_usart_dev *usart_dev)
|
static bool PIOS_USART_validate(struct pios_usart_dev *usart_dev)
|
||||||
@ -194,6 +200,11 @@ int32_t PIOS_USART_Init(uint32_t *usart_id, const struct pios_usart_cfg *cfg)
|
|||||||
|
|
||||||
*usart_id = (uint32_t)usart_dev;
|
*usart_id = (uint32_t)usart_dev;
|
||||||
|
|
||||||
|
/* Set initial control line state */
|
||||||
|
PIOS_USART_SetCtrlLine((uint32_t)usart_dev,
|
||||||
|
COM_CTRL_LINE_DTR_MASK | COM_CTRL_LINE_RTS_MASK,
|
||||||
|
COM_CTRL_LINE_DTR_MASK | COM_CTRL_LINE_RTS_MASK);
|
||||||
|
|
||||||
/* Configure USART Interrupts */
|
/* Configure USART Interrupts */
|
||||||
switch ((uint32_t)usart_dev->cfg->regs) {
|
switch ((uint32_t)usart_dev->cfg->regs) {
|
||||||
case (uint32_t)USART1:
|
case (uint32_t)USART1:
|
||||||
@ -276,6 +287,19 @@ static void PIOS_USART_ChangeBaud(uint32_t usart_id, uint32_t baud)
|
|||||||
USART_Init(usart_dev->cfg->regs, &USART_InitStructure);
|
USART_Init(usart_dev->cfg->regs, &USART_InitStructure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void PIOS_USART_SetCtrlLine(uint32_t usart_id, uint32_t mask, uint32_t state)
|
||||||
|
{
|
||||||
|
struct pios_usart_dev *usart_dev = (struct pios_usart_dev *)usart_id;
|
||||||
|
|
||||||
|
bool valid = PIOS_USART_validate(usart_dev);
|
||||||
|
|
||||||
|
PIOS_Assert(valid);
|
||||||
|
|
||||||
|
if (usart_dev->ctrl_line_cb) {
|
||||||
|
(usart_dev->ctrl_line_cb)(usart_dev->ctrl_line_context, mask, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void PIOS_USART_RegisterRxCallback(uint32_t usart_id, pios_com_callback rx_in_cb, uint32_t context)
|
static void PIOS_USART_RegisterRxCallback(uint32_t usart_id, pios_com_callback rx_in_cb, uint32_t context)
|
||||||
{
|
{
|
||||||
struct pios_usart_dev *usart_dev = (struct pios_usart_dev *)usart_id;
|
struct pios_usart_dev *usart_dev = (struct pios_usart_dev *)usart_id;
|
||||||
@ -308,6 +332,22 @@ static void PIOS_USART_RegisterTxCallback(uint32_t usart_id, pios_com_callback t
|
|||||||
usart_dev->tx_out_cb = tx_out_cb;
|
usart_dev->tx_out_cb = tx_out_cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void PIOS_USART_RegisterCtrlLineCallback(uint32_t usart_id, pios_com_callback_ctrl_line ctrl_line_cb, uint32_t context)
|
||||||
|
{
|
||||||
|
struct pios_usart_dev *usart_dev = (struct pios_usart_dev *)usart_id;
|
||||||
|
|
||||||
|
bool valid = PIOS_USART_validate(usart_dev);
|
||||||
|
|
||||||
|
PIOS_Assert(valid);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Order is important in these assignments since ISR uses _cb
|
||||||
|
* field to determine if it's ok to dereference _cb and _context
|
||||||
|
*/
|
||||||
|
usart_dev->ctrl_line_context = context;
|
||||||
|
usart_dev->ctrl_line_cb = ctrl_line_cb;
|
||||||
|
}
|
||||||
|
|
||||||
static void PIOS_USART_generic_irq_handler(uint32_t usart_id)
|
static void PIOS_USART_generic_irq_handler(uint32_t usart_id)
|
||||||
{
|
{
|
||||||
struct pios_usart_dev *usart_dev = (struct pios_usart_dev *)usart_id;
|
struct pios_usart_dev *usart_dev = (struct pios_usart_dev *)usart_id;
|
||||||
|
@ -866,6 +866,9 @@ void PIOS_Board_Init(void)
|
|||||||
case HWSETTINGS_RM_RCVRPORT_TELEMETRY:
|
case HWSETTINGS_RM_RCVRPORT_TELEMETRY:
|
||||||
PIOS_Board_configure_com(&pios_usart_rcvrport_cfg, PIOS_COM_TELEM_RF_RX_BUF_LEN, PIOS_COM_TELEM_RF_TX_BUF_LEN, &pios_usart_com_driver, &pios_com_telem_rf_id);
|
PIOS_Board_configure_com(&pios_usart_rcvrport_cfg, PIOS_COM_TELEM_RF_RX_BUF_LEN, PIOS_COM_TELEM_RF_TX_BUF_LEN, &pios_usart_com_driver, &pios_com_telem_rf_id);
|
||||||
break;
|
break;
|
||||||
|
case HWSETTINGS_RM_RCVRPORT_COMBRIDGE:
|
||||||
|
PIOS_Board_configure_com(&pios_usart_rcvrport_cfg, PIOS_COM_BRIDGE_RX_BUF_LEN, PIOS_COM_BRIDGE_TX_BUF_LEN, &pios_usart_com_driver, &pios_com_bridge_id);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<field name="RV_TelemetryPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,ComAux,ComBridge" defaultvalue="Telemetry"/>
|
<field name="RV_TelemetryPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,ComAux,ComBridge" defaultvalue="Telemetry"/>
|
||||||
<field name="RV_GPSPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,GPS,ComAux,ComBridge" defaultvalue="GPS"/>
|
<field name="RV_GPSPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,GPS,ComAux,ComBridge" defaultvalue="GPS"/>
|
||||||
|
|
||||||
<field name="RM_RcvrPort" units="function" type="enum" elements="1" options="Disabled,PWM,PPM,PPM+PWM,PPM+Telemetry,PPM+Outputs,Outputs,Telemetry" defaultvalue="PWM"/>
|
<field name="RM_RcvrPort" units="function" type="enum" elements="1" options="Disabled,PWM,PPM,PPM+PWM,PPM+Telemetry,PPM+Outputs,Outputs,Telemetry,ComBridge" defaultvalue="PWM"/>
|
||||||
<field name="RM_MainPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,GPS,S.Bus,DSM,DebugConsole,ComBridge,OsdHk" defaultvalue="Disabled"/>
|
<field name="RM_MainPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,GPS,S.Bus,DSM,DebugConsole,ComBridge,OsdHk" defaultvalue="Disabled"/>
|
||||||
<field name="RM_FlexiPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,GPS,I2C,DSM,DebugConsole,ComBridge,OsdHk" defaultvalue="Disabled"/>
|
<field name="RM_FlexiPort" units="function" type="enum" elements="1" options="Disabled,Telemetry,GPS,I2C,DSM,DebugConsole,ComBridge,OsdHk" defaultvalue="Disabled"/>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user