本文整理汇总了C++中SERIAL_S函数的典型用法代码示例。如果您正苦于以下问题:C++ SERIAL_S函数的具体用法?C++ SERIAL_S怎么用?C++ SERIAL_S使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SERIAL_S函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: serial_format
void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
{
struct serial_s *obj_s = SERIAL_S(obj);
if (data_bits == 9) {
obj_s->databits = UART_WORDLENGTH_9B;
} else {
obj_s->databits = UART_WORDLENGTH_8B;
}
switch (parity) {
case ParityOdd:
obj_s->parity = UART_PARITY_ODD;
break;
case ParityEven:
obj_s->parity = UART_PARITY_EVEN;
break;
default: // ParityNone
case ParityForced0: // unsupported!
case ParityForced1: // unsupported!
obj_s->parity = UART_PARITY_NONE;
break;
}
if (stop_bits == 2) {
obj_s->stopbits = UART_STOPBITS_2;
} else {
obj_s->stopbits = UART_STOPBITS_1;
}
init_uart(obj);
}
示例2: serial_irq_handler
void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id)
{
struct serial_s *obj_s = SERIAL_S(obj);
irq_handler = handler;
serial_irq_ids[obj_s->index] = id;
}
示例3: serial_rx_abort_asynch
/**
* Abort the ongoing RX transaction It disables the enabled interrupt for RX and
* flush RX hardware buffer if RX FIFO is used
*
* @param obj The serial object
*/
void serial_rx_abort_asynch(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
// disable interrupts
__HAL_UART_DISABLE_IT(huart, UART_IT_RXNE);
__HAL_UART_DISABLE_IT(huart, UART_IT_PE);
__HAL_UART_DISABLE_IT(huart, UART_IT_ERR);
// clear flags
volatile uint32_t tmpval __attribute__((unused)) = huart->Instance->RDR; // Clear RXNE
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_PEF);
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_FEF);
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_NEF);
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF);
// reset states
huart->RxXferCount = 0;
// update handle state
if (huart->RxState == HAL_UART_STATE_BUSY_TX_RX) {
huart->RxState = HAL_UART_STATE_BUSY_TX;
} else {
huart->RxState = HAL_UART_STATE_READY;
}
}
示例4: serial_get_irq_n
/**
* Get index of serial object TX IRQ, relating it to the physical peripheral.
*
* @param obj pointer to serial object
* @return internal NVIC TX IRQ index of U(S)ART peripheral
*/
static IRQn_Type serial_get_irq_n(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
IRQn_Type irq_n;
switch (obj_s->index) {
case 0:
irq_n = USART1_IRQn;
break;
case 1:
irq_n = USART2_IRQn;
break;
#if defined(USART3_BASE)
case 2:
irq_n = USART3_IRQn;
break;
#endif
#if defined(UART4_BASE)
case 3:
irq_n = UART4_IRQn;
break;
#endif
#if defined(UART5_BASE)
case 4:
irq_n = UART5_IRQn;
break;
#endif
default:
irq_n = (IRQn_Type)0;
}
return irq_n;
}
示例5: serial_break_set
void serial_break_set(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
HAL_LIN_SendBreak(huart);
}
示例6: serial_rx_asynch
/**
* Begin asynchronous RX transfer (enable interrupt for data collecting)
* The used buffer is specified in the serial object, rx_buff
*
* @param obj The serial object
* @param rx The buffer for sending
* @param rx_length The number of words to transmit
* @param rx_width The bit width of buffer word
* @param handler The serial handler
* @param event The logical OR of events to be registered
* @param handler The serial handler
* @param char_match A character in range 0-254 to be matched
* @param hint A suggestion for how to use DMA with this transfer
*/
void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint)
{
// TODO: DMA usage is currently ignored
(void) hint;
/* Sanity check arguments */
MBED_ASSERT(obj);
MBED_ASSERT(rx != (void*)0);
MBED_ASSERT(rx_width == 8); // support only 8b width
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
serial_enable_event(obj, SERIAL_EVENT_RX_ALL, 0);
serial_enable_event(obj, event, 1);
// set CharMatch
obj->char_match = char_match;
serial_rx_buffer_set(obj, rx, rx_length, rx_width);
IRQn_Type irq_n = serial_get_irq_n(obj);
NVIC_ClearPendingIRQ(irq_n);
NVIC_DisableIRQ(irq_n);
NVIC_SetPriority(irq_n, 0);
NVIC_SetVector(irq_n, (uint32_t)handler);
NVIC_EnableIRQ(irq_n);
// following HAL function will enable the RXNE interrupt + error interrupts
HAL_UART_Receive_IT(huart, (uint8_t*)rx, rx_length);
}
示例7: serial_baud
void serial_baud(serial_t *obj, int baudrate)
{
struct serial_s *obj_s = SERIAL_S(obj);
obj_s->baudrate = baudrate;
init_uart(obj);
}
示例8: init_uart
static void init_uart(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
huart->Instance = (USART_TypeDef *)(obj_s->uart);
huart->Init.BaudRate = obj_s->baudrate;
huart->Init.WordLength = obj_s->databits;
huart->Init.StopBits = obj_s->stopbits;
huart->Init.Parity = obj_s->parity;
#if DEVICE_SERIAL_FC
huart->Init.HwFlowCtl = obj_s->hw_flow_ctl;
#else
huart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
#endif
huart->TxXferCount = 0;
huart->TxXferSize = 0;
huart->RxXferCount = 0;
huart->RxXferSize = 0;
if (obj_s->pin_rx == NC) {
huart->Init.Mode = UART_MODE_TX;
} else if (obj_s->pin_tx == NC) {
huart->Init.Mode = UART_MODE_RX;
} else {
huart->Init.Mode = UART_MODE_TX_RX;
}
if (HAL_UART_Init(huart) != HAL_OK) {
error("Cannot initialize UART\n");
}
}
示例9: serial_clear
void serial_clear(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
__HAL_UART_CLEAR_IT(huart, UART_FLAG_TXE);
__HAL_UART_CLEAR_IT(huart, UART_FLAG_RXNE);
}
示例10: serial_clear
void serial_clear(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
__HAL_UART_CLEAR_FLAG(huart, UART_CLEAR_TCF);
__HAL_UART_SEND_REQ(huart, UART_RXDATA_FLUSH_REQUEST);
}
示例11: serial_getc
int serial_getc(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
while (!serial_readable(obj));
return (int)(huart->Instance->DR & 0x1FF);
}
示例12: serial_writable
int serial_writable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
// Check if data is transmitted
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_TXE) != RESET) ? 1 : 0;
}
示例13: serial_clear
void serial_clear(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
huart->TxXferCount = 0;
huart->RxXferCount = 0;
}
示例14: serial_putc
void serial_putc(serial_t *obj, int c)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
while (!serial_writable(obj));
huart->Instance->DR = (uint32_t)(c & 0x1FF);
}
示例15: serial_readable
int serial_readable(serial_t *obj)
{
struct serial_s *obj_s = SERIAL_S(obj);
UART_HandleTypeDef *huart = &uart_handlers[obj_s->index];
// Check if data is received
return (__HAL_UART_GET_FLAG(huart, UART_FLAG_RXNE) != RESET) ? 1 : 0;
}