Skip to content

Commit

Permalink
Fix the project on MacOS (#97)
Browse files Browse the repository at this point in the history
* Fix filename conflict on MacOS
See qemu/qemu@75eebe0

* Fix PUSH action for the encoder

* Fix struct f2xx_rtc cross-platform compatibility

The struct used the time_t to store target's ticks. However,
this datatype can (and has) a different size on different hosting platforms.

This commit makes sure we use the same datatype across platforms
for representing target's ticks.

NOTE: This commit may break VM states.
  • Loading branch information
dragomirecky authored Dec 2, 2021
1 parent 511f882 commit 808b288
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hw/arm/prusa/parts/encoder_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static int encoder_input_process_action(P404ScriptIF *obj, unsigned int action,
break;
}
case ACT_PUSH:
encoder_input_handle_key(P404_KEYCLIENT(obj), 0x13);
encoder_input_handle_key(P404_KEYCLIENT(obj), 0xd);
break;
case ACT_RESET:
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
Expand Down
11 changes: 6 additions & 5 deletions hw/arm/prusa/stm32f407/stm32f2xx_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ f2xx_rtc_compute_target_time_from_host_time(f2xx_rtc *s, uint64_t rtc_period_ns,

// Return the current date and time as stored in the RTC TR and DR registers in two forms:
// By filling in the passed in tm struct and by returning the UTC time in seconds.
static time_t
static uint64_t
f2xx_rtc_get_current_target_time(f2xx_rtc *s, struct tm *target_tm)
{
memset(target_tm, 0, sizeof(*target_tm));
Expand All @@ -177,15 +177,15 @@ f2xx_rtc_get_current_target_time(f2xx_rtc *s, struct tm *target_tm)
target_tm->tm_year = from_bcd((date_reg & 0x00FF0000) >> 16) + 100;

// Have mktime fill in the remaining fields and return the UTC seconds as well
return mktimegm(target_tm);
return (uint64_t)mktimegm(target_tm);
}



// Compute the host to target offset based on the passed in target ticks and the current
// host time.
static int64_t
f2xx_rtc_compute_host_to_target_offset(f2xx_rtc *s, int64_t period_ns, time_t target_ticks)
f2xx_rtc_compute_host_to_target_offset(f2xx_rtc *s, int64_t period_ns, uint64_t target_ticks)
{
// Convert target ticks to real clock microseconds
int64_t target_time_us = target_ticks * period_ns / 1000;
Expand Down Expand Up @@ -481,7 +481,8 @@ f2xx_update_current_date_and_time(void *arg)
} else {
while (s->ticks != new_target_ticks) {
s->ticks += 1;
gmtime_r(&s->ticks, &new_target_tm);
time_t host_ticks = (time_t)s->ticks;
gmtime_r(&host_ticks, &new_target_tm);
f2xx_rtc_set_time_and_date_registers(s, &new_target_tm);

f2xx_alarm_check(s, 0);
Expand Down Expand Up @@ -610,7 +611,7 @@ static const VMStateDescription vmstate_stm32f2xx_rtc = {
VMSTATE_TIMER_PTR(timer,f2xx_rtc),
VMSTATE_TIMER_PTR(wu_timer,f2xx_rtc),
VMSTATE_INT64(host_to_target_offset_us,f2xx_rtc),
VMSTATE_INT64(ticks,f2xx_rtc),
VMSTATE_UINT64(ticks,f2xx_rtc),
VMSTATE_UINT32_ARRAY(regs,f2xx_rtc,R_RTC_MAX),
VMSTATE_INT32(wp_count,f2xx_rtc),
VMSTATE_END_OF_LIST()
Expand Down
2 changes: 1 addition & 1 deletion hw/arm/prusa/stm32f407/stm32f2xx_rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct f2xx_rtc{
int64_t host_to_target_offset_us;

// target time in ticks (seconds according to the RTC registers)
time_t ticks;
uint64_t ticks;

uint32_t regs[R_RTC_MAX];
int wp_count; /* Number of correct writes to WP reg */
Expand Down
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,7 @@ common_all = common_ss.apply(config_all, strict: false)
common_all = static_library('common',
build_by_default: false,
sources: common_all.sources() + genh,
implicit_include_directories: false,
dependencies: common_all.dependencies(),
name_suffix: 'fa')

Expand Down Expand Up @@ -2218,6 +2219,7 @@ foreach target : target_dirs
dependencies: arch_deps,
objects: objects,
include_directories: target_inc,
implicit_include_directories: false,
c_args: c_args,
build_by_default: false,
name_suffix: 'fa')
Expand Down

0 comments on commit 808b288

Please sign in to comment.