calculate cpu load with the ti-rtos clock

this is wholly innacurate as the baseline is the cpu usage on startup (high)
and the results are round to the nearest tick, which is 10% of the sample

does "work" though
This commit is contained in:
Andy Killorin 2025-04-12 18:54:33 -04:00
parent 281c0f68d5
commit f64dbda320
2 changed files with 13 additions and 9 deletions

19
main.c
View file

@ -102,22 +102,22 @@ void start_signal() {
PWMGenEnable(PWM0_BASE, PWM_GEN_1); PWMGenEnable(PWM0_BASE, PWM_GEN_1);
} }
uint8_t cpu_load_active = 0; // Clock_isActive does not change
uint32_t cpu_load_count(void) uint32_t cpu_load_count(void)
{ {
uint32_t i = 0; uint32_t i = 0;
TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); cpu_load_active = 1;
TimerEnable(TIMER1_BASE, TIMER_A); // start one-shot timer Clock_start(cpu_clock);
while (!(TimerIntStatus(TIMER1_BASE, false) & TIMER_TIMA_TIMEOUT)) while (cpu_load_active)
i++; i++;
return i; return i;
} }
void cpu_timer_end(void) {
cpu_load_active = 0;
};
void start_cputimer() { void start_cputimer() {
// initialize timer 1 in one-shot mode for polled timing
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
TimerDisable(TIMER1_BASE, TIMER_BOTH);
TimerConfigure(TIMER1_BASE, TIMER_CFG_ONE_SHOT);
TimerLoadSet(TIMER1_BASE, TIMER_A, gSystemClock/100); // 10ms interval
// baseline load // baseline load
cputime_unloaded = cpu_load_count(); cputime_unloaded = cpu_load_count();
} }
@ -133,7 +133,6 @@ int main(void)
start_signal(); start_signal();
start_sampler(); start_sampler();
ButtonInit(); ButtonInit();
start_cputimer();
Crystalfontz128x128_Init(); // Initialize the LCD display driver Crystalfontz128x128_Init(); // Initialize the LCD display driver
Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP); // set screen orientation Crystalfontz128x128_SetOrientation(LCD_ORIENTATION_UP); // set screen orientation
@ -159,6 +158,8 @@ void task0_func(UArg arg1, UArg arg2)
void capture_waveform(UArg arg1, UArg arg2) void capture_waveform(UArg arg1, UArg arg2)
{ {
IntMasterEnable(); IntMasterEnable();
start_cputimer();
while(true) { while(true) {
Semaphore_pend(capture_sem, BIOS_WAIT_FOREVER); Semaphore_pend(capture_sem, BIOS_WAIT_FOREVER);

View file

@ -593,3 +593,6 @@ var task5Params = new Task.Params();
task5Params.instance.name = "user_input"; task5Params.instance.name = "user_input";
task5Params.priority = 6; task5Params.priority = 6;
Program.global.user_input = Task.create("&handle_user_input", task5Params); Program.global.user_input = Task.create("&handle_user_input", task5Params);
var clock1Params = new Clock.Params();
clock1Params.instance.name = "cpu_clock";
Program.global.cpu_clock = Clock.create("&cpu_timer_end", 10, clock1Params);