初始化各路串口
- void all_usart_init () {
- PORT_DebugPortSetting(TDI,Disable);
- int len = sizeof(usart) / sizeof(usart[0]);
- for ( int i = 0 ; i < len ; i++) {
- new_usart_init(&usart[i]);
- }
- }
-
- void new_usart_init(Usart *u){
-
- stc_irq_regi_conf_t stcIrqRegiCfg;
- const stc_usart_uart_init_t stcInitCfg = {
- UsartIntClkCkNoOutput,
- u->clk,
- UsartDataBits8,
- UsartDataLsbFirst,
- UsartOneStopBit,
- u->usart_type,
- UsartSampleBit8,
- UsartStartBitFallEdge,
- UsartRtsEnable,
- };
-
- PORT_SetFunc(u->Rx_Port, u->Rx_Pin, u->USART_RX_FUNC, Disable);
- PORT_SetFunc(u->Tx_Port, u->Tx_Pin, u->USART_TX_FUNC, Disable);
-
- USART_UART_Init(u->usart_ch, &stcInitCfg);
-
- USART_SetBaudrate(u->usart_ch, u->BAUDRATE);
-
- stcIrqRegiCfg.enIRQn = u->Rx_IRQn;
- stcIrqRegiCfg.pfnCallback = usart_common_call;
- stcIrqRegiCfg.enIntSrc = u->INT_USART_RI ;
- enIrqRegistration(&stcIrqRegiCfg);
- NVIC_SetPriority(stcIrqRegiCfg.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
- NVIC_ClearPendingIRQ(stcIrqRegiCfg.enIRQn);
- NVIC_EnableIRQ(stcIrqRegiCfg.enIRQn);
-
- stcIrqRegiCfg.enIRQn =u->Tx_IRQn;
- stcIrqRegiCfg.pfnCallback = usart_common_err_call;
- stcIrqRegiCfg.enIntSrc = u->INT_USART_EI;
- enIrqRegistration(&stcIrqRegiCfg);
- NVIC_SetPriority(stcIrqRegiCfg.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
- NVIC_ClearPendingIRQ(stcIrqRegiCfg.enIRQn);
- NVIC_EnableIRQ(stcIrqRegiCfg.enIRQn);
-
- USART_FuncCmd(u->usart_ch, UsartRx, Enable);
- USART_FuncCmd(u->usart_ch, UsartRxInt, Enable);
- USART_FuncCmd(u->usart_ch, UsartTx, Enable);
- }
|