// +FHDR -----------------------------------------------------------------------
// Copyright (c) 2014, Beijing Hongsi Electronic Technology Co., Ltd.
// HSEC Confidential Proprietary
// 2014/05/08
//
// HSEC is a trademark of Beijing Hongsi Electronic Technology Co., Ltd.
// -----------------------------------------------------------------------------
// File Name: uart.c
// Type: C Language
//
// -----------------------------------------------------------------------------
// Description:
// This is a sample for uart operations
//
// -----------------------------------------------------------------------------
// Background Description:
//
// -----------------------------------------------------------------------------
// Revision History
// DATE AUTHOR DESCRIPTION
// 2014/05/08 V1.0
// -FHDR -----------------------------------------------------------------------
// ---------------------------------------------------------------------
// Include File Declarations
// ---------------------------------------------------------------------
#include "HSC32K1_CGM.h"
#include "HSC32K1_Registers.h"
#include "types.h"
#include "uart.h"
#include
//#include "cgm.h"
#define __va_start(parm) (__std(va_list)) ((char *)&parm + (sizeof(parm) + (1U) & ~(1U))) /* mm 9708027 */
#define va_start(ap, parm) ap = __va_start(parm)
#define va_end(ap)
#define va_copy(dest, src) dest = src /* mm 980824 */
#define Print_jeffasd(_x_) printf _x_ printf("\r\n");
#define printf sio_printf
#define NULL 0
typedef char * va_list;
int sio_printf(const char *fmt,...);
/*
void UART_Init(void)
{
//enable USI (UART) clock
MCGCR |= USI1_ON;
// UART参数配置
USI1_BR = 0x0027; // 设置波特率为38400 (24M系统时钟下)
USI1_CR = 0x1c00; // 8bit 清空fifo 常规模式接收/发送 数据位8无奇偶校验
USI1_CR |= 0x0010; // 使能接收器 !RAM接收不定长数据,详见数据手册RAM接收相关章节
// UART中断配置
USI1_IER |= 0x30; //TC中断使能,RC中断使能;
MCGCR &= (~USI1_ON);
}
*/
void UART_Init(void)
{
MCGCR |= USI1_ON;
// UART参数配置
USI1_BR = 0x0027; // 设置波特率为38400 (24M系统时钟下)
USI1_CR = 0x1c20; // 8bit 清空fifo 常规模式接收/发送 数据位8无奇偶校验
USI1_CR |= 1<<4;//使能 发送
// UART中断配置
USI1_IER |= 0x00; //;
MCGCR &= (~USI1_ON);
}
void UART_USI3_Init(void)
{
MCGCR |= USI3_ON;
// UART参数配置
USI3_BR = 0x0027; // 设置波特率为38400 (24M系统时钟下)
USI3_CR = 0x1c20; // 8bit 清空fifo 常规模式接收/发送 数据位8无奇偶校验
USI3_CR |= 1<<4;//使能 发送
// UART中断配置
USI3_IER |= 0x00; //;
MCGCR &= (~USI3_ON);
}
void UART_FIFO_Transmit(char cValue)
{
//enable USI (UART) clock
USI1_SR|=1<<4;//TC写1 清零
MCGCR |= USI1_ON;
while((USI1_SR&(1<<1))==0);//发送满,一直等待
USI1_DRL = cValue;
while((USI1_SR&(1<<4))==0);//发送未完成,一直等待 0
USI1_SR|=1<<4;//TC写1 清零
}
void TERMIO_PutChar(char cValue)
{
//enable USI (UART) clock
USI1_SR|=1<<4;//TC写1 清零
MCGCR |= USI1_ON;
while((USI1_SR&(1<<1))==0);//发送满,一直等待
USI1_DRL = cValue;
while((USI1_SR&(1<<4))==0);//发送未完成,一直等待 0
USI1_SR|=1<<4;//TC写1 清零
}
void TERMIO_PutChar_USI3(char cValue)
{
//enable USI (UART) clock
USI3_SR|=1<<4;//TC写1 清零
MCGCR |= USI3_ON;
while((USI3_SR&(1<<1))==0);//发送满,一直等待
USI3_DRL = cValue;
while((USI3_SR&(1<<4))==0);//发送未完成,一直等待 0
USI3_SR|=1<<4;//TC写1 清零
}
void UART_RAM_Transmit(U16 addr, U16 len)
{
//enable USI (UART) clock
MCGCR |= USI1_ON;
USI1_RADDR = addr;
USI1_RLENR = len;
USI1_SR |= 0x0010;
USI1_CR |= 0x0040; //RAM缓存发送 ;
USI1_CR |= 0x0080; //RAM启动;
//not wait for the completion of the transmitting
//it will be processed in interrupt service
}
void UART_RAM_Receive(U16 addr, U16 len)
{
//enable USI (UART) clock to ensure it works
MCGCR |= USI1_ON;
USI1_RADDR = addr;
USI1_RLENR = len;
USI1_CR &= (~0x0040); //RAM缓存接收 ;
USI1_CR |= 0x0080; //RAM启动;
//not wait for the completion of the receiving
//it will be processed in interrupt service
}
void HAL_UART_PrintStr(char *pszMsg)
{
if(pszMsg == NULL)
{
return;
}
while(pszMsg[0] != NULL)
{
// TERMIO_PutChar(pszMsg[0]);//串口1
TERMIO_PutChar_USI3(pszMsg[0]);//串口3
pszMsg++;
}
}
static void putLine(void)
{
sio_printf("\r\n");
}
int sio_printf(const char *fmt,...)
{
char __printf_buf[128];
va_list args;
int i;
//if(donot_print)
//return 0;
va_start(args, fmt);
i=3;
vsprintf(__printf_buf,fmt,args);
va_end(args);
HAL_UART_PrintStr(__printf_buf);
return i;
}
阅读(1437) | 评论(0) | 转发(0) |