~aleteoryx/muditaos

ref: a0677af340a1fec8e8652b64fb97ca7f0902de12 muditaos/module-bsp/board/rt1051/drivers/RT1051DriverDMAMux.cpp -rw-r--r-- 2.0 KiB
a0677af3 — Marek Niepieklo [CP-615] Update existing backup/restore implementation in OS 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "RT1051DriverDMAMux.hpp"
#include <algorithm>

namespace drivers
{

    RT1051DriverDMAMux::RT1051DriverDMAMux(const drivers::DMAMuxInstances &inst,
                                           const drivers::DriverDMAMuxParams &params)
        : DriverDMAMux(params), instance(inst)
    {
        switch (instance) {
        case DMAMuxInstances::DMAMUX0: {
            base = DMAMUX;
            DMAMUX_Init(base);
            LOG_DEBUG("Init: DMAMUX0");
        } break;
        default:
            break;
        }
    }

    RT1051DriverDMAMux::~RT1051DriverDMAMux()
    {
        switch (instance) {
        case DMAMuxInstances::DMAMUX0: {
            for (auto &w : channels) {
                DMAMUX_DisableChannel(base, w);
            }
            DMAMUX_Deinit(DMAMUX);
            LOG_DEBUG("Deinit DMAMUX0");
        } break;
        default:
            break;
        }
    }

    void RT1051DriverDMAMux::Enable(const uint32_t channel, const uint32_t source)
    {
        cpp_freertos::LockGuard lock(mutex);
        if (std::find(std::begin(channels), std::end(channels), channel) == std::end(channels)) {
            if (source != UINT32_MAX) {
                DMAMUX_SetSource(base, channel, (uint8_t)source);
            }

            DMAMUX_EnableChannel(base, channel);
            channels.push_back(channel);
        }
        else {
            LOG_ERROR("Trying to enable channel that is already enabled");
        }
    }

    void RT1051DriverDMAMux::Disable(const uint32_t channel)
    {
        cpp_freertos::LockGuard lock(mutex);
        auto ret = std::find(std::begin(channels), std::end(channels), channel);
        if (ret != std::end(channels)) {
            DMAMUX_DisableChannel(base, channel);
            channels.erase(ret);
        }
        else {
            LOG_ERROR("Trying to disable channel that doesn't exist");
        }
    }

} // namespace drivers