Skip to content

Commit

Permalink
use H8_BITFIELD in places where it was missed
Browse files Browse the repository at this point in the history
  • Loading branch information
celerizer committed Dec 31, 2024
1 parent b05ff9a commit 885a35f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 70 deletions.
22 changes: 11 additions & 11 deletions registers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@
*/
typedef union
{
struct
{
H8_BITFIELD_8
(
/** Program */
h8_u8 p : 1;
h8_u8 p : 1,

/** Erase */
h8_u8 e : 1;
h8_u8 e : 1,

/** Program-Verify */
h8_u8 pv : 1;
h8_u8 pv : 1,

/** Erase-Verify */
h8_u8 ev : 1;
h8_u8 ev : 1,

/** Program Setup */
h8_u8 psu : 1;
h8_u8 psu : 1,

/** Erase Setup */
h8_u8 esu : 1;
h8_u8 esu : 1,

/** Software Write Enable */
h8_u8 swe : 1;
h8_u8 swe : 1,

/** Reserved */
h8_u8 r : 1;
} flags;
h8_u8 r : 1
) flags;
h8_byte_t raw;
} h8_flmcr1_t;

Expand Down
32 changes: 16 additions & 16 deletions rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ void h8_rtc_set(h8_rtc_t *rtc, const time_t time)
local_time = localtime(&ttime);

/* Update seconds */
rtc->rsecdr.co = local_time->tm_sec % 10;
rtc->rsecdr.ct = (h8_u8)local_time->tm_sec / 10;
rtc->rsecdr.bsy = 0;
rtc->rsecdr.flags.co = local_time->tm_sec % 10;
rtc->rsecdr.flags.ct = (h8_u8)local_time->tm_sec / 10;
rtc->rsecdr.flags.bsy = 0;

/* Update minutes */
rtc->rmindr.co = local_time->tm_min % 10;
rtc->rmindr.ct = (h8_u8)local_time->tm_min / 10;
rtc->rmindr.bsy = 0;
rtc->rmindr.flags.co = local_time->tm_min % 10;
rtc->rmindr.flags.ct = (h8_u8)local_time->tm_min / 10;
rtc->rmindr.flags.bsy = 0;

/* Update hours */
if (rtc->rtccr1.om)
if (rtc->rtccr1.flags.om)
{
/* Update in 24-hour mode */
rtc->rhrdr.co = local_time->tm_hour % 10;
rtc->rhrdr.ct = (h8_u8)local_time->tm_hour / 10;
rtc->rhrdr.flags.co = local_time->tm_hour % 10;
rtc->rhrdr.flags.ct = (h8_u8)local_time->tm_hour / 10;
}
else
{
Expand All @@ -33,20 +33,20 @@ void h8_rtc_set(h8_rtc_t *rtc, const time_t time)

if (trunctime >= 12)
{
rtc->rtccr1.pm = 1;
rtc->rtccr1.flags.pm = 1;
trunctime -= 12;
}
else
rtc->rtccr1.pm = 0;
rtc->rtccr1.flags.pm = 0;

rtc->rhrdr.co = trunctime % 10;
rtc->rhrdr.ct = (h8_u8)trunctime / 10;
rtc->rhrdr.flags.co = trunctime % 10;
rtc->rhrdr.flags.ct = (h8_u8)trunctime / 10;
}
rtc->rhrdr.bsy = 0;
rtc->rhrdr.flags.bsy = 0;

/* Update day of the week */
rtc->rwkdr.wk = (h8_u8)local_time->tm_wday;
rtc->rwkdr.bsy = 0;
rtc->rwkdr.flags.wk = (h8_u8)local_time->tm_wday;
rtc->rwkdr.flags.bsy = 0;
}

void h8_rtc_set_current(h8_rtc_t *rtc, const time_t offset)
Expand Down
86 changes: 43 additions & 43 deletions rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
*/
typedef union
{
struct
{
H8_BITFIELD_3
(
/**
* RTC Busy.
* This bit is set to 1 when the RTC is updating (operating) the values of
* second, minute, hour, and day-of-week data registers. When this bit is
* 0, the values of second, minute, hour, and day-of-week data registers
* must be adopted.
*/
h8_u8 bsy : 1;
h8_u8 bsy : 1,

/** Counting Ten's Position. Counts from 0-5. */
h8_u8 ct : 3;
h8_u8 ct : 3,

/** Counting One's Position. Counts from 0-9. */
h8_u8 co : 4;
};
h8_u8 bits;
h8_u8 co : 4
) flags;
h8_byte_t raw;
} h8_rsecdr_t;

