~aleteoryx/muditaos

muditaos/module-platform/rt1051/src/RT1051Platform.cpp -rw-r--r-- 1.4 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include <platform/rt1051/RT1051Platform.hpp>

#include "BlockDeviceFactory.hpp"

#include <bsp/bsp.hpp>
#include <purefs/vfs_subsystem.hpp>
#include <exception>
#include <Logger.hpp>

using platform::rt1051::BlockDeviceFactory;
using platform::rt1051::RT1051Platform;

RT1051Platform::RT1051Platform()
{
    bsp::board_init();
    bsp::register_exit_function(Log::Logger::destroyInstance);
}

void RT1051Platform::init()
{
    initFilesystem();
}

void RT1051Platform::initFilesystem()
{
    if (usesFilesystem) {
        throw std::runtime_error("Filesystem already initialized");
    }

    auto blockDeviceFactory = std::make_unique<BlockDeviceFactory>();
    vfs                     = purefs::subsystem::initialize(std::move(blockDeviceFactory));

    if (const auto err = purefs::subsystem::mount_defaults(); err != 0) {
        throw std::runtime_error("Failed to initiate filesystem: " + std::to_string(err));
    }

    usesFilesystem = true;
}
void platform::rt1051::RT1051Platform::deinit()
{
    if (usesFilesystem) {
        if (const auto err = purefs::subsystem::unmount_all(); err != 0) {
            throw std::runtime_error("Failed to unmount all: " + std::to_string(err));
        }
        usesFilesystem = false;
    }
}