/*------------------------------------------------ initialize --------------------------------------------------*/ void InitAlarm(void) { ALARMSTRUCT item; PALARMSTRUCT pitem; int jihou; clear_list(m_pAlarm); m_pAlarm = NULL; jihou = 0; if(GetMyRegLong("", "Jihou", FALSE)) jihou = 1; // read settings m_pAlarm = LoadAlarm(); // common/alarmstruct.c // cuckoo clock if(jihou) { memset(&item, 0, sizeof(ALARMSTRUCT)); strcpy(item.name, "cuckoo"); strcpy(item.strHours, "*"); strcpy(item.strMinutes, "0"); strcpy(item.strWDays, "*"); SetAlarmTime(&item); // common/alarmstruct.c item.bEnable = TRUE; item.bHour12 = TRUE; GetMyRegStr("", "JihouFile", item.fname, MAX_PATH, ""); if(GetMyRegLong("", "JihouRepeat", FALSE)) item.bRepeatJihou = TRUE; if(GetMyRegLong("", "JihouBlink", FALSE)) { item.bBlink = TRUE; item.nBlinkSec = 60; } m_pAlarm = copy_listitem(m_pAlarm, &item, sizeof(item)); } m_bCheckEverySeconds = FALSE; pitem = m_pAlarm; while(pitem) { if(pitem->bEnable) { if(pitem->second) m_bCheckEverySeconds = TRUE; else if(pitem->bInterval) { if(!pitem->bBootExec) pitem->tickLast = GetTickCount(); m_bCheckEverySeconds = TRUE; } if(pitem->bResumeExec) m_bCheckEverySeconds = TRUE; } pitem = pitem->next; } }
//这2个函数可以放在lib中,...结束 VOID RtcCtrlInit(VOID) { #ifdef FUNC_UARTDBG_EN BYTE i; #endif #ifdef FUNC_ALARM_EN extern BYTE GetRtcCurAlarmNum(VOID); InitRtc(gAlarmList, sizeof(gAlarmList) / sizeof(AlARM_INFO)); gCurAlarmNum = GetRtcCurAlarmNum(); //0表示没有闹钟 DBG(("gCurAlarmNum:%02BX\n", gCurAlarmNum)); #else InitRtc(NULL, 0); // 该函数必须调用 #endif RtcState = RTC_STATE_IDLE; RtcSubState = RTC_SET_NONE; RtcUpdateDisplay = FALSE; RtcFlag = 1; RtcAutOutTimeCount = 0; TimeOutSet(&RtcReadTimer, 0); TimeOutSet(&RtcSetCntTimer, 0); #ifdef FUNC_ALARM_EN #ifdef FUNC_BREAK_POINT_EN BP_SaveInfo((BYTE *)&gBreakPointInfo.PowerMemory.AlarmList2Store, sizeof(gBreakPointInfo.PowerMemory.AlarmList2Store)); #endif #ifdef FUNC_UARTDBG_EN for(i = 0; i < MAX_ALARM_NUM; i++) { DBG(("gpAlarmList[%bu].AlarmMode:%bx,", i, gAlarmList[i].AlarmMode)); DBG(("gAlarmList[%bu].AlarmTimeAsSeconds:%lu,", i, gAlarmList[i].AlarmTimeAsSeconds)); DBG(("gAlarmList[%bu].AlarmStatus:%bx\n", i, gAlarmList[i].AlarmStatus)); } #endif #ifdef AU6210K_CAR_MODEL_DEMO DBG(("InitRtc2\n")); RtcSourceState = RTC_SOURCE_CLOCK; DBG(("RtcSourceState=%bu\n", RtcSourceState)); if(GetAlarmStatus(RtcAlarmNum)) { gAlarmState = ALARM_STATUS_OPEN; DBG(("gAlarmState= ALARM_STATUS_OPEN\n")); } else { gAlarmState = ALARM_STATUS_CLOSE; DBG(("gAlarmState= ALARM_STATUS_CLOSE\n")); } #endif #ifdef AU6210K_BOOMBOX_DEMO if(GetAlarmStatus(1)) { gAlarm1State = ALARM_STATUS_OPEN; DBG(("gAlarm1State= ALARM1_STATUS_OPEN\n")); } else { gAlarm1State = ALARM_STATUS_CLOSE; DBG(("gAlarm1State= ALARM1_STATUS_CLOSE\n")); } if(GetAlarmStatus(2)) { gAlarm2State = ALARM_STATUS_OPEN; DBG(("gAlarm2State= ALARM2_STATUS_OPEN\n")); } else { gAlarm2State = ALARM_STATUS_CLOSE; DBG(("gAlarm2State= ALARM2_STATUS_CLOSE\n")); } #endif #endif // //测试用,客户根据实际情况设置。 // gRtcTime.Year = 1980; // gRtcTime.Mon = 1; // gRtcTime.Date = 1; // gRtcTime.WDay = 1; // 0:星期日 // gRtcTime.Hour = 7; // gRtcTime.Min = 0; // gRtcTime.Sec = 0; // SetRTCCurrTime(&gRtcTime); // gAlarmTime.Year = 1980; // gAlarmTime.Mon = 1; // gAlarmTime.Date = 1; // gAlarmTime.WDay = 1; // gAlarmTime.Hour = 8; // gAlarmTime.Min = 0; // gAlarmTime.Sec = 0; // gAlarmMode = ALARM_MODE_ONCE_ONLY; // SetAlarmTime(RtcAlarmNum, gAlarmMode, &gAlarmTime); #ifdef AU6210K_BOOMBOX_DEMO gRtcTime.Hour = 12; gRtcTime.Min = 0; gRtcTime.Sec = 0; SetRTCCurrTime(&gRtcTime); gAlarmTime.Hour = 0; gAlarmTime.Min = 0; gAlarmTime.Sec = 0; gAlarmMode = ALARM_MODE_PER_DAY; SetAlarmTime(1, gAlarmMode, &gAlarmTime); SetAlarmTime(2, gAlarmMode, &gAlarmTime); #endif }
//如果有和此函数类似用法(嵌入到各个模式)的函数位于其后,此函数不要有default,防止拦截后者有用的消息 VOID RtcMsgPro(BYTE Msg) { if(RtcState == RTC_STATE_IDLE) { #ifdef AU6210K_CAR_MODEL_DEMO if((Msg != MSG_NONE) && (gAlarmOnFlag == TRUE)) { gAlarmOnFlag = FALSE; } #endif switch(Msg) { #ifdef AU6210K_CAR_MODEL_DEMO case MSG_REPEAT: #endif #ifdef AU6210K_BOOMBOX_DEMO case MSG_CLOCK: #endif case MSG_RTC_SET: DBG(("RTC_SET\n")); RtcFlag = 1; RtcUpdateDisplay = TRUE; RtcAutOutTimeCount = RTC_AUTO_OUT_TIME_COUNT; #ifdef AU6210K_BOOMBOX_DEMO RtcSubState = RTC_SET_HR; RtcState = RTC_STATE_SET_TIME; break; #endif RtcState = RTC_STATE_SET_TIME; RtcSubState = RTC_SET_NONE; #ifdef AU6210K_CAR_MODEL_DEMO if(Msg == MSG_REPEAT) #else if(Msg == MSG_RTC_SET) #endif { gRtcRdWrFlag = SET_RTC_TIME_YEAR; } else { gRtcRdWrFlag = READ_RTC_TIME; } RtcNextSubState(); break; #ifdef FUNC_ALARM_EN #ifdef AU6210K_BOOMBOX_DEMO case MSG_ALARM1_SET: case MSG_ALARM2_SET: #endif case MSG_ALARM_SET: #ifndef AU6210K_CAR_MODEL_DEMO DBG(("ALARM_SET\n")); RtcFlag = 2; RtcUpdateDisplay = TRUE; RtcAutOutTimeCount = RTC_AUTO_OUT_TIME_COUNT; #ifdef AU6210K_BOOMBOX_DEMO if(Msg == MSG_ALARM1_SET) { RtcAlarmNum = 1; } else if(Msg == MSG_ALARM2_SET) { RtcAlarmNum = 2; } #endif if((RtcAlarmNum > 0) && (RtcAlarmNum <= MAX_ALARM_NUM)) { gAlarmMode = GetAlarmTime(RtcAlarmNum, &gAlarmTime); if((gAlarmMode < ALARM_MODE_ONCE_ONLY) || (gAlarmMode > ALARM_MODE_PER_WEEK)) { gAlarmMode = ALARM_MODE_PER_DAY; } CheckAlarmTime(RtcAlarmNum, gAlarmMode, &gAlarmTime); } else { DBG(("闹钟错误\n")); } #ifdef AU6210K_BOOMBOX_DEMO RtcSubState = RTC_SET_HR; RtcState = RTC_STATE_SET_ALARM; break; #endif RtcState = RTC_STATE_SET_ALARM; RtcSubState = RTC_SET_NONE; RtcNextSubState(); #endif #endif break; default: break; } } else if(RtcState == RTC_STATE_SET_TIME) { switch(Msg) { #ifdef AU6210K_CAR_MODEL_DEMO case MSG_PRE: #endif #ifdef AU6210K_BOOMBOX_DEMO case MSG_PREV1: #endif case MSG_RTC_DOWN: DBG(("RTC_DOWN\n")); RtcUpdateDisplay = TRUE; GetRTCCurrTime(&gRtcTime); RtcTimeDown(&gRtcTime); SetRTCCurrTime(&gRtcTime); RtcAutOutTimeCount = RTC_AUTO_OUT_TIME_COUNT; break; #ifdef AU6210K_CAR_MODEL_DEMO case MSG_NEXT: #endif #ifdef AU6210K_BOOMBOX_DEMO case MSG_NEXT1: #endif case MSG_RTC_UP: DBG(("RTC_UP\n")); RtcUpdateDisplay = TRUE; GetRTCCurrTime(&gRtcTime); RtcTimeUp(&gRtcTime); SetRTCCurrTime(&gRtcTime); RtcAutOutTimeCount = RTC_AUTO_OUT_TIME_COUNT; break; #ifdef AU6210K_CAR_MODEL_DEMO case MSG_PLAY_PAUSE: #endif #ifdef AU6210K_BOOMBOX_DEMO case MSG_CLOCK: #endif case MSG_RTC_SW: DBG(("RTC_SW\n")); #ifdef AU6210K_BOOMBOX_DEMO if(RtcSubState == RTC_SET_MIN) { RtcState = RTC_STATE_IDLE; RtcSubState = RTC_SET_NONE; RtcAutOutTimeCount = 0; break; } #endif RtcUpdateDisplay = TRUE; RtcNextSubState(); RtcAutOutTimeCount = RTC_AUTO_OUT_TIME_COUNT; break; default: break; } if(TRUE == RtcAlarmSetWaitTime()) { //这样设置时间是因为SetRtcRefcnt函数有延时如果此时在播放mp3按键有卡声音 if(gRtcRdWrFlag != READ_RTC_TIME) { SetRTCCurrTime(&gRtcTime); } } } #ifdef FUNC_ALARM_EN else if(RtcState == RTC_STATE_SET_ALARM) { switch(Msg) { #ifdef AU6210K_CAR_MODEL_DEMO case MSG_PRE: #endif #ifdef AU6210K_BOOMBOX_DEMO case MSG_PREV1: #endif case MSG_RTC_DOWN: DBG(("ALARM RTC_DOWN\n")); RtcUpdateDisplay = TRUE; RtcTimeDown(&gAlarmTime); CheckAlarmTime(RtcAlarmNum, gAlarmMode, &gAlarmTime); SetAlarmTime(RtcAlarmNum, gAlarmMode, &gAlarmTime); RtcAutOutTimeCount = RTC_AUTO_OUT_TIME_COUNT; #ifdef FUNC_BREAK_POINT_EN BP_SaveInfo((BYTE*)&gBreakPointInfo.PowerMemory.AlarmList2Store, sizeof(gBreakPointInfo.PowerMemory.AlarmList2Store)); #endif break; #ifdef AU6210K_CAR_MODEL_DEMO case MSG_NEXT: #endif #ifdef AU6210K_BOOMBOX_DEMO case MSG_NEXT1: #endif case MSG_RTC_UP: DBG(("ALARM RTC_UP\n")); RtcUpdateDisplay = TRUE; RtcTimeUp(&gAlarmTime); CheckAlarmTime(RtcAlarmNum, gAlarmMode, &gAlarmTime); SetAlarmTime(RtcAlarmNum, gAlarmMode, &gAlarmTime); RtcAutOutTimeCount = RTC_AUTO_OUT_TIME_COUNT; #ifdef FUNC_BREAK_POINT_EN BP_SaveInfo((BYTE*)&gBreakPointInfo.PowerMemory.AlarmList2Store, sizeof(gBreakPointInfo.PowerMemory.AlarmList2Store)); #endif break; #ifdef AU6210K_CAR_MODEL_DEMO case MSG_PLAY_PAUSE: #endif #ifdef AU6210K_BOOMBOX_DEMO case MSG_ALARM1_SET: case MSG_ALARM2_SET: #endif case MSG_RTC_SW: DBG(("ALARM SW\n")); #ifdef AU6210K_BOOMBOX_DEMO if(((RtcAlarmNum == 1) && (Msg != MSG_ALARM1_SET)) || ((RtcAlarmNum == 2) && (Msg != MSG_ALARM2_SET))) { break; } if(RtcSubState == RTC_SET_ALARM_VOLUME) { RtcState = RTC_STATE_IDLE; RtcSubState = RTC_SET_NONE; RtcAutOutTimeCount = 0; break; } #endif RtcUpdateDisplay = TRUE; RtcNextSubState(); RtcAutOutTimeCount = RTC_AUTO_OUT_TIME_COUNT; break; default: break; } if(TRUE == RtcAlarmSetWaitTime()) { DBG(("EXIT RTC_STATE_SET_TIME!\n")); RtcState = RTC_STATE_IDLE; RtcSubState = RTC_SET_NONE; RtcFlag = 1; } } #endif #ifdef AU6210K_CAR_MODEL_DEMO else if(RtcState == RTC_STATE_SET_SOURCE) { switch(Msg) { case MSG_PRE: DBG(("RTC SOURCE_DOWN\n")); RtcUpdateDisplay = TRUE; RtcSourceDown(); RtcAutOutTimeCount = RTC_AUTO_OUT_TIME_COUNT; break; case MSG_NEXT: DBG(("RTC SOURCE_UP\n")); RtcUpdateDisplay = TRUE; RtcSourceUp(); RtcAutOutTimeCount = RTC_AUTO_OUT_TIME_COUNT; break; case MSG_REPEAT: DBG(("RTC SOURCE_Enter\n")); RtcUpdateDisplay = TRUE; RtcSourceEnter(); RtcAutOutTimeCount = RTC_AUTO_OUT_TIME_COUNT; break; default: break; } if(TRUE == RtcAlarmSetWaitTime()) { DBG(("EXIT RTC_STATE_SET_SOURCE!\n")); RtcState = RTC_STATE_IDLE; RtcSubState = RTC_SET_NONE; RtcFlag = 1; } } #endif }