aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/rfnoc/actions.cpp
blob: 86bc576f3c0853b2bdbc65be3cc84f39eba9d2a7 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//

#include <uhd/rfnoc/actions.hpp>
#include <uhd/rfnoc/defaults.hpp>
#include <atomic>

using namespace uhd::rfnoc;

namespace {
// A static counter, which we use to uniquely label actions
std::atomic<size_t> action_counter{0};
} // namespace

action_info::action_info(const std::string& key, const uhd::device_addr_t& args)
    : id(action_counter++), key(key), args(args)
{
    // nop
}

//! Factory function
action_info::sptr action_info::make(
    const std::string& key, const uhd::device_addr_t& args)
{
    struct action_info_make_shared : public action_info
    {
    };
    if (key == ACTION_KEY_STREAM_CMD) {
        return stream_cmd_action_info::make(
            uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
    }
    // return std::make_shared<action_info_make_shared>(key, args);
    return sptr(new action_info(key, args));
}

/*** Stream Command Action Info **********************************************/
stream_cmd_action_info::stream_cmd_action_info(
    const uhd::stream_cmd_t::stream_mode_t stream_mode)
    : action_info(ACTION_KEY_STREAM_CMD), stream_cmd(stream_mode)
{
    // nop
}

stream_cmd_action_info::sptr stream_cmd_action_info::make(
    const uhd::stream_cmd_t::stream_mode_t stream_mode)
{
    return sptr(new stream_cmd_action_info(stream_mode));
}

/*** RX Metadata Action Info *************************************************/
rx_event_action_info::rx_event_action_info(uhd::rx_metadata_t::error_code_t error_code_)
    : action_info(ACTION_KEY_RX_EVENT), error_code(error_code_)
{
    // nop
}

rx_event_action_info::sptr rx_event_action_info::make(
    uhd::rx_metadata_t::error_code_t error_code)
{
    struct rx_event_action_info_make_shared : public rx_event_action_info
    {
        rx_event_action_info_make_shared(uhd::rx_metadata_t::error_code_t error_code)
            : rx_event_action_info(error_code)
        {
        }
    };
    return std::make_shared<rx_event_action_info_make_shared>(error_code);
}

/*** TX Metadata Action Info *************************************************/
tx_event_action_info::tx_event_action_info(
    uhd::async_metadata_t::event_code_t event_code_,
    const boost::optional<uint64_t>& tsf_)
    : action_info(ACTION_KEY_TX_EVENT), event_code(event_code_), has_tsf(tsf_)
{
    if (has_tsf) {
        tsf = tsf_.get();
    }
}

tx_event_action_info::sptr tx_event_action_info::make(
    uhd::async_metadata_t::event_code_t event_code, const boost::optional<uint64_t>& tsf)
{
    struct tx_event_action_info_make_shared : public tx_event_action_info
    {
        tx_event_action_info_make_shared(uhd::async_metadata_t::event_code_t event_code,
            const boost::optional<uint64_t>& tsf)
            : tx_event_action_info(event_code, tsf)
        {
        }
    };
    return std::make_shared<tx_event_action_info_make_shared>(event_code, tsf);
}