📄 init.c
字号:
//*----------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name : init.c
//* Object : Low level initialisations written in C
//* Creation : ODi 06/26/2002
//* Enable the seception JPP 03/jun/2003
//*----------------------------------------------------------------------------
#include "AT91RM9200.h"
//*----------------------------------------------------------------------------
//* Function Name : AT91F_DBGU_Get
//* Object : Get a string to USART manage Blackspace and echo
//* Input Parameters : com descriptor, type string & val return value
//* Output Parameters : none
//*----------------------------------------------------------------------------
unsigned int AT91F_DBGU_Get( char *val)
{
if ((AT91F_US_RxReady((AT91PS_USART)AT91C_BASE_DBGU)) == 0)
return (1);
else
{
*val= AT91F_US_GetChar((AT91PS_USART)AT91C_BASE_DBGU);
return (0);
}
}
//*----------------------------------------------------------------------------
//* Function Name : AT91F_DBGU_scanf
//* Object : Get a string to USART manage Blackspace and echo
//* Input Parameters : com descriptor, type string & val return value
//* Output Parameters : none
//*----------------------------------------------------------------------------
void AT91F_DBGU_scanf(char * type,unsigned int * val)
{//* Begin
unsigned int read = 0;
char buff[10];
unsigned int nb_read =0;
while( (read != 0x0D) & (nb_read != sizeof(buff)) ) {
//* wait the USART Ready for reception
while((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_RXRDY) == 0 ) ;
//* Get a char
read = AT91C_BASE_DBGU->DBGU_RHR ;
buff[nb_read]= (char)read;
//* Manage Blackspace
while((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXRDY) ==0) {}
if ((char)read == 0x08) {
if ( nb_read != 0 ) {
nb_read--;
AT91C_BASE_DBGU->DBGU_THR = read;
}
}
else {
//* echo
AT91C_BASE_DBGU->DBGU_THR = read;
nb_read++;
}
}
//* scan the value
sscanf(buff,type,val);
}//* End
//*----------------------------------------------------------------------------
//* \fn AT91F_DBGU_Printk
//* \brief This function is used to send a string through the DBGU channel (Very low level debugging)
//*----------------------------------------------------------------------------
void AT91F_DBGU_Printk(
char *buffer) // \arg pointer to a string ending by \0
{
while(*buffer != '\0') {
while (!AT91F_US_TxReady((AT91PS_USART)AT91C_BASE_DBGU));
AT91F_US_PutChar((AT91PS_USART)AT91C_BASE_DBGU, *buffer++);
}
}
//*----------------------------------------------------------------------------
//* \fn AT91F_LowLevelInit
//* \brief This function performs very low level HW initialization
//*----------------------------------------------------------------------------
void AT91F_LowLevelInit()
{
// Open PIO for DBGU
AT91F_DBGU_CfgPIO();
// Configure DBGU
AT91F_US_Configure (
(AT91PS_USART) AT91C_BASE_DBGU, // DBGU base address
18432000, // 48 MHz
AT91C_US_ASYNC_MODE , // mode Register to be programmed
115200, // baudrate to be programmed
0); // timeguard to be programmed
// Enable Transmitter and recivier
AT91F_US_EnableTx((AT91PS_USART) AT91C_BASE_DBGU);
AT91F_US_EnableRx((AT91PS_USART) AT91C_BASE_DBGU);
AT91F_DBGU_Printk("AT91F_LowLevelInit()\n\r");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -