0


I want to log my embedded system start time and date in to memory. here I want to know that there is any standard to save datetime stamp within 4 bytes.
The system is worked on arm7 with free rtos. The board contains RTC
Thanks.

Saru
  • 15
  • 1
  • 4
  • 2
    http://en.wikipedia.org/wiki/Unix_time – Mics Aug 06 '14 at 05:56
  • Do your system have any kind of operating system? Does it have any functionality to get the current time (like the [`time`](http://en.cppreference.com/w/c/chrono/time) function)? What is the size of the data type returned by that function? Is it four bytes or less? Then you have your solution. – Some programmer dude Aug 06 '14 at 06:00
  • If you *don't* have any operating system, but run on the "bare metal", then you could read the real-time clock directly and format the date and time in just any way you please. – Some programmer dude Aug 06 '14 at 06:02
  • @JoachimPileborg And even if one has an operating system, one could still get RTC time. – askmish Aug 06 '14 at 06:13
  • The system is worked on arm7 with free rtos. The board contains RTC – Saru Aug 06 '14 at 06:17

2 Answers2

2

The structures below show three methods of storing time and date within 4 bytes (or 32 bits).

#pragma pack(1)
typedef struct TIMESTAMP_32_A_S
   {
   uint8_t   seconds    : 6; // 0-60 (0-63 max)
   uint8_t   minutes    : 6; // 0-60 (0-63 max)
   uint8_t   hours24    : 5; // 0-23 (0-31 max)
   uint8_t   dayOfMonth : 5; // 1-31 (0-31 max)
   uint8_t   month      : 4; // 1-12 (0-15 max)
   uint8_t   year       : 6; // Epoch start: 2014, Range: 2014 thru 2077
   } TIMESTAMP_32_A_T;                                                  
#pragma pack()

The structure above assumes that the granularity of seconds is important to the application. It also assumes that the application will not be executed prior to the year 2014, or after the year 2077 (at which time, year will roll back to 2014).

#pragma pack(1)
typedef struct TIMESTAMP_32_B_S
   {
   uint8_t   minutes    : 6; // 0-60 (0-63 max)
   uint8_t   hours24    : 5; // 0-23 (0-31 max)
   uint8_t   dayOfMonth : 5; // 1-31 (0-31 max)
   uint8_t   month      : 4; // 1-12 (0-15 max)
   uint16_t  year       : 12; // Epoch start: 2014, Range: 2014 thru 4061
   } TIMESTAMP_32_B_T;
#pragma pack()

The structure above assumes that seconds are irrelevant to the application. It also assumes that the application will not be executed prior to the year 2014, or after the year 4061 (at which time, year will roll back to 2014).

#pragma pack(1)
typedef struct TIMESTAMP_32_C_S
   {
   uint8_t   secondsBy2 : 5; // 0-30 (0-31 max)
   uint8_t   minutes    : 6; // 0-60 (0-63 max)
   uint8_t   hours24    : 5; // 0-23 (0-31 max)
   uint8_t   dayOfMonth : 5; // 1-31 (0-31 max)
   uint8_t   month      : 4; // 1-12 (0-15 max)
   uint8_t   year       : 7; // Epoch start: 2014, Range: 2014 thru 2141
   } TIMESTAMP_32_C_T;
#pragma pack()

The structure above assumes that a seconds granularity of 2-second intervals are is sufficient to the application. It also assumes that the application will not be executed prior to the year 2014, or after the year 2141 (at which time, year will roll back to 2014). MSDOS used a similar structure.

Mahonri Moriancumer
  • 5,993
  • 2
  • 18
  • 28
0

You can measure the seconds since specific time, like stated here.

For example, measuring seconds since 1970 will provide range until year 2038.

If you measure secs since 2021, it will provide you range for up to 2089.

AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277