Logging improvements WRT handshake
This commit is contained in:
parent
0fb0118ffa
commit
3cede6be0f
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.13.1)
|
cmake_minimum_required(VERSION 3.13.1)
|
||||||
set(CONF_FILE c3.conf)
|
set(CONF_FILE application-c3wireless_em_ble.conf)
|
||||||
|
|
||||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||||
project(hci_uart_h5)
|
project(hci_uart_h5)
|
||||||
|
|
42
src/main.c
42
src/main.c
|
@ -595,7 +595,7 @@ static void h5_init(void)
|
||||||
|
|
||||||
static int h5_open(struct device *unused)
|
static int h5_open(struct device *unused)
|
||||||
{
|
{
|
||||||
LOG_DBG("Open");
|
LOG_DBG("h5_open");
|
||||||
|
|
||||||
hci_uart_dev = device_get_binding(CONFIG_BT_CTLR_TO_HOST_UART_DEV_NAME);
|
hci_uart_dev = device_get_binding(CONFIG_BT_CTLR_TO_HOST_UART_DEV_NAME);
|
||||||
if (!hci_uart_dev) {
|
if (!hci_uart_dev) {
|
||||||
|
@ -622,7 +622,7 @@ static int h5_open(struct device *unused)
|
||||||
#if defined(CONFIG_BT_CTLR_ASSERT_HANDLER)
|
#if defined(CONFIG_BT_CTLR_ASSERT_HANDLER)
|
||||||
void bt_ctlr_assert_handle(char *file, u32_t line)
|
void bt_ctlr_assert_handle(char *file, u32_t line)
|
||||||
{
|
{
|
||||||
printk("BT_CTLR Assert %s:%u", file, line);
|
LOG_ERR("BT_CTLR Assert %s:%u", file, line);
|
||||||
sys_reboot(SYS_REBOOT_COLD);
|
sys_reboot(SYS_REBOOT_COLD);
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_CTLR_ASSERT_HANDLER */
|
#endif /* CONFIG_BT_CTLR_ASSERT_HANDLER */
|
||||||
|
@ -672,7 +672,7 @@ static struct gpio_callback gpio_cb;
|
||||||
|
|
||||||
void gpio_callback(struct device *port,
|
void gpio_callback(struct device *port,
|
||||||
struct gpio_callback *cb, u32_t pins) {
|
struct gpio_callback *cb, u32_t pins) {
|
||||||
printk("Host wants the bootloader, rebooting\n");
|
LOG_ERR("Host wants the bootloader, rebooting\n");
|
||||||
k_sleep(250);
|
k_sleep(250);
|
||||||
sys_reboot(SYS_REBOOT_COLD);
|
sys_reboot(SYS_REBOOT_COLD);
|
||||||
}
|
}
|
||||||
|
@ -683,23 +683,23 @@ void gpio_init() {
|
||||||
int ret;
|
int ret;
|
||||||
gpio_dev = device_get_binding("GPIO_0");
|
gpio_dev = device_get_binding("GPIO_0");
|
||||||
if (!gpio_dev) {
|
if (!gpio_dev) {
|
||||||
printk("Cannot find %s!\n", "GPIO_0");
|
LOG_ERR("Cannot find %s!\n", "GPIO_0");
|
||||||
}
|
}
|
||||||
ret = gpio_pin_configure(gpio_dev, BOOTLOADER_REQ_GPIO_PIN,
|
ret = gpio_pin_configure(gpio_dev, BOOTLOADER_REQ_GPIO_PIN,
|
||||||
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE | GPIO_INT_ACTIVE_LOW | GPIO_PUD_PULL_UP));
|
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE | GPIO_INT_ACTIVE_LOW | GPIO_PUD_PULL_UP));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk("Error configuring GPIO_%d!\n", BOOTLOADER_REQ_GPIO_PIN);
|
LOG_ERR("Error configuring GPIO_%d!\n", BOOTLOADER_REQ_GPIO_PIN);
|
||||||
}
|
}
|
||||||
gpio_init_callback(&gpio_cb, gpio_callback, BIT(BOOTLOADER_REQ_GPIO_PIN));
|
gpio_init_callback(&gpio_cb, gpio_callback, BIT(BOOTLOADER_REQ_GPIO_PIN));
|
||||||
|
|
||||||
ret = gpio_add_callback(gpio_dev, &gpio_cb);
|
ret = gpio_add_callback(gpio_dev, &gpio_cb);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk("Cannot setup callback!\n");
|
LOG_ERR("Cannot setup callback!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gpio_pin_enable_callback(gpio_dev, BOOTLOADER_REQ_GPIO_PIN);
|
ret = gpio_pin_enable_callback(gpio_dev, BOOTLOADER_REQ_GPIO_PIN);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk("Error enabling callback!\n");
|
LOG_ERR("Error enabling callback!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -707,8 +707,10 @@ void gpio_init() {
|
||||||
static linkstate_t do_uninit(struct net_buf const *buf) {
|
static linkstate_t do_uninit(struct net_buf const *buf) {
|
||||||
if (packet_is_sync_response(buf)) {
|
if (packet_is_sync_response(buf)) {
|
||||||
h5_send_config();
|
h5_send_config();
|
||||||
|
LOG_DBG("RX'd SYNC RESPONSE: UNINIT -> INIT");
|
||||||
return INIT;
|
return INIT;
|
||||||
} else {
|
} else {
|
||||||
|
LOG_DBG("RX'd Incorrect Type: UNINIT -> UNINIT");
|
||||||
/* SYNC is the answer to any non-SYNC_RESP packets in UNINIT state */
|
/* SYNC is the answer to any non-SYNC_RESP packets in UNINIT state */
|
||||||
h5_send_sync();
|
h5_send_sync();
|
||||||
return UNINIT;
|
return UNINIT;
|
||||||
|
@ -720,33 +722,38 @@ static linkstate_t do_init(struct net_buf const *buf) {
|
||||||
h5.tx_win = conf_rsp[2] & 0x7;
|
h5.tx_win = conf_rsp[2] & 0x7;
|
||||||
h5.tx_seq = 0;
|
h5.tx_seq = 0;
|
||||||
h5.tx_ack = 0;
|
h5.tx_ack = 0;
|
||||||
LOG_DBG("Finished H5 configuration, tx_win %u", h5.tx_win);
|
LOG_DBG("Finished H5 configuration, tx_win %u: INIT -> ACTIVE", h5.tx_win);
|
||||||
return ACTIVE;
|
return ACTIVE;
|
||||||
}
|
}
|
||||||
if (packet_is_config(buf)) {
|
if (packet_is_config(buf)) {
|
||||||
|
LOG_DBG("RX'd CONFIG: INIT -> INIT");
|
||||||
h5_send_config_response();
|
h5_send_config_response();
|
||||||
|
} else {
|
||||||
|
LOG_DBG("RX'd Other: INIT -> INIT");
|
||||||
}
|
}
|
||||||
return INIT;
|
return INIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static linkstate_t do_active(struct net_buf *buf) {
|
static linkstate_t do_active(struct net_buf *buf) {
|
||||||
if (packet_is_config(buf)) {
|
|
||||||
h5_send_config_response();
|
|
||||||
return ACTIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packet_is_config_response(buf)) {
|
|
||||||
return ACTIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packet_is_sync_response(buf) || packet_is_config(buf)) {
|
if (packet_is_sync_response(buf) || packet_is_config(buf)) {
|
||||||
|
LOG_DBG("Bad packet for ACTIVE state: ACTIVE -> UNINIT");
|
||||||
h5_send_sync();
|
h5_send_sync();
|
||||||
return UNINIT;
|
return UNINIT;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (packet_is_config(buf)) {
|
||||||
|
h5_send_config_response();
|
||||||
|
LOG_DBG("RX'd CONFIG: ACTIVE -> ACTIVE");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packet_is_config_response(buf)) {
|
||||||
|
LOG_DBG("RX'd CONFIG RESPONSE: ACTIVE -> ACTIVE");
|
||||||
|
}
|
||||||
|
|
||||||
// Presumably something from the controller
|
// Presumably something from the controller
|
||||||
if (bt_buf_get_type(buf) == BT_BUF_EVT) {
|
if (bt_buf_get_type(buf) == BT_BUF_EVT) {
|
||||||
|
LOG_DBG("RX'd CONTROLLER EVENT: ACTIVE -> ACTIVE");
|
||||||
h5_send(buf->data, HCI_EVENT_PKT, buf->len);
|
h5_send(buf->data, HCI_EVENT_PKT, buf->len);
|
||||||
} else {
|
} else {
|
||||||
LOG_HEXDUMP_ERR(buf->data, buf->len, "Unexpected buffer in host_queue");
|
LOG_HEXDUMP_ERR(buf->data, buf->len, "Unexpected buffer in host_queue");
|
||||||
|
@ -766,6 +773,7 @@ void main(void)
|
||||||
buf = net_buf_get(&h5.host_queue, K_FOREVER);
|
buf = net_buf_get(&h5.host_queue, K_FOREVER);
|
||||||
|
|
||||||
if (packet_is_sync(buf)) {
|
if (packet_is_sync(buf)) {
|
||||||
|
LOG_DBG("RX'd SYNC: %d -> UNINIT", h5.link_state);
|
||||||
h5.link_state = UNINIT;
|
h5.link_state = UNINIT;
|
||||||
h5_send_sync_response();
|
h5_send_sync_response();
|
||||||
goto next;
|
goto next;
|
||||||
|
|
Loading…
Reference in New Issue