Adds sitara_depot/free_rtos Original one is on server_gorbunov/SmartForce4.0/sitara_depot
78 lines
1.8 KiB
C++
78 lines
1.8 KiB
C++
/*
|
|
* timer.cpp
|
|
*
|
|
* Created on: 10 ìàð. 2023 ã.
|
|
* Author: sychev
|
|
*/
|
|
#include "timer/timer.hpp"
|
|
#include <kernel/dpl/TimerP.h>
|
|
#include <drivers/soc.h>
|
|
#include <kernel/dpl/AddrTranslateP.h>
|
|
|
|
using namespace free_rtos;
|
|
|
|
void free_rtos::timer_isr_callback(void * arg)
|
|
{
|
|
Timer * const p_timer = (Timer * const)arg;
|
|
|
|
p_timer->sem_.post();
|
|
|
|
TimerP_clearOverflowInt(p_timer->base_addr_);
|
|
HwiP_clearInt(p_timer->int_num_);
|
|
}
|
|
|
|
bool free_rtos::Timer::Init(Settings& sett)
|
|
{
|
|
TimerP_Params timerParams;
|
|
HwiP_Params timerHwiParams;
|
|
int32_t status;
|
|
|
|
/* set timer clock source */
|
|
SOC_controlModuleUnlockMMR(SOC_DOMAIN_ID_MAIN, 2);
|
|
*(volatile uint32_t*)AddrTranslateP_getLocalAddr(sett.clock_src_mux_addr) = 0; /// CLOCK_SRC_MCU_HFOSC0
|
|
SOC_controlModuleLockMMR(SOC_DOMAIN_ID_MAIN, 2);
|
|
|
|
base_addr_ = (uint32_t)AddrTranslateP_getLocalAddr(sett.base_address);
|
|
|
|
TimerP_Params_init(&timerParams);
|
|
timerParams.inputPreScaler = 1;
|
|
timerParams.inputClkHz = sett.input_clk_Hz;
|
|
timerParams.periodInNsec = sett.period_us * 1000;
|
|
timerParams.oneshotMode = 0;
|
|
timerParams.enableOverflowInt = 1;
|
|
timerParams.enableDmaTrigger = 0;
|
|
|
|
TimerP_setup(base_addr_, &timerParams);
|
|
|
|
int_num_ = sett.int_num;
|
|
|
|
HwiP_Params_init(&timerHwiParams);
|
|
|
|
timerHwiParams.intNum = int_num_;
|
|
timerHwiParams.callback = free_rtos::timer_isr_callback;
|
|
timerHwiParams.args = (void*)this;
|
|
timerHwiParams.isPulse = 0;
|
|
timerHwiParams.priority = sett.int_priority;
|
|
|
|
status = HwiP_construct(&hwi_obj_, &timerHwiParams);
|
|
|
|
return (status == SystemP_SUCCESS);
|
|
}
|
|
|
|
void free_rtos::Timer::Wait() {
|
|
sem_.pend();
|
|
}
|
|
|
|
void free_rtos::Timer::Start() {
|
|
TimerP_start(base_addr_);
|
|
}
|
|
|
|
void free_rtos::Timer::Stop() {
|
|
TimerP_stop(base_addr_);
|
|
}
|
|
|
|
|
|
|
|
|
|
|