/**
******************************************************************************************************************************************************************************************
*@file                       cpu_deepsleep.h
*@author         
*@data                       
*@version                    v1.0
*@par Copyright(c):
*
*@par History:
*     version:author,date,desc
*     v1.0   :create this file
*
*******************************************************************************************************************************************************************************************
*/
#ifndef _CPU_DEEPSLEEP__H__
#define _CPU_DEEPSLEEP__H__

#include "cpu.h"

#define MAX_BACKUP_SIZE     240
#define MAX_BACKUP_WORD_SIZE    60+20   //1024/4=256

typedef struct backup_table_s {    
    uint32_t backupmem[MAX_BACKUP_WORD_SIZE];   
} backup_table_s;

typedef enum cpu_prevent_sleep
{
    /* Flag indicating that the amic is ongoing */
    AMIC_ONGOING    	 	= 0x00000001,		// ADC采集
    UART0_RX_ONGOING   	= 0x00000002,
	UART0_TX_ONGOING   	= 0x00000004,
	UART1_RX_ONGOING   	= 0x00000008,
    UART1_TX_ONGOING   	= 0x00000010,
	SPI0_RX_ONGOING		= 0x00000020,
	SPI0_TX_ONGOING   		= 0x00000040,
	SPI1_RX_ONGOING		= 0x00000080,
	SPI1_TX_ONGOING   		= 0x00000100,
	IIC_RX_ONGOING			= 0x00000200,
	IIC_TX_ONGOING   		= 0x00000400,
	QDEC_ONGOING			= 0x00000800,		//正交解码器
	DMA1_RX_ONGOING 		= 0x00001000,
	DMA1_TX_ONGOING 		= 0x00002000,
	DMA2_RX_ONGOING 		= 0x00004000,
	DMA2_TX_ONGOING 		= 0x00008000,	
	DMA3_RX_ONGOING 		= 0x00010000,
	DMA3_TX_ONGOING 		= 0x00020000,	
	DMA4_RX_ONGOING 		= 0x00040000,
	DMA4_TX_ONGOING 		= 0x00080000,
    TIMER0_ONGOING  		= 0x00100000,
    TIMER1_ONGOING  		= 0x00200000,
    TIMER2_ONGOING  		= 0x00400000,
	TIMER3_ONGOING			= 0x00800000,
	GPADC_ONGOING 			= 0x01000000,
	SYS_STICK_ONGOING     = 0x02000000,
// ... 用户自行添加	 ...
	KEYBOARD_FACTORY		= 0x04000000,
	USER_INT0_ONGOING		= 0x08000000,
	USER_INT1_ONGOING		= 0x10000000,
	USER_INT2_ONGOING		= 0x20000000,
	USER_INT3_ONGOING		= 0x40000000,

	
}cpu_prevent_sleep_t;

__ASM void deep_sleep_enter(void);
void deepsleep_prepare(void);



void deepsleep_exit(void);
void cpu_prevent_sleep_clear(uint32_t prv_slp_bit);
void cpu_prevent_sleep_set(uint32_t prv_slp_bit);
uint32_t cpu_prevent_sleep_get(void);

void set_retain_ram_to_standbye(void);
void clear_retain_ram_to_standbye(void);
char get_retain_ram_standbye_sta(void);
void enter_standbye(deep_sleep_retain type);

#endif

