/*
 * spv40xx_wfi.h
 *
 *  Created on: 2023年5月12日
 *      Author: mglsq
 */

#ifndef _HAL_WFI_H_
#define _HAL_WFI_H_

#include "platform.h"

typedef enum
{
    WFI_CLK_EN_PSRAM = DEV_WFI_CTL_PSRAM,
    WFI_CLK_EN_MEM = DEV_WFI_CTL_MEM,
    WFI_CLK_EN_HST = DEV_WFI_CTL_HST,
    WFI_CLK_EN_DEV = DEV_WFI_CTL_DEV,
    WFI_CLK_EN_RAM7 = DEV_WFI_CTL_RAM7,
    WFI_CLK_EN_RAM6 = DEV_WFI_CTL_RAM6,
    WFI_CLK_EN_RAM5 = DEV_WFI_CTL_RAM5,
    WFI_CLK_EN_RAM4 = DEV_WFI_CTL_RAM4,
    WFI_CLK_EN_RAM3 = DEV_WFI_CTL_RAM3,
    WFI_CLK_EN_RAM2 = DEV_WFI_CTL_RAM2,
    WFI_CLK_EN_RAM1 = DEV_WFI_CTL_RAM1,
    WFI_CLK_EN_RAM0 = DEV_WFI_CTL_RAM0,
    WFI_CLK_EN_CACHE = DEV_WFI_CTL_CACHE,
    WFI_CLK_EN_NORC = DEV_WFI_CTL_NORC,
    WFI_CLK_EN_SYS = DEV_WFI_CTL_SYS,
    WFI_CLK_EN_CPU = DEV_WFI_CTL_CPU
} wfi_clk_en_t;

typedef enum
{
    WFI_MASK0_TRAP = (1u << 0),
    WFI_MASK0_WDOG = (1u << IRQ_SOURCE_WDOG),
    WFI_MASK0_PMU = (1u << IRQ_SOURCE_PMU),
    WFI_MASK0_LRADC = (1u << IRQ_SOURCE_LRADC),
    WFI_MASK0_ADUI = (1u << IRQ_SOURCE_ADUI),
    WFI_MASK0_UDSP = (1u << IRQ_SOURCE_UDSP),
    WFI_MASK0_NPU_TAB = (1u << IRQ_SOURCE_NPU_TAB),
    WFI_MASK0_NPU_RES = (1u << IRQ_SOURCE_NPU_RES),
    WFI_MASK0_TIMER0 = (1u << IRQ_SOURCE_TIMER0),
    WFI_MASK0_TIMER1 = (1u << IRQ_SOURCE_TIMER1),
    WFI_MASK0_TIMER2 = (1u << IRQ_SOURCE_TIMER2),
    WFI_MASK0_TIMER3 = (1u << IRQ_SOURCE_TIMER3),
    WFI_MASK0_CAPTURE0 = (1u << IRQ_SOURCE_CAPTURE0),
    WFI_MASK0_CAPTURE1 = (1u << IRQ_SOURCE_CAPTURE1),
    WFI_MASK0_CAPTURE2 = (1u << IRQ_SOURCE_CAPTURE2),
    WFI_MASK0_CAPTURE3 = (1u << IRQ_SOURCE_CAPTURE3),
    WFI_MASK0_IRRX = (1u << IRQ_SOURCE_IRRX),
    WFI_MASK0_IRTX = (1u << IRQ_SOURCE_IRTX),
    WFI_MASK0_SPI0 = (1u << IRQ_SOURCE_SPI0),
    WFI_MASK0_SPI1 = (1u << IRQ_SOURCE_SPI1),
    WFI_MASK0_SDC = (1u << IRQ_SOURCE_SDC),
    WFI_MASK0_ADC = (1u << IRQ_SOURCE_ADC),
    WFI_MASK0_DAC = (1u << IRQ_SOURCE_DAC),
    WFI_MASK0_SRC = (1u << IRQ_SOURCE_SRC),
    WFI_MASK0_DMA = (1u << IRQ_SOURCE_DMA),
    WFI_MASK0_MMU = (1u << IRQ_SOURCE_MMU),
    WFI_MASK0_NORC = (1u << IRQ_SOURCE_NORC),
    WFI_MASK0_UART0 = (1u << IRQ_SOURCE_UART0),
    WFI_MASK0_UART1 = (1u << IRQ_SOURCE_UART1),
    WFI_MASK0_UART2 = (1u << IRQ_SOURCE_UART2),
    WFI_MASK0_I2C0 = (1u << IRQ_SOURCE_I2C0),
    WFI_MASK0_I2C1 = (1u << IRQ_SOURCE_I2C1)
} wfi_mask0_t;

typedef enum
{
    WFI_MASK1_ASI0 = (1u << (IRQ_SOURCE_ASI0 - 32)),
    WFI_MASK1_ASI1 = (1u << (IRQ_SOURCE_ASI1 - 32)),
    WFI_MASK1_USB_MAC = (1u << (IRQ_SOURCE_USB_MAC - 32)),
    WFI_MASK1_USB_DMA = (1u << (IRQ_SOURCE_USB_DMA - 32)),
    WFI_MASK1_GPIO0 = (1u << (IRQ_SOURCE_GPIO0 - 32)),
    WFI_MASK1_GPIO1 = (1u << (IRQ_SOURCE_GPIO1 - 32)),
    WFI_MASK1_PWM = (1u << (IRQ_SOURCE_PWM - 32)),
    WFI_MASK1_CAMERA = (1u << (IRQ_SOURCE_CAMERA - 32)),
    WFI_MASK1_UART3 = (1u << (IRQ_SOURCE_UART3 - 32)),
    WFI_MASK1_PSRAM = (1u << (IRQ_SOURCE_PSRAM - 32)),
    WFI_MASK1_MPU = (1u << (IRQ_SOURCE_MPU - 32))
} wfi_mask1_t;

typedef enum
{
    WFI_NMI_MASK0_TRAP = (1u << 0),
    WFI_NMI_MASK0_WDOG = (1u << IRQ_SOURCE_WDOG),
    WFI_NMI_MASK0_PMU = (1u << IRQ_SOURCE_PMU),
    WFI_NMI_MASK0_LRADC = (1u << IRQ_SOURCE_LRADC),
    WFI_NMI_MASK0_ADUI = (1u << IRQ_SOURCE_ADUI),
    WFI_NMI_MASK0_UDSP = (1u << IRQ_SOURCE_UDSP),
    WFI_NMI_MASK0_NPU_TAB = (1u << IRQ_SOURCE_NPU_TAB),
    WFI_NMI_MASK0_NPU_RES = (1u << IRQ_SOURCE_NPU_RES),
    WFI_NMI_MASK0_TIMER0 = (1u << IRQ_SOURCE_TIMER0),
    WFI_NMI_MASK0_TIMER1 = (1u << IRQ_SOURCE_TIMER1),
    WFI_NMI_MASK0_TIMER2 = (1u << IRQ_SOURCE_TIMER2),
    WFI_NMI_MASK0_TIMER3 = (1u << IRQ_SOURCE_TIMER3),
    WFI_NMI_MASK0_CAPTURE0 = (1u << IRQ_SOURCE_CAPTURE0),
    WFI_NMI_MASK0_CAPTURE1 = (1u << IRQ_SOURCE_CAPTURE1),
    WFI_NMI_MASK0_CAPTURE2 = (1u << IRQ_SOURCE_CAPTURE2),
    WFI_NMI_MASK0_CAPTURE3 = (1u << IRQ_SOURCE_CAPTURE3),
    WFI_NMI_MASK0_IRRX = (1u << IRQ_SOURCE_IRRX),
    WFI_NMI_MASK0_IRTX = (1u << IRQ_SOURCE_IRTX),
    WFI_NMI_MASK0_SPI0 = (1u << IRQ_SOURCE_SPI0),
    WFI_NMI_MASK0_SPI1 = (1u << IRQ_SOURCE_SPI1),
    WFI_NMI_MASK0_SDC = (1u << IRQ_SOURCE_SDC),
    WFI_NMI_MASK0_ADC = (1u << IRQ_SOURCE_ADC),
    WFI_NMI_MASK0_DAC = (1u << IRQ_SOURCE_DAC),
    WFI_NMI_MASK0_SRC = (1u << IRQ_SOURCE_SRC),
    WFI_NMI_MASK0_DMA = (1u << IRQ_SOURCE_DMA),
    WFI_NMI_MASK0_MMU = (1u << IRQ_SOURCE_MMU),
    WFI_NMI_MASK0_NORC = (1u << IRQ_SOURCE_NORC),
    WFI_NMI_MASK0_UART0 = (1u << IRQ_SOURCE_UART0),
    WFI_NMI_MASK0_UART1 = (1u << IRQ_SOURCE_UART1),
    WFI_NMI_MASK0_UART2 = (1u << IRQ_SOURCE_UART2),
    WFI_NMI_MASK0_I2C0 = (1u << IRQ_SOURCE_I2C0),
    WFI_NMI_MASK0_I2C1 = (1u << IRQ_SOURCE_I2C1)
} wfi_nmi_mask0_t;

typedef enum
{
    WFI_NMI_MASK1_ASI0 = (1u << (IRQ_SOURCE_ASI0 - 32)),
    WFI_NMI_MASK1_ASI1 = (1u << (IRQ_SOURCE_ASI1 - 32)),
    WFI_NMI_MASK1_USB_MAC = (1u << (IRQ_SOURCE_USB_MAC - 32)),
    WFI_NMI_MASK1_USB_DMA = (1u << (IRQ_SOURCE_USB_DMA - 32)),
    WFI_NMI_MASK1_GPIO0 = (1u << (IRQ_SOURCE_GPIO0 - 32)),
    WFI_NMI_MASK1_GPIO1 = (1u << (IRQ_SOURCE_GPIO1 - 32)),
    WFI_NMI_MASK1_PWM = (1u << (IRQ_SOURCE_PWM - 32)),
    WFI_NMI_MASK1_CAMERA = (1u << (IRQ_SOURCE_CAMERA - 32)),
    WFI_NMI_MASK1_UART3 = (1u << (IRQ_SOURCE_UART3 - 32)),
    WFI_NMI_MASK1_PSRAM = (1u << (IRQ_SOURCE_PSRAM - 32)),
    WFI_NMI_MASK1_MPU = (1u << (IRQ_SOURCE_MPU - 32))
} wfi_nmi_mask1_t;

//WFI时钟使能配置
void wfi_clk_en_config(wfi_clk_en_t clk_en, uint32_t en);
uint32_t wfi_get_clk_en_config(void);

//WFI中断唤醒MASK0配置
void wfi_mask0_config(wfi_mask0_t wfi_mask0, uint32_t en);
uint32_t wfi_get_mask0_config(void);

//WFI中断唤醒MASK1配置
void wfi_mask1_config(wfi_mask1_t wfi_mask1, uint32_t en);
uint32_t wfi_get_mask1_config(void);

//获取WFI中断唤醒状态STA0
uint32_t wfi_get_status0(void);

//获取WFI中断唤醒状态STA1
uint32_t wfi_get_status1(void);

//WFI NMI中断唤醒MASK0配置
void wfi_nmi_mask0_config(wfi_nmi_mask0_t wfi_nmi_mask0, uint32_t en);
uint32_t wfi_nmi_get_mask0_config(void);

//WFI NMI中断唤醒MASK1配置
void wfi_nmi_mask1_config(wfi_nmi_mask1_t wfi_nmi_mask1, uint32_t en);
uint32_t wfi_nmi_get_mask1_config(void);

//获取WFI NMI中断唤醒状态STA0
uint32_t wfi_get_nmi_status0(void);

//获取WFI NMI中断唤醒状态STA1
uint32_t wfi_get_nmi_status1(void);

#endif /* DRIVER_SPV40XX_WFI_H_ */
