~aleteoryx/muditaos

ref: 74ae1a6589caaf2f822bec932476bbd4b4c12a94 muditaos/module-platform/rt1051/src/RT1051Platform.cpp -rw-r--r-- 1.1 KiB
74ae1a65 — Marcin Smoczyński [EGD-7031] Remove UT deps to the production image 4 years 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <platform/rt1051/RT1051Platform.hpp>

#include "BlockDeviceFactory.hpp"

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

#include <exception>

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

RT1051Platform::RT1051Platform()
{
    bsp::BoardInit();
}

RT1051Platform::~RT1051Platform()
{
    if (usesFilesystem) {
        purefs::subsystem::unmount_all();
    }
}

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 (int err = purefs::subsystem::mount_defaults(); err != 0) {
        throw std::runtime_error("Failed to initiate filesystem: " + std::to_string(err));
    }

    usesFilesystem = true;
}