Skip to content

Commit

Permalink
dbg
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaosanti committed Dec 2, 2023
1 parent 6058088 commit df42160
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 218 deletions.
6 changes: 0 additions & 6 deletions flight/pios/common/pios_board_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,9 @@ void PIOS_BOARD_IO_Configure_UART_COM(const struct pios_usart_cfg *hw_config,
{
uint32_t usart_id;

#ifdef PIOS_USART_USE_DMA
if (PIOS_USART_DMA_Init(&usart_id, hw_config)) {
PIOS_Assert(0);
}
#else
if (PIOS_USART_Init(&usart_id, hw_config)) {
PIOS_Assert(0);
}
#endif

if (PIOS_COM_Init(com_id, &pios_usart_com_driver, usart_id,
0, rx_buf_len,
Expand Down
15 changes: 13 additions & 2 deletions flight/pios/common/pios_dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ int32_t PIOS_DBus_Init(uint32_t *dbus_id,
*dbus_id = (uint32_t)dbus_dev;

/* Set rest of the parameters and enable */
// there is one USART_Init before
if (driver->set_config) {
driver->set_config(lower_id, PIOS_COM_Word_length_8b, PIOS_COM_Parity_Even, PIOS_COM_StopBits_1, PIOS_DBUS_BAUD_RATE);
}
Expand Down Expand Up @@ -242,7 +243,7 @@ static uint8_t PIOS_DBus_ChannelDataValid(struct pios_dbus_state *state) {
}
ch[5] = DBUS_SW_DOWN; //sw
ch[6] = DBUS_SW_DOWN;
for (uint8_t i = 0; i< 6; i++) { // mouse * 5 + key * 1
for (uint8_t i = 7; i < 13; i++) { // mouse * 5 + key * 1
ch[i] = 0;
}
return 0; // invalid
Expand All @@ -256,13 +257,23 @@ static uint16_t PIOS_DBus_RxInCallback(uint32_t context,
uint16_t *headroom,
bool *need_yield)
{
if (buf_len != DBUS_FRAME_LENGTH) {
return 0;
}
struct pios_dbus_dev *dbus_dev = (struct pios_dbus_dev *)context;
bool valid = PIOS_DBus_Validate(dbus_dev);
PIOS_Assert(valid);
struct pios_dbus_state *state = &(dbus_dev->state);
for (auto i = 0; i < buf_len; i++) {
state->received_data[i] = buf[i];
}
PIOS_DBus_UnrollChannels(state);
volatile uint16_t ch[16];
for (auto i = 0; i < 13; i++) {
ch[i] = state->channel_data[i];
}
if (!PIOS_DBus_ChannelDataValid(state)) {
PIOS_USART_DMA_Reinit(context);
//PIOS_USART_DMA_Reinit(context);
return 0;
}
/* We never need a yield */
Expand Down
5 changes: 2 additions & 3 deletions flight/pios/inc/pios_usart_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,16 @@ struct pios_usart_cfg {
struct stm32_gpio tx;
struct stm32_gpio dtr;

bool use_dma;
#ifdef PIOS_USART_USE_DMA
char** rx_buf; // double buffer
uint16_t buf_len;
struct stm32_dma dma;
#endif // PIOS_USART_USE_DMA

/* provide hook for board specific ioctls */
int32_t (*ioctl)(uint32_t id, uint32_t ctl, void *param);
};

extern int32_t PIOS_USART_Init(uint32_t *usart_id, const struct pios_usart_cfg *cfg);
extern int32_t PIOS_USART_Init(uint32_t *usart_id, struct pios_usart_cfg *cfg);

const struct pios_usart_cfg *PIOS_USART_GetConfig(uint32_t usart_id);

Expand Down
Loading

0 comments on commit df42160

Please sign in to comment.