amiro-os / include / amiro / bluetooth / bluetooth-transport.hpp @ 0f37fb41
History | View | Annotate | Download (2.311 KB)
1 |
#ifndef _BLUETOOTH_TRANSPORT_H_
|
---|---|
2 |
#define _BLUETOOTH_TRANSPORT_H_
|
3 |
|
4 |
#include <amiro/bluetooth/bluetooth-descriptor.hpp> |
5 |
|
6 |
#define BLUETOOTH_TRANSPORT_STORAGE_MAILBOX_SIZE 10 |
7 |
#define BLUETOOTH_TRANSPORT_TRANSMIT_MAILBOX_SIZE 5 |
8 |
|
9 |
#define TRANSMIT_COMPLETED_EVENT 1 |
10 |
|
11 |
#define FRAME_HEADER_SIZE 4 |
12 |
#define FRAME_TRAILER_SIZE 1 |
13 |
|
14 |
namespace amiro {
|
15 |
|
16 |
class BluetoothTransport : public chibios_rt::BaseStaticThread<128>, protected UARTConfig { |
17 |
public:
|
18 |
BluetoothTransport(UARTDriver* uart); |
19 |
|
20 |
chibios_rt::Mailbox* bluetoothTransportGetStorageMailbox(); |
21 |
chibios_rt::Mailbox* bluetoothTransportGetTransmitMailbox(); |
22 |
|
23 |
void bluetoothTransportSetReceiveMailbox(uint8_t linkId, chibios_rt::Mailbox* mailbox);
|
24 |
void bluetoothTransportResetState();
|
25 |
bool bluetoothTransportIsMuxMode();
|
26 |
|
27 |
protected:
|
28 |
virtual msg_t main(void); |
29 |
|
30 |
virtual void bluetoothTransportTransmitCompleted(); |
31 |
virtual void bluetoothTransportCharacterReceived(uint16_t c); |
32 |
virtual void bluetoothTransportReceiveCompleted(); |
33 |
|
34 |
private:
|
35 |
static void bluetoothTransportTransmitCompleted_cb(UARTDriver *uart); |
36 |
static void bluetoothTransportCharacterReceived_cb(UARTDriver *uart, uint16_t c); |
37 |
static void bluetoothTransportReceiveCompleted_cb(UARTDriver *uart); |
38 |
|
39 |
UARTDriver *uart; |
40 |
|
41 |
chibios_rt::Mailbox* receiveMailbox[10];
|
42 |
chibios_rt::Mailbox storageMailbox; |
43 |
chibios_rt::Mailbox transmitMailbox; |
44 |
|
45 |
msg_t storageMailboxBuffer[BLUETOOTH_TRANSPORT_STORAGE_MAILBOX_SIZE]; |
46 |
msg_t transmitMailboxBuffer[BLUETOOTH_TRANSPORT_TRANSMIT_MAILBOX_SIZE]; |
47 |
|
48 |
enum BluetoothTransportState {
|
49 |
BLUETOOTH_TRANSPORT_PLAIN = 0,
|
50 |
BLUETOOTH_TRANSPORT_HEADER = 1,
|
51 |
BLUETOOTH_TRANSPORT_DECODE = 2,
|
52 |
BLUETOOTH_TRANSPORT_PAYLOAD = 3,
|
53 |
BLUETOOTH_TRANSPORT_TRAILER = 4,
|
54 |
BLUETOOTH_TRANSPORT_IDLE = 5
|
55 |
}transmitState, receiveState; |
56 |
|
57 |
BluetoothDescriptor descriptor[BLUETOOTH_TRANSPORT_STORAGE_MAILBOX_SIZE]; |
58 |
BluetoothDescriptor *receive; |
59 |
BluetoothDescriptor *transmit; |
60 |
|
61 |
size_t rcvlength; |
62 |
|
63 |
/* These arrays Contain header and trailer */
|
64 |
uint8_t receiveFrameBuffer[5];
|
65 |
uint8_t transmitFrameBuffer[5];
|
66 |
|
67 |
void postReceiveDescriptorI();
|
68 |
void postTransmitDescriptorI();
|
69 |
|
70 |
uint8_t* getEncodeHeader(); |
71 |
uint8_t* getEncodeTailer(); |
72 |
int decodeHeader();
|
73 |
}; |
74 |
} |
75 |
|
76 |
#endif /* _BLUETOOTH_TRANSPORT_H_ */ |