csl_uart.h
来自「dsp在音频处理中的运用」· C头文件 代码 · 共 1,414 行 · 第 1/3 页
H
1,414 行
#define CSL_UART_CONFIG_DEFAULTS { \
CSL_UART_DLH_RESETVAL, \
CSL_UART_DLL_RESETVAL, \
CSL_UART_IER_RESETVAL, \
CSL_UART_FCR_RESETVAL, \
CSL_UART_EFR_RESETVAL, \
CSL_UART_MCR_RESETVAL, \
CSL_UART_XON1_RESETVAL, \
CSL_UART_XON2_RESETVAL, \
CSL_UART_XOFF1_RESETVAL, \
CSL_UART_XOFF2_RESETVAL, \ CSL_UART_MDR1_RESETVAL, \
CSL_UART_TCR_RESETVAL, \
CSL_UART_TLR_RESETVAL, \
CSL_UART_SCR_RESETVAL, \
CSL_UART_SYSC_RESETVAL, \
CSL_UART_WER_RESETVAL \
}/** @brief CSL_UartHwSetupFlowCtrl is a substructure of the CSL_UartHwSetup.** It has the fields required for the configuration of Modem Flow Control*/typedef struct CSL_UartHwSetupFlowCtrl{ /** Software Rx Control Parameter */ CSL_UartSwFlow swRxctrl; /** Software Tx Control Parameter */ CSL_UartSwFlow swTxctrl; /** Standard Flow Control Types */ CSL_UartFlowControl flowType; /** Rx Threshold to stop reception CSL_UartReg */ Uint16 rxFifoTriggerHalt; /** Rx Threshold to resume reception */ Uint16 rxFifoTriggerResume; /** AUTO RTS Enable \n TRUE - Enable Auto RTS \n FALSE - Disable Auto RTS */ Bool autorts; /** AUTO CTS Enable \n TRUE - Enable Auto CTS \n FALSE - Disable Auto CTS */ Bool autocts; /** xon1 character (relevant if flowType is SW) */ Uint8 xon1; /** xon2 character (relevant if flowType is SW) */ Uint8 xon2; /** xoff1 character (relevant if flowType is SW) */ Uint8 xoff1; /** xoff2 character (relevant if flowType is SW) */ Uint8 xoff2;}CSL_UartHwSetupFlowCtrl;/**@}*//* Default Setup Structure *//** Modem setup defaluts */#define CSL_UART_HWMODEM_SETUP_DEFAULTS { \ /* char length */ (CSL_UartCharLen)CSL_UART_CHARLEN_8, \ /* stop bit */(CSL_UartNumStop)CSL_UART_NUMSTOP_2, \ /* parity type */ (CSL_UartParity)CSL_UART_PARITY_EVEN \ }/** Receive dma trigger level */#define CSL_UART_TRIG_RX_DMA_TRIG 32/** Transmit dma trigger level */#define CSL_UART_TRIG_TX_DMA_TRIG 32/** Ctrl setup defaults */#define CSL_UART_HWCTRL_SETUP_DEFAULTS { \ /* Module Clock Frequency(Hz) */ (Uint32)48000000,\ /* Standard baudrate setting */ (Uint32)CSL_UART_BAUD_9_6K, \ /* Uart Mode*/ (CSL_UartMode)CSL_UART_MODE_16X,\ /* DMA modes */ (CSL_UartDmaMode)CSL_UART_DMAMODE_NONE,\ /* Transmit trigger level */ (Uint16)CSL_UART_TRIG_RX_DMA_TRIG,\ /* Receive trigger level */ (Uint16)CSL_UART_TRIG_TX_DMA_TRIG,\ /* Uart event */ (CSL_BitMask16)(CSL_UART_EVENT_RHR|CSL_UART_EVENT_THR),\ /* Fifo enable */ (Bool)TRUE, \ /* loopback disable */ (Bool)FALSE \ }/** flow ctrl setup defaults */#define CSL_UART_HWFLOWCTRL_SETUP_DEFAULTS{ \ /* Rx SW Flow Control */(CSL_UartSwFlow)CSL_UART_SWFLOW_NONE, \ /* Tx SW Flow Control */(CSL_UartSwFlow)CSL_UART_SWFLOW_NONE, \ /* Flow Control Type */(CSL_UartFlowControl)CSL_UART_FLOWCONTROL_HW, \ /* Rx Fifo Trigger Halt */(Uint16)56, \ /* Rx Fifo Trigger Resume */(Uint16)16, \ /* Auto RTS Enable */(Bool)TRUE, \ /* Auto CTS Enable */(Bool)TRUE, \ /* XON1 Character */(Uint8)0x0, \ /* XON2 Character */(Uint8)0x0, \ /* XOFF1 Character */(Uint8)0x0, \ /* XOFF2 Character */(Uint8)0x0 \ }/** @addtogroup CSL_UART_DATASTRUCT** @{ *//** @brief CSL_UartHwSetup has all the fields required to configure UART** This structure has the substructures required to configure UART at* Power-Up/Reset.**/typedef struct CSL_UartHwSetup { /** Configuration parameters at power Up/Reset */ CSL_UartHwCtrlSetup* hwCtrlSetup; /** Configuration parameters for Modem Setup */ CSL_UartHwSetupModem* modemSetup; /** Configuration parameters for Flow Control */ CSL_UartHwSetupFlowCtrl* flowCtrlSetup;}CSL_UartHwSetup;/**@}*//**@addtogroup CSL_UART_DATASTRUCT@{*//** @brief This object contains the reference to the instance of UART opened * using the @a CSL_uartOpen(). * * The pointer to this, is passed to all UART CSL APIs. */typedef struct CSL_UartObj { /** This is a pointer to the registers of the instance of UART * referred to by this object */ CSL_UartRegsOvly regs; /** This is the instance of UART being referred to by this object */ CSL_InstNum perNum;} CSL_UartObj;/** @brief this is a pointer to @a CSL_UartObj & is passed as the first
* parameter to all UART CSL APIs */typedef struct CSL_UartObj *CSL_UartHandle;/** @brief This will have the base-address information for the peripheral * instance */typedef struct { /** Base-address of the Configuration registers of the peripheral */ CSL_UartRegsOvly regs;} CSL_UartBaseAddress;/** @brief Module specific parameters. Present implementation doesn't have * any module specific parameters. */typedef struct{ /** Bit mask to be used for module specific parameters. * The below declaration is just a place-holder for future * implementation. */ CSL_BitMask16 flags;} CSL_UartParam;/** @brief Module specific context information. Present implementation doesn't have * any Context information. */typedef struct { /** Context information of UART. * The below declaration is just a place-holder for future * implementation. */ Uint16 contextInfo;} CSL_UartContext;/** @brief Opens the instance of UART requested. * * The open call sets up the data structures for the particular instance of * UART device. The device can be re-opened anytime after it has been normally * closed if so required. The handle returned by this call is input as an * essential argument for rest of the APIs described for this module. * * <b> Usage Constraints: </b> * UART must be successfully initialized via @a CSL_uartInit() before calling * this function. Memory for the @a CSL_uartObj must be allocated outside * this call. This object must be retained while usage of this peripheral. * * @b Example: * @verbatim CSL_UartObj uartObj; CSL_Status status; ... hUart = CSL_uartOpen(&uartObj, CSL_UART_1, NULL, &status); @endverbatim * * @return returns a handle @a CSL_UartHandle to the requested instance of * UART if the call is successful, otherwise, a @a NULL is returned. * */CSL_UartHandle CSL_uartOpen ( /** Pointer to the object that holds reference to the * instance of UART requested after the call */ CSL_UartObj* pUartObj, /** Instance of UART to which a handle is requested */ CSL_InstNum uartNum, /** Module specific parameters; * Currently there are none; the user should pass 'NULL' */ CSL_UartParam *pUartParam, /** This returns the status (success/errors) of the call. * Could be 'NULL' if the user does not want status information. */ CSL_Status *pStatus );/**@defgroup CSL_UART_CLOSE_API UART Close API@ingroup CSL_UART_FUNCTION@brief Closes the instance of UART requested@{*/CSL_Status CSL_uartClose( /** Pointer to the object that holds reference to the * instance of UART requested after the call */ CSL_UartHandle hUart);/**@}*//**@defgroup CSL_UART_SETUP_API UART Setup API@ingroup CSL_UART_FUNCTION@brief Programs the UART with the setup configuration as specified in the arguments@{*/CSL_Status CSL_uartHwSetup( /** Pointer to the object that holds reference to the * instance of UART requested after the call */ CSL_UartHandle hUart, /** Pointer to setup structure which contains the * information to program UART to a useful state */ CSL_UartHwSetup* setup);/**@}*//**@defgroup CSL_UART_GETSETUP_API UART Get Setup API@ingroup CSL_UART_FUNCTION@brief Reads the setup from the peripheral registers.@{*/CSL_Status CSL_uartGetHwSetup( /** Pointer to the object that holds reference to the * instance of UART requested after the call */ CSL_UartHandle hUart, /** Placeholder to return the status; @a CSL_UartHwSetup* */ CSL_UartHwSetup* mySetup);/**@}*//**@defgroup CSL_UART_CONTROL_API UART Control API@ingroup CSL_UART_FUNCTION@brief Controls the different operations that can be performed by UART@{*/CSL_Status CSL_uartHwControl( /** Pointer to the object that holds reference to the * instance of UART requested after the call */ CSL_UartHandle hUart, /** The command to this API which indicates the action to be taken */ CSL_UartHwControlCmd cmd, /** Optional argument @a void* casted */ void *cmdArg);/**@}*//** @brief Peripheral specific initialization function. * * This is the peripheral specific intialization function. This function is * idempotent in that calling it many times is same as calling it once. * This function initializes the CSL data structures, and doesn't touches * the hardware. * * <b> Usage Constraints: </b> * This function should be called before using any of the CSL APIs in the UART * module. * * Note: As UART doesn't have any context based information, currently, the function * just returns CSL_SOK. User is expected to pass NULL in the function call. * * @b Example: * @verbatim ... if (CSL_SOK != CSL_uartInit(NULL)) { return; } @endverbatim * * @return returns the status of the operation * */CSL_Status CSL_uartInit( /** UART specific context information */ CSL_UartContext * pContext );/**@defgroup CSL_UART_QUERY_API UART Query API@ingroup CSL_UART_FUNCTION@brief Returns the status of the requested operation/parameter of UART@{*/CSL_Status CSL_uartGetHwStatus( /** Pointer to the object that holds reference to the * instance of UART requested after the call */ CSL_UartHandle hUart, /** The query to this API which indicates the status/setup * to be returned */ CSL_UartHwStatusQuery myQuery, /** Placeholder to return the status; @a void* casted */ void *response);/**@}*//** @brief Function to get the Base-address of the peripheral instance. * * This function is used for getting the base-address of the peripheral * instance. This function will be called inside the @ CSL_uartOpen() * function call. * * Note: This function is open for re-implementing if the user wants to modify * the base address of the peripheral object to point to a different * location and there by allow CSL initiated write/reads into peripheral * MMR's go to an alternate location. Please refer the documentation for * more details. * * @b Example: * @verbatim CSL_Status status; CSL_UartBaseAddress baseAddress; ... status = CSL_uartGetBaseAddress(CSL_UART_1, NULL, &baseAddress); @endverbatim * * @return Returns the status of the operation (see @a CSL_Status) * */CSL_Status CSL_uartGetBaseAddress( /** Instance number */ CSL_InstNum uartNum, /** Module specific parameters */ CSL_UartParam * pUartParam, /** Base address details */ CSL_UartBaseAddress * pBaseAddress);/**@}*//** @brief Function to configure the UART Hardware. * * This function is used for raw configuration of the UART hardware. The * register values are specifed by the 'config' parameter. * * @b Example: * @verbatim CSL_Status status; CSL_UartConfig uartConfig; ... uartConfig->DLH = 0x12; ... status = CSL_uartHwSetupRaw(hUart, &uartConfig); * * @return Returns CSL_SOK */
CSL_Status CSL_uartHwSetupRaw (
/** Pointer to the object that holds reference to the
* instance of uart requested after the call
*/
CSL_UartHandle hUart,
/** Pointer to setup structure which contains the
* information to program UART to a useful state
*/
CSL_UartConfig * config
);/**@defgroup EXAMPLE Example Usage in an ISR@ingroup CSL_UART_API@{In order to clarify on the usage of some of the CSL APIs, a skeleton is presented below \nExample: Interrupt driven Low level Driver\nMain routine\nVoid main(){\n CSL_UartHwSetup hwSetup = CSL_UART_HWSETUP_DEFAULTS;\n CSL_UartObj UARTObj,\n CSL_UartNum uartNum,\n CSL_OpenMode openMode,\n CSL_Status stat;\n// Initialize system before making any module calls specific calls \nIf (CSL_sysInit() == CSL_SOK){\n CSL_uartInit();\n}\n// Open the Module with default configuration for setup \n// Interrupts enabled include CSL_UART_EVENT_RHR,CSL_UART_EVENT_RHR,CSL_UART_EVENT_LINESTS,\nCSL_UART_EVENT_MODEMSTShUart = CSL_uartOpen(&UARTObj,CSL_UART_0,CSL_EXCLUSIVE,&hwSetup,&stat);\nif (hUart == NULL)\n exit;\n} // End of Main \nInterrupt Service Routine\n---------------------------\nIsr_enter{\nCSL_UartIntrSource intrSource;\nUin16 status;\nCSL_BitMask16 suppStatus;\n CSL_uartGetHwStatus(hUart, CSL_UART_QUERY_EVENTS,&intrSource);\n Switch (intrSource) {\n Case CSL_UART_INTRSOURCE_NONE: \n // Check if it is the wakeup interrupt\n CSL_uartGetHwStatus(hUart,CSL_UART_QUERY_SUPPSTATUS ,&status);\n If (status & CSL_UART_SUPPSTATUS_RCD_WAKE_UP)\n WakeupFxn(); // Call appropriate fxn for the wakeup Event\n Case CSL_UART_INTRSOURCE_LINESTS: \n // Read LineStatus Register \n CSL_uartGetHwStatus(hUart,CSL_UART_QUERY_LINESTATUS,&suppStatus);\n Case CSL_UART_INTRSOURCE_RHR :\n }\n} // ISR Exit \n@}*/#ifdef __cplusplus}#endif#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?