📄 bsp.c
字号:
reg_val = EMCDINAMICCTRL;
reg_val &= ~BSP_EMC_DYNAMIC_CTRL_INIT_MASK;
reg_val |= BSP_EMC_DYNAMIC_CTRL_INIT_MODE;
EMCDINAMICCTRL = reg_val; /* SDRAM MODE Command */
dummy = *((volatile CPU_INT32U *)((CPU_INT32U)BSP_SDRAM_BASE_ADDR | (0x33 << 12)));
dummy = dummy;
reg_val = EMCDINAMICCTRL;
reg_val &= ~BSP_EMC_DYNAMIC_CTRL_INIT_MASK;
reg_val |= BSP_EMC_DYNAMIC_CTRL_INIT_NORMAL;
EMCDINAMICCTRL = reg_val;
EMCDYNAMICCFG0 |= DEF_BIT_19;
OSTimeDlyHMSM(0, 0, 0, 1);
return DEF_TRUE;
}
/*
*********************************************************************************************************
*********************************************************************************************************
** LED FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSP_LED_On()
*
* Description : Turn ON any or all the LEDs on the board.
*
* Argument(s) : led_id The ID of the LED to control:
*
* 0 turn ON all LEDs on the board.
* 1 turn ON USB_UP_LED1.
* 2 turn ON USB_UP_LED2.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void BSP_LED_On (CPU_INT08U led)
{
if (led == 0) {
IO1CLR = BSP_GPIO1_LED_GRP;
} else if (led == 1) {
IO1CLR = BSP_GPIO1_USB_UP_LED1;
} else {
IO1CLR = BSP_GPIO1_USB_UP_LED2;
}
}
/*
*********************************************************************************************************
* BSP_LED_Off()
*
* Description : Turn OFF any or all the LEDs on the board.
*
* Argument(s) : led_id The ID of the LED to control:
*
* 0 turn OFF all LEDs on the board
* 1 turn OFF USB_UP_LED1
* 2 turn OFF USB_UP_LED2
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void BSP_LED_Off (CPU_INT08U led)
{
if (led == 0) {
IO1SET = BSP_GPIO1_LED_GRP;
} else if (led == 1) {
IO1SET = BSP_GPIO1_USB_UP_LED1;
} else {
IO1SET = BSP_GPIO1_USB_UP_LED2;
}
}
/*
*********************************************************************************************************
* BSP_LED_Toggle()
*
* Description : Toggles any or all the LEDs on the board.
*
* Argument(s) : led_id The ID of the LED to control:
*
* 0 toggle all LEDs on the board
* 1 toggle USB_UP_LED1
* 2 toggle USB_UP_LED2
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void BSP_LED_Toggle (CPU_INT08U led)
{
CPU_INT32U reg_val;
reg_val = IO1PIN;
if (led == 0) {
IO1SET = ( reg_val & BSP_GPIO1_LED_GRP);
IO1CLR = (~reg_val & BSP_GPIO1_LED_GRP);
} else if (led == 1) {
IO1SET = ( reg_val & BSP_GPIO1_USB_UP_LED1);
IO1CLR = (~reg_val & BSP_GPIO1_USB_UP_LED1);
} else {
IO1SET = ( reg_val & BSP_GPIO1_USB_UP_LED1);
IO1CLR = (~reg_val & BSP_GPIO1_USB_UP_LED2);
}
}
/*
*********************************************************************************************************
*********************************************************************************************************
** PB FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSP_PB_GetStatus()
*
* Description : Get the status of a push button on the board.
*
* Argument(s) : pb_id The ID of the push button to probe
*
* 1 probe the push button B1
* 2 probe the push button B2
*
* Return(s) : DEF_FALSE if the push button is not pressed
* DEF_TRUE if the push button is pressed
*********************************************************************************************************
*/
CPU_BOOLEAN BSP_PB_GetStatus (CPU_INT08U pb_id)
{
CPU_INT32U reg_val;
CPU_BOOLEAN pb_status;
reg_val = FIO2PIN;
pb_status = DEF_FALSE;
switch (pb_id) {
case 1:
pb_status = DEF_BIT_IS_CLR(reg_val, BSP_GPIO2_PB1);
break;
case 2:
pb_status = DEF_BIT_IS_CLR(reg_val, BSP_GPIO2_PB2);
break;
default:
break;
}
return (pb_status);
}
/*
*********************************************************************************************************
*********************************************************************************************************
** SERIAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* BSP_Ser_Init()
*
* Description : This function initializes a UART.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void BSP_Ser_Init (CPU_INT32U baud_rate)
{
CPU_FP32 div_fp; /* Baud rate divisor floating point precision */
CPU_INT16U div_int; /* Baud rate divisor floating point precision */
CPU_INT08U divlo;
CPU_INT08U divhi;
CPU_INT32U pclk_freq;
pclk_freq = BSP_CPU_PclkFreq(BSP_PCLK_UART0); /* Get peripheral clock frequency */
div_fp = (pclk_freq / 16.0 / baud_rate); /* Compute divisor for desired baud rate */
div_int = (CPU_INT16U)(div_fp + 0.5); /* Round the number up */
divlo = div_int & 0x00FF; /* Split divisor into LOW and HIGH bytes */
divhi = (div_int >> 8) & 0x00FF;
PCONP |= BSP_PCONP_UART0_EN; /* Enable the power bit for UART0 */
U0LCR = BSP_LCR_DLAB; /* Enable acces to Divisor latches */
U0DLL = divlo; /* Load divisor */
U0DLM = divhi;
U0FCR |= BSP_FCR_FIFO_EN;
U0LCR = BSP_LCR_WLS_8
| BSP_LCR_SBS_1;
U0LCR &= (~BSP_LCR_DLAB); /* Disable acces to Divisor latches */
PINSEL0 &= ~BSP_PINSEL0_U0_CLR;
PINSEL0 |= BSP_PINSEL0_TXD0 /* Enable TXDO function */
| BSP_PINSEL0_RXD0; /* Enable RXD0 function */
}
/*
*********************************************************************************************************
* BSP_Ser_WrByte()
*
* Description : Transmit a single byte.
*
* Argument(s) : byte The byte that should be transmitted.
*
* Return(s) : none.
*
* Caller(s) : Application
*
* Note(s) : none.
*********************************************************************************************************
*/
void BSP_Ser_WrByte (CPU_INT08U tx_byte)
{
while ((U0LSR & BSP_LSR_THRE) == 0) {
;
}
U0THR = tx_byte;
}
/*
*********************************************************************************************************
* BSP_Ser_WrStr()
*
* Description : Transmits a string.
*
* Argument(s) : tx_str The string that will be transmitted.
*
* Return(s) : none.
*
* Caller(s) : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void BSP_Ser_WrStr (CPU_CHAR * tx_str)
{
while ((*tx_str) != 0) {
BSP_Ser_WrByte(*tx_str++);
OSTimeDly(1);
}
}
/*
*********************************************************************************************************
* BSP_Ser_RdByte()
*
* Description : Receive a single byte.
*
* Argument(s) : none.
*
* Return(s) : The received byte
*********************************************************************************************************
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -