sdk7a400_cpld_driver.c
来自「Sharp LH7A400 BSP平台无关部分的代码,有很高的参考价值,尤其是系」· C语言 代码 · 共 647 行 · 第 1/2 页
C
647 行
*
* Notes: None
*
**********************************************************************/
BOOL_32 cpld_ts_int_pending(void)
{
BOOL_32 pending = FALSE;
if (((* (volatile UNS_16 *) INTMSK_REG_BASE) &
INTMSK_TS_PENDING) == 0)
{
pending = TRUE;
}
return pending;
}
/***********************************************************************
*
* Function: cpld_int_pending
*
* Purpose: Return CPLD interrupt pending status
*
* Processing:
* If the CPLD interrupt is pending (per the CPLD), return
* TRUE to the caller. Otherwise, return FALSE.
*
* Parameters: None
*
* Outputs: None
*
* Returns: TRUE of the CPLD int is pending, otherwise FALSE
*
* Notes: None
*
**********************************************************************/
BOOL_32 cpld_int_pending(void)
{
BOOL_32 pending = FALSE;
if (((* (volatile UNS_16 *) INTMSK_REG_BASE) &
INTMSK_CPLD_PENDING) == 0)
{
pending = TRUE;
}
return pending;
}
/***********************************************************************
*
* Function: cpld_usb1c_int_pending
*
* Purpose: Return USB 1 connection interrupt pending status
*
* Processing:
* If the USB 1 connection interrupt is pending (per the CPLD),
* return TRUE to the caller. Otherwise, return FALSE.
*
* Parameters: None
*
* Outputs: None
*
* Returns: TRUE of the USB 1 int is pending, otherwise FALSE
*
* Notes: None
*
**********************************************************************/
BOOL_32 cpld_usb1c_int_pending(void)
{
BOOL_32 pending = FALSE;
if (((* (volatile UNS_16 *) CARDE_REG_BASE) &
CARDE_USB1INT_PENDING) == 0)
{
pending = TRUE;
}
return pending;
}
/***********************************************************************
*
* Function: cpld_enable_flash_prog
*
* Purpose: Enable or disable FLASH programming
*
* Processing:
* If enable is TRUE, enable FLASH programming (by disabling FLASH
* write protection). Otherwise, disable it.
*
* Parameters:
* enable: TRUE to enable FLASH programming, FALSE to disable it
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void cpld_enable_flash_prog(BOOL_32 enable)
{
if (enable == TRUE)
{
/* Enable FLASH programming */
* (volatile UNS_16 *) FLASH_REG_BASE |= FLASH_PROG_ENABLE;
}
else
{
/* Disable FLASH programming */
* (volatile UNS_16 *) FLASH_REG_BASE &= ~FLASH_PROG_ENABLE;
}
}
/***********************************************************************
*
* Function: cpld_get_flash_sts
*
* Purpose: Read FLASH STS1 or STS2 bit
*
* Processing:
* For the passed value of flash_sts, check the status of the
* STS bit in the CPLD FLASH register. If the bit is set, return
* TRUE to the caller. Otherwise, return FALSE.
*
* Parameters:
* flash_sts: Must be CPLD_STS1 or CPLD_STS2
*
* Outputs: None
*
* Returns:
* TRUE of the STS signal for the selected device is high,
* otherwise FALSE
*
* Notes: None
*
**********************************************************************/
BOOL_32 cpld_get_flash_sts(CPLD_FLASH_STS_T flash_sts)
{
UNS_16 mask = FLASH_STS1_MASK;
BOOL_32 set = FALSE;
if (flash_sts == CPLD_STS2)
{
mask = FLASH_STS2_MASK;
}
if (((* (volatile UNS_16 *) FLASH_REG_BASE) & mask) != 0)
{
set = TRUE;
}
return set;
}
/***********************************************************************
*
* Function: cpld_enable_led
*
* Purpose: Set or disable an application board LED
*
* Processing:
* Set the value of mask with the LED mask bit for the passed value
* of led. If set is TRUE, enable the LED for the value of mask.
* Otherwise, disable (turn off) the LED.
*
* Parameters:
* led: Must be LED_GPIO or LED_STATUS
* set: TRUE to turn on the LED, FALSE to turn it off
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void cpld_enable_led(CPLD_LED_TYPE led, BOOL_32 set)
{
UNS_16 mask;
switch (led)
{
case LED_GPIO:
mask = LED_GPIO_DISABLE;
break;
case LED_STATUS1:
mask = LED_STATUS1_DISABLE;
break;
case LED_STATUS2:
default:
mask = LED_STATUS2_DISABLE;
break;
}
if (set == TRUE)
{
* (volatile UNS_16 *) LED_REG_BASE &= ~mask;
}
else
{
* (volatile UNS_16 *) LED_REG_BASE |= mask;
}
}
/***********************************************************************
*
* Function: cpld_set_gpio_dir
*
* Purpose: Set direction of CPLD GPIO data bit 0
*
* Processing:
* if input is TRUE, set the GPIO data direction register in the
* CPLD to input mode. Otherwise, set it to output mode.
*
* Parameters:
* gpio_dir : Data direction enumeration (CPLD_GPIO_DIR_T)
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void cpld_set_gpio_dir(CPLD_GPIO_DIR_T gpio_dir)
{
if (gpio_dir == CPLD_GPIO_INPUT)
{
* (volatile UNS_16 *) GPDIR_REG_BASE |=
GPDIR_INPUT_CPLD2_SEL;
}
else
{
* (volatile UNS_16 *) GPDIR_REG_BASE &=
~GPDIR_INPUT_CPLD2_SEL;
}
}
/***********************************************************************
*
* Function: cpld_set_gpio_data
*
* Purpose: Set the CPLD GPIO data register
*
* Processing:
* Set the CPLD GPIO data register with the passed value of data.
*
* Parameters:
* data: Value to set the CPLD GPIO data register with
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void cpld_set_gpio_data(UNS_8 data)
{
* (volatile UNS_16 *) GPDAT_REG_BASE = (UNS_16) data;
}
/***********************************************************************
*
* Function: cpld_get_gpio_data
*
* Purpose: Get the CPLD GPIO data register
*
* Processing:
* Read the CPLD GPIO data register and return the value to the
* caller.
*
* Parameters: None
*
* Outputs: None
*
* Returns: The value of the CPLD GPIO data register
*
* Notes: None
*
**********************************************************************/
UNS_8 cpld_get_gpio_data(void)
{
return (UNS_8) (* (volatile UNS_16 *) GPDAT_REG_BASE & 0xFF);
}
/***********************************************************************
*
* Function: cpld_usb1pwr_enable
*
* Purpose: Enable or disable USB 1 power
*
* Processing:
* If enable is TRUE, enable USB 1 power. Otherwise, disable it.
*
* Parameters:
* enable: TRUE to enable USB power, FALSE to disable it
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void cpld_usb1pwr_enable(BOOL_32 enable)
{
if (enable == TRUE)
{
/* Enable USB power */
* (volatile UNS_16 *) CARDE_REG_BASE |= CARDE_USB1PWR_ENABLE;
}
else
{
/* Disable USB power */
* (volatile UNS_16 *) CARDE_REG_BASE &= ~CARDE_USB1PWR_ENABLE;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?