SY883x_For_Clients_langxun-J8/UsrSrc/uart/uart.c

302 lines
5.4 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;
idata uint8_t RX0_Buffer[COM0_Data_Lenth] = 0; //½ÓÊÕ»º³å
bit Uart0_RX_Finish_Flag = 0;
#endif
#ifdef _DEBUG_ALL
char putchar(char c)
{
while(!TI0);
TI0 = 0;
return (S0BUF = c);
}
#endif
#if UART0_ENABLE
/*
*******************************************************************************
* 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(busy0);
ACC = *TransBuf++;
busy0 = 1;
S0BUF = ACC;
}
}
#endif
#endif
#if UART0_ENABLE
#ifdef VOX_RX
/*
*******************************************************************************
* void HandleRxCommand(ACK_TYPE_E RxCommand)
*
* Description : ¶ú»ú¶Ë·¢Ë͵ÄÊý¾Ý°üµÄ½âÎö¼°´¦Àí
* Ack payload:
* Header checksum side cmd len Data
* 1bytes 1byte 1byte 1byte 1byte Len bytes
*
* Arguments : ACK_TYPE_E RxCommand:
* Returns :
*
* Notes :
*
*******************************************************************************
*/
void HandleRxMsg(VOX_FAC_COMMAND_E RxCommand)
{
uint8_t i = 0;
switch(RxCommand)
{
case CMD_FAC_START:
break;
case CMD_FAC_HALL:
break;
case CMD_FAC_GUAGE:
break;
case CMD_FAC_LED:
break;
case CMD_FAC_SHUTDOWN:
break;
case CMD_FAC_GET_DAUGE:
break;
case CMD_FAC_GET_NTC:
break;
case CMD_FAC_GET_FWVER:
break;
case CMD_FAC_SET_VOX_5V:
break;
default:
break;
}
}
/*
*******************************************************************************
* void HandleVoxCommMsg(void)
*
* Description : Vox ͨѶ¹¦ÄÜ´¦Àíº¯Êý£¬100ms¶¨Ê±µ÷Óá£ÓÉÓںͶú»úͨÐÅǰÐèÒª´ò¿ª¶ú»ú¶ËµÄTRX¹¦ÄÜ£¬²¢ÇÒÿ´ÎͨÐÅÖ»ÄÜÒ»Ö»¶ú»ú¡£Í¨¹ýÇл»VOL/VORͨÐÅ¿ª¹Ø½øÐÐͨÐÅ
*
* Arguments : NONE
* Returns : NONE
* Notes : NONE
*
*******************************************************************************
*/
void HandleVoxCommMsg(void)
{
uint8_t CrcCheckSum = 0;
uint8_t i = 0;
/*RXÊý¾Ý´¦Àí*/
if( Uart0_RX_Finish_Flag )
{
Uart0_RX_Finish_Flag = 0;
if( CrcCheckSum == RX0_Buffer[1] )
{
HandleRxMsg((VOX_FAC_COMMAND_E)RX0_Buffer[2]);
}
else
{
return;
}
}
}
#endif
#define Vox_Comm_Data_Len 5
#define Vox_R_W_FLAG 4
/*uart0Öжϴ¦Àíº¯Êý*/
void uart0_Interrupt(void) interrupt Interrupt_Vector_RI_TI
{
#ifdef VOX_RX
static uint8_t Rx0Status;
static uint8_t RX0_Cnt;
static uint8_t RX0DataLen;
#endif
/*´¦ÀíUART0·¢ËÍÖжÏ*/
if(TI0)
{
TI0 = 0;
busy0 = 0;
}
/*´¦ÀíUART0½ÓÊÕÖжÏ*/
if(RI0)
{
RI0 = 0;
#if SLEEP_ENABLE
Enter_Sleep_Cnt_Restart_Flag = 1;
#endif
#ifdef VOX_RX
switch(Rx0Status)
{
case 0:
if( S0BUF == 0x04 )
{
Rx0Status = 1;
RX0_Buffer[0] = S0BUF;
}
else
{
Rx0Status = 0;
RX0_Cnt = 0;
}
break;
case 1:
if( S0BUF == 0xFB )
{
Rx0Status = 2;
RX0_Cnt = 1;
RX0_Buffer[RX0_Cnt] = S0BUF;
RX0_Cnt++;
}
else
{
Rx0Status = 0;
RX0_Cnt = 0;
}
break;
case 2:
RX0_Buffer[RX0_Cnt] = S0BUF;
RX0_Cnt++;
if( (RX0_Buffer[3] == 1) || (RX0_Buffer[4] == 0) ) //¶Á²Ù×÷»òдÊý¾Ý³¤¶ÈΪ0£¬Ôò²»´ø4×Ö½ÚCRCУÑéºÍ
{
RX0_Cnt = 0;
Rx0Status = 0;
Uart0_RX_Finish_Flag = 1;
break;
}
if( RX0_Cnt == Vox_Comm_Data_Len )
{
RX0DataLen = RX0_Buffer[4] + 9; //»ñÈ¡Êý¾Ý³¤¶È:Header(2Bytes) + CMD(1Bytes) + W Flag(1Bytes) + Datalen(1Bytes) + Data + CRC(4Bytes)
}
if( (RX0DataLen == RX0_Cnt) || (RX0_Cnt > COM0_Data_Lenth) ) //µ±½ÓÊÕµ½µÄdata¸öÊýµÈÓÚRX0DataLen£¬Õâ½áÊø±¾´Î´«Êä¡£
{
RX0_Cnt = 0;
Rx0Status = 0;
Uart0_RX_Finish_Flag = 1;
}
}
#endif
}
}
#endif