mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
com/usart: generalize com driver API
- Created a pluggable COM layer - Converted COM + USART init into static initializers rather than typedefs - Generalized the USB HID COM API to match the USART API. - Changed USART and COM layers to be data driven rather than #ifdef'ing/switching on the specifics of each port git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@760 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
8d015a57d0
commit
771a56ca9d
@ -67,7 +67,7 @@ int main()
|
|||||||
HMC5843_InitStructure.Mode = PIOS_HMC5843_MODE_CONTINUOS;
|
HMC5843_InitStructure.Mode = PIOS_HMC5843_MODE_CONTINUOS;
|
||||||
PIOS_HMC5843_Config(&HMC5843_InitStructure);
|
PIOS_HMC5843_Config(&HMC5843_InitStructure);
|
||||||
|
|
||||||
uint8_t id[3] = {0};
|
uint8_t id[4] = {0};
|
||||||
int16_t data[3] = {0};
|
int16_t data[3] = {0};
|
||||||
int32_t heading = 0;
|
int32_t heading = 0;
|
||||||
|
|
||||||
@ -90,10 +90,10 @@ int main()
|
|||||||
if(heading < 0) heading += 360;
|
if(heading < 0) heading += 360;
|
||||||
|
|
||||||
// Output Heading data to
|
// Output Heading data to
|
||||||
PIOS_COM_SendFormattedString(COM_USART1, "HMC5843 Chip ID: %s\rHeading: %d\rRaw Mag Values: X=%d Y=%d Y=%d\r", id, heading, data[0], data[1], data[2]);
|
PIOS_COM_SendFormattedString(PIOS_COM_AUX, "HMC5843 Chip ID: %s Heading: %d Raw Mag Values: X=%d Y=%d Z=%d ", id, heading, data[0], data[1], data[2]);
|
||||||
|
|
||||||
// Test ADC
|
// Test ADC
|
||||||
PIOS_COM_SendFormattedString(COM_USART1, "ADC Values: %d,%d,%d,%d,%d,%d\r\n", PIOS_ADC_PinGet(0), PIOS_ADC_PinGet(1), PIOS_ADC_PinGet(2), PIOS_ADC_PinGet(3), PIOS_ADC_PinGet(4), PIOS_ADC_PinGet(5));
|
PIOS_COM_SendFormattedString(PIOS_COM_AUX, "ADC Values: %d,%d,%d,%d,%d,%d\r\n", PIOS_ADC_PinGet(0), PIOS_ADC_PinGet(1), PIOS_ADC_PinGet(2), PIOS_ADC_PinGet(3), PIOS_ADC_PinGet(4), PIOS_ADC_PinGet(5));
|
||||||
|
|
||||||
// Delay until next reading
|
// Delay until next reading
|
||||||
PIOS_DELAY_WaitmS(500);
|
PIOS_DELAY_WaitmS(500);
|
||||||
|
@ -122,28 +122,13 @@ TIM8 | | | |
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
#define PIOS_OP_SPI 0
|
#define PIOS_OP_SPI 0
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
// PIOS_USART1
|
|
||||||
//-------------------------
|
|
||||||
#define PIOS_USART1_ENABLED 1
|
|
||||||
#define PIOS_USART1_USART USART3
|
|
||||||
#define PIOS_USART1_GPIO_PORT GPIOB
|
|
||||||
#define PIOS_USART1_RX_PIN GPIO_Pin_11
|
|
||||||
#define PIOS_USART1_TX_PIN GPIO_Pin_10
|
|
||||||
#define PIOS_USART1_REMAP_FUNC { }
|
|
||||||
#define PIOS_USART1_IRQ_CHANNEL USART3_IRQn
|
|
||||||
#define PIOS_USART1_IRQHANDLER_FUNC void USART3_IRQHandler(void)
|
|
||||||
#define PIOS_USART1_CLK_FUNC RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE)
|
|
||||||
#define PIOS_USART1_NVIC_PRIO PIOS_IRQ_PRIO_HIGH
|
|
||||||
#define PIOS_USART1_BAUDRATE 57600
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
// PIOS_USART
|
// PIOS_USART
|
||||||
//-------------------------
|
//-------------------------
|
||||||
#define PIOS_USART_NUM 1
|
|
||||||
#define PIOS_USART_RX_BUFFER_SIZE 256
|
#define PIOS_USART_RX_BUFFER_SIZE 256
|
||||||
#define PIOS_USART_TX_BUFFER_SIZE 256
|
#define PIOS_USART_TX_BUFFER_SIZE 256
|
||||||
#define PIOS_COM_DEBUG_PORT USART_1
|
#define PIOS_COM_AUX 0
|
||||||
|
#define PIOS_COM_DEBUG PIOS_COM_AUX
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
@ -141,4 +141,92 @@ void PIOS_SPI_op_irq_handler(void)
|
|||||||
PIOS_SPI_IRQ_Handler(PIOS_OP_SPI);
|
PIOS_SPI_IRQ_Handler(PIOS_OP_SPI);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /* PIOS_INCLUDE_SPI */
|
||||||
|
|
||||||
|
#if defined(PIOS_INCLUDE_USART)
|
||||||
|
#include <pios_usart_priv.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* AUX USART
|
||||||
|
*/
|
||||||
|
void PIOS_USART_aux_irq_handler(void);
|
||||||
|
void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_aux_irq_handler")));
|
||||||
|
const struct pios_usart_cfg pios_usart_aux_cfg = {
|
||||||
|
.regs = USART3,
|
||||||
|
.init = {
|
||||||
|
.USART_BaudRate = 57600,
|
||||||
|
.USART_WordLength = USART_WordLength_8b,
|
||||||
|
.USART_Parity = USART_Parity_No,
|
||||||
|
.USART_StopBits = USART_StopBits_1,
|
||||||
|
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||||
|
.USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
|
||||||
|
},
|
||||||
|
.irq = {
|
||||||
|
.handler = PIOS_USART_aux_irq_handler,
|
||||||
|
.init = {
|
||||||
|
.NVIC_IRQChannel = USART3_IRQn,
|
||||||
|
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||||
|
.NVIC_IRQChannelSubPriority = 0,
|
||||||
|
.NVIC_IRQChannelCmd = ENABLE,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.rx = {
|
||||||
|
.gpio = GPIOB,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_11,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
.GPIO_Mode = GPIO_Mode_IPU,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.tx = {
|
||||||
|
.gpio = GPIOB,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_10,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Board specific number of devices.
|
||||||
|
*/
|
||||||
|
struct pios_usart_dev pios_usart_devs[] = {
|
||||||
|
#define PIOS_USART_AUX 0
|
||||||
|
{
|
||||||
|
.cfg = &pios_usart_aux_cfg,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t pios_usart_num_devices = NELEMENTS(pios_usart_devs);
|
||||||
|
|
||||||
|
void PIOS_USART_aux_irq_handler(void)
|
||||||
|
{
|
||||||
|
PIOS_USART_IRQ_Handler(PIOS_USART_AUX);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* PIOS_INCLUDE_USART */
|
||||||
|
|
||||||
|
#if defined(PIOS_INCLUDE_COM)
|
||||||
|
#include <pios_com_priv.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* COM devices
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Board specific number of devices.
|
||||||
|
*/
|
||||||
|
extern const struct pios_com_driver pios_usart_com_driver;
|
||||||
|
|
||||||
|
struct pios_com_dev pios_com_devs[] = {
|
||||||
|
{
|
||||||
|
.id = PIOS_USART_AUX,
|
||||||
|
.driver = &pios_usart_com_driver,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t pios_com_num_devices = NELEMENTS(pios_com_devs);
|
||||||
|
|
||||||
|
#endif /* PIOS_INCLUDE_COM */
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ void nmeaProcessGPGSA(char* packet);
|
|||||||
// Private types
|
// Private types
|
||||||
|
|
||||||
// Private variables
|
// Private variables
|
||||||
static COMPortTypeDef gpsPort;
|
static uint8_t gpsPort;
|
||||||
static xTaskHandle gpsTaskHandle;
|
static xTaskHandle gpsTaskHandle;
|
||||||
cBuffer gpsRxBuffer;
|
cBuffer gpsRxBuffer;
|
||||||
static char gpsRxData[512];
|
static char gpsRxData[512];
|
||||||
@ -100,7 +100,7 @@ int32_t GPSInitialize(void)
|
|||||||
timeOfLastUpdateMs = 0;
|
timeOfLastUpdateMs = 0;
|
||||||
|
|
||||||
// TODO: Get gps settings object
|
// TODO: Get gps settings object
|
||||||
gpsPort = COM_USART2;
|
gpsPort = PIOS_COM_GPS;
|
||||||
|
|
||||||
// Init input buffer size 512
|
// Init input buffer size 512
|
||||||
bufferInit(&gpsRxBuffer, (unsigned char *)gpsRxData, 512);
|
bufferInit(&gpsRxBuffer, (unsigned char *)gpsRxData, 512);
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
// Private types
|
// Private types
|
||||||
|
|
||||||
// Private variables
|
// Private variables
|
||||||
static COMPortTypeDef telemetryPort;
|
static uint8_t telemetryPort;
|
||||||
static xQueueHandle queue;
|
static xQueueHandle queue;
|
||||||
static xQueueHandle priorityQueue;
|
static xQueueHandle priorityQueue;
|
||||||
static xTaskHandle telemetryTxTaskHandle;
|
static xTaskHandle telemetryTxTaskHandle;
|
||||||
@ -300,7 +300,7 @@ static void telemetryTxPriTask(void* parameters)
|
|||||||
*/
|
*/
|
||||||
static void telemetryRxTask(void* parameters)
|
static void telemetryRxTask(void* parameters)
|
||||||
{
|
{
|
||||||
COMPortTypeDef inputPort;
|
uint8_t inputPort;
|
||||||
int32_t len;
|
int32_t len;
|
||||||
|
|
||||||
// Task loop
|
// Task loop
|
||||||
@ -310,7 +310,7 @@ static void telemetryRxTask(void* parameters)
|
|||||||
// Determine input port (USB takes priority over telemetry port)
|
// Determine input port (USB takes priority over telemetry port)
|
||||||
if(PIOS_USB_HID_CheckAvailable())
|
if(PIOS_USB_HID_CheckAvailable())
|
||||||
{
|
{
|
||||||
inputPort = COM_USB_HID;
|
inputPort = PIOS_COM_TELEM_USB;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* ALLOW_HID_TELEMETRY */
|
#endif /* ALLOW_HID_TELEMETRY */
|
||||||
@ -339,7 +339,7 @@ static void telemetryRxTask(void* parameters)
|
|||||||
*/
|
*/
|
||||||
static int32_t transmitData(uint8_t* data, int32_t length)
|
static int32_t transmitData(uint8_t* data, int32_t length)
|
||||||
{
|
{
|
||||||
COMPortTypeDef outputPort;
|
uint8_t outputPort;
|
||||||
|
|
||||||
// Determine input port (USB takes priority over telemetry port)
|
// Determine input port (USB takes priority over telemetry port)
|
||||||
#if ALLOW_HID_TELEMETRY
|
#if ALLOW_HID_TELEMETRY
|
||||||
@ -533,7 +533,7 @@ static void updateTelemetryStats()
|
|||||||
static void updateSettings()
|
static void updateSettings()
|
||||||
{
|
{
|
||||||
// Set port
|
// Set port
|
||||||
telemetryPort = COM_USART1;
|
telemetryPort = PIOS_COM_TELEM_RF;
|
||||||
// Retrieve settings
|
// Retrieve settings
|
||||||
TelemetrySettingsGet(&settings);
|
TelemetrySettingsGet(&settings);
|
||||||
// Set port speed
|
// Set port speed
|
||||||
|
@ -108,57 +108,21 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8
|
|||||||
#define PIOS_BMP085_OVERSAMPLING 2
|
#define PIOS_BMP085_OVERSAMPLING 2
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
// PIOS_USART1 (TELEM)
|
// USART
|
||||||
|
//
|
||||||
|
// See also pios_board.c
|
||||||
//-------------------------
|
//-------------------------
|
||||||
#define PIOS_USART1_ENABLED 1
|
|
||||||
#define PIOS_USART1_USART USART2
|
|
||||||
#define PIOS_USART1_GPIO_PORT GPIOA
|
|
||||||
#define PIOS_USART1_RX_PIN GPIO_Pin_3
|
|
||||||
#define PIOS_USART1_TX_PIN GPIO_Pin_2
|
|
||||||
#define PIOS_USART1_REMAP_FUNC { }
|
|
||||||
#define PIOS_USART1_IRQ_CHANNEL USART2_IRQn
|
|
||||||
#define PIOS_USART1_IRQHANDLER_FUNC void USART2_IRQHandler(void)
|
|
||||||
#define PIOS_USART1_CLK_FUNC RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE)
|
|
||||||
#define PIOS_USART1_NVIC_PRIO PIOS_IRQ_PRIO_HIGHEST
|
|
||||||
#define PIOS_USART1_BAUDRATE 57600
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
// PIOS_USART2 (GPS)
|
|
||||||
//-------------------------
|
|
||||||
#define PIOS_USART2_ENABLED 1
|
|
||||||
#define PIOS_USART2_USART USART3
|
|
||||||
#define PIOS_USART2_GPIO_PORT GPIOC
|
|
||||||
#define PIOS_USART2_RX_PIN GPIO_Pin_11
|
|
||||||
#define PIOS_USART2_TX_PIN GPIO_Pin_10
|
|
||||||
#define PIOS_USART2_REMAP_FUNC { GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE); }
|
|
||||||
#define PIOS_USART2_IRQ_CHANNEL USART3_IRQn
|
|
||||||
#define PIOS_USART2_IRQHANDLER_FUNC void USART3_IRQHandler(void)
|
|
||||||
#define PIOS_USART2_CLK_FUNC RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE)
|
|
||||||
#define PIOS_USART2_NVIC_PRIO PIOS_IRQ_PRIO_HIGH
|
|
||||||
#define PIOS_USART2_BAUDRATE 57600
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
// PIOS_USART3 (AUX) (RX5/RX6)
|
|
||||||
//-------------------------
|
|
||||||
#define PIOS_USART3_ENABLED 0
|
|
||||||
#define PIOS_USART3_USART USART1
|
|
||||||
#define PIOS_USART3_GPIO_PORT GPIOA
|
|
||||||
#define PIOS_USART3_RX_PIN GPIO_Pin_10
|
|
||||||
#define PIOS_USART3_TX_PIN GPIO_Pin_9
|
|
||||||
#define PIOS_USART3_REMAP_FUNC { }
|
|
||||||
#define PIOS_USART3_IRQ_CHANNEL USART1_IRQn
|
|
||||||
#define PIOS_USART3_IRQHANDLER_FUNC void USART1_IRQHandler(void)
|
|
||||||
#define PIOS_USART3_CLK_FUNC RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE)
|
|
||||||
#define PIOS_USART3_NVIC_PRIO PIOS_IRQ_PRIO_HIGH
|
|
||||||
#define PIOS_USART3_BAUDRATE 57600
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
// PIOS_USART
|
|
||||||
//-------------------------
|
|
||||||
#define PIOS_USART_NUM 3
|
|
||||||
#define PIOS_USART_RX_BUFFER_SIZE 1024
|
#define PIOS_USART_RX_BUFFER_SIZE 1024
|
||||||
#define PIOS_USART_TX_BUFFER_SIZE 256
|
#define PIOS_USART_TX_BUFFER_SIZE 256
|
||||||
#define PIOS_COM_DEBUG_PORT USART_1
|
|
||||||
|
#define PIOS_COM_TELEM_RF 0
|
||||||
|
#define PIOS_COM_GPS 1
|
||||||
|
#define PIOS_COM_TELEM_USB 2
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#define PIOS_COM_AUX 3
|
||||||
|
#define PIOS_COM_DEBUG PIOS_COM_AUX
|
||||||
|
#endif
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
// SPI
|
// SPI
|
||||||
|
@ -53,7 +53,7 @@ static void TaskHIDTest(void *pvParameters);
|
|||||||
static void TaskServos(void *pvParameters);
|
static void TaskServos(void *pvParameters);
|
||||||
static void TaskSDCard(void *pvParameters);
|
static void TaskSDCard(void *pvParameters);
|
||||||
#endif
|
#endif
|
||||||
int32_t CONSOLE_Parse(COMPortTypeDef port, char c);
|
int32_t CONSOLE_Parse(uint8_t port, char c);
|
||||||
void OP_ADC_NotifyChange(uint32_t pin, uint32_t pin_value);
|
void OP_ADC_NotifyChange(uint32_t pin, uint32_t pin_value);
|
||||||
|
|
||||||
/* Prototype of generated InitModules() function */
|
/* Prototype of generated InitModules() function */
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include <pios.h>
|
#include <pios.h>
|
||||||
#include <pios_spi_priv.h>
|
#include <pios_spi_priv.h>
|
||||||
|
#include <pios_usart_priv.h>
|
||||||
|
#include <pios_com_priv.h>
|
||||||
|
|
||||||
/* MicroSD Interface
|
/* MicroSD Interface
|
||||||
*
|
*
|
||||||
@ -243,3 +245,205 @@ void PIOS_SPI_ahrs_irq_handler(void)
|
|||||||
/* Call into the generic code to handle the IRQ for this specific device */
|
/* Call into the generic code to handle the IRQ for this specific device */
|
||||||
PIOS_SPI_IRQ_Handler(PIOS_OPAHRS_SPI);
|
PIOS_SPI_IRQ_Handler(PIOS_OPAHRS_SPI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Telemetry USART
|
||||||
|
*/
|
||||||
|
void PIOS_USART_telem_irq_handler(void);
|
||||||
|
void USART2_IRQHandler() __attribute__ ((alias ("PIOS_USART_telem_irq_handler")));
|
||||||
|
const struct pios_usart_cfg pios_usart_telem_cfg = {
|
||||||
|
.regs = USART2,
|
||||||
|
.init = {
|
||||||
|
.USART_BaudRate = 57600,
|
||||||
|
.USART_WordLength = USART_WordLength_8b,
|
||||||
|
.USART_Parity = USART_Parity_No,
|
||||||
|
.USART_StopBits = USART_StopBits_1,
|
||||||
|
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||||
|
.USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
|
||||||
|
},
|
||||||
|
.irq = {
|
||||||
|
.handler = PIOS_USART_telem_irq_handler,
|
||||||
|
.init = {
|
||||||
|
.NVIC_IRQChannel = USART2_IRQn,
|
||||||
|
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGHEST,
|
||||||
|
.NVIC_IRQChannelSubPriority = 0,
|
||||||
|
.NVIC_IRQChannelCmd = ENABLE,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.rx = {
|
||||||
|
.gpio = GPIOA,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_3,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
.GPIO_Mode = GPIO_Mode_IPU,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.tx = {
|
||||||
|
.gpio = GPIOA,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_2,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GPS USART
|
||||||
|
*/
|
||||||
|
void PIOS_USART_gps_irq_handler(void);
|
||||||
|
void USART3_IRQHandler() __attribute__ ((alias ("PIOS_USART_gps_irq_handler")));
|
||||||
|
const struct pios_usart_cfg pios_usart_gps_cfg = {
|
||||||
|
.regs = USART3,
|
||||||
|
.remap = GPIO_PartialRemap_USART3,
|
||||||
|
.init = {
|
||||||
|
.USART_BaudRate = 57600,
|
||||||
|
.USART_WordLength = USART_WordLength_8b,
|
||||||
|
.USART_Parity = USART_Parity_No,
|
||||||
|
.USART_StopBits = USART_StopBits_1,
|
||||||
|
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||||
|
.USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
|
||||||
|
},
|
||||||
|
.irq = {
|
||||||
|
.handler = PIOS_USART_gps_irq_handler,
|
||||||
|
.init = {
|
||||||
|
.NVIC_IRQChannel = USART3_IRQn,
|
||||||
|
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||||
|
.NVIC_IRQChannelSubPriority = 0,
|
||||||
|
.NVIC_IRQChannelCmd = ENABLE,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.rx = {
|
||||||
|
.gpio = GPIOC,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_11,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
.GPIO_Mode = GPIO_Mode_IPU,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.tx = {
|
||||||
|
.gpio = GPIOC,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_10,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef PIOS_COM_AUX
|
||||||
|
/*
|
||||||
|
* AUX USART
|
||||||
|
*/
|
||||||
|
void PIOS_USART_aux_irq_handler(void);
|
||||||
|
void USART1_IRQHandler() __attribute__ ((alias ("PIOS_USART_aux_irq_handler")));
|
||||||
|
const struct pios_usart_cfg pios_usart_aux_cfg = {
|
||||||
|
.regs = USART1,
|
||||||
|
.init = {
|
||||||
|
.USART_BaudRate = 57600,
|
||||||
|
.USART_WordLength = USART_WordLength_8b,
|
||||||
|
.USART_Parity = USART_Parity_No,
|
||||||
|
.USART_StopBits = USART_StopBits_1,
|
||||||
|
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
|
||||||
|
.USART_Mode = USART_Mode_Rx | USART_Mode_Tx,
|
||||||
|
},
|
||||||
|
.irq = {
|
||||||
|
.handler = PIOS_USART_aux_irq_handler,
|
||||||
|
.init = {
|
||||||
|
.NVIC_IRQChannel = USART1_IRQn,
|
||||||
|
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
|
||||||
|
.NVIC_IRQChannelSubPriority = 0,
|
||||||
|
.NVIC_IRQChannelCmd = ENABLE,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.rx = {
|
||||||
|
.gpio = GPIOA,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_10,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
.GPIO_Mode = GPIO_Mode_IPU,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.tx = {
|
||||||
|
.gpio = GPIOA,
|
||||||
|
.init = {
|
||||||
|
.GPIO_Pin = GPIO_Pin_9,
|
||||||
|
.GPIO_Speed = GPIO_Speed_2MHz,
|
||||||
|
.GPIO_Mode = GPIO_Mode_AF_PP,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Board specific number of devices.
|
||||||
|
*/
|
||||||
|
struct pios_usart_dev pios_usart_devs[] = {
|
||||||
|
#define PIOS_USART_TELEM 0
|
||||||
|
{
|
||||||
|
.cfg = &pios_usart_telem_cfg,
|
||||||
|
},
|
||||||
|
#define PIOS_USART_GPS 1
|
||||||
|
{
|
||||||
|
.cfg = &pios_usart_gps_cfg,
|
||||||
|
},
|
||||||
|
#ifdef PIOS_COM_AUX
|
||||||
|
#define PIOS_USART_AUX 2
|
||||||
|
{
|
||||||
|
.cfg = &pios_usart_aux_cfg,
|
||||||
|
},
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t pios_usart_num_devices = NELEMENTS(pios_usart_devs);
|
||||||
|
|
||||||
|
void PIOS_USART_telem_irq_handler(void)
|
||||||
|
{
|
||||||
|
PIOS_USART_IRQ_Handler(PIOS_USART_TELEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PIOS_USART_gps_irq_handler(void)
|
||||||
|
{
|
||||||
|
PIOS_USART_IRQ_Handler(PIOS_USART_GPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PIOS_COM_AUX
|
||||||
|
void PIOS_USART_aux_irq_handler(void)
|
||||||
|
{
|
||||||
|
PIOS_USART_IRQ_Handler(PIOS_USART_AUX);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* COM devices
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Board specific number of devices.
|
||||||
|
*/
|
||||||
|
extern const struct pios_com_driver pios_usart_com_driver;
|
||||||
|
extern const struct pios_com_driver pios_usb_com_driver;
|
||||||
|
|
||||||
|
struct pios_com_dev pios_com_devs[] = {
|
||||||
|
{
|
||||||
|
.id = PIOS_USART_TELEM,
|
||||||
|
.driver = &pios_usart_com_driver,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = PIOS_USART_GPS,
|
||||||
|
.driver = &pios_usart_com_driver,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.id = 0,
|
||||||
|
.driver = &pios_usb_com_driver,
|
||||||
|
},
|
||||||
|
#ifdef PIOS_COM_AUX
|
||||||
|
{
|
||||||
|
.id = PIOS_USART_AUX,
|
||||||
|
.driver = &pios_usart_com_driver,
|
||||||
|
},
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t pios_com_num_devices = NELEMENTS(pios_com_devs);
|
||||||
|
|
||||||
|
@ -32,12 +32,18 @@
|
|||||||
|
|
||||||
#if defined(PIOS_INCLUDE_COM)
|
#if defined(PIOS_INCLUDE_COM)
|
||||||
|
|
||||||
|
#include <pios_com_priv.h>
|
||||||
|
|
||||||
/* Global Variables */
|
static struct pios_com_dev * find_com_dev_by_id (uint8_t port)
|
||||||
|
{
|
||||||
/* Local Variables */
|
if (port >= pios_com_num_devices) {
|
||||||
static int32_t (*receive_callback_func)(COMPortTypeDef port, char c);
|
/* Undefined COM port for this board (see pios_board.c) */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get a handle for the device configuration */
|
||||||
|
return &(pios_com_devs[port]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialises COM layer
|
* Initialises COM layer
|
||||||
@ -48,9 +54,6 @@ int32_t PIOS_COM_Init(void)
|
|||||||
{
|
{
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
||||||
/* Disable callback by default */
|
|
||||||
receive_callback_func = NULL;
|
|
||||||
|
|
||||||
/* If any COM assignment: */
|
/* If any COM assignment: */
|
||||||
#if defined(PIOS_INCLUDE_USART)
|
#if defined(PIOS_INCLUDE_USART)
|
||||||
PIOS_USART_Init();
|
PIOS_USART_Init();
|
||||||
@ -70,30 +73,23 @@ int32_t PIOS_COM_Init(void)
|
|||||||
* \return -1 if port not available
|
* \return -1 if port not available
|
||||||
* \return 0 on success
|
* \return 0 on success
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_COM_ChangeBaud(COMPortTypeDef port, uint32_t baud)
|
int32_t PIOS_COM_ChangeBaud(uint8_t port, uint32_t baud)
|
||||||
{
|
{
|
||||||
/* Branch depending on selected port */
|
struct pios_com_dev * com_dev;
|
||||||
switch(port) {
|
|
||||||
#if defined(PIOS_INCLUDE_USART)
|
com_dev = find_com_dev_by_id (port);
|
||||||
case COM_DEBUG_USART:
|
|
||||||
PIOS_USART_ChangeBaud(PIOS_COM_DEBUG_PORT, baud);
|
if (!com_dev) {
|
||||||
return 0;
|
/* Undefined COM port for this board (see pios_board.c) */
|
||||||
case COM_USART1:
|
return -1;
|
||||||
PIOS_USART_ChangeBaud(USART_1, baud);
|
}
|
||||||
return 0;
|
|
||||||
case COM_USART2:
|
/* Invoke the driver function if it exists */
|
||||||
PIOS_USART_ChangeBaud(USART_2, baud);
|
if (com_dev->driver->set_baud) {
|
||||||
return 0;
|
com_dev->driver->set_baud(com_dev->id, baud);
|
||||||
case COM_USART3:
|
}
|
||||||
PIOS_USART_ChangeBaud(USART_3, baud);
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
|
||||||
case COM_USB_HID:
|
|
||||||
return 0;
|
|
||||||
default:
|
|
||||||
/* Invalid port */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,35 +102,23 @@ int32_t PIOS_COM_ChangeBaud(COMPortTypeDef port, uint32_t baud)
|
|||||||
* caller should retry until buffer is free again
|
* caller should retry until buffer is free again
|
||||||
* \return 0 on success
|
* \return 0 on success
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_COM_SendBufferNonBlocking(COMPortTypeDef port, uint8_t *buffer, uint16_t len)
|
int32_t PIOS_COM_SendBufferNonBlocking(uint8_t port, uint8_t *buffer, uint16_t len)
|
||||||
{
|
{
|
||||||
/* Branch depending on selected port */
|
struct pios_com_dev * com_dev;
|
||||||
switch(port) {
|
|
||||||
#if defined(PIOS_INCLUDE_USART)
|
|
||||||
case COM_DEBUG_USART:
|
|
||||||
return PIOS_USART_TxBufferPutMoreNonBlocking(PIOS_COM_DEBUG_PORT, buffer, len);
|
|
||||||
#endif
|
|
||||||
#if PIOS_USART1_ENABLED
|
|
||||||
case COM_USART1:
|
|
||||||
return PIOS_USART_TxBufferPutMoreNonBlocking(USART_1, buffer, len);
|
|
||||||
#endif
|
|
||||||
#if PIOS_USART2_ENABLED
|
|
||||||
case COM_USART2:
|
|
||||||
return PIOS_USART_TxBufferPutMoreNonBlocking(USART_2, buffer, len);
|
|
||||||
#endif
|
|
||||||
#if PIOS_USART3_ENABLED
|
|
||||||
case COM_USART3:
|
|
||||||
return PIOS_USART_TxBufferPutMoreNonBlocking(USART_3, buffer, len);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(PIOS_INCLUDE_USB_HID)
|
com_dev = find_com_dev_by_id (port);
|
||||||
case COM_USB_HID:
|
|
||||||
return PIOS_USB_HID_TxBufferPutMoreNonBlocking(buffer, len);
|
if (!com_dev) {
|
||||||
#endif
|
/* Undefined COM port for this board (see pios_board.c) */
|
||||||
default:
|
return -1;
|
||||||
/* Invalid port */
|
}
|
||||||
return -1;
|
|
||||||
}
|
/* Invoke the driver function if it exists */
|
||||||
|
if (com_dev->driver->tx_nb) {
|
||||||
|
return com_dev->driver->tx_nb(com_dev->id, buffer, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -146,35 +130,23 @@ int32_t PIOS_COM_SendBufferNonBlocking(COMPortTypeDef port, uint8_t *buffer, uin
|
|||||||
* \return -1 if port not available
|
* \return -1 if port not available
|
||||||
* \return 0 on success
|
* \return 0 on success
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_COM_SendBuffer(COMPortTypeDef port, uint8_t *buffer, uint16_t len)
|
int32_t PIOS_COM_SendBuffer(uint8_t port, uint8_t *buffer, uint16_t len)
|
||||||
{
|
{
|
||||||
/* Branch depending on selected port */
|
struct pios_com_dev * com_dev;
|
||||||
switch(port) {
|
|
||||||
#if defined(PIOS_INCLUDE_USART)
|
|
||||||
case COM_DEBUG_USART:
|
|
||||||
return PIOS_USART_TxBufferPutMore(PIOS_COM_DEBUG_PORT, buffer, len);
|
|
||||||
#endif
|
|
||||||
#if PIOS_USART1_ENABLED
|
|
||||||
case COM_USART1:
|
|
||||||
return PIOS_USART_TxBufferPutMore(USART_1, buffer, len);
|
|
||||||
#endif
|
|
||||||
#if PIOS_USART2_ENABLED
|
|
||||||
case COM_USART2:
|
|
||||||
return PIOS_USART_TxBufferPutMore(USART_2, buffer, len);
|
|
||||||
#endif
|
|
||||||
#if PIOS_USART3_ENABLED
|
|
||||||
case COM_USART3:
|
|
||||||
return PIOS_USART_TxBufferPutMore(USART_3, buffer, len);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(PIOS_INCLUDE_USB_HID)
|
com_dev = find_com_dev_by_id (port);
|
||||||
case COM_USB_HID:
|
|
||||||
return PIOS_USB_HID_TxBufferPutMore(buffer, len);
|
if (!com_dev) {
|
||||||
#endif
|
/* Undefined COM port for this board (see pios_board.c) */
|
||||||
default:
|
return -1;
|
||||||
/* Invalid port */
|
}
|
||||||
return -1;
|
|
||||||
}
|
/* Invoke the driver function if it exists */
|
||||||
|
if (com_dev->driver->tx) {
|
||||||
|
return com_dev->driver->tx(com_dev->id, buffer, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,7 +158,7 @@ int32_t PIOS_COM_SendBuffer(COMPortTypeDef port, uint8_t *buffer, uint16_t len)
|
|||||||
* caller should retry until buffer is free again
|
* caller should retry until buffer is free again
|
||||||
* \return 0 on success
|
* \return 0 on success
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_COM_SendCharNonBlocking(COMPortTypeDef port, char c)
|
int32_t PIOS_COM_SendCharNonBlocking(uint8_t port, char c)
|
||||||
{
|
{
|
||||||
return PIOS_COM_SendBufferNonBlocking(port, (uint8_t *)&c, 1);
|
return PIOS_COM_SendBufferNonBlocking(port, (uint8_t *)&c, 1);
|
||||||
}
|
}
|
||||||
@ -199,7 +171,7 @@ int32_t PIOS_COM_SendCharNonBlocking(COMPortTypeDef port, char c)
|
|||||||
* \return -1 if port not available
|
* \return -1 if port not available
|
||||||
* \return 0 on success
|
* \return 0 on success
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_COM_SendChar(COMPortTypeDef port, char c)
|
int32_t PIOS_COM_SendChar(uint8_t port, char c)
|
||||||
{
|
{
|
||||||
return PIOS_COM_SendBuffer(port, (uint8_t *)&c, 1);
|
return PIOS_COM_SendBuffer(port, (uint8_t *)&c, 1);
|
||||||
}
|
}
|
||||||
@ -213,7 +185,7 @@ int32_t PIOS_COM_SendChar(COMPortTypeDef port, char c)
|
|||||||
* caller should retry until buffer is free again
|
* caller should retry until buffer is free again
|
||||||
* \return 0 on success
|
* \return 0 on success
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_COM_SendStringNonBlocking(COMPortTypeDef port, char *str)
|
int32_t PIOS_COM_SendStringNonBlocking(uint8_t port, char *str)
|
||||||
{
|
{
|
||||||
return PIOS_COM_SendBufferNonBlocking(port, (uint8_t *)str, (uint16_t)strlen(str));
|
return PIOS_COM_SendBufferNonBlocking(port, (uint8_t *)str, (uint16_t)strlen(str));
|
||||||
}
|
}
|
||||||
@ -226,7 +198,7 @@ int32_t PIOS_COM_SendStringNonBlocking(COMPortTypeDef port, char *str)
|
|||||||
* \return -1 if port not available
|
* \return -1 if port not available
|
||||||
* \return 0 on success
|
* \return 0 on success
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_COM_SendString(COMPortTypeDef port, char *str)
|
int32_t PIOS_COM_SendString(uint8_t port, char *str)
|
||||||
{
|
{
|
||||||
return PIOS_COM_SendBuffer(port, (uint8_t *)str, strlen(str));
|
return PIOS_COM_SendBuffer(port, (uint8_t *)str, strlen(str));
|
||||||
}
|
}
|
||||||
@ -241,7 +213,7 @@ int32_t PIOS_COM_SendString(COMPortTypeDef port, char *str)
|
|||||||
* caller should retry until buffer is free again
|
* caller should retry until buffer is free again
|
||||||
* \return 0 on success
|
* \return 0 on success
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_COM_SendFormattedStringNonBlocking(COMPortTypeDef port, char *format, ...)
|
int32_t PIOS_COM_SendFormattedStringNonBlocking(uint8_t port, char *format, ...)
|
||||||
{
|
{
|
||||||
uint8_t buffer[128]; // TODO: tmp!!! Provide a streamed COM method later!
|
uint8_t buffer[128]; // TODO: tmp!!! Provide a streamed COM method later!
|
||||||
|
|
||||||
@ -261,7 +233,7 @@ int32_t PIOS_COM_SendFormattedStringNonBlocking(COMPortTypeDef port, char *forma
|
|||||||
* \return -1 if port not available
|
* \return -1 if port not available
|
||||||
* \return 0 on success
|
* \return 0 on success
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_COM_SendFormattedString(COMPortTypeDef port, char *format, ...)
|
int32_t PIOS_COM_SendFormattedString(uint8_t port, char *format, ...)
|
||||||
{
|
{
|
||||||
uint8_t buffer[128]; // TODO: tmp!!! Provide a streamed COM method later!
|
uint8_t buffer[128]; // TODO: tmp!!! Provide a streamed COM method later!
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -276,34 +248,15 @@ int32_t PIOS_COM_SendFormattedString(COMPortTypeDef port, char *format, ...)
|
|||||||
* \param[in] port COM port
|
* \param[in] port COM port
|
||||||
* \returns Byte from buffer
|
* \returns Byte from buffer
|
||||||
*/
|
*/
|
||||||
uint8_t PIOS_COM_ReceiveBuffer(COMPortTypeDef port)
|
uint8_t PIOS_COM_ReceiveBuffer(uint8_t port)
|
||||||
{
|
{
|
||||||
switch(port) {
|
struct pios_com_dev * com_dev;
|
||||||
#if defined(PIOS_INCLUDE_USART)
|
|
||||||
case COM_DEBUG_USART:
|
|
||||||
return PIOS_USART_RxBufferGet(PIOS_COM_DEBUG_PORT);
|
|
||||||
#endif
|
|
||||||
#if PIOS_USART1_ENABLED
|
|
||||||
case COM_USART1:
|
|
||||||
return PIOS_USART_RxBufferGet(USART_1);
|
|
||||||
#endif
|
|
||||||
#if PIOS_USART2_ENABLED
|
|
||||||
case COM_USART2:
|
|
||||||
return PIOS_USART_RxBufferGet(USART_2);
|
|
||||||
#endif
|
|
||||||
#if PIOS_USART3_ENABLED
|
|
||||||
case COM_USART3:
|
|
||||||
return PIOS_USART_RxBufferGet(USART_3);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(PIOS_INCLUDE_USB_HID)
|
com_dev = find_com_dev_by_id (port);
|
||||||
case COM_USB_HID:
|
PIOS_DEBUG_Assert(com_dev);
|
||||||
return PIOS_USB_HID_RxBufferGet();
|
PIOS_DEBUG_Assert(com_dev->driver->rx);
|
||||||
#endif
|
|
||||||
/* To suppress warnings */
|
return com_dev->driver->rx(com_dev->id);
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -311,34 +264,22 @@ uint8_t PIOS_COM_ReceiveBuffer(COMPortTypeDef port)
|
|||||||
* \param[in] port COM port
|
* \param[in] port COM port
|
||||||
* \return Number of bytes used in buffer
|
* \return Number of bytes used in buffer
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_COM_ReceiveBufferUsed(COMPortTypeDef port)
|
int32_t PIOS_COM_ReceiveBufferUsed(uint8_t port)
|
||||||
{
|
{
|
||||||
switch(port) {
|
struct pios_com_dev * com_dev;
|
||||||
|
|
||||||
#if defined(PIOS_INCLUDE_USART)
|
com_dev = find_com_dev_by_id (port);
|
||||||
case COM_DEBUG_USART:
|
|
||||||
return PIOS_USART_RxBufferUsed(PIOS_COM_DEBUG_PORT);
|
if (!com_dev) {
|
||||||
#if PIOS_USART1_ENABLED
|
/* Undefined COM port for this board (see pios_board.c) */
|
||||||
case COM_USART1:
|
return 0;
|
||||||
return PIOS_USART_RxBufferUsed(USART_1);
|
}
|
||||||
#endif
|
|
||||||
#if PIOS_USART2_ENABLED
|
if (!com_dev->driver->rx_avail) {
|
||||||
case COM_USART2:
|
return 0;
|
||||||
return PIOS_USART_RxBufferUsed(USART_2);
|
}
|
||||||
#endif
|
|
||||||
#if PIOS_USART3_ENABLED
|
return com_dev->driver->rx_avail(com_dev->id);
|
||||||
case COM_USART3:
|
|
||||||
return PIOS_USART_RxBufferUsed(USART_3);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#if defined(PIOS_INCLUDE_USB_HID)
|
|
||||||
case COM_USB_HID:
|
|
||||||
return PIOS_USB_HID_RxBufferUsed();
|
|
||||||
#endif
|
|
||||||
/* To suppress warnings */
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,14 +39,13 @@
|
|||||||
|
|
||||||
static void printchar(char **str, int c)
|
static void printchar(char **str, int c)
|
||||||
{
|
{
|
||||||
// extern int putchar(int c);
|
|
||||||
|
|
||||||
if (str) {
|
if (str) {
|
||||||
**str = c;
|
**str = c;
|
||||||
++(*str);
|
++(*str);
|
||||||
}
|
}
|
||||||
|
#ifdef PIOS_COM_DEBUG
|
||||||
else PIOS_COM_SendChar(COM_DEBUG_USART, c); // (void)putchar(c);
|
else PIOS_COM_SendChar(PIOS_COM_DEBUG, c);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,9 +91,10 @@ void PIOS_DEBUG_PinLow(uint8_t Pin)
|
|||||||
*/
|
*/
|
||||||
void PIOS_DEBUG_Panic(const char* msg)
|
void PIOS_DEBUG_Panic(const char* msg)
|
||||||
{
|
{
|
||||||
|
#ifdef PIOS_COM_DEBUG
|
||||||
register int *lr asm ("lr"); // Link-register holds the PC of the caller
|
register int *lr asm ("lr"); // Link-register holds the PC of the caller
|
||||||
|
PIOS_COM_SendFormattedStringNonBlocking(PIOS_COM_DEBUG, "\r%s @0x%x\r", msg, lr);
|
||||||
PIOS_COM_SendFormattedStringNonBlocking(COM_DEBUG_USART, "\r%s @0x%x\r", msg, lr);
|
#endif
|
||||||
|
|
||||||
// Stay put
|
// Stay put
|
||||||
while(1);
|
while(1);
|
||||||
|
@ -32,151 +32,78 @@
|
|||||||
|
|
||||||
#if defined(PIOS_INCLUDE_USART)
|
#if defined(PIOS_INCLUDE_USART)
|
||||||
|
|
||||||
|
#include <pios_usart_priv.h>
|
||||||
|
|
||||||
/* Global Variables */
|
/* Provide a COM driver */
|
||||||
|
const struct pios_com_driver pios_usart_com_driver = {
|
||||||
|
.set_baud = PIOS_USART_ChangeBaud,
|
||||||
|
.tx_nb = PIOS_USART_TxBufferPutMoreNonBlocking,
|
||||||
|
.tx = PIOS_USART_TxBufferPutMore,
|
||||||
|
.rx = PIOS_USART_RxBufferGet,
|
||||||
|
.rx_avail = PIOS_USART_RxBufferUsed,
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct pios_usart_dev * find_usart_dev_by_id (uint8_t usart)
|
||||||
|
{
|
||||||
|
if (usart >= pios_usart_num_devices) {
|
||||||
|
/* Undefined USART port for this board (see pios_board.c) */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Local Variables */
|
/* Get a handle for the device configuration */
|
||||||
static uint8_t rx_buffer[PIOS_USART_NUM][PIOS_USART_RX_BUFFER_SIZE];
|
return &(pios_usart_devs[usart]);
|
||||||
static volatile uint8_t rx_buffer_tail[PIOS_USART_NUM];
|
}
|
||||||
static volatile uint8_t rx_buffer_head[PIOS_USART_NUM];
|
|
||||||
static volatile uint8_t rx_buffer_size[PIOS_USART_NUM];
|
|
||||||
|
|
||||||
static uint8_t tx_buffer[PIOS_USART_NUM][PIOS_USART_TX_BUFFER_SIZE];
|
|
||||||
static volatile uint8_t tx_buffer_tail[PIOS_USART_NUM];
|
|
||||||
static volatile uint8_t tx_buffer_head[PIOS_USART_NUM];
|
|
||||||
static volatile uint8_t tx_buffer_size[PIOS_USART_NUM];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise the onboard USARTs
|
* Initialise the onboard USARTs
|
||||||
*/
|
*/
|
||||||
void PIOS_USART_Init(void)
|
void PIOS_USART_Init(void)
|
||||||
{
|
{
|
||||||
/* Clear buffer counters */
|
struct pios_usart_dev * usart_dev;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
for(i = 0; i < PIOS_USART_NUM; ++i) {
|
|
||||||
rx_buffer_tail[i] = rx_buffer_head[i] = rx_buffer_size[i] = 0;
|
|
||||||
tx_buffer_tail[i] = tx_buffer_head[i] = tx_buffer_size[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Configure USART Pins */
|
for (i = 0; i < pios_usart_num_devices; i++) {
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
/* Get a handle for the device configuration */
|
||||||
GPIO_StructInit(&GPIO_InitStructure);
|
usart_dev = find_usart_dev_by_id(i);
|
||||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
PIOS_DEBUG_Assert(usart_dev);
|
||||||
|
|
||||||
/* Configure and Init USARTs */
|
/* Clear buffer counters */
|
||||||
USART_InitTypeDef USART_InitStructure;
|
usart_dev->rx.head = usart_dev->rx.tail = usart_dev->rx.size = 0;
|
||||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
usart_dev->tx.head = usart_dev->tx.tail = usart_dev->tx.size = 0;
|
||||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
|
||||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
|
||||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
|
||||||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
|
||||||
|
|
||||||
/* Configure the USART Interrupts */
|
/* Enable the USART Pins Software Remapping */
|
||||||
NVIC_InitTypeDef NVIC_InitStructure;
|
if (usart_dev->cfg->remap) {
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
GPIO_PinRemapConfig(usart_dev->cfg->remap, ENABLE);
|
||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
}
|
||||||
|
|
||||||
#if (PIOS_USART1_ENABLED)
|
/* Initialize the USART Rx and Tx pins */
|
||||||
/* Enable the USART Pins Software Remapping */
|
GPIO_Init(usart_dev->cfg->rx.gpio, &usart_dev->cfg->rx.init);
|
||||||
PIOS_USART1_REMAP_FUNC;
|
GPIO_Init(usart_dev->cfg->tx.gpio, &usart_dev->cfg->tx.init);
|
||||||
|
|
||||||
/* Configure and Init USART Tx as alternate function push-pull */
|
/* Enable USART clock */
|
||||||
GPIO_InitStructure.GPIO_Pin = PIOS_USART1_TX_PIN;
|
switch ((uint32_t)usart_dev->cfg->regs) {
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
case (uint32_t)USART1:
|
||||||
GPIO_Init(PIOS_USART1_GPIO_PORT, &GPIO_InitStructure);
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||||
|
break;
|
||||||
|
case (uint32_t)USART2:
|
||||||
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||||
|
break;
|
||||||
|
case (uint32_t)USART3:
|
||||||
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Configure and Init USART Rx input with internal pull-ups */
|
/* Enable USART */
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
USART_Init(usart_dev->cfg->regs, &usart_dev->cfg->init);
|
||||||
GPIO_InitStructure.GPIO_Pin = PIOS_USART1_RX_PIN;
|
|
||||||
GPIO_Init(PIOS_USART1_GPIO_PORT, &GPIO_InitStructure);
|
|
||||||
|
|
||||||
/* Enable USART clock */
|
/* Configure USART Interrupts */
|
||||||
PIOS_USART1_CLK_FUNC;
|
NVIC_Init(&usart_dev->cfg->irq.init);
|
||||||
|
USART_ITConfig(usart_dev->cfg->regs, USART_IT_RXNE, ENABLE);
|
||||||
/* Enable USART Receive and Transmit interrupts */
|
USART_ITConfig(usart_dev->cfg->regs, USART_IT_TXE, ENABLE);
|
||||||
USART_InitStructure.USART_BaudRate = PIOS_USART1_BAUDRATE;
|
|
||||||
USART_Init(PIOS_USART1_USART, &USART_InitStructure);
|
|
||||||
USART_ITConfig(PIOS_USART1_USART, USART_IT_RXNE, ENABLE);
|
|
||||||
USART_ITConfig(PIOS_USART1_USART, USART_IT_TXE, ENABLE);
|
|
||||||
|
|
||||||
/* Configure the USART Interrupts */
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = PIOS_USART1_IRQ_CHANNEL;
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_USART1_NVIC_PRIO;
|
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
|
||||||
USART_ITConfig(PIOS_USART1_USART, USART_IT_RXNE, ENABLE);
|
|
||||||
|
|
||||||
/* Enable USART */
|
|
||||||
USART_Cmd(PIOS_USART1_USART, ENABLE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (PIOS_USART2_ENABLED)
|
|
||||||
/* Enable the USART Pins Software Remapping */
|
|
||||||
PIOS_USART2_REMAP_FUNC;
|
|
||||||
|
|
||||||
/* Configure and Init USART Tx as alternate function push-pull */
|
|
||||||
GPIO_InitStructure.GPIO_Pin = PIOS_USART2_TX_PIN;
|
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
|
||||||
GPIO_Init(PIOS_USART2_GPIO_PORT, &GPIO_InitStructure);
|
|
||||||
|
|
||||||
/* Configure and Init USART Rx input with internal pull-ups */
|
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
|
||||||
GPIO_InitStructure.GPIO_Pin = PIOS_USART2_RX_PIN;
|
|
||||||
GPIO_Init(PIOS_USART2_GPIO_PORT, &GPIO_InitStructure);
|
|
||||||
|
|
||||||
/* Enable USART clock */
|
|
||||||
PIOS_USART2_CLK_FUNC;
|
|
||||||
|
|
||||||
/* Enable USART Receive and Transmit interrupts */
|
|
||||||
USART_InitStructure.USART_BaudRate = PIOS_USART2_BAUDRATE;
|
|
||||||
USART_Init(PIOS_USART2_USART, &USART_InitStructure);
|
|
||||||
USART_ITConfig(PIOS_USART2_USART, USART_IT_RXNE, ENABLE);
|
|
||||||
USART_ITConfig(PIOS_USART2_USART, USART_IT_TXE, ENABLE);
|
|
||||||
|
|
||||||
/* Configure the USART Interrupts */
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = PIOS_USART2_IRQ_CHANNEL;
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_USART2_NVIC_PRIO;
|
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
|
||||||
USART_ITConfig(PIOS_USART2_USART, USART_IT_RXNE, ENABLE);
|
|
||||||
|
|
||||||
/* Enable USART */
|
|
||||||
USART_Cmd(PIOS_USART2_USART, ENABLE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (PIOS_USART3_ENABLED)
|
|
||||||
/* Enable the USART Pins Software Remapping */
|
|
||||||
PIOS_USART3_REMAP_FUNC;
|
|
||||||
|
|
||||||
/* Configure and Init USART Tx as alternate function push-pull */
|
|
||||||
GPIO_InitStructure.GPIO_Pin = PIOS_USART3_TX_PIN;
|
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
|
||||||
GPIO_Init(PIOS_USART3_GPIO_PORT, &GPIO_InitStructure);
|
|
||||||
|
|
||||||
/* Configure and Init USART Rx input with internal pull-ups */
|
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
|
||||||
GPIO_InitStructure.GPIO_Pin = PIOS_USART3_RX_PIN;
|
|
||||||
GPIO_Init(PIOS_USART3_GPIO_PORT, &GPIO_InitStructure);
|
|
||||||
|
|
||||||
/* Enable USART clock */
|
|
||||||
PIOS_USART3_CLK_FUNC;
|
|
||||||
|
|
||||||
/* Enable USART Receive and Transmit interrupts */
|
|
||||||
USART_InitStructure.USART_BaudRate = PIOS_USART3_BAUDRATE;
|
|
||||||
USART_Init(PIOS_USART3_USART, &USART_InitStructure);
|
|
||||||
USART_ITConfig(PIOS_USART3_USART, USART_IT_RXNE, ENABLE);
|
|
||||||
USART_ITConfig(PIOS_USART3_USART, USART_IT_TXE, ENABLE);
|
|
||||||
|
|
||||||
/* Configure the USART Interrupts */
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = PIOS_USART3_IRQ_CHANNEL;
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_USART3_NVIC_PRIO;
|
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
|
||||||
USART_ITConfig(PIOS_USART3_USART, USART_IT_RXNE, ENABLE);
|
|
||||||
|
|
||||||
/* Enable USART */
|
|
||||||
USART_Cmd(PIOS_USART3_USART, ENABLE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
/* Enable USART */
|
||||||
|
USART_Cmd(usart_dev->cfg->regs, ENABLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,26 +111,29 @@ void PIOS_USART_Init(void)
|
|||||||
* \param[in] usart USART name (GPS, TELEM, AUX)
|
* \param[in] usart USART name (GPS, TELEM, AUX)
|
||||||
* \param[in] baud Requested baud rate
|
* \param[in] baud Requested baud rate
|
||||||
*/
|
*/
|
||||||
void PIOS_USART_ChangeBaud(USARTNumTypeDef usart, uint32_t baud)
|
void PIOS_USART_ChangeBaud(uint8_t usart, uint32_t baud)
|
||||||
{
|
{
|
||||||
USART_InitTypeDef USART_InitStructure;
|
struct pios_usart_dev * usart_dev;
|
||||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
USART_InitTypeDef USART_InitStructure;
|
||||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
|
||||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
/* Get a handle for the device configuration */
|
||||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
usart_dev = find_usart_dev_by_id(usart);
|
||||||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
|
||||||
USART_InitStructure.USART_BaudRate = baud;
|
#if 0
|
||||||
if (usart == USART_1) {
|
if (!usart_dev) {
|
||||||
USART_Init(PIOS_USART1_USART, &USART_InitStructure);
|
/* Undefined USART port for this board (see pios_board.c) */
|
||||||
} else if (usart == USART_2) {
|
return -2;
|
||||||
#if (PIOS_USART2_ENABLED)
|
}
|
||||||
USART_Init(PIOS_USART2_USART, &USART_InitStructure);
|
|
||||||
#endif
|
#endif
|
||||||
} else if (usart == USART_3) {
|
|
||||||
#if (PIOS_USART3_ENABLED)
|
/* Start with a copy of the default configuration for the peripheral */
|
||||||
USART_Init(PIOS_USART3_USART, &USART_InitStructure);
|
USART_InitStructure = usart_dev->cfg->init;
|
||||||
#endif
|
|
||||||
}
|
/* Adjust the baud rate */
|
||||||
|
USART_InitStructure.USART_BaudRate = baud;
|
||||||
|
|
||||||
|
/* Write back the new configuration */
|
||||||
|
USART_Init(usart_dev->cfg->regs, &USART_InitStructure);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -213,13 +143,19 @@ void PIOS_USART_ChangeBaud(USARTNumTypeDef usart, uint32_t baud)
|
|||||||
* \return 1: USART available
|
* \return 1: USART available
|
||||||
* \return 0: USART not available
|
* \return 0: USART not available
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_RxBufferFree(USARTNumTypeDef usart)
|
int32_t PIOS_USART_RxBufferFree(uint8_t usart)
|
||||||
{
|
{
|
||||||
if(usart >= PIOS_USART_NUM) {
|
struct pios_usart_dev * usart_dev;
|
||||||
return 0;
|
|
||||||
} else {
|
/* Get a handle for the device configuration */
|
||||||
return PIOS_USART_RX_BUFFER_SIZE - rx_buffer_size[usart];
|
usart_dev = find_usart_dev_by_id(usart);
|
||||||
}
|
|
||||||
|
if (!usart_dev) {
|
||||||
|
/* Undefined USART port for this board (see pios_board.c) */
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (sizeof(usart_dev->rx.buf) - usart_dev->rx.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -229,13 +165,19 @@ int32_t PIOS_USART_RxBufferFree(USARTNumTypeDef usart)
|
|||||||
* \return 0 if USART not available
|
* \return 0 if USART not available
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_RxBufferUsed(USARTNumTypeDef usart)
|
int32_t PIOS_USART_RxBufferUsed(uint8_t usart)
|
||||||
{
|
{
|
||||||
if(usart >= PIOS_USART_NUM) {
|
struct pios_usart_dev * usart_dev;
|
||||||
return 0;
|
|
||||||
} else {
|
/* Get a handle for the device configuration */
|
||||||
return rx_buffer_size[usart];
|
usart_dev = find_usart_dev_by_id(usart);
|
||||||
}
|
|
||||||
|
if (!usart_dev) {
|
||||||
|
/* Undefined USART port for this board (see pios_board.c) */
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (usart_dev->rx.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -246,28 +188,34 @@ int32_t PIOS_USART_RxBufferUsed(USARTNumTypeDef usart)
|
|||||||
* \return >= 0: number of received bytes
|
* \return >= 0: number of received bytes
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_RxBufferGet(USARTNumTypeDef usart)
|
int32_t PIOS_USART_RxBufferGet(uint8_t usart)
|
||||||
{
|
{
|
||||||
if(usart >= PIOS_USART_NUM) {
|
struct pios_usart_dev * usart_dev;
|
||||||
/* USART not available */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(!rx_buffer_size[usart]) {
|
|
||||||
/* nothing new in buffer */
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get byte - this operation should be atomic! */
|
/* Get a handle for the device configuration */
|
||||||
PIOS_IRQ_Disable();
|
usart_dev = find_usart_dev_by_id(usart);
|
||||||
uint8_t b = rx_buffer[usart][rx_buffer_tail[usart]];
|
|
||||||
if(++rx_buffer_tail[usart] >= PIOS_USART_RX_BUFFER_SIZE) {
|
|
||||||
rx_buffer_tail[usart] = 0;
|
|
||||||
}
|
|
||||||
--rx_buffer_size[usart];
|
|
||||||
PIOS_IRQ_Enable();
|
|
||||||
|
|
||||||
/* Return received byte */
|
if (!usart_dev) {
|
||||||
return b;
|
/* Undefined USART port for this board (see pios_board.c) */
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!usart_dev->rx.size) {
|
||||||
|
/* Nothing new in the buffer */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get byte - this operation should be atomic! */
|
||||||
|
PIOS_IRQ_Disable();
|
||||||
|
uint8_t b = usart_dev->rx.buf[usart_dev->rx.tail++];
|
||||||
|
if (usart_dev->rx.tail >= sizeof(usart_dev->rx.buf)) {
|
||||||
|
usart_dev->rx.tail = 0;
|
||||||
|
}
|
||||||
|
usart_dev->rx.size--;
|
||||||
|
PIOS_IRQ_Enable();
|
||||||
|
|
||||||
|
/* Return received byte */
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -278,25 +226,30 @@ int32_t PIOS_USART_RxBufferGet(USARTNumTypeDef usart)
|
|||||||
* \return >= 0: number of received bytes
|
* \return >= 0: number of received bytes
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_RxBufferPeek(USARTNumTypeDef usart)
|
int32_t PIOS_USART_RxBufferPeek(uint8_t usart)
|
||||||
{
|
{
|
||||||
if(usart >= PIOS_USART_NUM) {
|
struct pios_usart_dev * usart_dev;
|
||||||
/* USART not available */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!rx_buffer_size[usart]) {
|
/* Get a handle for the device configuration */
|
||||||
/* Nothing new in buffer */
|
usart_dev = find_usart_dev_by_id(usart);
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get byte - this operation should be atomic! */
|
if (!usart_dev) {
|
||||||
PIOS_IRQ_Disable();
|
/* Undefined USART port for this board (see pios_board.c) */
|
||||||
uint8_t b = rx_buffer[usart][rx_buffer_tail[usart]];
|
return -2;
|
||||||
PIOS_IRQ_Enable();
|
}
|
||||||
|
|
||||||
/* Return received byte */
|
if (!usart_dev->rx.size) {
|
||||||
return b;
|
/* Nothing new in the buffer */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get byte - this operation should be atomic! */
|
||||||
|
PIOS_IRQ_Disable();
|
||||||
|
uint8_t b = usart_dev->rx.buf[usart_dev->rx.tail];
|
||||||
|
PIOS_IRQ_Enable();
|
||||||
|
|
||||||
|
/* Return received byte */
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -308,30 +261,35 @@ int32_t PIOS_USART_RxBufferPeek(USARTNumTypeDef usart)
|
|||||||
* \return -2 if buffer full (retry)
|
* \return -2 if buffer full (retry)
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_RxBufferPut(USARTNumTypeDef usart, uint8_t b)
|
int32_t PIOS_USART_RxBufferPut(uint8_t usart, uint8_t b)
|
||||||
{
|
{
|
||||||
if(usart >= PIOS_USART_NUM) {
|
struct pios_usart_dev * usart_dev;
|
||||||
/* USART not available */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rx_buffer_size[usart] >= PIOS_USART_RX_BUFFER_SIZE) {
|
/* Get a handle for the device configuration */
|
||||||
/* Buffer full (retry) */
|
usart_dev = find_usart_dev_by_id(usart);
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy received byte into receive buffer */
|
if (!usart_dev) {
|
||||||
/* This operation should be atomic! */
|
/* Undefined USART port for this board (see pios_board.c) */
|
||||||
PIOS_IRQ_Disable();
|
return -1;
|
||||||
rx_buffer[usart][rx_buffer_head[usart]] = b;
|
}
|
||||||
if(++rx_buffer_head[usart] >= PIOS_USART_RX_BUFFER_SIZE) {
|
|
||||||
rx_buffer_head[usart] = 0;
|
|
||||||
}
|
|
||||||
++rx_buffer_size[usart];
|
|
||||||
PIOS_IRQ_Enable();
|
|
||||||
|
|
||||||
/* No error */
|
if (usart_dev->rx.size >= sizeof(usart_dev->rx.buf)) {
|
||||||
return 0;
|
/* Buffer full (retry) */
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy received byte into receive buffer */
|
||||||
|
/* This operation should be atomic! */
|
||||||
|
PIOS_IRQ_Disable();
|
||||||
|
usart_dev->rx.buf[usart_dev->rx.head++] = b;
|
||||||
|
if (usart_dev->rx.head >= sizeof(usart_dev->rx.buf)) {
|
||||||
|
usart_dev->rx.head = 0;
|
||||||
|
}
|
||||||
|
usart_dev->rx.size++;
|
||||||
|
PIOS_IRQ_Enable();
|
||||||
|
|
||||||
|
/* No error */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -341,13 +299,19 @@ int32_t PIOS_USART_RxBufferPut(USARTNumTypeDef usart, uint8_t b)
|
|||||||
* \return 0 if USART not available
|
* \return 0 if USART not available
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_TxBufferFree(USARTNumTypeDef usart)
|
int32_t PIOS_USART_TxBufferFree(uint8_t usart)
|
||||||
{
|
{
|
||||||
if(usart >= PIOS_USART_NUM) {
|
struct pios_usart_dev * usart_dev;
|
||||||
return 0;
|
|
||||||
} else {
|
/* Get a handle for the device configuration */
|
||||||
return PIOS_USART_TX_BUFFER_SIZE - tx_buffer_size[usart];
|
usart_dev = find_usart_dev_by_id(usart);
|
||||||
}
|
|
||||||
|
if (!usart_dev) {
|
||||||
|
/* Undefined USART port for this board (see pios_board.c) */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (sizeof(usart_dev->tx.buf) - usart_dev->tx.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -357,13 +321,19 @@ int32_t PIOS_USART_TxBufferFree(USARTNumTypeDef usart)
|
|||||||
* \return 0 if USART not available
|
* \return 0 if USART not available
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_TxBufferUsed(USARTNumTypeDef usart)
|
int32_t PIOS_USART_TxBufferUsed(uint8_t usart)
|
||||||
{
|
{
|
||||||
if(usart >= PIOS_USART_NUM) {
|
struct pios_usart_dev * usart_dev;
|
||||||
return 0;
|
|
||||||
} else {
|
/* Get a handle for the device configuration */
|
||||||
return tx_buffer_size[usart];
|
usart_dev = find_usart_dev_by_id(usart);
|
||||||
}
|
|
||||||
|
if (!usart_dev) {
|
||||||
|
/* Undefined USART port for this board (see pios_board.c) */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (usart_dev->tx.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -374,29 +344,34 @@ int32_t PIOS_USART_TxBufferUsed(USARTNumTypeDef usart)
|
|||||||
* \return >= 0: transmitted byte
|
* \return >= 0: transmitted byte
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_TxBufferGet(USARTNumTypeDef usart)
|
int32_t PIOS_USART_TxBufferGet(uint8_t usart)
|
||||||
{
|
{
|
||||||
if(usart >= PIOS_USART_NUM) {
|
struct pios_usart_dev * usart_dev;
|
||||||
/* USART not available */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!tx_buffer_size[usart]) {
|
/* Get a handle for the device configuration */
|
||||||
/* Nothing new in buffer */
|
usart_dev = find_usart_dev_by_id(usart);
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get byte - this operation should be atomic! */
|
if (!usart_dev) {
|
||||||
PIOS_IRQ_Disable();
|
/* Undefined USART port for this board (see pios_board.c) */
|
||||||
uint8_t b = tx_buffer[usart][tx_buffer_tail[usart]];
|
return -1;
|
||||||
if(++tx_buffer_tail[usart] >= PIOS_USART_TX_BUFFER_SIZE) {
|
}
|
||||||
tx_buffer_tail[usart] = 0;
|
|
||||||
}
|
|
||||||
--tx_buffer_size[usart];
|
|
||||||
PIOS_IRQ_Enable();
|
|
||||||
|
|
||||||
/* Return transmitted byte */
|
if (!usart_dev->tx.size) {
|
||||||
return b;
|
/* Nothing new in the buffer */
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get byte - this operation should be atomic! */
|
||||||
|
PIOS_IRQ_Disable();
|
||||||
|
uint8_t b = usart_dev->tx.buf[usart_dev->tx.tail++];
|
||||||
|
if (usart_dev->tx.tail >= sizeof(usart_dev->tx.buf)) {
|
||||||
|
usart_dev->tx.tail = 0;
|
||||||
|
}
|
||||||
|
usart_dev->tx.size--;
|
||||||
|
PIOS_IRQ_Enable();
|
||||||
|
|
||||||
|
/* Return received byte */
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -410,55 +385,45 @@ int32_t PIOS_USART_TxBufferGet(USARTNumTypeDef usart)
|
|||||||
* \return -3 if USART not supported by USARTTxBufferPut Routine
|
* \return -3 if USART not supported by USARTTxBufferPut Routine
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_TxBufferPutMoreNonBlocking(USARTNumTypeDef usart, uint8_t *buffer, uint16_t len)
|
int32_t PIOS_USART_TxBufferPutMoreNonBlocking(uint8_t usart, uint8_t *buffer, uint16_t len)
|
||||||
{
|
{
|
||||||
if(usart >= PIOS_USART_NUM) {
|
struct pios_usart_dev * usart_dev;
|
||||||
/* USART not available */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((tx_buffer_size[usart]+len) >= PIOS_USART_TX_BUFFER_SIZE) {
|
/* Get a handle for the device configuration */
|
||||||
/* Buffer full or cannot get all requested bytes (retry) */
|
usart_dev = find_usart_dev_by_id(usart);
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy bytes to be transmitted into transmit buffer */
|
if (!usart_dev) {
|
||||||
/* This operation should be atomic! */
|
/* Undefined USART port for this board (see pios_board.c) */
|
||||||
PIOS_IRQ_Disable();
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t i;
|
if (usart_dev->tx.size + len >= sizeof(usart_dev->tx.buf)) {
|
||||||
for(i = 0; i < len; ++i) {
|
/* Buffer cannot accept all requested bytes (retry) */
|
||||||
tx_buffer[usart][tx_buffer_head[usart]] = *buffer++;
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
if(++tx_buffer_head[usart] >= PIOS_USART_TX_BUFFER_SIZE) {
|
/* Copy bytes to be transmitted into transmit buffer */
|
||||||
tx_buffer_head[usart] = 0;
|
/* This operation should be atomic! */
|
||||||
}
|
PIOS_IRQ_Disable();
|
||||||
|
|
||||||
/* Enable Tx interrupt if buffer was empty */
|
uint16_t i;
|
||||||
if(++tx_buffer_size[usart] == 1) {
|
for(i = 0; i < len; ++i) {
|
||||||
switch(usart) {
|
usart_dev->tx.buf[usart_dev->tx.head++] = *buffer++;
|
||||||
#if (PIOS_USART1_ENABLED)
|
if (usart_dev->tx.head >= sizeof(usart_dev->tx.buf)) {
|
||||||
/* Enable TXE interrupt (TXEIE=1) */
|
usart_dev->tx.head = 0;
|
||||||
case 0: PIOS_USART1_USART->CR1 |= (1 << 7); break;
|
}
|
||||||
#endif
|
|
||||||
#if (PIOS_USART2_ENABLED)
|
|
||||||
/* Enable TXE interrupt (TXEIE=1) */
|
|
||||||
case 1: PIOS_USART2_USART->CR1 |= (1 << 7); break;
|
|
||||||
#endif
|
|
||||||
#if (PIOS_USART3_ENABLED)
|
|
||||||
/* Enable TXE interrupt (TXEIE=1) */
|
|
||||||
case 2: PIOS_USART3_USART->CR1 |= (1 << 7); break;
|
|
||||||
/* USART not supported by routine (yet) */
|
|
||||||
#endif
|
|
||||||
default: PIOS_IRQ_Enable(); return -3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PIOS_IRQ_Enable();
|
usart_dev->tx.size++;
|
||||||
|
if (usart_dev->tx.size == 1) {
|
||||||
|
/* Buffer has just become non-empty, enable tx interrupt. */
|
||||||
|
USART_ITConfig(usart_dev->cfg->regs, USART_IT_TXE, ENABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* No error */
|
PIOS_IRQ_Enable();
|
||||||
return 0;
|
|
||||||
|
/* No error */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -472,13 +437,13 @@ int32_t PIOS_USART_TxBufferPutMoreNonBlocking(USARTNumTypeDef usart, uint8_t *bu
|
|||||||
* \return -3 if USART not supported by USARTTxBufferPut Routine
|
* \return -3 if USART not supported by USARTTxBufferPut Routine
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_TxBufferPutMore(USARTNumTypeDef usart, uint8_t *buffer, uint16_t len)
|
int32_t PIOS_USART_TxBufferPutMore(uint8_t usart, uint8_t *buffer, uint16_t len)
|
||||||
{
|
{
|
||||||
int error;
|
int32_t rc;
|
||||||
|
|
||||||
while((error = PIOS_USART_TxBufferPutMoreNonBlocking(usart, buffer, len)) == -2);
|
while((rc = PIOS_USART_TxBufferPutMoreNonBlocking(usart, buffer, len)) == -2);
|
||||||
|
|
||||||
return error;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -491,11 +456,9 @@ int32_t PIOS_USART_TxBufferPutMore(USARTNumTypeDef usart, uint8_t *buffer, uint1
|
|||||||
* \return -3 if USART not supported by USARTTxBufferPut Routine
|
* \return -3 if USART not supported by USARTTxBufferPut Routine
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_TxBufferPut_NonBlocking(USARTNumTypeDef usart, uint8_t b)
|
int32_t PIOS_USART_TxBufferPut_NonBlocking(uint8_t usart, uint8_t b)
|
||||||
{
|
{
|
||||||
/* For more comfortable usage... */
|
return PIOS_USART_TxBufferPutMoreNonBlocking(usart, &b, 1);
|
||||||
/* -> Just forward to USARTTxBufferPutMore */
|
|
||||||
return PIOS_USART_TxBufferPutMore(usart, &b, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -508,105 +471,44 @@ int32_t PIOS_USART_TxBufferPut_NonBlocking(USARTNumTypeDef usart, uint8_t b)
|
|||||||
* \return -3 if USART not supported by USARTTxBufferPut Routine
|
* \return -3 if USART not supported by USARTTxBufferPut Routine
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USART_TxBufferPut(USARTNumTypeDef usart, uint8_t b)
|
int32_t PIOS_USART_TxBufferPut(uint8_t usart, uint8_t b)
|
||||||
{
|
{
|
||||||
int error;
|
return PIOS_USART_TxBufferPutMore(usart, &b, 1);
|
||||||
|
|
||||||
while((error = PIOS_USART_TxBufferPutMore(usart, &b, 1)) == -2);
|
|
||||||
|
|
||||||
return error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (PIOS_USART1_ENABLED)
|
void PIOS_USART_IRQ_Handler(uint8_t usart)
|
||||||
/* Interrupt handler for USART1 */
|
|
||||||
PIOS_USART1_IRQHANDLER_FUNC
|
|
||||||
{
|
{
|
||||||
/* Check if RXNE flag is set */
|
struct pios_usart_dev * usart_dev;
|
||||||
if(PIOS_USART1_USART->SR & USART_SR_RXNE) {
|
|
||||||
uint8_t b = PIOS_USART1_USART->DR;
|
|
||||||
|
|
||||||
if(PIOS_USART_RxBufferPut(USART_1, b) < 0) {
|
/* Get a handle for the device configuration */
|
||||||
/* Here we could add some error handling */
|
usart_dev = find_usart_dev_by_id(usart);
|
||||||
}
|
PIOS_DEBUG_Assert(usart_dev);
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if TXE flag is set */
|
/* Check if RXNE flag is set */
|
||||||
if(PIOS_USART1_USART->SR & USART_SR_TXE) {
|
if (usart_dev->cfg->regs->SR & USART_SR_RXNE) {
|
||||||
if(PIOS_USART_TxBufferUsed(USART_1) > 0) {
|
uint8_t b = usart_dev->cfg->regs->DR;
|
||||||
int b = PIOS_USART_TxBufferGet(USART_1);
|
|
||||||
if(b < 0) {
|
if (PIOS_USART_RxBufferPut(usart, b) < 0) {
|
||||||
/* Here we could add some error handling */
|
/* Here we could add some error handling */
|
||||||
PIOS_USART1_USART->DR = 0xff;
|
}
|
||||||
} else {
|
}
|
||||||
PIOS_USART1_USART->DR = b;
|
|
||||||
}
|
/* Check if TXE flag is set */
|
||||||
} else {
|
if (usart_dev->cfg->regs->SR & USART_SR_TXE) {
|
||||||
/* Disable TXE interrupt (TXEIE=0) */
|
if (PIOS_USART_TxBufferUsed(usart) > 0) {
|
||||||
PIOS_USART1_USART->CR1 &= ~(USART_CR1_TXEIE);
|
int32_t b = PIOS_USART_TxBufferGet(usart);
|
||||||
}
|
|
||||||
}
|
if(b < 0) {
|
||||||
|
/* Here we could add some error handling */
|
||||||
|
usart_dev->cfg->regs->DR = 0xff;
|
||||||
|
} else {
|
||||||
|
usart_dev->cfg->regs->DR = b & 0xff;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Disable TXE interrupt (TXEIE=0) */
|
||||||
|
USART_ITConfig(usart_dev->cfg->regs, USART_IT_TXE, DISABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (PIOS_USART2_ENABLED)
|
|
||||||
/* Interrupt handler for USART2 */
|
|
||||||
PIOS_USART2_IRQHANDLER_FUNC
|
|
||||||
{
|
|
||||||
/* check if RXNE flag is set */
|
|
||||||
if(PIOS_USART2_USART->SR & USART_SR_RXNE) {
|
|
||||||
uint8_t b = PIOS_USART2_USART->DR;
|
|
||||||
|
|
||||||
if(PIOS_USART_RxBufferPut(USART_2, b) < 0) {
|
|
||||||
/* Here we could add some error handling */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if TXE flag is set */
|
|
||||||
if(PIOS_USART2_USART->SR & USART_SR_TXE) {
|
|
||||||
if(PIOS_USART_TxBufferUsed(USART_2) > 0) {
|
|
||||||
int b = PIOS_USART_TxBufferGet(USART_2);
|
|
||||||
if(b < 0) {
|
|
||||||
/* Here we could add some error handling */
|
|
||||||
PIOS_USART2_USART->DR = 0xff;
|
|
||||||
} else {
|
|
||||||
PIOS_USART2_USART->DR = b;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Disable TXE interrupt (TXEIE=0) */
|
|
||||||
PIOS_USART2_USART->CR1 &= ~(USART_CR1_TXEIE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (PIOS_USART3_ENABLED)
|
|
||||||
/* Interrupt handler for USART3 */
|
|
||||||
PIOS_USART3_IRQHANDLER_FUNC
|
|
||||||
{
|
|
||||||
/* check if RXNE flag is set */
|
|
||||||
if(PIOS_USART3_USART->SR & USART_SR_RXNE) {
|
|
||||||
uint8_t b = PIOS_USART3_USART->DR;
|
|
||||||
|
|
||||||
if(PIOS_USART_RxBufferPut(USART_3, b) < 0) {
|
|
||||||
/* Here we could add some error handling */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(PIOS_USART3_USART->SR & USART_SR_TXE) { // check if TXE flag is set
|
|
||||||
if(PIOS_USART_TxBufferUsed(USART_3) > 0) {
|
|
||||||
int b = PIOS_USART_TxBufferGet(USART_3);
|
|
||||||
if(b < 0) {
|
|
||||||
/* Here we could add some error handling */
|
|
||||||
PIOS_USART3_USART->DR = 0xff;
|
|
||||||
} else {
|
|
||||||
PIOS_USART3_USART->DR = b;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Disable TXE interrupt (TXEIE=0) */
|
|
||||||
PIOS_USART3_USART->CR1 &= ~(USART_CR1_TXEIE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -33,6 +33,12 @@
|
|||||||
|
|
||||||
#if defined(PIOS_INCLUDE_USB_HID)
|
#if defined(PIOS_INCLUDE_USB_HID)
|
||||||
|
|
||||||
|
const struct pios_com_driver pios_usb_com_driver = {
|
||||||
|
.tx_nb = PIOS_USB_HID_TxBufferPutMoreNonBlocking,
|
||||||
|
.tx = PIOS_USB_HID_TxBufferPutMore,
|
||||||
|
.rx = PIOS_USB_HID_RxBufferGet,
|
||||||
|
.rx_avail = PIOS_USB_HID_RxBufferUsed,
|
||||||
|
};
|
||||||
|
|
||||||
/* Local types */
|
/* Local types */
|
||||||
typedef enum _HID_REQUESTS {
|
typedef enum _HID_REQUESTS {
|
||||||
@ -127,7 +133,7 @@ int32_t PIOS_USB_HID_ChangeConnectionState(uint32_t Connected)
|
|||||||
* \return 0: interface not available
|
* \return 0: interface not available
|
||||||
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USB_HID_CheckAvailable(void)
|
int32_t PIOS_USB_HID_CheckAvailable(uint8_t id)
|
||||||
{
|
{
|
||||||
return transfer_possible ? 1 : 0;
|
return transfer_possible ? 1 : 0;
|
||||||
}
|
}
|
||||||
@ -140,7 +146,7 @@ int32_t PIOS_USB_HID_CheckAvailable(void)
|
|||||||
* \return -1 if too many bytes to be send
|
* \return -1 if too many bytes to be send
|
||||||
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USB_HID_TxBufferPutMoreNonBlocking(uint8_t *buffer, uint16_t len)
|
int32_t PIOS_USB_HID_TxBufferPutMoreNonBlocking(uint8_t id, uint8_t *buffer, uint16_t len)
|
||||||
{
|
{
|
||||||
if(len > PIOS_USB_HID_DATA_LENGTH) {
|
if(len > PIOS_USB_HID_DATA_LENGTH) {
|
||||||
/* Cannot send all requested bytes */
|
/* Cannot send all requested bytes */
|
||||||
@ -167,11 +173,11 @@ int32_t PIOS_USB_HID_TxBufferPutMoreNonBlocking(uint8_t *buffer, uint16_t len)
|
|||||||
* \return -1 if too many bytes to be send
|
* \return -1 if too many bytes to be send
|
||||||
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USB_HID_TxBufferPutMore(uint8_t *buffer, uint16_t len)
|
int32_t PIOS_USB_HID_TxBufferPutMore(uint8_t id, uint8_t *buffer, uint16_t len)
|
||||||
{
|
{
|
||||||
int32_t error;
|
int32_t error;
|
||||||
|
|
||||||
while((error = PIOS_USB_HID_TxBufferPutMoreNonBlocking(buffer, len)) == -2);
|
while((error = PIOS_USB_HID_TxBufferPutMoreNonBlocking(id, buffer, len)) == -2);
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@ -182,7 +188,7 @@ int32_t PIOS_USB_HID_TxBufferPutMore(uint8_t *buffer, uint16_t len)
|
|||||||
* \return >= 0: received byte
|
* \return >= 0: received byte
|
||||||
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call this function directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
uint8_t PIOS_USB_HID_RxBufferGet(void)
|
int32_t PIOS_USB_HID_RxBufferGet(uint8_t id)
|
||||||
{
|
{
|
||||||
if(rx_buffer_new_data_ctr == 0) {
|
if(rx_buffer_new_data_ctr == 0) {
|
||||||
/* Nothing new in buffer */
|
/* Nothing new in buffer */
|
||||||
@ -205,7 +211,7 @@ uint8_t PIOS_USB_HID_RxBufferGet(void)
|
|||||||
* \return 0 nothing available
|
* \return 0 nothing available
|
||||||
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
* \note Applications shouldn't call these functions directly, instead please use \ref PIOS_COM layer functions
|
||||||
*/
|
*/
|
||||||
int32_t PIOS_USB_HID_RxBufferUsed(void)
|
int32_t PIOS_USB_HID_RxBufferUsed(uint8_t id)
|
||||||
{
|
{
|
||||||
return rx_buffer_new_data_ctr;
|
return rx_buffer_new_data_ctr;
|
||||||
}
|
}
|
||||||
|
@ -27,29 +27,29 @@
|
|||||||
#ifndef PIOS_COM_H
|
#ifndef PIOS_COM_H
|
||||||
#define PIOS_COM_H
|
#define PIOS_COM_H
|
||||||
|
|
||||||
/* Global Types */
|
|
||||||
typedef enum {
|
|
||||||
COM_DEBUG_USART = 0,
|
|
||||||
COM_USART1 = 1,
|
|
||||||
COM_USART2 = 2,
|
|
||||||
COM_USART3 = 3,
|
|
||||||
COM_USB_HID = 4
|
|
||||||
} COMPortTypeDef;
|
|
||||||
|
|
||||||
/* Public Functions */
|
/* Public Functions */
|
||||||
extern int32_t PIOS_COM_Init(void);
|
extern int32_t PIOS_COM_Init(void);
|
||||||
extern int32_t PIOS_COM_ChangeBaud(COMPortTypeDef port, uint32_t baud);
|
extern int32_t PIOS_COM_ChangeBaud(uint8_t port, uint32_t baud);
|
||||||
extern int32_t PIOS_COM_SendCharNonBlocking(COMPortTypeDef port, char c);
|
extern int32_t PIOS_COM_SendCharNonBlocking(uint8_t port, char c);
|
||||||
extern int32_t PIOS_COM_SendChar(COMPortTypeDef port, char c);
|
extern int32_t PIOS_COM_SendChar(uint8_t port, char c);
|
||||||
extern int32_t PIOS_COM_SendBufferNonBlocking(COMPortTypeDef port, uint8_t *buffer, uint16_t len);
|
extern int32_t PIOS_COM_SendBufferNonBlocking(uint8_t port, uint8_t *buffer, uint16_t len);
|
||||||
extern int32_t PIOS_COM_SendBuffer(COMPortTypeDef port, uint8_t *buffer, uint16_t len);
|
extern int32_t PIOS_COM_SendBuffer(uint8_t port, uint8_t *buffer, uint16_t len);
|
||||||
extern int32_t PIOS_COM_SendStringNonBlocking(COMPortTypeDef port, char *str);
|
extern int32_t PIOS_COM_SendStringNonBlocking(uint8_t port, char *str);
|
||||||
extern int32_t PIOS_COM_SendString(COMPortTypeDef port, char *str);
|
extern int32_t PIOS_COM_SendString(uint8_t port, char *str);
|
||||||
extern int32_t PIOS_COM_SendFormattedStringNonBlocking(COMPortTypeDef port, char *format, ...);
|
extern int32_t PIOS_COM_SendFormattedStringNonBlocking(uint8_t port, char *format, ...);
|
||||||
extern int32_t PIOS_COM_SendFormattedString(COMPortTypeDef port, char *format, ...);
|
extern int32_t PIOS_COM_SendFormattedString(uint8_t port, char *format, ...);
|
||||||
extern uint8_t PIOS_COM_ReceiveBuffer(COMPortTypeDef port);
|
extern uint8_t PIOS_COM_ReceiveBuffer(uint8_t port);
|
||||||
extern int32_t PIOS_COM_ReceiveBufferUsed(COMPortTypeDef port);
|
extern int32_t PIOS_COM_ReceiveBufferUsed(uint8_t port);
|
||||||
|
|
||||||
extern int32_t PIOS_COM_ReceiveHandler(void);
|
extern int32_t PIOS_COM_ReceiveHandler(void);
|
||||||
|
|
||||||
|
struct pios_com_driver {
|
||||||
|
void (*init)(uint8_t id);
|
||||||
|
void (*set_baud)(uint8_t id, uint32_t baud);
|
||||||
|
int32_t (*tx_nb)(uint8_t id, uint8_t *buffer, uint16_t len);
|
||||||
|
int32_t (*tx)(uint8_t id, uint8_t *buffer, uint16_t len);
|
||||||
|
int32_t (*rx)(uint8_t id);
|
||||||
|
int32_t (*rx_avail)(uint8_t id);
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* PIOS_COM_H */
|
#endif /* PIOS_COM_H */
|
||||||
|
41
flight/PiOS/inc/pios_com_priv.h
Normal file
41
flight/PiOS/inc/pios_com_priv.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file pios_com_priv.h
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* Parts by Thorsten Klose (tk@midibox.org)
|
||||||
|
* @brief COM private definitions.
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PIOS_COM_PRIV_H
|
||||||
|
#define PIOS_COM_PRIV_H
|
||||||
|
|
||||||
|
#include <pios.h>
|
||||||
|
|
||||||
|
struct pios_com_dev {
|
||||||
|
uint8_t id;
|
||||||
|
const struct pios_com_driver * const driver;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct pios_com_dev pios_com_devs[];
|
||||||
|
extern uint8_t pios_com_num_devices;
|
||||||
|
|
||||||
|
#endif /* PIOS_COM_PRIV_H */
|
||||||
|
|
@ -29,23 +29,23 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Global Types */
|
/* Global Types */
|
||||||
typedef enum {USART_1 = 0, USART_2 = 1, USART_3 = 2} USARTNumTypeDef;
|
|
||||||
|
|
||||||
/* Public Functions */
|
/* Public Functions */
|
||||||
extern void PIOS_USART_Init(void);
|
extern void PIOS_USART_Init(void);
|
||||||
extern void PIOS_USART_ChangeBaud(USARTNumTypeDef usart, uint32_t baud);
|
extern void PIOS_USART_ChangeBaud(uint8_t usart, uint32_t baud);
|
||||||
|
|
||||||
extern int32_t PIOS_USART_RxBufferFree(USARTNumTypeDef uart);
|
extern int32_t PIOS_USART_RxBufferFree(uint8_t usart);
|
||||||
extern int32_t PIOS_USART_RxBufferUsed(USARTNumTypeDef uart);
|
extern int32_t PIOS_USART_RxBufferUsed(uint8_t usart);
|
||||||
extern int32_t PIOS_USART_RxBufferGet(USARTNumTypeDef uart);
|
extern int32_t PIOS_USART_RxBufferGet(uint8_t usart);
|
||||||
extern int32_t PIOS_USART_RxBufferPeek(USARTNumTypeDef uart);
|
extern int32_t PIOS_USART_RxBufferPeek(uint8_t usart);
|
||||||
extern int32_t PIOS_USART_RxBufferPut(USARTNumTypeDef uart, uint8_t b);
|
extern int32_t PIOS_USART_RxBufferPut(uint8_t usart, uint8_t b);
|
||||||
|
|
||||||
extern int32_t PIOS_USART_TxBufferFree(USARTNumTypeDef uart);
|
extern int32_t PIOS_USART_TxBufferFree(uint8_t usart);
|
||||||
extern int32_t PIOS_USART_TxBufferGet(USARTNumTypeDef uart);
|
extern int32_t PIOS_USART_TxBufferGet(uint8_t usart);
|
||||||
extern int32_t PIOS_USART_TxBufferPutMoreNonBlocking(USARTNumTypeDef uart, uint8_t *buffer, uint16_t len);
|
extern int32_t PIOS_USART_TxBufferPutMoreNonBlocking(uint8_t usart, uint8_t *buffer, uint16_t len);
|
||||||
extern int32_t PIOS_USART_TxBufferPutMore(USARTNumTypeDef uart, uint8_t *buffer, uint16_t len);
|
extern int32_t PIOS_USART_TxBufferPutMore(uint8_t usart, uint8_t *buffer, uint16_t len);
|
||||||
extern int32_t PIOS_USART_TxBufferPutNonBlocking(uint8_t uart, uint8_t b);
|
extern int32_t PIOS_USART_TxBufferPutNonBlocking(uint8_t usart, uint8_t b);
|
||||||
extern int32_t PIOS_USART_TxBufferPut(USARTNumTypeDef uart, uint8_t b);
|
extern int32_t PIOS_USART_TxBufferPut(uint8_t usart, uint8_t b);
|
||||||
|
|
||||||
|
extern void PIOS_USART_IRQ_Handler(uint8_t usart);
|
||||||
#endif /* PIOS_USART_H */
|
#endif /* PIOS_USART_H */
|
||||||
|
58
flight/PiOS/inc/pios_usart_priv.h
Normal file
58
flight/PiOS/inc/pios_usart_priv.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file pios_usart_priv.h
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* Parts by Thorsten Klose (tk@midibox.org)
|
||||||
|
* @brief USART private definitions.
|
||||||
|
* @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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PIOS_USART_PRIV_H
|
||||||
|
#define PIOS_USART_PRIV_H
|
||||||
|
|
||||||
|
#include <pios.h>
|
||||||
|
#include <pios_stm32.h>
|
||||||
|
|
||||||
|
struct pios_usart_cfg {
|
||||||
|
USART_TypeDef * regs;
|
||||||
|
uint32_t remap; /* GPIO_Remap_* */
|
||||||
|
USART_InitTypeDef init;
|
||||||
|
struct stm32_gpio rx;
|
||||||
|
struct stm32_gpio tx;
|
||||||
|
struct stm32_irq irq;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct pios_usart_buffer {
|
||||||
|
uint8_t buf[PIOS_USART_RX_BUFFER_SIZE];
|
||||||
|
uint16_t head;
|
||||||
|
uint16_t tail;
|
||||||
|
uint16_t size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct pios_usart_dev {
|
||||||
|
const struct pios_usart_cfg * const cfg;
|
||||||
|
struct pios_usart_buffer rx;
|
||||||
|
struct pios_usart_buffer tx;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct pios_usart_dev pios_usart_devs[];
|
||||||
|
extern uint8_t pios_usart_num_devices;
|
||||||
|
|
||||||
|
#endif /* PIOS_USART_PRIV_H */
|
@ -39,11 +39,11 @@
|
|||||||
/* Global functions */
|
/* Global functions */
|
||||||
extern int32_t PIOS_USB_HID_Init(uint32_t mode);
|
extern int32_t PIOS_USB_HID_Init(uint32_t mode);
|
||||||
extern int32_t PIOS_USB_HID_ChangeConnectionState(uint32_t Connected);
|
extern int32_t PIOS_USB_HID_ChangeConnectionState(uint32_t Connected);
|
||||||
extern int32_t PIOS_USB_HID_CheckAvailable(void);
|
extern int32_t PIOS_USB_HID_CheckAvailable(uint8_t id);
|
||||||
extern int32_t PIOS_USB_HID_TxBufferPutMoreNonBlocking(uint8_t *buffer, uint16_t len);
|
extern int32_t PIOS_USB_HID_TxBufferPutMoreNonBlocking(uint8_t id, uint8_t *buffer, uint16_t len);
|
||||||
extern int32_t PIOS_USB_HID_TxBufferPutMore(uint8_t *buffer, uint16_t len);
|
extern int32_t PIOS_USB_HID_TxBufferPutMore(uint8_t id, uint8_t *buffer, uint16_t len);
|
||||||
extern uint8_t PIOS_USB_HID_RxBufferGet(void);
|
extern int32_t PIOS_USB_HID_RxBufferGet(uint8_t id);
|
||||||
extern int32_t PIOS_USB_HID_RxBufferUsed(void);
|
extern int32_t PIOS_USB_HID_RxBufferUsed(uint8_t id);
|
||||||
extern int32_t PIOS_USB_HID_CB_Data_Setup(uint8_t RequestNo);
|
extern int32_t PIOS_USB_HID_CB_Data_Setup(uint8_t RequestNo);
|
||||||
extern int32_t PIOS_USB_HID_CB_NoData_Setup(uint8_t RequestNo);
|
extern int32_t PIOS_USB_HID_CB_NoData_Setup(uint8_t RequestNo);
|
||||||
extern void PIOS_USB_HID_EP1_OUT_Callback(void);
|
extern void PIOS_USB_HID_EP1_OUT_Callback(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user