📄 bsp.c
字号:
return (mck_frq);
}
/*
*********************************************************************************************************
* INITIALIZE THE INTERRUPT CONTROLLER
*
* Description : This function is called to disable ALL interrupts.
*
* Arguments : none
*
* Notes : 1) The spurious interrupt register must be written to 0 in order to ensure
* that OS_CPU_ExceptHndlr() terminates after the last pending interrupt
* is serviced.
*********************************************************************************************************
*/
static void BSP_IntCtrlInit (void)
{
CPU_INT16U i;
BSP_RAM_REMAP_TEST_BYTE = 0xAA; /* Write a byte to address 0x30 */
if (BSP_RAM_REMAP_TEST_BYTE != 0xAA) { /* Check if the write to RAM failed */
AT91C_BASE_MATRIX->MATRIX_MCFG = 3; /* If so, toggle mem map so internal RAM is located at 0x00 */
}
OS_CPU_InitExceptVect(); /* Write the exception vectors into RAM, address 0x00-0x3F */
AT91C_BASE_AIC->AIC_ICCR = AT91C_BASE_AIC->AIC_ISR; /* Clear the current interrupt (if any pending) */
AT91C_BASE_AIC->AIC_EOICR = 0x00000000; /* End-of-interrupt command */
for (i = 0; i < 32; i++) { /* Initialize all ISR's to the Dummy ISR handler */
AT91C_BASE_AIC->AIC_SVR[i] = (CPU_INT32U)BSP_DummyISR_Handler;
AT91C_BASE_AIC->AIC_SMR[i] = 0;
}
AT91C_BASE_AIC->AIC_SPU = (CPU_INT32U)0;
}
/*
*********************************************************************************************************
* External Memory Initialization
*
* Description : This function initializes the SMC (dataflash) and SDRAM operating parameters
*
* Arguments : none
*
* Notes : 1) This function should not be called when booting from the dataflash boot loader
* since the boot loader provides code for external memory initialization. Initializing
* the external memory once code has been placed there can cause unexpected behavior.
* However, the function has been provided for convenience when booting from internal RAM
* and the need for external SDRAM storage exists. The function may be enabled by setting
* BSP_EXT_MEM_INIT to 1 within app_cfg.h. Additionally, there is no need to initialize
* external memory when your application resides in external memory since this should be
* performed via macro (RAM-Flash.mac) before code is loaded.
* 2) This function must be called after PLL and OS Ticker initialiation
*********************************************************************************************************
*/
#if BSP_EXT_MEM_INIT
static void ExtMemory_Init (void)
{
CPU_INT32U *pSDRAM;
CPU_INT08U i;
CPU_INT32U MCK_Frq;
MCK_Frq = BSP_MCK_Frq(); /* Get the MCK frequency in Hz, used to set SDRAM TR reg */
MCK_Frq /= 1000000; /* Convert into MHz */
pSDRAM = (CPU_INT32U *)0x20000000; /* Define a pointer to the base address of SDRAM */
AT91C_BASE_PIOC->PIO_ASR = 0xFFFF0000; /* Assign port C pins [31:16] to peripheral A */
AT91C_BASE_PIOC->PIO_BSR = 0; /* Assign none of the pins to peripheral B */
AT91C_BASE_PIOC->PIO_PDR = 0xFFFF0000; /* Assign port C pins [31:16] to peripheral mode */
AT91C_BASE_MATRIX->MATRIX_EBICSA |= AT91C_MATRIX_CS1A_SDRAMC; /* Configure CS1 for use with the SDRAM controller */
OSTimeDlyHMSM(0, 0, 0, 2); /* Wait for setup to complete */
/* ------------ Setup the SDRAM Control Register ---------- */
AT91C_BASE_SDRAMC->SDRAMC_CR = 0x85227279; /* SDRAM Configuration Register */
/* TXSR [31:28] = 8 Clock Cycles */
/* TRAS [27:24] = 5 Clock Cycles */
/* TRCD [23:20] = 2 Clock Cycles */
/* TRP [19:16] = 2 Clock Cycles */
/* TRC [15:12] = 7 Clock Cycles */
/* TWR [11:08] = 2 Clock Cycles */
/* DBW [07:07] = 32 bit */
/* CAS [06:05] = 3 Clock Cycles */
/* NB [04:04] = 4 Banks */
/* NR [03:02] = 13 Rows Bits */
/* NC [01:00] = 9 Column Bits */
/* -------------- Perform SDRAM Precharging --------------- */
AT91C_BASE_SDRAMC->SDRAMC_MR = 0x00000002; /* Precharge all command */
*pSDRAM = 0; /* Perform SDRAM precharge */
OSTimeDlyHMSM(0, 0, 0, 2); /* Wait min 200uS for precharge to complete */
AT91C_BASE_SDRAMC->SDRAMC_MR = AT91C_SDRAMC_MODE_RFSH_CMD; /* Set refresh command (perform 8 writes to autorefresh) */
for(i = 1; i <= 8; i++) { /* Issue 8 refresh cycles */
*(pSDRAM + (i * 16)) = i; /* *(AT91C_SDRAM + (i * 16) = i; */
} /* 0x20000010, 0x20000020, 0x20000030, ..., 0x20000080 */
AT91C_BASE_SDRAMC->SDRAMC_MR = AT91C_SDRAMC_MODE_LMR_CMD; /* Set LMR mode */
*(pSDRAM + 0x24) = 0xCAFEDEDE; /* A mode reg cycle is used to program the SDRAM params */
/* --------- Initialize the SDRAM Timing Register --------- */
AT91C_BASE_SDRAMC->SDRAMC_TR = MCK_Frq * 7; /* SDRAM Refresh Time (7.81uS * MCLK) */
/* where 7.81uS is the RAM tREF parameter */
/* See Section 22.5.1 SDRAM Device Initialization in */
/* 6062.pdf, the AT91SAM9261 datasheet. */
/* See page 17, in 256MBSDRAM.pdf, the Micron Documentation */
/* for the 48LC16M16A2-75 Type D SDRAM */
/* Note: It is OK to use 7 instead of 7.81 & refresh faster */
/* ------------ Complete SDRAM Initialization ------------- */
AT91C_BASE_SDRAMC->SDRAMC_MR = AT91C_SDRAMC_MODE_NORMAL_CMD; /* Set Normal mode */
*pSDRAM = 0x00000000; /* Perform Normal mode */
}
#endif
/*
*********************************************************************************************************
* DISABLE ALL INTERRUPTS
*
* Description : This function is called to disable ALL interrupts.
*
* Arguments : none
*********************************************************************************************************
*/
void BSP_IntDisAll (void)
{
AT91C_BASE_AIC->AIC_IDCR = 0xFFFFFFFF; /* Disable all interrupts */
}
/*
*********************************************************************************************************
* BSP INITIALIZATION
*
* Description : This function should be called by your application code before you make use of any of the
* functions found in this module.
*
* Arguments : none
*********************************************************************************************************
*/
void LED_Init (void)
{
AT91C_BASE_PIOA->PIO_PER = BSP_LED2 | BSP_LED1; /* Enable register */
AT91C_BASE_PIOA->PIO_OER = BSP_LED2 | BSP_LED1; /* Output enable */
AT91C_BASE_PIOA->PIO_IDR = BSP_LED2 | BSP_LED1; /* Disable LED pin interrupt */
LED_Off(BSP_LED_ALL); /* Turn OFF all the LEDs */
}
/*
*********************************************************************************************************
* LED ON
*
* Description : This function is used to control any or all the LEDs on the board.
*
* Arguments : led is the number of the LED to control
* 0 indicates that you want ALL the LEDs to be ON
* 1 turns ON LED1 on the board
* 2 turns ON LED2 on the board
*********************************************************************************************************
*/
void LED_On (CPU_INT08U led)
{
switch (led) {
case 0:
AT91C_BASE_PIOA->PIO_CODR = BSP_LED2 | BSP_LED1;
break;
case 1:
AT91C_BASE_PIOA->PIO_CODR = BSP_LED1;
break;
case 2:
AT91C_BASE_PIOA->PIO_CODR = BSP_LED2;
break;
}
}
/*
*********************************************************************************************************
* LED OFF
*
* Description : This function is used to control any or all the LEDs on the board.
*
* Arguments : led is the number of the LED to turn OFF
* 0 indicates that you want ALL the LEDs to be OFF
* 1 turns OFF LED1 on the board
* 2 turns OFF LED2 on the board
*********************************************************************************************************
*/
void LED_Off (CPU_INT08U led)
{
switch (led) {
case 0:
AT91C_BASE_PIOA->PIO_SODR = BSP_LED2 | BSP_LED1;
break;
case 1:
AT91C_BASE_PIOA->PIO_SODR = BSP_LED1;
break;
case 2:
AT91C_BASE_PIOA->PIO_SODR = BSP_LED2;
break;
}
}
/*
*********************************************************************************************************
* LED TOGGLE
*
* Description : This function is used to toggle any or all the LEDs on the board.
*
* Arguments : led is the number of the LED to toggle
* 0 indicates that you want ALL the LEDs to be toggle
* 1 toggles LED1 on the board
* 2 toggles LED2 on the board
*********************************************************************************************************
*/
void LED_Toggle (CPU_INT08U led)
{
switch (led) {
case 0:
if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED1) {
AT91C_BASE_PIOA->PIO_CODR = BSP_LED1;
} else {
AT91C_BASE_PIOA->PIO_SODR = BSP_LED1;
}
if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED2) {
AT91C_BASE_PIOA->PIO_CODR = BSP_LED2;
} else {
AT91C_BASE_PIOA->PIO_SODR = BSP_LED2;
}
break;
case 1:
if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED1) {
AT91C_BASE_PIOA->PIO_CODR = BSP_LED1;
} else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -