rtc.c value overflow check?

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For usage of internal RTC on Due (SAM3X), (under packages/arduino/sam/(version)/system/libsam/source) there is a c file named rtc.c.

 

Under that c file, is a function named RTC_SetTime.

 

On line 175, it checks for "value overflow" according to the note.

 

But I am not sure what sort of overflow it's looking for.

 

The line of code :

 

if ( (ucHour_bcd & (uint8_t)(~RTC_HOUR_BIT_LEN_MASK)) |
     (ucMin_bcd & (uint8_t)(~RTC_MIN_BIT_LEN_MASK)) |
     (ucSec_bcd & (uint8_t)(~RTC_SEC_BIT_LEN_MASK)))
{
    return 1 ;
}

where hour minute and second are represented in BCD, and RTC_HOUR_BIT_LEN_MASK = 0x3F, and MIN&SEC bitmask are 7F. 

 

The question is, what sort of overflow it is trying to detect? 

 

Minutes, for instance, 0x7F = 0111/1111. ~0x7F = 1000/0000. 

 

I understand it is an overflow detection based off the datasheet (8bit being unused), but what if the user tries to set the minute to 61(= 0110/0001 )?It passes the overflow test and goes straight to the register. Does SAM have a separate validation check on the background?

 

 

Last Edited: Fri. Sep 16, 2022 - 08:08 AM