/* ****************************************************************************** * * @file uart.c * @brief uart module * @ic sy8837/8 * * @version 1.0 * @date 2024/11/01 15:00:40 * @author Alex Xu * * Copyright (c) 2013-2099,Tkplusemi Technology Co.,Ltd. * All Rights Reserved * * History: * Revision Date Author Desc * 1.0.0 2024/11/01 Alex build this file ******************************************************************************/ /*_____ I N C L U D E S ____________________________________________________*/ #include "uart.h" #include "system.h" #include "vox_module.h" #include "sleep.h" #include "vox_comm.h" /******************************************************************************\ Macro definitions \******************************************************************************/ #define NONE_PARITY 0 //无校验 #define ODD_PARITY 1 //奇校验 #define EVEN_PARITY 2 //偶校验 #define MARK_PARITY 3 //标记校验 #define SPACE_PARITY 4 //空白校验 #define PARITYBIT EVEN_PARITY //定义校验位 /******************************************************************************\ Variables definitions \******************************************************************************/ bit busy0; #ifdef VOX_RX #if 0 idata uint8_t RX0_Buffer[COM0_Data_Lenth] = 0; //接收缓冲 bit Uart0_RX_Finish_Flag = 0; #endif #if UART1_ENABLE idata uint8_t RX1_Buffer[COM1_Data_Lenth]; //接收缓冲 bit Uart1_RX_Finish_Flag; #endif #endif #ifdef _DEBUG_ALL char putchar(char c) { #if 0 while(!TI0); TI0 = 0; return (S0BUF = c); #else Uart0SendData(c); return(c); #endif } /* ******************************************************************************* * void Uart1SendData(uint8_t Txdata) * * Description : UART1 Send Data * * Arguments : NONE * Returns : NONE * Notes : NONE * ******************************************************************************* */ void Uart0SendData(uint8_t Txdata) { while(busy0); busy0 = 1; S0BUF = Txdata; } #endif #ifdef UART0_ENABLE /* ******************************************************************************* * void UART0_Init(void) * * Description : UART0 Initialization UART0用于debug、打印、透传功能 * * Arguments : NONE * Returns : NONE * Notes : NONE * ******************************************************************************* */ void UART0_Init(void) { SFRADDR = MFP_CTL0; //Set P01 As TX. SFRDATA &=~ 0x0C; SFRDATA |= 0x04; BD = 1; //Select additional Baudrate generator PCON |= 0x80; //Baudrate double enable //baudrate set S0RELH = HIBYTE(S0REL_VALUE); S0RELL = LOBYTE(S0REL_VALUE); //s0rel=1023, baudrate = fclk/32 = 187.5k S0CON = 0x52; //SCON: MODE 1, 8-bit UART, RI enable ES0 = 1; //Enable UART0 IRQ } /* ******************************************************************************* * void Uart0SendPacket(uint8_t Length,uint8_t *TransBuf) * * Description : UART0 Send Packet * * Arguments : NONE * Returns : NONE * Notes : NONE * ******************************************************************************* */ #if 0 void Uart0SendPacket(uint16_t Length,uint8_t *TransBuf) { uint8_t i = 0; for(i=0;i COM1_Data_Lenth) ) //当接收到的data个数等于RX0DataLen,这结束本次传输。 { RX1_Cnt = 0; Rx1Status = 0; Uart1_RX_Finish_Flag = TRUE; } } #else switch(Rx1Status) { case 0: if( S1BUF == EARPHONE_HEADER_HIGH ) { Rx1Status = 1; RX1_Cnt = 0; RX1_Buffer[RX1_Cnt++] = S1BUF; } else { Rx1Status = 0; RX1_Cnt = 0; } break; case 1: if( S1BUF == EARPHONE_HEADER_LOW ) { Rx1Status = 2; RX1_Buffer[RX1_Cnt++] = S1BUF; } else { Rx1Status = 0; RX1_Cnt = 0; } break; case 2: { RX1_Buffer[RX1_Cnt++] = S1BUF; #if JIELI if ( ( RX1_Cnt >= ( RX1_Buffer[2] + Vox_Comm_JL_HEADER_DATA_LEN ) ) || ( RX1_Cnt > COM1_Data_Lenth ) ) #elif ZHONGKE if ( ( RX1_Cnt >= ( RX1_Buffer[4] + Vox_Comm_ZK_HEADER_DATA_LEN ) ) || ( RX1_Cnt > COM1_Data_Lenth ) ) #endif { RX1_Cnt = 0; Rx1Status = 0; Uart1_RX_Finish_Flag = TRUE; } } break; default: break; } #endif #endif } } #endif