Best option: Implement the get_core_clk_hz() and use the outcome in functions which are depending on the Core clock frequency.
This could de part of Init() and store the value as static variable.
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#define BCM2835_CORE_CLK_HZ 250000000
static uint32_t get_core_clk_hz(void) {
const char cmd[] = "vcgencmd measure_clock core";
uint32_t clock_hz = BCM2835_CORE_CLK_HZ;
char buf[64];
FILE *fp = popen(cmd, "r");
if (fgets(buf, sizeof(buf)-1, fp) != 0) {
sscanf(buf, "%*[*=]%d", clock_hz);
}
fclose(fp);
return clock_hz;
}
int main(void) {
printf("[%d]\n", get_core_clk_hz());
return 0;
}
- Arjan