embox

Форк
0
/
btm_bt112.c 
107 строк · 1.9 Кб
1
/**
2
 * @file
3
 * @brief Implements BTM 112 high-level routines.
4
 *
5
 * @date 15.11.11
6
 * @author Anton Kozlov
7
 */
8

9
#include <drivers/bluetooth/bluetooth.h>
10
#include <drivers/bluetooth/btm/btm112.h>
11
#include <embox/unit.h>
12

13
EMBOX_UNIT_INIT(btm112_init);
14

15
CALLBACK_INIT(nxt_bt_rx_handle_t, bt_rx);
16

17
typedef int (*string_handler)(int len, void *data);
18

19
enum state_num {
20
	CONNECT_WAIT = 0,
21
	LR_WAIT = 1,
22
	DISCONNECT_WAIT = 2
23
};
24

25
static const char *stamp[] = {
26
	"CONNECT",
27
	"\r\n",
28
	"DISCONNECT",
29
};
30

31
static int irq_hnd_wait_conn(int len, void *data);
32
static int irq_hnd_wait_lrlf(int len, void *data);
33
static int irq_hnd_wait_disconn(int len, void *data);
34

35
static string_handler str_hnds[] = {
36
	irq_hnd_wait_conn,
37
	irq_hnd_wait_lrlf,
38
	irq_hnd_wait_disconn,
39
};
40

41
static int rs_comm = 0;
42
static int rs_pos = 0;
43

44
static int set_state(int state_num) {
45
	rs_comm = state_num;
46
	rs_pos = 0;
47

48
	CALLBACK_REG(__bt_rx, str_hnds[state_num]);
49

50
	return 0;
51
}
52

53
static int general_handler(int cnt, void *data) {
54
	uint8_t *buff = (uint8_t *) data;
55

56
	while (cnt--) {
57
		if (*buff == stamp[rs_comm][rs_pos]) {
58
			rs_pos++;
59
		} else {
60
			rs_pos = 0;
61
		}
62
		if (stamp[rs_comm][rs_pos] == 0) {
63
			return 1;
64
		}
65
		buff++;
66
	}
67

68
	return 0;
69
}
70

71
static int irq_hnd_wait_conn(int len, void *data) {
72
	if (general_handler(len, data)) {
73
		set_state(LR_WAIT);
74
	}
75
	bluetooth_read(1);
76
	return 0;
77
}
78

79
static int irq_hnd_wait_lrlf(int len, void *data) {
80
	if (general_handler(len, data)) {
81
		set_state(DISCONNECT_WAIT);
82
		//Acknowlege about connect
83
		//FIXME
84
		CALLBACK(bt_state)();
85
		return 0;
86
	}
87
	bluetooth_read(1);
88
	return 0;
89
}
90

91
static int irq_hnd_wait_disconn(int len, void *data) {
92
	if (general_handler(len, data)) {
93
		set_state(CONNECT_WAIT);
94
		CALLBACK(bt_state)();
95
		bluetooth_read(1);
96
		return 0;
97
	}
98
	CALLBACK(bt_rx)(len, data);
99
	return 0;
100
}
101

102
static int btm112_init(void) {
103
	bluetooth_hw_hard_reset();
104
	CALLBACK_REG(__bt_rx, irq_hnd_wait_conn);
105
	bluetooth_read(1);
106
	return 0;
107
}
108

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.