?? 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 : GGi
//*----------------------------------------------------------------------------
// Include Standard files
#include <stdio.h>
#include "board.h"
#include "AT91C_MCI_Device.h"
/* Global variables */
#define SPEED (AT91C_MASTER_CLOCK/1000/10)
unsigned int LedSpeed = SPEED *10 ;
const int led_mask[8]= {LED7, LED8, LED9, LED10};
#define FALSE -1
#define TRUE 1
#define AT91C_MCI_TIMEOUT 1000000 /* For AT91F_MCIDeviceWaitReady */
#define BUFFER_SIZE_MCI_DEVICE 512
//* External Functions
extern void AT91F_DBGU_Printk(char *);
extern void AT91F_ASM_MCI_Handler(void);
extern void AT91F_MCI_Device_Handler(AT91PS_MciDevice,unsigned int);
extern AT91S_MCIDeviceStatus AT91F_MCI_SDCard_Init (AT91PS_MciDevice);
extern AT91S_MCIDeviceStatus AT91F_MCI_MMC_Init(AT91PS_MciDevice);
extern AT91S_MCIDeviceStatus AT91F_MCI_SetBlocklength(AT91PS_MciDevice,unsigned int);
extern AT91S_MCIDeviceStatus AT91F_MCI_MMC_SelectCard(AT91PS_MciDevice,unsigned int);
extern AT91S_MCIDeviceStatus AT91F_MCI_ReadBlock(AT91PS_MciDevice,int,unsigned int *,int);
extern AT91S_MCIDeviceStatus AT91F_MCI_WriteBlock(AT91PS_MciDevice,int,unsigned int *,int);
//* Global Variables
AT91S_MciDeviceFeatures MCI_Device_Features;
AT91S_MciDeviceDesc MCI_Device_Desc;
AT91S_MciDevice MCI_Device;
char Buffer[BUFFER_SIZE_MCI_DEVICE];
/* RTT irq handler */
void SYSC_handler(void){
volatile unsigned int st,tempo=100000;
}
//*--------------------------------------------------------------------------------------
//* Function Name : change_speed
//* Object : Adjust "LedSpeed" value depending on SW1 and SW2 are pressed or not
//* Input Parameters : none
//* Output Parameters : Update of LedSpeed value.
//*--------------------------------------------------------------------------------------
void change_speed ( void )
{//* Begin
if ( ((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & SW3) == 0) || \
((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & SW4) == 0) )
{
if ( LedSpeed > SPEED ) LedSpeed -=SPEED ;
}
if ( ((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & SW5) == 0) || \
((AT91F_PIO_GetInput(AT91C_BASE_PIOA) & SW6) == 0) )
{
if ( LedSpeed < AT91C_MASTER_CLOCK ) LedSpeed +=SPEED ;
}
}//* End
//*--------------------------------------------------------------------------------------
//* Function Name : wait
//* Object : Software waiting loop
//* Input Parameters : none. Waiting time is defined by the global variable LedSpeed.
//* Output Parameters : none
//*--------------------------------------------------------------------------------------
void wait ( void )
{//* Begin
unsigned int waiting_time ;
change_speed () ;
for(waiting_time = 0; waiting_time < LedSpeed; waiting_time++) ;
}//* End
//*----------------------------------------------------------------------------
//* \fn AT91F_DBGU_getc
//* \brief This function is used to receive a character to the DBGU channel
//*----------------------------------------------------------------------------
char AT91F_DBGU_getc(void)
{
while (!AT91F_US_RxReady((AT91PS_USART)AT91C_BASE_DBGU));
return AT91F_US_GetChar((AT91PS_USART) AT91C_BASE_DBGU);
}
//*----------------------------------------------------------------------------
//* \fn AT91F_MCIDeviceWaitReady
//* \brief Wait for MCI Device ready
//*----------------------------------------------------------------------------
void AT91F_MCIDeviceWaitReady(unsigned int timeout)
{
volatile int status;
do
{
status = AT91C_BASE_MCI->MCI_SR;
timeout--;
}
while( !(status & AT91C_MCI_NOTBUSY) && (timeout>0) );
}
//*----------------------------------------------------------------------------
//* \fn AT91F_Test
//* \brief Test Functions
//*----------------------------------------------------------------------------
int AT91F_Test(void)
{
int i;
unsigned int Max_Read_DataBlock_Length;
Max_Read_DataBlock_Length = MCI_Device.pMCI_DeviceFeatures->Max_Read_DataBlock_Length;
//* ReadBlock & WriteBlock Test -> Entire Block
//* Wait MCI Device Ready
AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
//* Read Block 1
for(i=0;i<BUFFER_SIZE_MCI_DEVICE;i++) Buffer[i] = 0x00;
AT91F_MCI_ReadBlock(&MCI_Device,(1*Max_Read_DataBlock_Length),(unsigned int*) Buffer,Max_Read_DataBlock_Length);
//* Wait end of Read
AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
//* Write Page 1
sprintf(Buffer,"\n\rThis sentence is written in your device... Congratulations !!!\n\r");
AT91F_MCI_WriteBlock(&MCI_Device,(1*Max_Read_DataBlock_Length),(unsigned int*) Buffer,Max_Read_DataBlock_Length);
//* Wait end of Write
AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
//* Read Block 1
for(i=0;i<BUFFER_SIZE_MCI_DEVICE;i++) Buffer[i] = 0x00;
AT91F_MCI_ReadBlock(&MCI_Device,(1*Max_Read_DataBlock_Length),(unsigned int*) Buffer,Max_Read_DataBlock_Length);
//* Wait end of Read
AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
//* End Of Test
AT91F_DBGU_Printk("\n\rTests Completed: !!!\n\r");
if (Buffer[0]!= 0x00)
{
AT91F_DBGU_Printk(Buffer);
return TRUE;
}
return FALSE;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_MCI_Handler
//* \brief MCI Handler
//*----------------------------------------------------------------------------
void AT91F_MCI_Handler(void)
{
int status;
status = ( AT91C_BASE_MCI->MCI_SR & AT91C_BASE_MCI->MCI_IMR );
AT91F_MCI_Device_Handler(&MCI_Device,status);
}
//*----------------------------------------------------------------------------
//* \fn AT91F_CfgDevice
//* \brief This function is used to initialise MMC or SDCard Features
//*----------------------------------------------------------------------------
void AT91F_CfgDevice(void)
{
// Init Device Structure
MCI_Device_Features.Relative_Card_Address = 0;
MCI_Device_Features.Card_Inserted = AT91C_CARD_REMOVED;
MCI_Device_Features.Max_Read_DataBlock_Length = 0;
MCI_Device_Features.Max_Write_DataBlock_Length = 0;
MCI_Device_Features.Read_Partial = 0;
MCI_Device_Features.Write_Partial = 0;
MCI_Device_Features.Erase_Block_Enable = 0;
MCI_Device_Features.Sector_Size = 0;
MCI_Device_Features.Memory_Capacity = 0;
MCI_Device_Desc.state = AT91C_MCI_IDLE;
MCI_Device_Desc.SDCard_bus_width = AT91C_MCI_SCDBUS;
// Init AT91S_DataFlash Global Structure, by default AT45DB choosen !!!
MCI_Device.pMCI_DeviceDesc = &MCI_Device_Desc;
MCI_Device.pMCI_DeviceFeatures = &MCI_Device_Features;
}
//*----------------------------------------------------------------------------
//* \fn AT91F_Test_MMC
//* \brief Configure MCI for MMC and complete MMC init, then jump to Test Functions
//*----------------------------------------------------------------------------
int AT91F_Test_MMC(void)
{
//////////////////////////////////////////////////////////
//* For MMC Init
//////////////////////////////////////////////////////////
AT91F_MCI_Configure(AT91C_BASE_MCI,
AT91C_MCI_DTOR_1MEGA_CYCLES,
0x834A, // 400kHz for MCK = 60MHz
AT91C_MCI_MMC_SLOTA);
//* Wait MCI Device Ready
AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
if(AT91F_MCI_MMC_Init(&MCI_Device) != AT91C_INIT_OK)
return FALSE;
// Select MMC Card n
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -