~aleteoryx/muditaos

ref: 1d2f5cf7a49cf1fb9463d289daa1492a2bec2d1d muditaos/module-bsp/board/rt1051/drivers/RT1051DriverDMA.cpp -rw-r--r-- 2.3 KiB
1d2f5cf7 — Piotr Tański [EGD-7754] Dates bumped in disclaimers 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
70
71
72
73
74
75
76
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "RT1051DriverDMA.hpp"
#include <algorithm>
#include <log/log.hpp>

namespace drivers
{

    RT1051DriverDMAHandle::RT1051DriverDMAHandle(const DMA_Type *base,
                                                 const uint32_t channel,
                                                 std::function<void()> callback)
    {
        EDMA_CreateHandle(&handle, const_cast<DMA_Type *>(base), channel);
        if (callback) {
            EDMA_SetCallback(&handle, edmaCallback, this);
        }
    }

    RT1051DriverDMAHandle::~RT1051DriverDMAHandle()
    {
        EDMA_AbortTransfer(&handle);
    }

    RT1051DriverDMA::RT1051DriverDMA(const drivers::DMAInstances &inst, const drivers::DriverDMAParams &params)
        : DriverDMA(params), instance(inst)
    {
        switch (instance) {
        case DMAInstances::DMA_0: {
            base                    = DMA0;
            edma_config_t dmaConfig = {};

            EDMA_GetDefaultConfig(&dmaConfig);
            EDMA_Init(base, &dmaConfig);
            LOG_DEBUG("Init: DMA_0");
        } break;
        default:
            break;
        }
    }

    RT1051DriverDMA::~RT1051DriverDMA()
    {
        switch (instance) {
        case DMAInstances::DMA_0:
            EDMA_Deinit(base);
            LOG_DEBUG("Deinit: DMA_0");
        default:
            break;
        }
    }

    std::unique_ptr<DriverDMAHandle> RT1051DriverDMA::CreateHandle(const uint32_t channel,
                                                                   std::function<void()> callback)
    {

        cpp_freertos::LockGuard lock(mutex);

        /* Create EDMA handle */
        /*
         * dmaConfig.enableRoundRobinArbitration = false;
         * dmaConfig.enableHaltOnError = true;
         * dmaConfig.enableContinuousLinkMode = false;
         * dmaConfig.enableDebugMode = false;
         */
        return std::make_unique<RT1051DriverDMAHandle>(base, channel, callback);
    }

    void edmaCallback(struct _edma_handle *handle, void *userData, bool transferDone, uint32_t tcds)
    {
        RT1051DriverDMAHandle *entry = reinterpret_cast<RT1051DriverDMAHandle *>(userData);
        entry->callback();
    }

} // namespace drivers