SY883x_For_Client_JLAB_JS07/UsrSrc/uart/uart.c

151 lines
3.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
******************************************************************************
*
* @file uart.c
* @brief uart module
*
*
* @version 1.0
* @date 2022/12/14 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 2022/12/14 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"
#if UART0_ENABLE
/******************************************************************************\
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
idata uint8_t RX0_Buffer[COM0_Data_Lenth] = 0; //接收缓冲
bit Uart0_RX_Finish_Flag = 0;
#endif
#ifdef _DEBUG_ALL
void Uart0SendData(uint8_t Txdata)
{
while(busy0);
ACC = Txdata;
if (P) //根据P来设置校验位
{
#if (PARITYBIT == ODD_PARITY)
TB80 = 0; //设置校验位为0
#elif (PARITYBIT == EVEN_PARITY)
TB80 = 1; //设置校验位为1
#endif
}
else
{
#if (PARITYBIT == ODD_PARITY)
TB80 = 1; //设置校验位为1
#elif (PARITYBIT == EVEN_PARITY)
TB80 = 0; //设置校验位为0
#endif
}
busy0 = 1;
S0BUF = ACC;
}
char putchar(char c)
{
#if 0
while(!TI0);
TI0 = 0;
return (S0BUF = c);
#else
Uart0SendData(c);
return(c);
#endif
}
#endif
/*
*******************************************************************************
* void Uart0SendPacket(uint8_t Length,uint8_t *TransBuf)
*
* Description : UART0 Send Packet
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
#ifdef VOX_TX
void Uart0SendPacket(uint8_t Length,uint8_t *TransBuf)
{
uint8_t i = 0;
for(i=0;i<Length;i++)
//while( Length-- )
{
while(busy0);
ACC = *TransBuf++;
busy0 = 1;
S0BUF = ACC;
}
}
#endif
#if 1
#define Vox_Comm_Data_Len 5
#define Vox_R_W_FLAG 4
/*uart0中断处理函数*/
void uart0_Interrupt(void) interrupt Interrupt_Vector_RI_TI
{
// uint16_t CrcCheckSum = 0;
/*处理UART0发送中断*/
if(TI0)
{
TI0 = 0;
busy0 = 0;
}
/*处理UART0接收中断透传开关功能协议监听。*/
if(RI0)
{
RI0 = 0;
}
}
#endif
#endif