2011-07-08 15:13:20 +08:00
|
|
|
/***************************************************************************//**
|
|
|
|
* @file drv_usart.h
|
2011-02-17 11:33:15 +08:00
|
|
|
* @brief USART driver of RT-Thread RTOS for EFM32
|
2011-02-28 12:47:50 +08:00
|
|
|
* COPYRIGHT (C) 2011, RT-Thread Development Team
|
2011-02-17 11:33:15 +08:00
|
|
|
* @author onelife
|
2011-07-08 15:13:20 +08:00
|
|
|
* @version 0.4 beta
|
|
|
|
*******************************************************************************
|
2011-02-17 11:33:15 +08:00
|
|
|
* @section License
|
2011-12-16 09:05:50 +08:00
|
|
|
* The license and distribution terms for this file may be found in the file
|
2011-07-08 15:13:20 +08:00
|
|
|
* LICENSE in this distribution or at http://www.rt-thread.org/license/LICENSE
|
|
|
|
*******************************************************************************
|
2011-02-17 11:33:15 +08:00
|
|
|
* @section Change Logs
|
|
|
|
* Date Author Notes
|
|
|
|
* 2010-12-22 onelife Initial creation for EFM32
|
2011-07-08 15:13:20 +08:00
|
|
|
* 2011-06-27 onelife Fix a bug when using compiler optimization
|
2011-12-16 09:05:50 +08:00
|
|
|
* 2011-07-26 onelife Add lock (semaphore) to prevent simultaneously
|
2011-07-29 10:47:37 +08:00
|
|
|
* access
|
2011-12-16 09:05:50 +08:00
|
|
|
* 2011-12-09 onelife Add giant gecko support
|
|
|
|
* 2011-12-09 onelife Add UART module support
|
2011-07-08 15:13:20 +08:00
|
|
|
******************************************************************************/
|
2011-02-17 11:33:15 +08:00
|
|
|
#ifndef __DRV_USART_H__
|
|
|
|
#define __DRV_USART_H__
|
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
|
/* Exported types ------------------------------------------------------------*/
|
2011-02-17 11:33:15 +08:00
|
|
|
struct efm32_usart_int_mode_t
|
|
|
|
{
|
2011-07-29 10:47:37 +08:00
|
|
|
rt_uint8_t *data_ptr;
|
|
|
|
rt_uint8_t data_size;
|
|
|
|
rt_uint32_t read_index, save_index;
|
2011-02-17 11:33:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct efm32_usart_dma_mode_t
|
|
|
|
{
|
|
|
|
/* DMA Channel */
|
2011-07-29 10:47:37 +08:00
|
|
|
rt_uint32_t dma_channel;
|
2011-02-17 11:33:15 +08:00
|
|
|
|
|
|
|
/* buffer info */
|
2011-07-29 10:47:37 +08:00
|
|
|
rt_uint32_t *data_ptr;
|
|
|
|
rt_uint8_t data_size;
|
2011-02-17 11:33:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct efm32_usart_device_t
|
|
|
|
{
|
2011-07-29 10:47:37 +08:00
|
|
|
/* Counter */
|
|
|
|
rt_uint32_t counter;
|
|
|
|
/* Lock */
|
|
|
|
struct rt_semaphore *lock;
|
2011-02-17 11:33:15 +08:00
|
|
|
/* Unit number */
|
2011-07-29 10:47:37 +08:00
|
|
|
rt_uint8_t unit;
|
2011-02-17 11:33:15 +08:00
|
|
|
/* State */
|
2011-07-29 10:47:37 +08:00
|
|
|
volatile rt_uint8_t state;
|
2011-02-17 11:33:15 +08:00
|
|
|
/* Pointer to USART device structure */
|
2011-07-29 10:47:37 +08:00
|
|
|
USART_TypeDef *usart_device;
|
2011-02-17 11:33:15 +08:00
|
|
|
/* Pointer to RX structure */
|
2011-07-29 10:47:37 +08:00
|
|
|
void *rx_mode;
|
2011-02-17 11:33:15 +08:00
|
|
|
/* Pointer to TX structure */
|
2011-07-29 10:47:37 +08:00
|
|
|
void *tx_mode;
|
2011-02-17 11:33:15 +08:00
|
|
|
};
|
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
/* Exported constants --------------------------------------------------------*/
|
|
|
|
/* Exported macro ------------------------------------------------------------*/
|
2011-02-17 11:33:15 +08:00
|
|
|
#define USART_WAIT_TIME_TX (RT_TICK_PER_SECOND / 100 * 3)
|
|
|
|
|
|
|
|
#define USART_STATE_CONSOLE (1 << 0)
|
2011-12-16 09:05:50 +08:00
|
|
|
#define USART_STATE_ASYNC_ONLY (1 << 1)
|
|
|
|
#define USART_STATE_SYNC (1 << 2)
|
|
|
|
#define USART_STATE_MASTER (1 << 3)
|
|
|
|
#define USART_STATE_AUTOCS (1 << 4)
|
|
|
|
#define USART_STATE_TX_BUSY (1 << 5)
|
|
|
|
#define USART_STATE_RX_BUSY (1 << 6)
|
2011-02-17 11:33:15 +08:00
|
|
|
|
|
|
|
|
2011-07-08 15:13:20 +08:00
|
|
|
/* Exported functions ------------------------------------------------------- */
|
2011-02-17 11:33:15 +08:00
|
|
|
void rt_hw_usart_init(void);
|
|
|
|
|
|
|
|
#endif /* __DRV_USART_H__ */
|