mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
366 lines
14 KiB
C
366 lines
14 KiB
C
/*********************************************************************************************************************
|
||
* COPYRIGHT NOTICE
|
||
* Copyright (c) 2020,<2C><><EFBFBD>ɿƼ<C9BF>
|
||
* All rights reserved.
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>QQȺ<51><C8BA><EFBFBD><EFBFBD>Ⱥ<EFBFBD><C8BA>824575535
|
||
*
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD>У<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>;<EFBFBD><CDBE>
|
||
* <20><>ӭ<EFBFBD><D3AD>λʹ<CEBB>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>뱣<EFBFBD><EBB1A3><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC>İ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*
|
||
* @file uart
|
||
* @company <09>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD><EFBFBD>˾
|
||
* @author <09><><EFBFBD>ɿƼ<C9BF>(QQ3184284598)
|
||
* @version <09>鿴doc<6F><63>version<6F>ļ<EFBFBD> <20>汾˵<E6B1BE><CBB5>
|
||
* @Software ADS v1.2.2
|
||
* @Target core TC264D
|
||
* @Taobao https://seekfree.taobao.com/
|
||
* @date 2020-3-23
|
||
********************************************************************************************************************/
|
||
|
||
|
||
#include "IFXPORT.h"
|
||
#include "stdio.h"
|
||
#include "ifxAsclin_reg.h"
|
||
#include "ifxCpu_Irq.h"
|
||
#include "IFXASCLIN_CFG.h"
|
||
#include "SysSe/Bsp/Bsp.h"
|
||
#include "zf_assert.h"
|
||
#include "isr_config.h"
|
||
#include "TC264_config.h"
|
||
#include "zf_uart.h"
|
||
|
||
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>handle<6C><65><EFBFBD><EFBFBD>
|
||
IfxAsclin_Asc uart0_handle;
|
||
IfxAsclin_Asc uart1_handle;
|
||
IfxAsclin_Asc uart2_handle;
|
||
IfxAsclin_Asc uart3_handle;
|
||
|
||
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ascConfig<69>Ľṹ<C4BD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>ڳ<EFBFBD>ʼ<EFBFBD><CABC>ʱֻ<CAB1><D6BB>
|
||
static IfxAsclin_Asc_Config uart_config;
|
||
|
||
|
||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
static uint8 uart0_tx_buffer[UART0_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
|
||
static uint8 uart0_rx_buffer[UART0_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
|
||
|
||
static uint8 uart1_tx_buffer[UART1_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
|
||
static uint8 uart1_rx_buffer[UART1_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
|
||
|
||
static uint8 uart2_tx_buffer[UART2_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
|
||
static uint8 uart2_rx_buffer[UART2_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
|
||
|
||
static uint8 uart3_tx_buffer[UART3_TX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
|
||
static uint8 uart3_rx_buffer[UART3_RX_BUFFER_SIZE + sizeof(Ifx_Fifo) + 8];
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
void uart_set_interrupt_priority(UARTN_enum uartn)
|
||
{
|
||
switch(uartn)
|
||
{
|
||
case UART_0:
|
||
{
|
||
uart_config.interrupt.txPriority = UART0_TX_INT_PRIO;
|
||
uart_config.interrupt.rxPriority = UART0_RX_INT_PRIO;
|
||
uart_config.interrupt.erPriority = UART0_ER_INT_PRIO;
|
||
uart_config.interrupt.typeOfService = UART0_INT_SERVICE;
|
||
}break;
|
||
case UART_1:
|
||
{
|
||
uart_config.interrupt.txPriority = UART1_TX_INT_PRIO;
|
||
uart_config.interrupt.rxPriority = UART1_RX_INT_PRIO;
|
||
uart_config.interrupt.erPriority = UART1_ER_INT_PRIO;
|
||
uart_config.interrupt.typeOfService = UART1_INT_SERVICE;
|
||
}break;
|
||
case UART_2:
|
||
{
|
||
uart_config.interrupt.txPriority = UART2_TX_INT_PRIO;
|
||
uart_config.interrupt.rxPriority = UART2_RX_INT_PRIO;
|
||
uart_config.interrupt.erPriority = UART2_ER_INT_PRIO;
|
||
uart_config.interrupt.typeOfService = UART2_INT_SERVICE;
|
||
}break;
|
||
case UART_3:
|
||
{
|
||
uart_config.interrupt.txPriority = UART3_TX_INT_PRIO;
|
||
uart_config.interrupt.rxPriority = UART3_RX_INT_PRIO;
|
||
uart_config.interrupt.erPriority = UART3_ER_INT_PRIO;
|
||
uart_config.interrupt.typeOfService = UART3_INT_SERVICE;
|
||
}break;
|
||
default: ZF_ASSERT(FALSE);
|
||
}
|
||
}
|
||
|
||
void uart_set_buffer(UARTN_enum uartn)
|
||
{
|
||
switch(uartn)
|
||
{
|
||
case UART_0:
|
||
{
|
||
uart_config.txBuffer = &uart0_tx_buffer;
|
||
uart_config.rxBuffer = &uart0_rx_buffer;
|
||
uart_config.txBufferSize = UART0_TX_BUFFER_SIZE;
|
||
uart_config.rxBufferSize = UART0_RX_BUFFER_SIZE;
|
||
}break;
|
||
case UART_1:
|
||
{
|
||
uart_config.txBuffer = &uart1_tx_buffer;
|
||
uart_config.rxBuffer = &uart1_rx_buffer;
|
||
uart_config.txBufferSize = UART1_TX_BUFFER_SIZE;
|
||
uart_config.rxBufferSize = UART1_RX_BUFFER_SIZE;
|
||
}break;
|
||
case UART_2:
|
||
{
|
||
uart_config.txBuffer = &uart2_tx_buffer;
|
||
uart_config.rxBuffer = &uart2_rx_buffer;
|
||
uart_config.txBufferSize = UART2_TX_BUFFER_SIZE;
|
||
uart_config.rxBufferSize = UART2_RX_BUFFER_SIZE;
|
||
}break;
|
||
case UART_3:
|
||
{
|
||
uart_config.txBuffer = &uart3_tx_buffer;
|
||
uart_config.rxBuffer = &uart3_rx_buffer;
|
||
uart_config.txBufferSize = UART3_TX_BUFFER_SIZE;
|
||
uart_config.rxBufferSize = UART3_RX_BUFFER_SIZE;
|
||
}break;
|
||
default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
|
||
}
|
||
}
|
||
|
||
|
||
IfxAsclin_Asc* uart_get_handle(UARTN_enum uartn)
|
||
{
|
||
switch(uartn)
|
||
{
|
||
case UART_0: return &uart0_handle;
|
||
case UART_1: return &uart1_handle;
|
||
case UART_2: return &uart2_handle;
|
||
case UART_3: return &uart3_handle;
|
||
default: IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
|
||
}
|
||
|
||
return NULL;
|
||
}
|
||
|
||
void uart_mux(UARTN_enum uartn, UART_PIN_enum tx_pin, UART_PIN_enum rx_pin, uint32 *set_tx_pin, uint32 *set_rx_pin)
|
||
{
|
||
switch(uartn)
|
||
{
|
||
case UART_0:
|
||
{
|
||
if (UART0_TX_P14_0 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin0_TX_P14_0_OUT;
|
||
else if(UART0_TX_P14_1 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin0_TX_P14_1_OUT;
|
||
else if(UART0_TX_P15_2 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin0_TX_P15_2_OUT;
|
||
else if(UART0_TX_P15_3 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin0_TX_P15_3_OUT;
|
||
else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
|
||
|
||
if (UART0_RX_P14_1 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin0_RXA_P14_1_IN;
|
||
else if(UART0_RX_P15_3 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin0_RXB_P15_3_IN;
|
||
else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
|
||
|
||
}break;
|
||
case UART_1:
|
||
{
|
||
if (UART1_TX_P02_2 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin1_TX_P02_2_OUT;
|
||
else if(UART1_TX_P11_12 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin1_TX_P11_12_OUT;
|
||
else if(UART1_TX_P14_10 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin1_TX_P14_10_OUT;
|
||
else if(UART1_TX_P15_0 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin1_TX_P15_0_OUT;
|
||
else if(UART1_TX_P15_1 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin1_TX_P15_1_OUT;
|
||
else if(UART1_TX_P15_4 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin1_TX_P15_4_OUT;
|
||
else if(UART1_TX_P15_5 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin1_TX_P15_5_OUT;
|
||
else if(UART1_TX_P20_10 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin1_TX_P20_10_OUT;
|
||
else if(UART1_TX_P33_12 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin1_TX_P33_12_OUT;
|
||
else if(UART1_TX_P33_13 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin1_TX_P33_13_OUT;
|
||
else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
|
||
|
||
if (UART1_RX_P15_1 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin1_RXA_P15_1_IN;
|
||
else if(UART1_RX_P15_5 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin1_RXB_P15_5_IN;
|
||
else if(UART1_RX_P20_9 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin1_RXC_P20_9_IN;
|
||
else if(UART1_RX_P14_8 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin1_RXD_P14_8_IN;
|
||
else if(UART1_RX_P11_10 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin1_RXE_P11_10_IN;
|
||
else if(UART1_RX_P33_13 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin1_RXF_P33_13_IN;
|
||
else if(UART1_RX_P02_3 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin1_RXG_P02_3_IN;
|
||
else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
|
||
|
||
}break;
|
||
case UART_2:
|
||
{
|
||
if (UART2_TX_P02_0 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin2_TX_P02_0_OUT;
|
||
else if(UART2_TX_P10_5 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin2_TX_P10_5_OUT;
|
||
else if(UART2_TX_P14_2 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin2_TX_P14_2_OUT;
|
||
else if(UART2_TX_P14_3 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin2_TX_P14_3_OUT;
|
||
else if(UART2_TX_P33_8 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin2_TX_P33_8_OUT;
|
||
else if(UART2_TX_P33_9 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin2_TX_P33_9_OUT;
|
||
else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
|
||
|
||
if (UART2_RX_P14_3 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin2_RXA_P14_3_IN;
|
||
else if(UART2_RX_P02_1 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin2_RXB_P02_1_IN;
|
||
else if(UART2_RX_P10_6 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin2_RXD_P10_6_IN;
|
||
else if(UART2_RX_P33_8 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin2_RXE_P33_8_IN;
|
||
else if(UART2_RX_P02_0 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin2_RXG_P02_0_IN;
|
||
|
||
else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
|
||
|
||
}break;
|
||
case UART_3:
|
||
{
|
||
if (UART3_TX_P00_0 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin3_TX_P00_0_OUT;
|
||
else if(UART3_TX_P00_1 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin3_TX_P00_1_OUT;
|
||
else if(UART3_TX_P15_6 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin3_TX_P15_6_OUT;
|
||
else if(UART3_TX_P15_7 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin3_TX_P15_7_OUT;
|
||
else if(UART3_TX_P20_0 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin3_TX_P20_0_OUT;
|
||
else if(UART3_TX_P20_3 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin3_TX_P20_3_OUT;
|
||
else if(UART3_TX_P21_7 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin3_TX_P21_7_OUT;
|
||
else if(UART3_TX_P32_2 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin3_TX_P32_2_OUT;
|
||
else if(UART3_TX_P32_3 == tx_pin) *set_tx_pin = (uint32)&IfxAsclin3_TX_P32_3_OUT;
|
||
else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
|
||
|
||
if (UART3_RX_P15_7 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin3_RXA_P15_7_IN;
|
||
else if(UART3_RX_P20_3 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin3_RXC_P20_3_IN;
|
||
else if(UART3_RX_P32_2 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin3_RXD_P32_2_IN;
|
||
else if(UART3_RX_P00_1 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin3_RXE_P00_1_IN;
|
||
else if(UART3_RX_P21_6 == rx_pin) *set_rx_pin = (uint32)&IfxAsclin3_RXF_P21_6_IN;
|
||
else IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
|
||
|
||
}break;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief <20><><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC>
|
||
// @param uartn <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>(UART_0,UART_1,UART_2,UART_3)
|
||
// @param baud <20><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
|
||
// @param tx_pin <20><><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @param rx_pin <20><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @return uint32 ʵ<>ʲ<EFBFBD><CAB2><EFBFBD><EFBFBD><EFBFBD>
|
||
// Sample usage: uart_init(UART_0,115200,UART0_TX_P14_0,UART0_RX_P14_1); // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>115200 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>P14_0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>P14_1
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void uart_init(UARTN_enum uartn, uint32 baud, UART_PIN_enum tx_pin, UART_PIN_enum rx_pin)
|
||
{
|
||
boolean interrupt_state = disableInterrupts();
|
||
|
||
volatile Ifx_ASCLIN *moudle = IfxAsclin_getAddress((IfxAsclin_Index)uartn);
|
||
|
||
IfxAsclin_Asc_initModuleConfig(&uart_config, moudle); //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ýṹ<C3BD><E1B9B9>
|
||
|
||
uart_set_buffer(uartn);//<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||
uart_set_interrupt_priority(uartn);//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>
|
||
|
||
uart_config.baudrate.prescaler = 4;
|
||
uart_config.baudrate.baudrate = (float32)baud;
|
||
uart_config.baudrate.oversampling = IfxAsclin_OversamplingFactor_8;
|
||
|
||
IfxAsclin_Asc_Pins pins;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
pins.cts = NULL;
|
||
pins.rts = NULL;
|
||
uart_mux(uartn, tx_pin, rx_pin, (uint32 *)&pins.tx, (uint32 *)&pins.rx);
|
||
pins.rxMode = IfxPort_InputMode_pullUp;
|
||
pins.txMode = IfxPort_OutputMode_pushPull;
|
||
pins.pinDriver = IfxPort_PadDriver_cmosAutomotiveSpeed1;
|
||
uart_config.pins = &pins;
|
||
|
||
IfxAsclin_Asc_initModule(uart_get_handle(uartn), &uart_config);
|
||
|
||
restoreInterrupts(interrupt_state);
|
||
}
|
||
|
||
|
||
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief <20><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @param uartn <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>(UART_0,UART_1,UART_2,UART_3)
|
||
// @param dat <20><>Ҫ<EFBFBD><D2AA><EFBFBD>͵<EFBFBD><CDB5>ֽ<EFBFBD>
|
||
// @return void
|
||
// Sample usage: uart_putchar(UART_0, 0xA5); // <20><><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>0xA5
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void uart_putchar(UARTN_enum uartn, uint8 dat)
|
||
{
|
||
// IfxAsclin_Asc_blockingWrite(uart_get_handle(uartn),dat);
|
||
Ifx_SizeT count = 1;
|
||
(void)IfxAsclin_Asc_write(uart_get_handle(uartn), &dat, &count, TIME_INFINITE);
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief <20><><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @param uartn <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>(UART_0,UART_1,UART_2,UART_3)
|
||
// @param *buff Ҫ<><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||
// @param len <20><><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD>
|
||
// @return void
|
||
// Sample usage: uart_putbuff(UART_0,&a[0],5);
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void uart_putbuff(UARTN_enum uartn, uint8 *buff, uint32 len)
|
||
{
|
||
while(len)
|
||
{
|
||
uart_putchar(uartn, *buff);
|
||
len--;
|
||
buff++;
|
||
}
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief <20><><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||
// @param uartn <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>(UART_0,UART_1,UART_2,UART_3)
|
||
// @param *str Ҫ<><D2AA><EFBFBD>͵<EFBFBD><CDB5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ַ
|
||
// @return void
|
||
// Sample usage: uart_putstr(UART_0,"i lvoe you");
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void uart_putstr(UARTN_enum uartn, const int8 *str)
|
||
{
|
||
while(*str)
|
||
{
|
||
uart_putchar(uartn, *str++);
|
||
}
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD>ڽ<EFBFBD><DABD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݣ<EFBFBD>whlie<69>ȴ<EFBFBD><C8B4><EFBFBD>
|
||
// @param uartn <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>(UART_0,UART_1,UART_2,UART_3)
|
||
// @param *dat <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĵ<DDB5>ַ
|
||
// @return void
|
||
// Sample usage: uint8 dat; uart_getchar(UART_0,&dat); // <20><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dat<61><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
void uart_getchar(UARTN_enum uartn, uint8 *dat)
|
||
{
|
||
while(!IfxAsclin_Asc_getReadCount(uart_get_handle(uartn)));
|
||
*dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uartn));
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD>ڽ<EFBFBD><DABD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD>գ<EFBFBD>
|
||
// @param uartn <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>(UART_0,UART_1,UART_2,UART_3)
|
||
// @param *dat <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĵ<DDB5>ַ
|
||
// @return uint8 1<><31><EFBFBD><EFBFBD><EFBFBD>ճɹ<D5B3> 0<><30>δ<EFBFBD><CEB4><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
|
||
// Sample usage: uint8 dat; uart_query(UART_0,&dat); // <20><><EFBFBD>մ<EFBFBD><D5B4><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dat<61><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
uint8 uart_query(UARTN_enum uartn, uint8 *dat)
|
||
{
|
||
if(IfxAsclin_Asc_getReadCount(uart_get_handle(uartn)) >0)
|
||
{
|
||
*dat = IfxAsclin_Asc_blockingRead(uart_get_handle(uartn));
|
||
return 1;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
// @brief <20>ض<EFBFBD><D8B6><EFBFBD>printf <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @param ch <20><>Ҫ<EFBFBD><D2AA>ӡ<EFBFBD><D3A1><EFBFBD>ֽ<EFBFBD>
|
||
// @param stream <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// @note <20>˺<EFBFBD><CBBA><EFBFBD><EFBFBD>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>printf<74><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
//-------------------------------------------------------------------------------------------------------------------
|
||
int fputc(int ch, FILE *stream)
|
||
{
|
||
uart_putchar(DEBUG_UART, (char)ch);
|
||
return(ch);
|
||
}
|
||
|