Skip to content

Commit

Permalink
Calculate spent CPU cycles and derive LFCLK
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Oct 24, 2024
1 parent 04ebbdf commit 7f98d89
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 33 deletions.
3 changes: 2 additions & 1 deletion include/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ typedef void (*mem_watchpoint_cb_t)(cpu_t *, bool isWrite, uint32_t addr, size_t
cpu_t *cpu_new(const uint8_t *program, size_t program_size, memory_map_t *mem, size_t max_external_interrupts, size_t priority_bits);
void cpu_free(cpu_t *);
void cpu_reset(cpu_t *);
void cpu_step(cpu_t *);
// Returns the number of cycles that the CPU ran for
int cpu_step(cpu_t *);

void cpu_clear_instruction_cache(cpu_t *);

Expand Down
4 changes: 4 additions & 0 deletions include/nrf52832.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#define NRF52832_MAX_EXTERNAL_INTERRUPTS 496

#define NRF52832_HFCLK_FREQUENCY (64 * 1000 * 1000)
#define NRF52832_LFCLK_FREQUENCY 32768

enum
{
INSTANCE_CLOCK = 0x00,
Expand Down Expand Up @@ -93,5 +96,6 @@ void *nrf52832_get_peripheral(NRF52832_t *, uint8_t instance_id);

size_t nrf52832_get_used_sram(NRF52832_t *);
size_t nrf52832_get_sram_size(NRF52832_t *);
uint64_t nrf52832_get_cycle_counter(NRF52832_t *);

bool nrf52832_flash_write(NRF52832_t *, uint32_t addr, uint8_t value);
2 changes: 1 addition & 1 deletion include/peripherals/dwt.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

PERIPHERAL(DWT, dwt)

void dwt_increment_cycle(DWT_t *dwt);
void dwt_increment_cycle(DWT_t *dwt, unsigned int count);
7 changes: 5 additions & 2 deletions include/ticker.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ typedef struct ticker_t ticker_t;

typedef void (*ticker_cb_t)(void *);

ticker_t *ticker_new(void);
ticker_t *ticker_new(int32_t lfclk_cycles);
void ticker_free(ticker_t *);
void ticker_reset(ticker_t *);
void ticker_tick(ticker_t *);

void ticker_hftick(ticker_t *, unsigned int count);
void ticker_lftick(ticker_t *);

void ticker_add(ticker_t *, ticker_cb_t cb, void *userdata, uint32_t interval, bool auto_reload);
void ticker_remove(ticker_t *, ticker_cb_t cb);
Loading

0 comments on commit 7f98d89

Please sign in to comment.