mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-19 04:52:12 +01:00
LP-270 - Implement PIOS_COM_ChangeConfig API (F1)
This commit is contained in:
parent
a0a2f30788
commit
6d80b55c60
@ -7,7 +7,8 @@
|
||||
* @{
|
||||
*
|
||||
* @file pios_com.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @author The LibrePilot Project, http://www.librepilot.org, Copyright (c) 2015
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief COM layer functions
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
@ -281,6 +282,24 @@ int32_t PIOS_COM_ChangeBaud(uint32_t com_id, uint32_t baud)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t PIOS_COM_ChangeConfig(uint32_t com_id, enum PIOS_COM_Word_Length word_len, enum PIOS_COM_StopBits stop_bits, enum PIOS_COM_Parity parity)
|
||||
{
|
||||
struct pios_com_dev *com_dev = (struct pios_com_dev *)com_id;
|
||||
|
||||
if (!PIOS_COM_validate(com_dev)) {
|
||||
/* Undefined COM port for this board (see pios_board.c) */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Invoke the driver function if it exists */
|
||||
if (com_dev->driver->set_config) {
|
||||
com_dev->driver->set_config(com_dev->lower_id, word_len, stop_bits, parity);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set control lines associated with the port
|
||||
* \param[in] port COM port
|
||||
|
@ -40,9 +40,31 @@ typedef void (*pios_com_callback_ctrl_line)(uint32_t context, uint32_t mask, uin
|
||||
typedef void (*pios_com_callback_baud_rate)(uint32_t context, uint32_t baud);
|
||||
typedef void (*pios_com_callback_available)(uint32_t context, uint32_t available);
|
||||
|
||||
enum PIOS_COM_Word_Length {
|
||||
PIOS_COM_Word_length_Unchanged = 0,
|
||||
PIOS_COM_Word_length_8b,
|
||||
PIOS_COM_Word_length_9b,
|
||||
};
|
||||
|
||||
enum PIOS_COM_StopBits {
|
||||
PIOS_COM_StopBits_Unchanged = 0,
|
||||
PIOS_COM_StopBits_0_5,
|
||||
PIOS_COM_StopBits_1,
|
||||
PIOS_COM_StopBits_1_5,
|
||||
PIOS_COM_StopBits_2,
|
||||
};
|
||||
|
||||
enum PIOS_COM_Parity {
|
||||
PIOS_COM_Parity_Unchanged = 0,
|
||||
PIOS_COM_Parity_No,
|
||||
PIOS_COM_Parity_Even,
|
||||
PIOS_COM_Parity_Odd,
|
||||
};
|
||||
|
||||
struct pios_com_driver {
|
||||
void (*init)(uint32_t id);
|
||||
void (*set_baud)(uint32_t id, uint32_t baud);
|
||||
void (*set_config)(uint32_t usart_id, enum PIOS_COM_Word_Length word_len, enum PIOS_COM_StopBits stop_bits, enum PIOS_COM_Parity parity);
|
||||
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 (*rx_start)(uint32_t id, uint16_t rx_bytes_avail);
|
||||
@ -61,6 +83,7 @@ struct pios_com_driver {
|
||||
/* 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_ChangeConfig(uint32_t com_id, enum PIOS_COM_Word_Length word_len, enum PIOS_COM_StopBits stop_bits, enum PIOS_COM_Parity parity);
|
||||
extern int32_t PIOS_COM_SetCtrlLine(uint32_t com_id, uint32_t mask, uint32_t state);
|
||||
extern int32_t PIOS_COM_RegisterCtrlLineCallback(uint32_t usart_id, pios_com_callback_ctrl_line ctrl_line_cb, uint32_t context);
|
||||
extern int32_t PIOS_COM_RegisterBaudRateCallback(uint32_t usart_id, pios_com_callback_baud_rate baud_rate_cb, uint32_t context);
|
||||
|
@ -7,7 +7,8 @@
|
||||
* @{
|
||||
*
|
||||
* @file pios_usart.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @author The LibrePilot Project, http://www.librepilot.org, Copyright (c) 2016
|
||||
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief USART commands. Inits USARTs, controls USARTs & Interupt handlers. (STM32 dependent)
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
@ -33,8 +34,10 @@
|
||||
#ifdef PIOS_INCLUDE_USART
|
||||
|
||||
#include <pios_usart_priv.h>
|
||||
#include <pios_usart.h>
|
||||
|
||||
/* Provide a COM driver */
|
||||
static void PIOS_USART_ChangeConfig(uint32_t usart_id, enum PIOS_COM_Word_Length word_len, enum PIOS_COM_StopBits stop_bits, enum PIOS_COM_Parity parity);
|
||||
static void PIOS_USART_ChangeBaud(uint32_t usart_id, uint32_t baud);
|
||||
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);
|
||||
@ -43,6 +46,7 @@ static void PIOS_USART_RxStart(uint32_t usart_id, uint16_t rx_bytes_avail);
|
||||
|
||||
const struct pios_com_driver pios_usart_com_driver = {
|
||||
.set_baud = PIOS_USART_ChangeBaud,
|
||||
.set_config = PIOS_USART_ChangeConfig,
|
||||
.tx_start = PIOS_USART_TxStart,
|
||||
.rx_start = PIOS_USART_RxStart,
|
||||
.bind_tx_cb = PIOS_USART_RegisterTxCallback,
|
||||
@ -249,6 +253,74 @@ static void PIOS_USART_ChangeBaud(uint32_t usart_id, uint32_t baud)
|
||||
USART_Init(usart_dev->cfg->regs, &USART_InitStructure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes configuration of the USART peripheral without re-initialising.
|
||||
* \param[in] usart_id USART name (GPS, TELEM, AUX)
|
||||
* \param[in] word_len Requested word length
|
||||
* \param[in] stop_bits Requested stop bits
|
||||
* \param[in] parity Requested parity
|
||||
*
|
||||
*/
|
||||
static void PIOS_USART_ChangeConfig(uint32_t usart_id,
|
||||
enum PIOS_COM_Word_Length word_len,
|
||||
enum PIOS_COM_StopBits stop_bits,
|
||||
enum PIOS_COM_Parity parity)
|
||||
{
|
||||
struct pios_usart_dev *usart_dev = (struct pios_usart_dev *)usart_id;
|
||||
|
||||
bool valid = PIOS_USART_validate(usart_dev);
|
||||
|
||||
PIOS_Assert(valid);
|
||||
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
|
||||
/* Start with a copy of the default configuration for the peripheral */
|
||||
USART_InitStructure = usart_dev->cfg->init;
|
||||
switch (word_len) {
|
||||
case PIOS_COM_Word_length_8b:
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
break;
|
||||
case PIOS_COM_Word_length_9b:
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (stop_bits) {
|
||||
case PIOS_COM_StopBits_0_5:
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_0_5;
|
||||
break;
|
||||
case PIOS_COM_StopBits_1:
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
break;
|
||||
case PIOS_COM_StopBits_1_5:
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1_5;
|
||||
break;
|
||||
case PIOS_COM_StopBits_2:
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (parity) {
|
||||
case PIOS_COM_Parity_No:
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
break;
|
||||
case PIOS_COM_Parity_Even:
|
||||
USART_InitStructure.USART_Parity = USART_Parity_Even;
|
||||
break;
|
||||
case PIOS_COM_Parity_Odd:
|
||||
USART_InitStructure.USART_Parity = USART_Parity_Odd;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* Write back the new configuration */
|
||||
USART_Init(usart_dev->cfg->regs, &USART_InitStructure);
|
||||
}
|
||||
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user