116 lines
2.3 KiB
C++
116 lines
2.3 KiB
C++
|
|
/**
|
|||
|
|
* \file AsyncRunner.cpp
|
|||
|
|
* \project EFC_PlatformC28x_Test
|
|||
|
|
*
|
|||
|
|
* Created on: 20 мая 2024 г.
|
|||
|
|
* Author: leonid
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#include "AsyncRunner.hh"
|
|||
|
|
|
|||
|
|
#include <sysctl.h>
|
|||
|
|
#include <interrupt.h>
|
|||
|
|
#include <cputimer.h>
|
|||
|
|
|
|||
|
|
void (*cputimer1_pfinthandler)();
|
|||
|
|
bool cputimer1_first_run;
|
|||
|
|
|
|||
|
|
__interrupt void cputimer1_interrupt() {
|
|||
|
|
|
|||
|
|
if( cputimer1_first_run )
|
|||
|
|
cputimer1_pfinthandler();
|
|||
|
|
|
|||
|
|
CPUTimer_stopTimer(CPUTIMER1_BASE);
|
|||
|
|
|
|||
|
|
cputimer1_first_run = false;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void cputimer1_init( void (*interrupt_handler)() ) {
|
|||
|
|
|
|||
|
|
cputimer1_pfinthandler = interrupt_handler;
|
|||
|
|
|
|||
|
|
Interrupt_register( INT_TIMER1, &cputimer1_interrupt );
|
|||
|
|
Interrupt_enable(INT_TIMER1);
|
|||
|
|
|
|||
|
|
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TIMER1);
|
|||
|
|
CPUTimer_stopTimer(CPUTIMER1_BASE);
|
|||
|
|
CPUTimer_setPreScaler(CPUTIMER1_BASE, CPUTIMER_CLOCK_PRESCALER_1);
|
|||
|
|
CPUTimer_enableInterrupt(CPUTIMER1_BASE);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//Запуск таймера
|
|||
|
|
void cputimer1_run( uint32_t processor_tick ) {
|
|||
|
|
|
|||
|
|
CPUTimer_setPeriod( CPUTIMER1_BASE, processor_tick + 1 );
|
|||
|
|
CPUTimer_reloadTimerCounter(CPUTIMER1_BASE);
|
|||
|
|
CPUTimer_clearOverflowFlag( CPUTIMER1_BASE );
|
|||
|
|
|
|||
|
|
cputimer1_first_run = true;
|
|||
|
|
|
|||
|
|
CPUTimer_startTimer(CPUTIMER1_BASE);
|
|||
|
|
|
|||
|
|
//Задержка для гарантии входа в прерывание, исключения непокрытого
|
|||
|
|
// кода после выполнения функции из-за отзывчивости прерываний.
|
|||
|
|
for( volatile int i = 0; i < 4; i++ );
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void cputimer1_stop() {
|
|||
|
|
|
|||
|
|
CPUTimer_stopTimer(CPUTIMER1_BASE);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
void platform::AsyncRunner::async_run() {
|
|||
|
|
|
|||
|
|
platform::AsyncRunner::getInstance().run();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
platform::AsyncRunner::AsyncRunner() : task(0), ran(false) {
|
|||
|
|
|
|||
|
|
cputimer1_init( &async_run );
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void platform::AsyncRunner::run_after( umlib::tests::TaskInterface * new_task,
|
|||
|
|
uint32_t processor_tick ) {
|
|||
|
|
|
|||
|
|
task = new_task;
|
|||
|
|
ran = false;
|
|||
|
|
|
|||
|
|
cputimer1_run(processor_tick);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void platform::AsyncRunner::cancel() {
|
|||
|
|
|
|||
|
|
cputimer1_stop();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool platform::AsyncRunner::is_ran() {
|
|||
|
|
|
|||
|
|
return ran;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void platform::AsyncRunner::run() {
|
|||
|
|
|
|||
|
|
if( task ) {
|
|||
|
|
task->do_task();
|
|||
|
|
ran = true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
platform::AsyncRunner & platform::AsyncRunner::getInstance() {
|
|||
|
|
|
|||
|
|
static AsyncRunner instance;
|
|||
|
|
return instance;
|
|||
|
|
|
|||
|
|
}
|