⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drvrtc.c

📁 cortex-m0 LCD1602程序
💻 C
📖 第 1 页 / 共 3 页
字号:
                RTCDEBUG ("RTC: 24-hour\n");
            }

  			RTC->DWR.DWR = sPt->u32cDayOfWeek;
		    
			/*---------------------------------------------------------------------------------------------*/
            /* Second, set RTC time data.                                                                  */
            /*---------------------------------------------------------------------------------------------*/
			u32Reg     = ((sPt->u32Year - DRVRTC_YEAR2000) / 10) << 20;
		    u32Reg    |= (((sPt->u32Year - DRVRTC_YEAR2000) % 10) << 16);
		    u32Reg    |= ((sPt->u32cMonth  / 10) << 12);
		    u32Reg    |= ((sPt->u32cMonth  % 10) << 8);
		    u32Reg    |= ((sPt->u32cDay    / 10) << 4);
		    u32Reg    |= (sPt->u32cDay     % 10);
            g_u32Reg = u32Reg;
			DrvRTC_WriteEnable();
          
			outpw(&RTC->CLR, (uint32_t)g_u32Reg);
			RTCDEBUG ("RTC: REG_RTC_CLR[0x%08x]\n", inpw(&RTC->CLR));  
            
		    u32Reg     = ((sPt->u32cHour / 10) << 20);
		    u32Reg    |= ((sPt->u32cHour % 10) << 16);
		    u32Reg    |= ((sPt->u32cMinute / 10) << 12);
		    u32Reg    |= ((sPt->u32cMinute % 10) << 8);
		    u32Reg    |= ((sPt->u32cSecond / 10) << 4);
		    u32Reg    |= (sPt->u32cSecond % 10);
			g_u32Reg = u32Reg;
		
			DrvRTC_WriteEnable();
           	outpw(&RTC->TLR, (uint32_t)g_u32Reg);
			RTCDEBUG ("RTC: REG_RTC_TLR[0x%08x]\n", inpw(&RTC->TLR));   
			
            return E_SUCCESS;

         case DRVRTC_ALARM_TIME:

            g_pfnRTCCallBack_Alarm = NULL;                                /* Initial call back function.*/
            
			/*---------------------------------------------------------------------------------------------*/
            /* Set Calender alarm time data.                                                               */
            /*---------------------------------------------------------------------------------------------*/
		    u32Reg     = ((sPt->u32Year - DRVRTC_YEAR2000) / 10) << 20;
		    u32Reg    |= (((sPt->u32Year - DRVRTC_YEAR2000) % 10) << 16);
		    u32Reg    |= ((sPt->u32cMonth  / 10) << 12);
		    u32Reg    |= ((sPt->u32cMonth  % 10) << 8);
		    u32Reg    |= ((sPt->u32cDay    / 10) << 4);
		    u32Reg    |= (sPt->u32cDay     % 10);
            g_u32Reg = u32Reg;
			DrvRTC_WriteEnable();
			
			outpw(&RTC->CAR, (uint32_t)g_u32Reg);
			RTCDEBUG ("RTC: REG_RTC_CAR[0x%08x]\n", inpw(&RTC->CAR));  
			
						 
            if (g_chHourMode == DRVRTC_CLOCK_12)
            {
                if (sPt->u8cAmPm == DRVRTC_PM)       /* important, range of 12-hour PM mode is 21 upto 32 */
                    sPt->u32cHour += 20;
            }

			/*---------------------------------------------------------------------------------------------*/
            /* Set Time alarm time data.                                                                   */
            /*---------------------------------------------------------------------------------------------*/
		    u32Reg     = ((sPt->u32cHour / 10) << 20);
		    u32Reg    |= ((sPt->u32cHour % 10) << 16);
		    u32Reg    |= ((sPt->u32cMinute / 10) << 12);
		    u32Reg    |= ((sPt->u32cMinute % 10) << 8);
		    u32Reg    |= ((sPt->u32cSecond / 10) << 4);
		    u32Reg    |= (sPt->u32cSecond % 10);

			g_u32Reg = u32Reg;
            DrvRTC_WriteEnable();
           	outpw(&RTC->TAR, (uint32_t)g_u32Reg);
			RTCDEBUG ("RTC: REG_RTC_TAR[0x%08x]\n", inpw(&RTC->TAR));   

			/*---------------------------------------------------------------------------------------------*/
            /* Finally, enable alarm interrupt.                                                            */
            /*---------------------------------------------------------------------------------------------*/
			DrvRTC_EnableInt(DRVRTC_ALARM_INT,NULL);
            
			RTC->TTR.TWKE = sPt->u8IsEnableWakeUp;
			return E_SUCCESS;


	        default:
	        {
	            return E_DRVRTC_ERR_ENOTTY;
	        }
    }
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvRTC_GetIntTick                                                                         */
/*                                                                                                         */
/* Parameter:                                                                                              */
/*               None.                                                                                     */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               Software Tick Count in tick interrupt                                                     */
/*               ex.If the RTC tick mode is 1 tick /sec. After 10 second , it should be return 10.         */
/*                                                                                                         */
/* DESCRIPTION                                                                                             */
/*               The function is used to get current Software tick count after enable tick interrupt.      */
//*--------------------------------------------------------------------------------------------------------*/
int32_t DrvRTC_GetIntTick()
{
   return g_u32RTC_Count;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvRTC_ResetIntTick                                                                       */
/*                                                                                                         */
/* Parameter:                                                                                              */
/*               None                                                                                      */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               None.                                                                                     */
/*                                                                                                         */
/* DESCRIPTION                                                                                             */
/*               The function is used to reset the tick count counting in interrupt                        */
//*--------------------------------------------------------------------------------------------------------*/
void DrvRTC_ResetIntTick()
{
   g_u32RTC_Count = 0;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvRTC_IsLeapYear                                                                         */
/*                                                                                                         */
/* Parameter:                                                                                              */
/*               None                                                                                      */
/* Returns:                                                                                                */
/*               1:  This year is LEAP year                                                                */
/*               0:  This year is NOT LEAP year                                                            */
/*                                                                                                         */
/* DESCRIPTION                                                                                             */
/*               According current time setting, return this is LEAP year or not.                          */
//*--------------------------------------------------------------------------------------------------------*/
int32_t DrcRTC_IsLeapYear()
{
	return (RTC->LIR.LIR == 0x1)?1:0;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvRTC_SetTickMode                                                                            */
/*                                                                                                         */
/* Parameters:        	                                                                                   */
/*               unMode[IN]	         the structure of DRVRTC_TICK. It is ued to set the RTC time           */
/*                                   tick period for Periodic Time Tick Interrupt request                  */
/*                                   It consists of                                                        */
/*                                      DRVRTC_TICK_1_SEC ~ DRVRTC_TICK_1_128_SEC                          */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               E_SUCCESS               Operation Successful                                              */
/*               E_DRVRTC_ERR_EIO        Access Enable failed                                              */
/*               E_DRVRTC_ERR_ENOTTY     Parameter is wrong                                                */
/*                                                                                                         */
/* Description:                                                                                            */
/*               TThe function is used to set time tick period for periodic time tick Interrupt.           */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvRTC_SetTickMode(uint8_t ucMode)
{
    g_u32RTC_Count = 0;
	
    if (DrvRTC_WriteEnable() != 0)              /* Write PASSWORD to access enable*/
    {
    	return E_DRVRTC_ERR_EIO ;
    }
    
	if (ucMode > DRVRTC_TICK_1_128_SEC)         /* Tick mode 0 to 7 */
    {
    	return E_DRVRTC_ERR_ENOTTY ;
    }
            
  	RTC->TTR.TTR = ucMode;            

	return E_SUCCESS;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvRTC_EnableInt                                                                          */
/*                                                                                                         */
/* Parameters:        	                                                                                   */
/*               str_IntSrc     Interrupt Source:  DRVRTC_TICK_INT / DRVRTC_ALARM_INT       			   */
/*               pfncallback    Callback function pointer                                                  */
/* Returns:                                                                                                */
/*               E_SUCCESS              Operation Successful                                               */
/*               E_DRVRTC_ERR_ENOTTY    Wrong Parameter                                                    */
/* Description:                                                                                            */
/*               This function is used to enable RTC specified interrupt and install callback function     */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvRTC_EnableInt(E_DRVRTC_INT_SOURCE str_IntSrc, PFN_DRVRTC_CALLBACK pfncallback)
{
	switch (str_IntSrc)
    {
    	case DRVRTC_TICK_INT:
        {
        	g_bIsEnableTickInt   	= TRUE;
   			RTC->RIER.TIER 			= 1; 
			g_pfnRTCCallBack_Tick  	= pfncallback;
   			break;
        }
        case DRVRTC_ALARM_INT:
        {
            g_bIsEnableAlarmInt  	= TRUE;
    		RTC->RIER.AIER 			= 1; 
			g_pfnRTCCallBack_Alarm 	= pfncallback;
            break;
        }
        default:
        {
            return E_DRVRTC_ERR_ENOTTY;
        }
    }

    NVIC_SetPriority(RTC_IRQn, (1<<__NVIC_PRIO_BITS) - 2);
	NVIC_EnableIRQ(RTC_IRQn); 

	return E_SUCCESS;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvRTC_DisableInt                                                                         */
/*                                                                                                         */
/* Parameters:        	                                                                                   */
/*               i32IntSrc  Interrupt Source:  DRVRTC_TICK_INT / DRVRTC_ALARM_INT /DRVRTC_ALL_INT          */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               None                                                                                      */
/*                                                                                                         */
/* Description:                                                                                            */
/*               This function is used to disable RTC specified interrupt and remove callback function     */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvRTC_DisableInt(E_DRVRTC_INT_SOURCE i32IntSrc)
{
	if ((i32IntSrc & DRVRTC_TICK_INT) == DRVRTC_TICK_INT)
	{
		g_bIsEnableTickInt  = FALSE;	
		RTC->RIER.TIER 		= 0; 
		RTC->RIIR.TIF 	    = 1; 
	}
	else if ((i32IntSrc & DRVRTC_ALARM_INT) == DRVRTC_ALARM_INT)
	{
        g_bIsEnableAlarmInt = FALSE;
    	RTC->RIER.AIER 		= 0; 
		RTC->RIIR.AIF 	    = 1; 
	}
	else
	{
		return E_DRVRTC_ERR_ENOTTY;
	}

	return E_SUCCESS;	
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function:     DrvRTC_Close                                                                              */
/*                                                                                                         */
/* Parameter:                                                                                              */
/*               None            							                                               */
/* Returns:                                                                                                */
/*               E_SUCCESS                Success.                                                         */
/*               E_DRVRTC_ERR_ENODEV      Interface number incorrect.                                      */
/*                                                                                                         */
/* DESCRIPTION                                                                                             */
/*               Disable NVIC channel of RTC and both tick and alarm interrupt..                           */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvRTC_Close(void)
{
    g_bIsEnableTickInt = FALSE;
    g_bIsEnableAlarmInt = FALSE;
    
  	NVIC_DisableIRQ(RTC_IRQn);
  
  	DrvRTC_DisableInt(DRVRTC_ALL_INT);
	
    return E_SUCCESS;
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvRTC_GetVersion                                                                             */
/*                                                                                                         */
/* Parameters:        	                                                                                   */
/*               None	                                                         						   */
/*                                                                                                         */
/* Returns:                                                                                                */
/*               The DrvRTC version number                                                                 */
/*                                                                                                         */
/* Description:                                                                                            */
/*               This function is used to get the DrvRTC version number                                    */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvRTC_GetVersion (void)
{
	return DRVRTC_VERSION_NUM;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -