📄 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 : ODi 06/26/2002
//*
//*----------------------------------------------------------------------------
#include <stdio.h>
#include "main.h"
#include "lib_arm920t.h"
AT91S_SVC_USBCTL usbEp0;
AT91S_SVC_USBIN usbEpIn;
AT91S_SVC_USBOUT usbEpOut;
AT91S_SVC_USBIN usbEpInt;
extern volatile unsigned char currentConfiguration;
extern volatile unsigned char currentConnection;
//*----------------------------------------------------------------------------
//* \fn AT91F_EnableICache
//* \brief Enable I Cache
//*----------------------------------------------------------------------------
void AT91F_EnableICache()
{
unsigned int ctl;
ctl = AT91F_ARM_ReadControl();
ctl |= (1 << 12);
AT91F_ARM_WriteControl(ctl);
}
//*----------------------------------------------------------------------------
//* \fn AT91F_InitDrivers
//* \brief This function initialize USART 1, the AIC and AT91S_SVC_USDRIVER driver
//*----------------------------------------------------------------------------
void AT91F_InitDrivers()
{
// ============================= Init USB driver =============================
// Configure PMC
AT91F_UDP_CfgPMC(); // Enable UDP peripheral
AT91C_BASE_PMC->PMC_SCER |= AT91C_PMC_UDP; // Enable 48 MHz
// Open DMA service for each endpoint
AT91F_SVC_USBCTL_Open(&usbEp0, AT91C_BASE_UDP);
usbEp0.DisptachSetup = AT91F_USB_DispatchRequest;
AT91F_SVC_USBIN_Open(&usbEpIn, AT91C_BASE_UDP, 2, 0x40, 2);
AT91F_SVC_USBOUT_Open(&usbEpOut, AT91C_BASE_UDP, 1, 0x40, 2);
AT91F_SVC_USBIN_Open(&usbEpInt, AT91C_BASE_UDP, 3, 8, 1);
// Configure AIC controller to handle USB interrupts
AT91F_AIC_ConfigureIt (
AT91C_BASE_AIC, // AIC base address
AT91C_ID_UDP, // System peripheral ID
AT91C_AIC_PRIOR_HIGHEST, // Max priority
AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, // Level sensitive
AT91F_ASM_UDP_Handler );
// Enable Udp interrupt in AIC
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_UDP);
// Enable UDP pullUp (PIOA10 on AT91RM3400DK)
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, AT91C_PIO_PA10);
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, AT91C_PIO_PA10);
}
#define BUFFER_SIZE 1024
char pBuffer[BUFFER_SIZE];
volatile char flgUsbOpAchieved;
void usbReceiveCallBack(AT91PS_SVC_USBOUT pUsbOut)
{
flgUsbOpAchieved = 1;
}
void usbSentCallBack(AT91PS_SVC_USBIN pUsbIn)
{
flgUsbOpAchieved = 1;
}
int main()
{
unsigned int messageSize, messageId = 0;
// Init USART 1 console driver
AT91F_InitDrivers();
AT91F_EnableICache();
AT91F_PIO_CfgOutput(AT91C_BASE_PIOC, (1 << 15) | (1 << 14));
printf("\n\n\r-I- ======================================\n\r-I- AT91RM9200 basic USB example\n\r-I- --------------------------------------\n\r-I- Please connect the board...\n\r-I- ======================================\n\r");
// Wait for a SET_CONFIGURATION
while (currentConfiguration != 1);
// Wait for an acknowledged connection
while (currentConnection != 3);
// Send a welcome message...
flgUsbOpAchieved = 0;
usbEpIn.Write(&usbEpIn,
"\n\n\r-I- USB serial emulation is active, all characters sent will be echo-ed\n\r",
77, usbSentCallBack);
while(!flgUsbOpAchieved);
// Main loop
while (1) {
flgUsbOpAchieved = 0;
usbEpOut.Read(&usbEpOut, pBuffer, BUFFER_SIZE, usbReceiveCallBack);
while(!flgUsbOpAchieved);
messageSize = BUFFER_SIZE - usbEpOut.bufferSize;
printf("-I- (%d) Message received: %d\n\r", messageId, messageSize);
flgUsbOpAchieved = 0;
usbEpIn.Write(&usbEpIn, pBuffer, messageSize, usbSentCallBack);
while(!flgUsbOpAchieved);
printf("-I- (%d) Message sent: %d\n\r", messageId, messageSize);
++messageId;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -