📄 sio_drv.c
字号:
/******************************************************************************
** File Name: sio_drv.c *
** Author: Xueliang.Wang *
** DATE: 11/10/2005 *
** Copyright: 2005 Spreatrum, Incoporated. All Rights Reserved. *
** Description: *
******************************************************************************
******************************************************************************
** Edit History *
** ------------------------------------------------------------------------- *
** DATE NAME DESCRIPTION *
** 11/10/2005 Xueliang.Wang Create. *
******************************************************************************/
#ifndef _SIO_DRV_C
#define _SIO_DRV_C
/**---------------------------------------------------------------------------*
** Dependencies *
**---------------------------------------------------------------------------*/
#include "sio_drv.h"
#include "arm_reg.h"
#include "sc6600d_reg.h"
/**---------------------------------------------------------------------------*
** Compiler Flag *
**---------------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C"
{
#endif
/**---------------------------------------------------------------------------*
** Global Variables *
**---------------------------------------------------------------------------*/
/**---------------------------------------------------------------------------*
** Local Function Prototypes *
**---------------------------------------------------------------------------*/
/**---------------------------------------------------------------------------*
** Function Definitions *
**---------------------------------------------------------------------------*/
/*****************************************************************************/
// Description: The function initialize sio.
// Global resource dependence:
// Author: Xueliang.Wang
// Note:
/*****************************************************************************/
PUBLIC BOOLEAN SIO_Init( //
UART_PORT_E com_id //
)
{
arm_uart_s * arm_uart_ptr;
if (COM0 == com_id)
{
*(volatile uint32 *)GR_GEN2 &= ~(BIT_8 | BIT_9);
*(volatile uint32 *)GR_GEN1 |= BIT_22;
arm_uart_ptr = (arm_uart_s *)ARM_UART0_BASE;
}
else if (COM1 == com_id)
{
*(volatile uint32 *)GR_GEN2 &= ~(BIT_10 | BIT_11 | BIT_14);
*(volatile uint32 *)GR_GEN1 |= BIT_23;
arm_uart_ptr = (arm_uart_s *)ARM_UART1_BASE;
}
else
{
return FALSE;
}
arm_uart_ptr->ie = 0;
arm_uart_ptr->ctl0 = 0x1C; //0b00011100
arm_uart_ptr->ctl1 = 0;
arm_uart_ptr->clkd0 = 0x71;
arm_uart_ptr->clkd1 = 0x00;
return TRUE;
}
/*****************************************************************************/
// Description: The function get a char from sio.
// Global resource dependence:
// Author: Xueliang.Wang
// Note:
/*****************************************************************************/
PUBLIC char SIO_GetChar( //
UART_PORT_E com_id //
)
{
arm_uart_s * arm_uart_ptr;
if (COM0 == com_id)
{
arm_uart_ptr = (arm_uart_s *)ARM_UART0_BASE;
}
else if (COM1 == com_id)
{
arm_uart_ptr = (arm_uart_s *)ARM_UART1_BASE;
}
else
{
return 0;
}
//If receive fifo is empty, waiting.
while((arm_uart_ptr->sts1 & 0xFF) == 0);
return ((char)arm_uart_ptr->rxd);
}
/*****************************************************************************/
// Description: The function output a char to sio.
// Global resource dependence:
// Author: Xueliang.Wang
// Note:
/*****************************************************************************/
PUBLIC void SIO_PutChar( //
UART_PORT_E com_id, //
char c //
)
{
arm_uart_s * arm_uart_ptr;
if (COM0 == com_id)
{
arm_uart_ptr = (arm_uart_s *)ARM_UART0_BASE;
}
else if (COM1 == com_id)
{
arm_uart_ptr = (arm_uart_s *)ARM_UART1_BASE;
}
else
{
return ;
}
//If the transfer fifo is nearly full, waiting.
while(((arm_uart_ptr->sts1 & 0xFF00) >> 8) > 126);
arm_uart_ptr->txd = (uint32)c;
}
/*****************************************************************************/
// Description: The function output a string to sio.
// Global resource dependence:
// Author: Xueliang.Wang
// Note:
/*****************************************************************************/
PUBLIC void SIO_PutChars( //
UART_PORT_E com_id, //
const char * str_buf, //
uint32 str_len //
)
{
uint32 i;
for (i = 0; i < str_len; i++)
{
SIO_PutChar(com_id, *(str_buf+i));
}
}
/**---------------------------------------------------------------------------*
** Compiler Flag *
**---------------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif // _SIO_DRV_C
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -