~aleteoryx/muditaos

ref: f9490f61e42a1740bbbf5c7df937a2bc77c477d9 muditaos/module-bsp/board/rt1051/bluetooth/BlueKitchen.cpp -rw-r--r-- 1.9 KiB
f9490f61 — Lefucjusz Revert "[BH-1673] Harmony random resets fixes" 2 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
77
78
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "bsp/bluetooth/Bluetooth.hpp"
#include <log/log.hpp>
#include "FreeRTOS.h"
#include "fsl_lpuart.h"
#include "board.h"

#if DEBUG_BLUETOOTH_HCI_COMS == 1
#define logHciStack(...) LOG_DEBUG(__VA_ARGS__)
#else
#define logHciStack(...)
#endif

using namespace bsp;

BlueKitchen::BlueKitchen()
{
    read_buff     = NULL;
    read_ready_cb = NULL;
    write_done_cb = NULL;
}

BlueKitchen::~BlueKitchen() = default;

BlueKitchen *BlueKitchen::getInstance()
{
    static BlueKitchen *k = NULL;
    if (k == NULL) {
        /// outcomming & incomming heap allocated buffers sizes
        /// packet on IP network cna have MTU 1500, so big enough buffers were added to not throttle comms
        k = new BlueKitchen();
    }
    return k;
}

BTdev::Error BlueKitchen::read(uint8_t *buf, size_t nbytes)
{
    logHciStack("BlueKitchen requested to read %d bytes", nbytes);

    uint8_t val;

    read_buff = buf; // point at the Bt stack read buffer
    read_len  = nbytes;

    if (BluetoothCommon::read(buf, nbytes) == Success) {
        val = bluetooth::Message::EvtReceiving;
        xQueueSend(qHandle, &val, portMAX_DELAY);
        return BTdev::Success;
    }
    else {
        val = bluetooth::Message::EvtReceivingError;
        xQueueSend(qHandle, &val, portMAX_DELAY);
        return BTdev::ErrorBSP;
    }
}

BTdev::Error BlueKitchen::write(const uint8_t *buf, size_t size)
{
    uint8_t val;

    logHciStack("BlueKitchen sends %d bytes", size);

    if (BluetoothCommon::write(buf, size) == Success) {
        val = bluetooth::Message::EvtSending;
        xQueueSend(qHandle, &val, portMAX_DELAY);
        return BTdev::Success;
    }
    else {
        val = bluetooth::Message::EvtSendingError;
        xQueueSend(qHandle, &val, portMAX_DELAY);
        return BTdev::ErrorBSP;
    }
}

void BlueKitchen::set_flowcontrol(int on)
{}