Skip to content

Commit

Permalink
More HPC timer edits
Browse files Browse the repository at this point in the history
  • Loading branch information
8bitbubsy committed Apr 13, 2024
1 parent 4873c40 commit bc169af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/pt2_hpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
** Hardware Performance Counter delay routines by 8bitbubsy.
**
** These are by no means well written, and are made for specific
** usage cases. There may be soome hackish design choices here.
** usage cases. There may be some hackish design choices here.
**
** NOTE: hpc_SetDurationInHz() has quite a bit of overhead, so it's
** recommended to have one hpcFreq_t counter for each delay value,
Expand Down Expand Up @@ -100,15 +100,15 @@ static uint64_t getFrac64FromU64DivU32(uint64_t dividend, uint32_t divisor)
return ((uint64_t)resultHi << 32) | resultLo;
}

void hpc_SetDurationInHz(hpc_t *hpc, double dHz) // dHz = max 8191.999inf Hz (0.12ms)
void hpc_SetDurationInHz(hpc_t *hpc, double dHz) // dHz = max 4095.999inf Hz (0.24ms)
{
#define BITS_IN_UINT32 32

/* 19 = Good compensation between fraction bits and max integer size.
** Non-realtime OSes probably can't do a thread delay with such a
** high precision (0.12ms) anyway.
/* 20 = Good compensation between fraction bits and max integer size.
** Most non-realtime OSes probably can't do a thread delay with such a
** high precision ( 0.24ms, 1000/(2^(32-20)-1) ) anyway.
*/
#define INPUT_FRAC_BITS 19
#define INPUT_FRAC_BITS 20
#define INPUT_FRAC_SCALE (1UL << INPUT_FRAC_BITS)
#define INPUT_INT_MAX ((1UL << (BITS_IN_UINT32-INPUT_FRAC_BITS))-1)

Expand All @@ -125,7 +125,7 @@ void hpc_SetDurationInHz(hpc_t *hpc, double dHz) // dHz = max 8191.999inf Hz (0.
hpc->resetFrame = ((uint64_t)fpHz * (60 * 30)) / INPUT_FRAC_SCALE; // reset counters every half an hour
}

void hpc_SetDurationInMs(hpc_t *hpc, double dMs) // dMs = minimum 0.12208521548 ms
void hpc_SetDurationInMs(hpc_t *hpc, double dMs) // dMs = minimum 0.2442002442 ms
{
hpc_SetDurationInHz(hpc, 1000.0 / dMs);
}
Expand Down
4 changes: 2 additions & 2 deletions src/pt2_hpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct
extern hpcFreq_t hpcFreq;

void hpc_Init(void);
void hpc_SetDurationInHz(hpc_t *hpc, double dHz); // dHz = max 8191.999inf Hz (0.12ms)
void hpc_SetDurationInMs(hpc_t *hpc, double dMs); // dMs = minimum 0.12208521548 ms
void hpc_SetDurationInHz(hpc_t *hpc, double dHz); // dHz = max 4095.999inf Hz (0.24ms)
void hpc_SetDurationInMs(hpc_t *hpc, double dMs); // dMs = minimum 0.2442002442 ms
void hpc_ResetCounters(hpc_t *hpc);
void hpc_Wait(hpc_t *hpc);

0 comments on commit bc169af

Please sign in to comment.