📄 main.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 : main.c
//* Object : main application written in C
//* Creation : FB 21/11/2002
//* Modified by zzs : 20/6/2006
//*----------------------------------------------------------------------------
#include <stdio.h>
#define AT91RM9200
#include "embedded_services.h"
#include "lib_AT91RM9200.h"
#define UPLOAD_BUF_SIZE_IN_BYTES (1*1024*1024) /* Max Size of the downloaded file 1Mega*/
/* --- External Functions
* -----------------------------
*/
extern void AT91F_DBGU_Printk(char *);
extern void AT91F_ASM_ST_DBGU_Handler(void);
/* --- Allocation of the service structures
* ------------------------------------------
*/
/* "ROM Entry" Service*/
AT91S_RomBoot const *pAT91;
/* "SBuffer and Pipe" structures for "Xmodem" Service*/
AT91S_SBuffer sXmBuffer;
AT91S_Pipe xmodemPipe;
AT91S_SvcXmodem svcXmodem;
/* "Tempo" Service */
AT91S_CtlTempo ctlTempo;
/*
* --- Global Variables
* ------------------------------------------
*/
char* Buffer_Xmodem= ((char*)(0x20000000));
volatile unsigned int StTick; // system timer tick count for timeout
volatile char EndOfTransmission=0; // flag for end of xmodem
//*----------------------------------------------------------------------------
//* \fn AT91_XmodemComplete
//* \brief Allows to correctly complete xmodem end of transmission
//*----------------------------------------------------------------------------
void AT91_XmodemComplete(AT91S_PipeStatus status, void *pVoid)
{
/* stop the Xmodem tempo */
svcXmodem.tempo.Stop(&(svcXmodem.tempo));
/* upload complete */
EndOfTransmission = 1;
}
//*----------------------------------------------------------------------------
//* \fn AT91_XmodemProtocol
//* \brief Allows to correctly complete xmodem end of transmission
//*----------------------------------------------------------------------------
void AT91_XmodemProtocol(AT91S_PipeStatus status, void *pVoid)
{
svcXmodem.tempo.Start(&(svcXmodem.tempo), 10, 0, AT91_XmodemComplete, svcXmodem.pUsart);
}
/*
*=================================================================
* --- Interrupt handlers
*=================================================================
*/
//*----------------------------------------------------------------------------
//* \fn AT91F_ST_DBGU_Handler
//* \brief C Interrupt handler for Interrupt source 1
//*----------------------------------------------------------------------------
void AT91F_ST_DBGU_Handler(void)
{
/*get DeBuG Unit Channel Status Register*/
volatile unsigned int csr = AT91C_BASE_DBGU->DBGU_CSR;
/* ========== Systimer interrupt ============== */
if (AT91C_BASE_ST->ST_SR & AT91C_ST_PITS) {
StTick++;
ctlTempo.CtlTempoTick(&ctlTempo);
return;
}
/* ========== DBGU interrupt ============== */
if (csr & (AT91C_US_PARE | AT91C_US_FRAME | AT91C_US_OVRE | AT91C_US_RXBRK))
{
// Stop previous Xmodem transmission
AT91C_BASE_DBGU->DBGU_CR = AT91C_US_RSTSTA;
AT91C_BASE_DBGU->DBGU_IDR = AT91C_US_ENDRX;
AT91C_BASE_DBGU->DBGU_IER = AT91C_US_RXRDY | AT91C_US_COMM_RX;
} else if (csr & ((AT91C_US_TXRDY | AT91C_US_ENDTX | AT91C_US_TXEMPTY) |
(AT91C_US_RXRDY | AT91C_US_ENDRX | AT91C_US_TIMEOUT) |
AT91C_US_RXBUFF))
{
svcXmodem.Handler(&svcXmodem, csr);
}
}
//*----------------------------------------------------------------------------
//* \fn main
//* \brief main function
//*----------------------------------------------------------------------------
int main()
{
AT91PS_Buffer pXmBuffer;
AT91PS_SvcComm pSvcXmodem;
// while(1)
{
AT91F_DBGU_Printk("\n\n\r======================================================");
AT91F_DBGU_Printk ("\n\rAT91RM9200 Basic ROM Services BootLoader Test\n\r");
AT91F_DBGU_Printk ("======================================================\n\r");
}
/* Call Open methods */
pAT91 = AT91C_ROM_BOOT_ADDRESS;
/* --- Init of the service Tempo
* --------------------------------------
*/
/* Open Tempo service*/
pAT91->OpenCtlTempo(&ctlTempo, (void *) &(pAT91->SYSTIMER_DESC) );
ctlTempo.CtlTempoStart((void *) &(pAT91->SYSTIMER_DESC) );
/* --- Init of the service Xmodem
* ----------------------------------
*/
/* Open SBuffer structure */
pXmBuffer = pAT91->OpenSBuffer(&sXmBuffer);
/* Open Xmodem service */
pSvcXmodem = pAT91->OpenSvcXmodem(&svcXmodem,(AT91PS_USART) AT91C_BASE_DBGU, &ctlTempo);
/* Open Pipe structure */
pAT91->OpenPipe(&xmodemPipe, pSvcXmodem, pXmBuffer);
/* --- Init the Uploader
* -----------------------------
*/
/* Initialize the Interrupt Source 1 for SysTimer and DBGU */
AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, /*pointer to the AIC registers */
AT91C_ID_SYS, /*interrupt number to initialize */
AT91C_AIC_PRIOR_LOWEST, /*priority to give to the interrupt*/
AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, /*activation and sense of activation [doc1768.pdf 22.8.2 AIC Source Mode Register]*/
AT91F_ASM_ST_DBGU_Handler); /*address of the interrupt handler */
/* Enable SysTimer and DBGU interrupt */
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_SYS);
/* --- Enter the uploading by Xmodem -> Service Xmodem + Service Tempo used
* ----------------------------------------------------------------------------------
*/
AT91F_DBGU_Printk("\n\rSend the file to write to SDRAM by Xmodem:\n\r");
xmodemPipe.Read(&xmodemPipe, (char *) Buffer_Xmodem, UPLOAD_BUF_SIZE_IN_BYTES, AT91_XmodemProtocol,NULL);
while (EndOfTransmission != 1);
EndOfTransmission =0;
AT91F_DBGU_Printk("\n\rXmodem Transmission Completed !!!");
AT91F_DBGU_Printk("\n\rCode Written in SDRAM address 0x20000000");
AT91F_DBGU_Printk("\n\r----program halt-----\n\r");
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -