Microchip® Advanced Software Framework

hci_transport_h5.c File Reference
#include "btstack_config.h"
#include <inttypes.h>
#include "hci.h"
#include "btstack_slip.h"
#include "btstack_debug.h"
#include "hci_transport.h"
#include "btstack_uart_block.h"

Macros

#define __BTSTACK_FILE__   "hci_transport_h5.c"
 
#define ENABLE_LOG_DEBUG
 
#define LINK_ACKNOWLEDGEMENT_TYPE   0x00
 
#define LINK_CONFIG_DATA_INTEGRITY_CHECK   1
 
#define LINK_CONFIG_FIELD   (LINK_CONFIG_SLIDING_WINDOW_SIZE | (LINK_CONFIG_OOF_FLOW_CONTROL << 3) | (LINK_CONFIG_DATA_INTEGRITY_CHECK << 4) | (LINK_CONFIG_VERSION_NR << 5))
 
#define LINK_CONFIG_OOF_FLOW_CONTROL   0
 
#define LINK_CONFIG_SLIDING_WINDOW_SIZE   1
 
#define LINK_CONFIG_VERSION_NR   0
 
#define LINK_CONTROL_MAX_LEN   3
 
#define LINK_CONTROL_PACKET_TYPE   0x0f
 
#define LINK_PERIOD_MS   250
 
#define LINK_SLIP_TX_CHUNK_LEN   64
 
#define LINK_WAKEUP_MS   50
 

Enumerations

enum  hci_transport_link_actions_t {
  HCI_TRANSPORT_LINK_SEND_SYNC = 1 << 0,
  HCI_TRANSPORT_LINK_SEND_SYNC_RESPONSE = 1 << 1,
  HCI_TRANSPORT_LINK_SEND_CONFIG = 1 << 2,
  HCI_TRANSPORT_LINK_SEND_CONFIG_RESPONSE_EMPTY = 1 << 3,
  HCI_TRANSPORT_LINK_SEND_CONFIG_RESPONSE = 1 << 4,
  HCI_TRANSPORT_LINK_SEND_SLEEP = 1 << 5,
  HCI_TRANSPORT_LINK_SEND_WOKEN = 1 << 6,
  HCI_TRANSPORT_LINK_SEND_WAKEUP = 1 << 7,
  HCI_TRANSPORT_LINK_SEND_QUEUED_PACKET = 1 << 8,
  HCI_TRANSPORT_LINK_SEND_ACK_PACKET = 1 << 9,
  HCI_TRANSPORT_LINK_ENTER_SLEEP = 1 << 10
}
 
enum  hci_transport_link_state_t {
  LINK_UNINITIALIZED,
  LINK_INITIALIZED,
  LINK_ACTIVE
}
 

Functions

static uint16_t btstack_reverse_bits_16 (uint16_t value)
 
static uint16_t crc16_calc_for_slip_frame (const uint8_t *header, const uint8_t *payload, uint16_t len)
 
static uint16_t crc16_ccitt_update (uint16_t crc, uint8_t ch)
 
static void hci_transport_h5_block_received (void)
 
static void hci_transport_h5_block_sent (void)
 
static int hci_transport_h5_can_send_packet_now (uint8_t packet_type)
 
static int hci_transport_h5_close (void)
 
static void hci_transport_h5_emit_sleep_state (int sleep_active)
 
void hci_transport_h5_enable_bcsp_mode (void)
 
static void hci_transport_h5_init (const void *transport_config)
 
const hci_transport_thci_transport_h5_instance (const btstack_uart_block_t *uart_driver)
 
static int hci_transport_h5_open (void)
 
static void hci_transport_h5_process_frame (uint16_t frame_size)
 
static void hci_transport_h5_queue_packet (uint8_t packet_type, uint8_t *packet, int size)
 
static void hci_transport_h5_read_next_byte (void)
 
static void hci_transport_h5_register_packet_handler (void(*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size))
 
static void hci_transport_h5_reset_link (void)
 
static int hci_transport_h5_send_packet (uint8_t packet_type, uint8_t *packet, int size)
 
void hci_transport_h5_set_auto_sleep (uint16_t inactivity_timeout_ms)
 
static int hci_transport_h5_set_baudrate (uint32_t baudrate)
 
static void hci_transport_inactivity_timeout_handler (btstack_timer_source_t *ts)
 
static void hci_transport_inactivity_timer_set (void)
 
static void hci_transport_link_calc_header (uint8_t *header, uint8_t sequence_nr, uint8_t acknowledgement_nr, uint8_t data_integrity_check_present, uint8_t reliable_packet, uint8_t packet_type, uint16_t payload_length)
 
static uint16_t hci_transport_link_calc_resend_timeout (uint32_t baudrate)
 
static void hci_transport_link_clear_queue (void)
 
static int hci_transport_link_have_outgoing_packet (void)
 
static int hci_transport_link_inc_seq_nr (int seq_nr)
 
static void hci_transport_link_init (void)
 
static void hci_transport_link_run (void)
 
static void hci_transport_link_send_ack_packet (void)
 
static void hci_transport_link_send_config (void)
 
static void hci_transport_link_send_config_response (void)
 
static void hci_transport_link_send_config_response_empty (void)
 
static void hci_transport_link_send_control (const uint8_t *message, int message_len)
 
static void hci_transport_link_send_queued_packet (void)
 
static void hci_transport_link_send_sleep (void)
 
static void hci_transport_link_send_sync (void)
 
static void hci_transport_link_send_sync_response (void)
 
static void hci_transport_link_send_wakeup (void)
 
static void hci_transport_link_send_woken (void)
 
static void hci_transport_link_set_timer (uint16_t timeout_ms)
 
static void hci_transport_link_timeout_handler (btstack_timer_source_t *timer)
 
static void hci_transport_link_update_resend_timeout (uint32_t baudrate)
 
static void hci_transport_slip_encode_chunk_and_send (int pos)
 
static void hci_transport_slip_init (void)
 
static void hci_transport_slip_send_frame (const uint8_t *header, const uint8_t *packet, uint16_t packet_size, uint16_t data_integrity_check)
 
static void hci_transport_slip_send_next_chunk (void)
 

Variables

static const btstack_uart_block_tbtstack_uart
 
static btstack_uart_sleep_mode_t btstack_uart_sleep_mode
 
static const uint16_t crc16_ccitt_table []
 
static uint8_t * hci_packet
 
static uint16_t hci_packet_size
 
static uint8_t hci_packet_type
 
static uint8_t hci_packet_with_pre_buffer [HCI_INCOMING_PRE_BUFFER_SIZE+6+HCI_PACKET_BUFFER_SIZE]
 
static int hci_transport_bcsp_mode
 
static const hci_transport_t hci_transport_h5
 
static uint32_t hci_transport_h5_receive_start
 
static int hci_transport_link_actions
 
static uint8_t hci_transport_link_read_byte
 H5 Interface. More...
 
static btstack_timer_source_t inactivity_timer
 
static uint8_t link_ack_nr
 
static const uint8_t link_control_config [] = { 0x03, 0xfc, LINK_CONFIG_FIELD}
 
static const uint8_t link_control_config_prefix_len = 2
 
static const uint8_t link_control_config_response [] = { 0x04, 0x7b, LINK_CONFIG_FIELD}
 
static const uint8_t link_control_config_response_empty [] = { 0x04, 0x7b}
 
static const uint8_t link_control_config_response_prefix_len = 2
 
static const uint8_t link_control_sleep [] = { 0x07, 0x78}
 
static const uint8_t link_control_sync [] = { 0x01, 0x7e}
 
static const uint8_t link_control_sync_response [] = { 0x02, 0x7d}
 
static const uint8_t link_control_wakeup [] = { 0x05, 0xfa}
 
static const uint8_t link_control_woken [] = { 0x06, 0xf9}
 
static uint16_t link_inactivity_timeout_ms
 
static uint8_t link_peer_asleep
 
static uint8_t link_peer_supports_data_integrity_check
 
static uint16_t link_resend_timeout_ms
 
static uint8_t link_seq_nr
 
static hci_transport_link_state_t link_state
 
static btstack_timer_source_t link_timer
 
static void(* packet_handler )(uint8_t packet_type, uint8_t *packet, uint16_t size)
 
static uint8_t slip_outgoing_buffer [LINK_SLIP_TX_CHUNK_LEN+4+1]
 
static uint16_t slip_outgoing_dic
 
static uint16_t slip_outgoing_dic_present
 
static int slip_write_active
 
static btstack_uart_config_t uart_config
 

#define __BTSTACK_FILE__   "hci_transport_h5.c"
#define ENABLE_LOG_DEBUG
#define LINK_ACKNOWLEDGEMENT_TYPE   0x00
#define LINK_CONFIG_DATA_INTEGRITY_CHECK   1
#define LINK_CONFIG_OOF_FLOW_CONTROL   0
#define LINK_CONFIG_SLIDING_WINDOW_SIZE   1
#define LINK_CONFIG_VERSION_NR   0
#define LINK_CONTROL_MAX_LEN   3
#define LINK_CONTROL_PACKET_TYPE   0x0f
#define LINK_SLIP_TX_CHUNK_LEN   64
#define LINK_WAKEUP_MS   50

Enumerator
HCI_TRANSPORT_LINK_SEND_SYNC 
HCI_TRANSPORT_LINK_SEND_SYNC_RESPONSE 
HCI_TRANSPORT_LINK_SEND_CONFIG 
HCI_TRANSPORT_LINK_SEND_CONFIG_RESPONSE_EMPTY 
HCI_TRANSPORT_LINK_SEND_CONFIG_RESPONSE 
HCI_TRANSPORT_LINK_SEND_SLEEP 
HCI_TRANSPORT_LINK_SEND_WOKEN 
HCI_TRANSPORT_LINK_SEND_WAKEUP 
HCI_TRANSPORT_LINK_SEND_QUEUED_PACKET 
HCI_TRANSPORT_LINK_SEND_ACK_PACKET 
HCI_TRANSPORT_LINK_ENTER_SLEEP 
Enumerator
LINK_UNINITIALIZED 
LINK_INITIALIZED 
LINK_ACTIVE 

static uint16_t btstack_reverse_bits_16 ( uint16_t  value)
static
static uint16_t crc16_calc_for_slip_frame ( const uint8_t *  header,
const uint8_t *  payload,
uint16_t  len 
)
static
static uint16_t crc16_ccitt_update ( uint16_t  crc,
uint8_t  ch 
)
static

References crc16_ccitt_table.

Referenced by crc16_calc_for_slip_frame().

static int hci_transport_h5_can_send_packet_now ( uint8_t  packet_type)
static
static int hci_transport_h5_close ( void  )
static
static void hci_transport_h5_emit_sleep_state ( int  sleep_active)
static
void hci_transport_h5_enable_bcsp_mode ( void  )
const hci_transport_t* hci_transport_h5_instance ( const btstack_uart_block_t uart_driver)

References hci_transport_h5, and uart_driver.

static void hci_transport_h5_queue_packet ( uint8_t  packet_type,
uint8_t *  packet,
int  size 
)
static
static void hci_transport_h5_read_next_byte ( void  )
static
static void hci_transport_h5_register_packet_handler ( void(*)(uint8_t packet_type, uint8_t *packet, uint16_t size)  handler)
static

References packet_handler.

static void hci_transport_h5_reset_link ( void  )
static
void hci_transport_h5_set_auto_sleep ( uint16_t  inactivity_timeout_ms)
static int hci_transport_h5_set_baudrate ( uint32_t  baudrate)
static
static void hci_transport_link_calc_header ( uint8_t *  header,
uint8_t  sequence_nr,
uint8_t  acknowledgement_nr,
uint8_t  data_integrity_check_present,
uint8_t  reliable_packet,
uint8_t  packet_type,
uint16_t  payload_length 
)
static
static uint16_t hci_transport_link_calc_resend_timeout ( uint32_t  baudrate)
static
static void hci_transport_link_clear_queue ( void  )
static
static int hci_transport_link_have_outgoing_packet ( void  )
static
static int hci_transport_link_inc_seq_nr ( int  seq_nr)
static
static void hci_transport_link_send_ack_packet ( void  )
static
static void hci_transport_link_send_config ( void  )
static
static void hci_transport_link_send_config_response ( void  )
static
static void hci_transport_link_send_config_response_empty ( void  )
static
static void hci_transport_link_send_sleep ( void  )
static
static void hci_transport_link_send_sync ( void  )
static
static void hci_transport_link_send_sync_response ( void  )
static
static void hci_transport_link_send_wakeup ( void  )
static
static void hci_transport_link_send_woken ( void  )
static
static void hci_transport_link_update_resend_timeout ( uint32_t  baudrate)
static
static void hci_transport_slip_send_frame ( const uint8_t *  header,
const uint8_t *  packet,
uint16_t  packet_size,
uint16_t  data_integrity_check 
)
static
static void hci_transport_slip_send_next_chunk ( void  )
inlinestatic

const btstack_uart_block_t* btstack_uart
static
const uint16_t crc16_ccitt_table[]
static
Initial value:
={
0x0000, 0x1081, 0x2102, 0x3183,
0x4204, 0x5285, 0x6306, 0x7387,
0x8408, 0x9489, 0xa50a, 0xb58b,
0xc60c, 0xd68d, 0xe70e, 0xf78f
}

Referenced by crc16_ccitt_update().

uint16_t hci_packet_size
static
uint8_t hci_packet_type
static
int hci_transport_bcsp_mode
static
const hci_transport_t hci_transport_h5
static
Initial value:
= {
"H5",
NULL,
}
static void hci_transport_h5_reset_link(void)
Definition: hci_transport_h5.c:901
static void hci_transport_h5_init(const void *transport_config)
Definition: hci_transport_h5.c:788
#define NULL
Definition: src/include/lwip/def.h:47
static void hci_transport_h5_register_packet_handler(void(*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size))
Definition: hci_transport_h5.c:855
static int hci_transport_h5_close(void)
Definition: hci_transport_h5.c:851
static int hci_transport_h5_open(void)
Definition: hci_transport_h5.c:811
static int hci_transport_h5_send_packet(uint8_t packet_type, uint8_t *packet, int size)
Definition: hci_transport_h5.c:865
static int hci_transport_h5_can_send_packet_now(uint8_t packet_type)
Definition: hci_transport_h5.c:859
static int hci_transport_h5_set_baudrate(uint32_t baudrate)
Definition: hci_transport_h5.c:891

Referenced by hci_transport_h5_instance().

uint32_t hci_transport_h5_receive_start
static
uint8_t hci_transport_link_read_byte
static
btstack_timer_source_t inactivity_timer
static
const uint8_t link_control_config[] = { 0x03, 0xfc, LINK_CONFIG_FIELD}
static
const uint8_t link_control_config_prefix_len = 2
static
const uint8_t link_control_config_response[] = { 0x04, 0x7b, LINK_CONFIG_FIELD}
static
const uint8_t link_control_config_response_empty[] = { 0x04, 0x7b}
static
const uint8_t link_control_config_response_prefix_len = 2
static
const uint8_t link_control_sleep[] = { 0x07, 0x78}
static
const uint8_t link_control_sync[] = { 0x01, 0x7e}
static
const uint8_t link_control_sync_response[] = { 0x02, 0x7d}
static
const uint8_t link_control_wakeup[] = { 0x05, 0xfa}
static
const uint8_t link_control_woken[] = { 0x06, 0xf9}
static
uint16_t link_inactivity_timeout_ms
static
uint8_t link_seq_nr
static
btstack_timer_source_t link_timer
static
void(* packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)
static
uint8_t slip_outgoing_buffer[LINK_SLIP_TX_CHUNK_LEN+4+1]
static
uint16_t slip_outgoing_dic
static
uint16_t slip_outgoing_dic_present
static
btstack_uart_config_t uart_config
static