MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_leuart_control

Function rt_leuart_control

bsp/efm32/drv_leuart.c:508–601  ·  view source on GitHub ↗

/ * @brief * Configure LEUART device * * @details * * @note * * @param[in] dev * Pointer to device descriptor * * @param[in] cmd * IIC control command * * @param[in] args * Arguments * * @return * Error code ******************************************************************************/

Source from the content-addressed store, hash-verified

506* Error code
507******************************************************************************/
508static rt_err_t rt_leuart_control (
509 rt_device_t dev,
510 rt_uint8_t cmd,
511 void *args)
512{
513 RT_ASSERT(dev != RT_NULL);
514
515 rt_err_t err_code;
516 struct efm32_leuart_device_t *leuart;
517
518 leuart = (struct efm32_leuart_device_t *)(dev->user_data);
519
520 /* Lock device */
521 if (rt_hw_interrupt_check())
522 {
523 err_code = rt_sem_take(leuart->lock, RT_WAITING_NO);
524 }
525 else
526 {
527 err_code = rt_sem_take(leuart->lock, RT_WAITING_FOREVER);
528 }
529 if (err_code != RT_EOK)
530 {
531 return err_code;
532 }
533
534 switch (cmd)
535 {
536 case RT_DEVICE_CTRL_SUSPEND:
537 /* Suspend device */
538 dev->flag |= RT_DEVICE_FLAG_SUSPENDED;
539 LEUART_Enable(leuart->leuart_device, leuartDisable);
540 break;
541
542 case RT_DEVICE_CTRL_RESUME:
543 /* Resume device */
544 dev->flag &= ~RT_DEVICE_FLAG_SUSPENDED;
545 LEUART_Enable(leuart->leuart_device, leuartEnable);
546 break;
547
548 case RT_DEVICE_CTRL_LEUART_RBUFFER:
549 /* Set RX buffer */
550 {
551 struct efm32_leuart_int_mode_t *int_rx;
552 rt_uint8_t size;
553
554 int_rx = (struct efm32_leuart_int_mode_t *)(leuart->rx_mode);
555 size = (rt_uint8_t)((rt_uint32_t)args & 0xFFUL);
556
557 /* Free previous RX buffer */
558 if (int_rx->data_ptr != RT_NULL)
559 {
560 if (size == 0)
561 { /* Free RX buffer */
562 rt_free(int_rx->data_ptr);
563 int_rx->data_ptr = RT_NULL;
564 }
565 else if (size != int_rx->data_size)

Callers

nothing calls this directly

Calls 6

rt_sem_takeFunction · 0.85
LEUART_EnableFunction · 0.85
rt_freeFunction · 0.85
rt_reallocFunction · 0.85
rt_mallocFunction · 0.85
rt_sem_releaseFunction · 0.85

Tested by

no test coverage detected