321 lines
9.9 KiB
C++
321 lines
9.9 KiB
C++
/**
|
|
* main.cpp
|
|
*/
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <memory_resource>
|
|
|
|
#include <FreeRTOS.h>
|
|
#include <task.h>
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
#include <UMLibrary/common/Result.hh>
|
|
|
|
#include <UMLibrary/configuration/AddProcessor.hpp>
|
|
#include <UMLibrary/configuration/software/AppBuilder.hh>
|
|
#include <UMLibrary/configuration/software/AppInfo.hh>
|
|
#include <UMLibrary/configuration/software/ApplicationConfigurator.hh>
|
|
#include <UMLibrary/configuration/software/CreateToBuilder.hpp>
|
|
|
|
#include <UMLibrary/systemic/ValueManager.hpp>
|
|
#include <UMLibrary/systemic/SystemException.hh>
|
|
#include <UMLibrary/systemic/Scheduler.hpp>
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
#include <Platform/Config.h>
|
|
|
|
#include <Platform/core/init/init.hpp>
|
|
|
|
#include <Platform/memory/MemoryRegions.hpp>
|
|
#include <Platform/memory/RtosMemoryResource.hpp>
|
|
#include "Platform/memory/StaticMemoryResource.hpp"
|
|
|
|
#include <Platform/rtos/task/InitTask.hpp>
|
|
#include <Platform/rtos/task/MainTask.hpp>
|
|
|
|
#include <Platform/driver/ipc/Ipc.hpp>
|
|
|
|
#include <Platform/application/config/ParamStorage.hpp>
|
|
#include <Platform/application/config/ParamUnpack.hpp>
|
|
#include <Platform/application/info/AppInfo.hpp>
|
|
#include <Platform/application/info/DeviceInfo.hpp>
|
|
#include <Platform/application/setup/PeriphConfigurator.hpp>
|
|
#include <Platform/application/setup/AppConfigurator.hpp>
|
|
#include <Platform/application/setup/Environment.hpp>
|
|
#include <Platform/application/setup/StatusHerald.hpp>
|
|
#include <Platform/application/setup/Service.hpp>
|
|
#include <Platform/application/setup/AppBuilder.hpp>
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
#include <sysctl.h>
|
|
#include <interrupt.h>
|
|
#include <ipc.h>
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
#include "autoconfig_cpu1.hh"
|
|
#include "autoadd.hh"
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
platform::memory::RtosMemoryResource rtos_heap_mr(
|
|
HeapRegion{ RTOS_HEAP0_START, RTOS_HEAP0_SIZE }
|
|
);
|
|
|
|
platform::memory::StaticMemoryResource app_heap_ecc_mr(
|
|
HeapRegion{ APP_HEAP0_START, APP_HEAP0_SIZE }
|
|
);
|
|
|
|
platform::memory::StaticMemoryResource app_heap_mr(
|
|
HeapRegion{ APP_HEAP1_START, APP_HEAP1_SIZE }
|
|
);
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
static platform::rtos::InitTask init_task;
|
|
static platform::rtos::MainTask main_task;
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
void platform::rtos::InitTask::process(void* param) {
|
|
std::srand(xTaskGetTickCount());
|
|
|
|
/* Чтение и разбор конфигуарции */
|
|
{
|
|
using namespace platform::application;
|
|
|
|
/* Таблицы инициализаторов кофнигурации */
|
|
{
|
|
const bool app_info_init =
|
|
info::AppInfo::init(rtos_heap_mr, PROJECT_CAP_APP_INFO_RECORDS);
|
|
|
|
if (!app_info_init) std::abort();
|
|
|
|
const bool dev_info_init =
|
|
info::DeviceInfo::init(rtos_heap_mr, PROJECT_CAP_DEVICE_INFO_RECORDS);
|
|
|
|
if (!dev_info_init) std::abort();
|
|
}
|
|
|
|
/* Получение и распаковка таблицы параметров конфигурации */
|
|
{
|
|
/*
|
|
// TODO Аппаратный доступ к хранилищу настроек IMemoryAccess
|
|
|
|
auto param_storage_init =
|
|
config::ParamStorage::init(config_file, sram_heap_mr);
|
|
|
|
if (param_storage_init.isErr()) std::abort();
|
|
|
|
auto& param_storage = *param_storage_init.unwrap();
|
|
|
|
auto param_unpack_init =
|
|
config::ParamUnpack(param_storage, info::AppInfo(), info::DeviceInfo()).unpack();
|
|
|
|
if (param_unpack_init.isErr()) std::abort();
|
|
*/
|
|
}
|
|
}
|
|
|
|
/* Создание окружения времени выполнения */
|
|
|
|
configuration::Environment* environment = nullptr;
|
|
|
|
{
|
|
using namespace platform::application;
|
|
|
|
/* Параметры платформы */
|
|
const EnvironmentCapacity env_capacity = {
|
|
.signals_capacity = PROJECT_NUM_SIGNALS,
|
|
.statuses_capacity = PROJECT_NUM_STATUSES,
|
|
.resources_capacity = PROJECT_NUM_OBJECTS,
|
|
.num_of_param_providers = PROJECT_NUM_PARPROVIDERS,
|
|
.num_of_scheduler = PROJECT_NUM_PROCSCHEDULERS,
|
|
};
|
|
|
|
/* Ресурсы памяти */
|
|
std::pmr::memory_resource& object_mr = app_heap_mr;
|
|
std::pmr::memory_resource& data_mr = app_heap_mr;
|
|
std::pmr::memory_resource& setup_mr = app_heap_ecc_mr;
|
|
|
|
/* Обработчик ошибок */
|
|
static char ex_data_buffer[PROJECT_EXCEPTION_DATA_BUFFER_SIZE];
|
|
|
|
auto exception_handler = systemic::ExceptionHandler(ex_data_buffer, sizeof(ex_data_buffer));
|
|
|
|
/* Глобальный объект окружения */
|
|
auto environment_setup =
|
|
setup::Environmnet(
|
|
app_heap_ecc_mr, /* env_mr */
|
|
app_heap_ecc_mr, /* table_mr */
|
|
app_heap_ecc_mr, /* local_mr */
|
|
object_mr,
|
|
data_mr,
|
|
setup_mr,
|
|
systemic::ResourceHolder::getDefault(),
|
|
systemic::ValueManager<bool>::getDefault(),
|
|
systemic::ValueManager<float>::getDefault(),
|
|
exception_handler,
|
|
env_capacity
|
|
);
|
|
|
|
environment = environment_setup.unwrap();
|
|
|
|
environment->platform_info = &setup::StatusHerald::platformInfo;
|
|
}
|
|
|
|
/* Инстанцирование базовых ресурсов */
|
|
{
|
|
using namespace platform::application;
|
|
|
|
/* Планировщик приложения */
|
|
{
|
|
using AppProcessor = systemic::Scheduler< PROJECT_APP_SCHEDULER_ID >;
|
|
|
|
configuration::addProcessor< AppProcessor >(
|
|
1. / (float) PROJECT_APP_SCHEDULER_FREQ,
|
|
PROJECT_APP_SCHEDULER_NUM_PROCESS,
|
|
*environment,
|
|
app_heap_ecc_mr,
|
|
app_heap_ecc_mr
|
|
);
|
|
}
|
|
|
|
/* Межпроцессорное взаимодействие */
|
|
{
|
|
platform::driver::Ipc::init();
|
|
}
|
|
|
|
/* Сервисный обмен */
|
|
{
|
|
auto service_setup = setup::Service(app_heap_mr);
|
|
|
|
if (service_setup.isErr()) std::abort();
|
|
}
|
|
}
|
|
|
|
/* Сборка платформенных инициализаторов */
|
|
{
|
|
using namespace platform::application;
|
|
|
|
/* Создание фабрики инициализаторов */
|
|
auto configurator_setup =
|
|
setup::PeriphConfigurator(
|
|
app_heap_ecc_mr,
|
|
app_heap_mr,
|
|
::platform::application::periph::periph_initializer_list_size
|
|
);
|
|
|
|
auto& configurator = *configurator_setup.unwrap();
|
|
|
|
/* Регистрация инициализаторов */
|
|
::platform::application::periph::add(configurator);
|
|
|
|
/* Сборка инициализаторов */
|
|
for (auto initializer : info::DeviceInfo::getInitializers()) {
|
|
const bool build_status = configurator.build(initializer, *environment);
|
|
|
|
if (!build_status) std::abort();
|
|
}
|
|
}
|
|
|
|
/* Сборка библиотечных инициализаторов */
|
|
{
|
|
using namespace platform::application;
|
|
|
|
/* Создание фабрики инициализаторов */
|
|
auto configurator_setup =
|
|
setup::AppConfigurator(
|
|
app_heap_ecc_mr,
|
|
app_heap_mr,
|
|
::application::info::application_initializer_list_size
|
|
);
|
|
|
|
auto& configurator = *configurator_setup.unwrap();
|
|
|
|
/* Создание процедуры сборки инициализаторов */
|
|
auto build_items_num = info::AppInfo::getInitializers().getSize();
|
|
|
|
auto build_teardown = [] () {
|
|
config::ParamStorage::drop();
|
|
info::AppInfo::drop();
|
|
info::DeviceInfo::drop();
|
|
|
|
// platform::driver::Ipc::lock();
|
|
};
|
|
|
|
auto app_builder_setup =
|
|
setup::AppBuilder(
|
|
app_heap_mr,
|
|
build_items_num,
|
|
*environment,
|
|
PROJECT_APP_SCHEDULER_ID,
|
|
build_teardown
|
|
);
|
|
|
|
auto& app_builder = *app_builder_setup.unwrap();
|
|
|
|
/* Регистрация инициализаторов */
|
|
::application::autoadd(configurator);
|
|
|
|
for (auto initializer : info::AppInfo::getInitializers()) {
|
|
configuration::software::CreateToBuilder(configurator, app_builder)(initializer);
|
|
}
|
|
}
|
|
|
|
/* Запуск основного потока */
|
|
main_task.handle = xTaskCreateStatic(
|
|
main_task.func,
|
|
main_task.name,
|
|
main_task.depth,
|
|
NULL,
|
|
main_task.prio,
|
|
main_task.stack,
|
|
&main_task.desc
|
|
);
|
|
|
|
if (main_task.handle == nullptr) std::abort();
|
|
|
|
vTaskDelete(nullptr);
|
|
}
|
|
|
|
void platform::rtos::MainTask::process(void* param) {
|
|
for (;;) {
|
|
TickType_t timestamp = xTaskGetTickCount();
|
|
|
|
systemic::Scheduler< PROJECT_APP_SCHEDULER_ID >::runOnce();
|
|
|
|
vTaskDelayUntil(×tamp, pdMS_TO_TICKS(1));
|
|
}
|
|
}
|
|
|
|
std::pmr::memory_resource* default_mr = &app_heap_mr;
|
|
|
|
int main(int argc, char* argv[]) {
|
|
if (!platform::core::init()) std::abort();
|
|
|
|
Interrupt_disableInProcessor();
|
|
|
|
const auto init_task_status =
|
|
xTaskCreate(
|
|
init_task.func,
|
|
init_task.name,
|
|
init_task.depth,
|
|
NULL,
|
|
init_task.prio,
|
|
&init_task.handle
|
|
);
|
|
|
|
if (init_task_status != pdPASS) std::abort();
|
|
|
|
Interrupt_enableInProcessor();
|
|
|
|
vTaskStartScheduler();
|
|
|
|
return 0;
|
|
}
|