/**
Expand All @@ -40,24 +40,24 @@ typedef union
*/
typedef union
{
struct
{
H8_BITFIELD_3
(
/**
* RTC Busy.
* This bit is set to 1 when the RTC is updating (operating) the values of
* second, minute, hour, and day-of-week data registers. When this bit is
* 0, the values of second, minute, hour, and day-of-week data registers
* must be adopted.
*/
h8_u8 bsy : 1;
h8_u8 bsy : 1,

/** Counting Ten's Position. Counts from 0-5. */
h8_u8 ct : 3;
h8_u8 ct : 3,

/** Counting One's Position. Counts from 0-9. */
h8_u8 co : 4;
};
h8_u8 bits;
h8_u8 co : 4
) flags;
h8_byte_t raw;
} h8_rmindr_t;

/**
Expand All @@ -68,27 +68,27 @@ typedef union
*/
typedef union
{
struct
{
H8_BITFIELD_4
(
/**
* RTC Busy.
* This bit is set to 1 when the RTC is updating (operating) the values of
* second, minute, hour, and day-of-week data registers. When this bit is
* 0, the values of second, minute, hour, and day-of-week data registers
* must be adopted.
*/
h8_u8 bsy : 1;
h8_u8 bsy : 1,

/** Reserved. This bit is always read as 0. */
h8_u8 r : 1;
h8_u8 r : 1,

/** Counting Ten's Position. Counts from 0-2. */
h8_u8 ct : 2;
h8_u8 ct : 2,

/** Counting One's Position. Counts from 0-9. */
h8_u8 co : 4;
};
h8_u8 bits;
h8_u8 co : 4
) flags;
h8_byte_t raw;
} h8_rhrdr_t;

enum
Expand All @@ -111,79 +111,79 @@ enum
*/
typedef union
{
struct
{
H8_BITFIELD_3
(
/**
* RTC Busy.
* This bit is set to 1 when the RTC is updating (operating) the values of
* second, minute, hour, and day-of-week data registers. When this bit is
* 0, the values of second, minute, hour, and day-of-week data registers
* must be adopted.
*/
h8_u8 bsy : 1;
h8_u8 bsy : 1,

/** Reserved. These bits are always read as 0. */
h8_u8 r : 4;
h8_u8 r : 4,

/** Day-of-Week Counting. Counts from 0-6. */
h8_u8 wk : 3;
};
h8_u8 bits;
h8_u8 wk : 3
) flags;
h8_byte_t raw;
} h8_rwkdr_t;

enum
{
H8_RTC_12H = 0,
H8_RTC_24H
H8_RTC_24H = 1
};

/**
* RTCCR1 controls start/stop and reset of the clock timer.
*/
typedef union
{
struct
{
H8_BITFIELD_6
(
/** RTC Operation Start. Represents whether RTC is active. */
h8_u8 run : 1;
h8_u8 run : 1,

/** Operating Mode. Using 24H mode when set. */
h8_u8 om : 1;
h8_u8 om : 1,

/** AM/PM. Set when after noon in 12H mode. */
h8_u8 pm : 1;
h8_u8 pm : 1,

/**
* Reset. Resets registers and control circuits except RTCCSR and this
* bit. Clear this bit to 0 after having been set to 1.
*/
h8_u8 rst : 1;
h8_u8 rst : 1,

/** Interrupt Occurrence Timing. @todo */
h8_u8 intr : 1;
h8_u8 intr : 1,

/** Reserved. These bits are always read as 0. */
h8_u8 r : 3;
};
h8_u8 bits;
h8_u8 r : 3
) flags;
h8_byte_t raw;
} h8_rtccr1_t;

/** RTCCR2. @todo Not particularly needed for an emulator. */
typedef union
{
h8_u8 bits;
h8_byte_t raw;
} h8_rtccr2_t;

/** RTCCSR. @todo Not particularly needed for an emulator. */
typedef union
{
h8_u8 bits;
h8_byte_t raw;
} h8_rtccsr_t;

/** RTCFLG. @todo Not particularly needed for an emulator. */
typedef union
{
h8_u8 bits;
h8_byte_t raw;
} h8_rtcflg_t;

typedef struct
Expand Down

0 comments on commit 885a35f

Please sign in to comment.