Skip to content

Commit

Permalink
semihosting: Add support for SYS_ELAPSED/SYS_TICKFREQ as milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTracer committed Jun 20, 2024
1 parent d2b62f0 commit 254bc26
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/target/semihosting.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,20 @@ int32_t semihosting_time(target_s *const target)
#endif
}

int32_t semihosting_elapsed(target_s *const target, const semihosting_s *const request)
{
/* Extract where the write should occur to */
const target_addr_t block_taddr = request->r1;
/*
* Acquire platform ticks (even if uint32_t ATM).
* BMP: SysTicks. This is faster (on-probe) than talking to GDB.
* BMDA: gettimeofday() as milliseconds.
*/
const uint64_t elapsed = platform_time_ms();
/* Write the elapsed ticks to the target as a pair of uint32_t in LE order per ABI */
return target_mem32_write(target, block_taddr, &elapsed, sizeof(elapsed)) ? -1 : 0;
}

int32_t semihosting_readc(target_s *const target)
{
/* Define space for a character */
Expand Down Expand Up @@ -860,9 +874,13 @@ int32_t semihosting_handle_request(target_s *const target, const semihosting_s *
case SEMIHOSTING_SYS_TMPNAM:
return semihosting_temp_name(target, request);

// not implemented yet:
case SEMIHOSTING_SYS_ELAPSED: /* elapsed */
case SEMIHOSTING_SYS_TICKFREQ: /* tickfreq */
case SEMIHOSTING_SYS_ELAPSED:
return semihosting_elapsed(target, request);

case SEMIHOSTING_SYS_TICKFREQ:
/* 1000 Hz SysTick, or BMDA "precision". Servicing breakpoints over SWD is not fast. */
return SYSTICKHZ;

default:
return -1;
}
Expand Down

0 comments on commit 254bc26

Please sign in to comment.