📄 bsp.c
字号:
return (result);
}
/*
******************************************************************************************************************************
******************************************************************************************************************************
** uC/LCD Display Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* WRITE DATA TO DISPLAY DEVICE
*
* Description : This function sends a single BYTE to the display device.
*
* Arguments : 'data' is the BYTE to send to the display device
*
* Returns : none
*
* Notes : (1) The LPC2148 evaluation board uses a 4 bit interface.
* If an 8 bit interface is used. BSP_IO_Init() and DispDataWr() will need
* to be modified to reflect the new databus. In 8 bit mode, DispDataWrOneNibble()
* is not necessary.
*********************************************************************************************************
*/
#ifdef DISP_MODULE_PRESENT
void DispDataWr (CPU_INT08U data)
{
CPU_INT32U value;
DispRW_Low(); /* Set R/W write LOW to write to the LCD module */
DispE_High(); /* Write the UPPER nibble to the LCD module */
value = ((data >> 4) & 0x0000000F);
GPIO_SetBits(GPIOC, value);
value = (~(data >> 4) & 0x0000000F);
GPIO_ResetBits(GPIOC, value);
DispDly_uS(1000);
DispE_Low();
DispDly_uS(1000); /* Write the LOWER nibble to the LCD module */
DispE_High();
value = (data & 0x0000000F);
GPIO_SetBits(GPIOC, value);
value = (~data & 0x0000000F);
GPIO_ResetBits(GPIOC, value);
DispDly_uS(1000);
DispE_Low();
}
#if DISP_BUS_WIDTH == 4
void DispDataWrOneNibble (CPU_INT08U data)
{
CPU_INT32U value;
DispRW_Low(); /* Set R/W write LOW to write to the LCD module */
DispE_High(); /* Write the UPPER nibble to the LCD module */
value = ((data >> 4) & 0x0F);
GPIO_SetBits(GPIOC, value);
value = (~(data >> 4) & 0x0F);
GPIO_ResetBits(GPIOC, value);
DispDly_uS(1000);
DispE_Low();
}
#endif
#endif
/*
*********************************************************************************************************
* DELAY
*
* Description : This function is called to delay for the specified number of microseconds.
*
* Arguments : us Number of microseconds
*
* Returns : none
*********************************************************************************************************
*/
#ifdef DISP_MODULE_PRESENT
void DispDly_uS (CPU_INT32U us)
{
DispTmr_Dly(us);
}
#endif
/*
*********************************************************************************************************
* INITIALIZE DISPLAY DRIVER I/O PORTS
*
* Description : This initializes the I/O ports used by the display driver.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
#ifdef DISP_MODULE_PRESENT
void DispInitPort (void)
{
GPIO_InitTypeDef gpio_init;
gpio_init.GPIO_Pin = GPIOC_LCD_DB4 | GPIOC_LCD_DB5 | GPIOC_LCD_DB6 | GPIOC_LCD_DB7
| GPIOC_LCD_RS | GPIOC_LCD_RW | GPIOC_LCD_E;
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
gpio_init.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &gpio_init);
DispTmr_Init();
}
#endif
/*
*********************************************************************************************************
* SELECT COMMAND OR DATA REGISTER
*
* Description : This changes the Register Select control line to the LCD controller.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
#ifdef DISP_MODULE_PRESENT
void DispSel (CPU_INT08U sel)
{
if (sel == DISP_SEL_CMD_REG) {
GPIO_ResetBits(GPIOC, GPIOC_LCD_RS); /* Select the command register (RS low) */
} else {
GPIO_SetBits(GPIOC, GPIOC_LCD_RS); /* Select the data register (RS high) */
}
}
#endif
/*
*********************************************************************************************************
* DISPLAY CONTROL LINE FUNCTIONS
*********************************************************************************************************
*/
#ifdef DISP_MODULE_PRESENT
static void DispE_High (void)
{
GPIO_SetBits(GPIOC, GPIOC_LCD_E);
}
static void DispE_Low (void)
{
GPIO_ResetBits(GPIOC, GPIOC_LCD_E);
}
static void DispRW_Low (void)
{
GPIO_ResetBits(GPIOC, GPIOC_LCD_RW);
}
#endif
/*
*********************************************************************************************************
* DispTmr_Dly()
*
* Description : Uses a timer to produce a short delay
*
* Arguments : dly The number of microseconds for which to delay
*
* Returns : None
*********************************************************************************************************
*/
#ifdef DISP_MODULE_PRESENT
static void DispTmr_Init (void)
{
TIM_TimeBaseInitTypeDef tim_init;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
tim_init.TIM_Period = 0xFFFF;
tim_init.TIM_Prescaler = 0x00;
tim_init.TIM_ClockDivision = 0x0;
tim_init.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &tim_init);
TIM_SetCounter(TIM3, 0);
TIM_PrescalerConfig(TIM3, 8, TIM_PSCReloadMode_Immediate);
TIM_Cmd(TIM3, ENABLE);
}
static void DispTmr_Dly (CPU_INT32U us)
{
CPU_INT32U original_val;
CPU_INT32U current_val;
CPU_INT32U clk_per_us;
CPU_INT32U clks;
original_val = TIM_GetCounter(TIM3);
clk_per_us = BSP_CPU_ClkFreq() / 1000000 + 1;
clks = clk_per_us * us;
if (clks > 32768 / 2) {
clks = 32768 / 2;
}
current_val = TIM_GetCounter(TIM3);
while ((current_val - original_val) < clks) {
current_val = TIM_GetCounter(TIM3);
}
}
#endif
/*
******************************************************************************************************************************
******************************************************************************************************************************
* uC/Probe Plug-In for uC/OS-II Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* INITIALIZE TIMER FOR uC/Probe Plug-In for uC/OS-II
*
* Description : This function is called to by uC/Probe Plug-In for uC/OS-II to initialize the
* free running timer that is used to make time measurements.
*
* Arguments : none
*
* Returns : none
*
* Note(s) : This function is EMPTY because the timer is initialized elsewhere.
*********************************************************************************************************
*/
#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN == 1)
void OSProbe_TmrInit (void)
{
TIM_TimeBaseInitTypeDef tim_init;
#if (OS_PROBE_TIMER_SEL == 2)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
tim_init.TIM_Period = 0xFFFF;
tim_init.TIM_Prescaler = 0x00;
tim_init.TIM_ClockDivision = 0x0;
tim_init.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &tim_init);
TIM_SetCounter(TIM2, 0);
TIM_PrescalerConfig(TIM2, 256, TIM_PSCReloadMode_Immediate);
TIM_Cmd(TIM2, ENABLE);
#elif (OS_PROBE_TIMER_SEL == 3)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
tim_init.TIM_Period = 0xFFFF;
tim_init.TIM_Prescaler = 0x00;
tim_init.TIM_ClockDivision = 0x0;
tim_init.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &tim_init);
TIM_SetCounter(TIM3, 0);
TIM_PrescalerConfig(TIM3, 256, TIM_PSCReloadMode_Immediate);
TIM_Cmd(TIM3, ENABLE);
#elif (OS_PROBE_TIMER_SEL == 4)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
tim_init.TIM_Period = 0xFFFF;
tim_init.TIM_Prescaler = 0x00;
tim_init.TIM_ClockDivision = 0x0;
tim_init.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &tim_init);
TIM_SetCounter(TIM4, 0);
TIM_PrescalerConfig(TIM4, 256, TIM_PSCReloadMode_Immediate);
TIM_Cmd(TIM4, ENABLE);
#endif
}
#endif
/*
*********************************************************************************************************
* READ TIMER FOR uC/Probe Plug-In for uC/OS-II
*
* Description : This function is called to read the current counts of a 16 bit free running timer.
*
* Arguments : none
*
* Returns : The 16 or 32 bit count of the timer assuming the timer is an UP counter.
*********************************************************************************************************
*/
#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN == 1)
CPU_INT32U OSProbe_TmrRd (void)
{
#if (OS_PROBE_TIMER_SEL == 2)
return ((CPU_INT32U)TIM_GetCounter(TIM2));
#elif (OS_PROBE_TIMER_SEL == 3)
return ((CPU_INT32U)TIM_GetCounter(TIM3));
#elif (OS_PROBE_TIMER_SEL == 4)
return ((CPU_INT32U)TIM_GetCounter(TIM4));
#endif
}
#endif
/*
******************************************************************************************************************************
******************************************************************************************************************************
** uC/OS-II Timer Functions
******************************************************************************************************************************
******************************************************************************************************************************
*/
/*
*********************************************************************************************************
* TICKER INITIALIZATION
*
* Description : This function is called to initialize uC/OS-II's tick source (typically a timer generating
* interrupts every 1 to 100 mS).
*
* Arguments : none
*
* Note(s) : 1) The timer is setup for output compare mode BUT 'MUST' also 'freerun' so that the timer
* count goes from 0x00000000 to 0xFFFFFFFF to ALSO be able to read the free running count.
* The reason this is needed is because we use the free-running count in uC/OS-View.
*********************************************************************************************************
*/
static void Tmr_TickInit (void)
{
RCC_ClocksTypeDef rcc_clocks;
CPU_INT32U cnts;
RCC_GetClocksFreq(&rcc_clocks);
cnts = (CPU_INT32U)rcc_clocks.HCLK_Frequency / OS_TICKS_PER_SEC;
SysTick_SetReload(cnts);
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
SysTick_CounterCmd(SysTick_Counter_Enable);
SysTick_ITConfig(ENABLE);
}
/*
*********************************************************************************************************
* TIMER IRQ HANDLER
*
* Description : This function handles the timer interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments : none
*
* Note(s) : 1) The timer is 'reloaded' with the count at compare + the time for the next interrupt.
* Since we are using 'unsigned' integer math, overflows are irrelevant.
*********************************************************************************************************
*/
void Tmr_TickISR_Handler (void)
{
OS_CPU_SR cpu_sr;
OS_ENTER_CRITICAL(); /* Tell uC/OS-II that we are starting an ISR */
OSIntNesting++;
OS_EXIT_CRITICAL();
OSTimeTick(); /* Call uC/OS-II's OSTimeTick() */
OSIntExit(); /* Tell uC/OS-II that we are leaving the ISR */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -