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:
parent
281c0f68d5
commit
f64dbda320
2 changed files with 13 additions and 9 deletions
19
main.c
19
main.c
|
@ -102,22 +102,22 @@ void start_signal() {
|
|||
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 i = 0;
|
||||
TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
|
||||
TimerEnable(TIMER1_BASE, TIMER_A); // start one-shot timer
|
||||
while (!(TimerIntStatus(TIMER1_BASE, false) & TIMER_TIMA_TIMEOUT))
|
||||
cpu_load_active = 1;
|
||||
Clock_start(cpu_clock);
|
||||
while (cpu_load_active)
|
||||
i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
void cpu_timer_end(void) {
|
||||
cpu_load_active = 0;
|
||||
};
|
||||
|
||||
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
|
||||
cputime_unloaded = cpu_load_count();
|
||||
}
|
||||
|
@ -133,7 +133,6 @@ int main(void)
|
|||
start_signal();
|
||||
start_sampler();
|
||||
ButtonInit();
|
||||
start_cputimer();
|
||||
|
||||
Crystalfontz128x128_Init(); // Initialize the LCD display driver
|
||||
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)
|
||||
{
|
||||
IntMasterEnable();
|
||||
start_cputimer();
|
||||
|
||||
while(true) {
|
||||
Semaphore_pend(capture_sem, BIOS_WAIT_FOREVER);
|
||||
|
||||
|
|
3
rtos.cfg
3
rtos.cfg
|
@ -593,3 +593,6 @@ var task5Params = new Task.Params();
|
|||
task5Params.instance.name = "user_input";
|
||||
task5Params.priority = 6;
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue