byte MCP7941x::setStatus( byte regadr, byte val ) { writeClock( regadr ); Wire.write( val ); errCode = Wire.endTransmission( ); if( errCode != 0 ) return RTC_ST_WR_ERR; return RTC_OK; } // setStatus - single byte
byte MCP7941x::setStatus( byte regadr, byte cnt, byte *setS ) { writeClock( regadr ); for( byte ix = 0; ix < cnt; ix++ ) Wire.write( setS[ix] ); errCode = Wire.endTransmission( ); if( errCode != 0 ) return RTC_ST_WR_ERR; return RTC_OK; } // setStatus - block
byte MCP7941x::setAlarm( byte almNr, byte *setA ) { writeClock( mcAlarm+almNr*7 ); for( byte ix = 0; ix < 6; ix++ ) Wire.write( setA[ix] ); errCode = Wire.endTransmission( ); if( errCode == 0 ) { return RTC_OK; } else { return RTC_AL_WR_ERR; } } // setAlarm
byte DS3231::setStatus( byte regadr, byte cnt, byte *setS ) { writeClock( regadr ); for( byte ix = 0; ix < cnt; ix++ ) Wire.write( setS[ix] ); errCode = Wire.endTransmission( ); if( errCode == 0 ) { return RTC_OK; } else { return RTC_ST_WR_ERR; } } // setStatus - array of bytes
byte DS3231::setAlarm( byte almNr, byte *setA ) { writeClock( dsAlarm+4*almNr ); if( almNr == 0 ) for( byte ix = 0; ix < 4; ix++ ) Wire.write( setA[ix] ); if( almNr == 1 ) for( byte ix = 0; ix < 3; ix++ ) Wire.write( setA[ix] ); errCode = Wire.endTransmission( ); if( errCode == 0 ) { return RTC_OK; } else { return RTC_AL_WR_ERR; } } // setAlarm
byte MCP7941x::setTime( Time &setT ) { writeClock( mcTime ); // setup writing to time registers Wire.write( setT.sec | 0x80 ); // fill in the time values Wire.write( setT.min ); Wire.write( setT.hr ); errCode = Wire.endTransmission( ); // send to chip if( errCode == 0 ) { return RTC_OK; } else { return RTC_TM_WR_ERR; } } // setTime
byte DS3231::setTime( Time &setT ) { writeClock( dsTime ); // setup writing to time registers Wire.write( setT.sec ); Wire.write( setT.min ); Wire.write( setT.hr ); errCode = Wire.endTransmission( ); if( errCode == 0 ) { return RTC_OK; } else { return RTC_TM_WR_ERR; } } // setTime
byte MCP7941x::setDate( Date &setD ) { writeClock( mcDate ); // setup writing to date registers Wire.write( setD.dow ); // fill in date values Wire.write( setD.dom ); Wire.write( setD.mo ); Wire.write( setD.yr ); errCode = Wire.endTransmission( ); //send to chip if( errCode == 0 ) { return RTC_OK; } else { return RTC_DT_WR_ERR; } } // setDate
byte DS3231::setDate( Date &setD ) { writeClock( dsDate ); // setup writing to date registers Wire.write( setD.dow ); Wire.write( setD.dom ); Wire.write( setD.mo ); Wire.write( setD.yr ); errCode = Wire.endTransmission( ); if( errCode == 0 ) { return RTC_OK; } else { return RTC_DT_WR_ERR; } } // setDate
if(xTaskGetTickCount()-saveDRequest>(TIMEDELAYREQUEST/portTICK_RATE_MS)){ saveDRequest=xTaskGetTickCount(); delayRequest(); } #endif } void printfClock(Clock clock){ if(clock.sign==true){ pc.printf("%lu s,%u\r\n",clock.second,(unsigned int)clock.halfmillis); } else{ pc.printf("-%lu s,%u\r\n",clock.second,(unsigned int)clock.halfmillis); } } void updateClock(void){ Clock diff; if(timeProt.correction.previousSignOffset==timeProt.offset.sign){ timeProt.correction.previousSignOffset=timeProt.offset.sign; timeProt.correction.previoustimeOffset.second=timeProt.correction.currentTimeOffsetSync.second; timeProt.correction.previoustimeOffset.halfmillis=timeProt.correction.currentTimeOffsetSync.halfmillis; readClock(&timeProt.correction.currentTimeOffsetSync); if(timeProt.correction.previoustimeOffset.second!=0){ if(sup(timeProt.correction.currentTimeOffsetSync,timeProt.correction.previoustimeOffset)){ diff=subClock(timeProt.correction.currentTimeOffsetSync,timeProt.correction.previoustimeOffset); //printf("diff: "); //printfClock(diff); timeProt.correction.sumTime=sumClock(timeProt.correction.sumTime,diff); sumOffset=sumClock(sumOffset,timeProt.offset); /*printf("sumOffset: "); printfClock(sumOffset); printf("sumClock: "); printfClock(timeProt.correction.sumTime); printf("nb corrr : %d",timeProt.correction.nbCorrection); */ timeProt.correction.nbCorrection++; } else{ resetSofftwareCorrection(); } } } else{ resetSofftwareCorrection(); } timeProt.correction.previousSignOffset=timeProt.offset.sign; Clock timeCopy;
if(xTaskGetTickCount()-saveDRequest>(TIMEDELAYREQUEST/portTICK_RATE_MS)){ saveDRequest=xTaskGetTickCount(); delayRequest(); } #endif } void printfClock(Clock clock){ if(clock.sign==true){ hmi.printf("%lu s,%u\r\n",clock.second,(unsigned int)clock.halfmillis); } else{ hmi.printf("-%lu s,%u\r\n",clock.second,(unsigned int)clock.halfmillis); } } void updateClock(void){ Clock diff; if(timeProt.correction.previousSignOffset==timeProt.offset.sign){ timeProt.correction.previousSignOffset=timeProt.offset.sign; timeProt.correction.previoustimeOffset.second=timeProt.correction.currentTimeOffsetSync.second; timeProt.correction.previoustimeOffset.halfmillis=timeProt.correction.currentTimeOffsetSync.halfmillis; readClock(&timeProt.correction.currentTimeOffsetSync); if(timeProt.correction.previoustimeOffset.second!=0){ if(sup(timeProt.correction.currentTimeOffsetSync,timeProt.correction.previoustimeOffset)){ diff=subClock(timeProt.correction.currentTimeOffsetSync,timeProt.correction.previoustimeOffset); //printf("diff: "); //printfClock(diff); timeProt.correction.sumTime=sumClock(timeProt.correction.sumTime,diff); sumOffset=sumClock(sumOffset,timeProt.offset); /*printf("sumOffset: "); printfClock(sumOffset); printf("sumClock: "); printfClock(timeProt.correction.sumTime); printf("nb corrr : %d",timeProt.correction.nbCorrection); */ timeProt.correction.nbCorrection++; } else{ resetSofftwareCorrection(); } } } else{ resetSofftwareCorrection(); } timeProt.correction.previousSignOffset=timeProt.offset.sign; Clock timeCopy; readClock(&timeCopy); timeCopy=sumClock(timeCopy,timeProt.offset);//add offset writeClock(timeCopy); uint8_t state; state=stateLed; report(timeProt.offset); if(timeManage.halfmillis<(RTC_FREQ/2)){//all 500ms stateLed=LOW; } else{ stateLed=HIGH;