~aleteoryx/muditaos

ref: f9490f61e42a1740bbbf5c7df937a2bc77c477d9 muditaos/module-bsp/board/rt1051/bluetooth/Bluetopia.cpp -rw-r--r-- 1.6 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

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

namespace bsp
{

    Bluetopia::Bluetopia(unsigned int in_size, unsigned int out_size, int threshold)
        : BluetoothCommon(default_buff_size, default_buff_size, 32)
    {}

    Bluetopia::~Bluetopia()
    {}

    Bluetopia *Bluetopia::getInstance()
    {
        static Bluetopia *inst = NULL;
        if (inst == NULL) {
            inst = new Bluetopia();
        }
        return inst;
    }

    ssize_t Bluetopia::read(void *, size_t nbytes)
    {
        LOG_INFO("not implemented");
        return 0;
    }

    extern "C"
    {
        void LPUART2_IRQHandler(void)
        {
            uint32_t isrReg               = LPUART_GetStatusFlags(BSP_BLUETOOTH_UART_BASE);
            static char characterReceived = 0;

            if (isrReg & kLPUART_RxDataRegFullFlag) {
                characterReceived  = LPUART_ReadByte(BSP_BLUETOOTH_UART_BASE);
                bsp::Bluetopia *bt = bsp::Bluetopia::getInstance();
                if (bt->in.push(characterReceived) == 0) {
                    bt->set_data();
                }
                if (bt->in.threshold_guard()) {
                    bt->set_rts(false);
                }
            }
            // TODO ths should be handled - othervise uart might be `nicelly` blocked
            if (isrReg & kLPUART_RxOverrunFlag) {
                printf("Overrun\n");
            }
            LPUART_ClearStatusFlags(BSP_BLUETOOTH_UART_BASE, isrReg);
        }
    };