//******************************************************************* // IRIS-SUBPモニタプログラム RTC関数 //******************************************************************* #include "IrisSubpMon.h" //--------------------- グローバル 変数 ------------------------------- //====================================================================== // RTC初期化 & リード(共用ワークRAM使用) //====================================================================== void InitRtc(void) { SharedWork *shwp = GetSharedWorkAddr(); SecureWork *scwp = GetSecureWorkAddr(); u8 rtcInitBuf[8]; u8 rtcSendIPL2Buf[8]; rtcInitBuf[0] = ReadRtcStatus1(); // RTCステータス1 チェック SendRtcOp(RTCOP_READ | RTCOP_YEAR | RTCOP_FIX_BITS); // RTC(年:月:日:曜日:時:分:秒)読み込み RecvRtcDataBuf(&rtcInitBuf[1], 7); if (rtcInitBuf[0] & (RTCSTAT1_RESET_REQUEST | RTCSTAT1_BATTERY_DOWN)) { rtcInitBuf[0] |= RTCSTAT1_RESET; // RTCリセット要求&パワーダウン対応 SendRtcOp(RTCOP_WRITE | RTCOP_STAT1 | RTCOP_FIX_BITS); SendRtcDataBuf(&rtcInitBuf[0], 1); } rtcSendIPL2Buf[0] = rtcInitBuf[0]; // RTCステータス1 コピー SendRtcOp(RTCOP_READ | RTCOP_YEAR | RTCOP_FIX_BITS); // RTC(年:月:日:曜日:時:分:秒)読み込み RecvRtcDataBuf(&rtcSendIPL2Buf[1], 7); // RTCエラーチェック(ステータス1 & 月データ) if ((ReadRtcStatus1() & (RTCSTAT1_RESET_REQUEST | RTCSTAT1_RESET)) || !rtcSendIPL2Buf[2]) shwp->rtcError = 1; // RTCリードデータ IPL2 へ通知 CpuCopyFast32(&rtcSendIPL2Buf, &shwp->recvRtc, sizeof(rtcSendIPL2Buf)); // RTC初期データ セキュアワークへコピー CpuCopyFast32(&rtcInitBuf, &scwp->recvRtcBuf, sizeof(rtcInitBuf)); } //---------------------------------------------------------------------- // R1レジスタ・アクセスウェイト //---------------------------------------------------------------------- __inline void WaitRtcFor5us(void) { WaitByLoop(200/4); } //---------------------------------------------------------------------- // コマンド送信 //---------------------------------------------------------------------- void SendRtcData(u32 data); u8 RecvRtcData(void); void SendRtcOp(u32 op) { int i; *(vu8 *)REG_R1_CNT = 1 // クロックHI | R1_RTC_DATA_DIR_OUT | R1_RTC_SCK; WaitRtcFor5us(); *(vu8 *)REG_R1_CNT = 1 // チップイネーブル | R1_RTC_DATA_DIR_OUT | R1_RTC_CS | R1_RTC_SCK; WaitRtcFor5us(); SendRtcData(op); } //---------------------------------------------------------------------- // データ送信(1Byte) //---------------------------------------------------------------------- void SendRtcData(u32 data) { int i; for (i=0; i<8; i++) { u32 dataBit = (data >>7) & R1_RTC_DATA_BIT; *(vu8 *)REG_R1_CNT = dataBit | R1_RTC_DATA_DIR_OUT | R1_RTC_CS; WaitRtcFor5us(); *(vu8 *)REG_R1_CNT = dataBit | R1_RTC_DATA_DIR_OUT | R1_RTC_CS | R1_RTC_SCK; WaitRtcFor5us(); data <<= 1; } } //---------------------------------------------------------------------- // データバッファ送信 //---------------------------------------------------------------------- void SendRtcDataBuf(u8 *srcp, s32 count) { u8 *srcEndp = srcp + count; while (srcp < srcEndp) { SendRtcData(*srcp++); } *(vu8 *)REG_R1_CNT = R1_RTC_DATA_DIR_IN // チップディセーブル | R1_RTC_SCK; WaitRtcFor5us(); } //---------------------------------------------------------------------- // データバッファ受信 //---------------------------------------------------------------------- void RecvRtcDataBuf(u8 *destp, s32 count) { u8 *destEndp = destp + count; while (destp < destEndp) { u8 data = 0; int i; for (i=0; i<8; i++) { *(vu8 *)REG_R1_CNT = R1_RTC_DATA_DIR_IN | R1_RTC_CS; WaitRtcFor5us(); *(vu8 *)REG_R1_CNT = R1_RTC_DATA_DIR_IN | R1_RTC_CS | R1_RTC_SCK; WaitRtcFor5us(); data |= (*(vu8 *)REG_R1_CNT & R1_RTC_DATA_BIT) <