2018-04-20 01:48:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/wireless/bluetooth/bt_uart_generic.c
|
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-04-20 01:48:04 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-04-20 01:48:04 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-04-20 01:48:04 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-04 07:10:42 +01:00
|
|
|
/* Generic UART based Bluetooth driver */
|
|
|
|
|
2018-04-20 01:48:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
|
|
|
|
#include "bt_uart.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btuart_register
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create the UART-based Bluetooth device and register it with the
|
|
|
|
* Bluetooth stack.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* lower - an instance of the lower half driver interface
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero is returned on success; a negated errno value is returned on any
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
|
|
|
|
{
|
|
|
|
FAR struct btuart_upperhalf_s *upper;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
wlinfo("lower %p\n", lower);
|
|
|
|
|
2021-01-17 21:07:37 +01:00
|
|
|
if (lower == NULL)
|
|
|
|
{
|
|
|
|
wlerr("ERROR: btuart lower half is NULL\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2018-04-20 01:48:04 +02:00
|
|
|
|
|
|
|
/* Allocate a new instance of the upper half driver state structure */
|
|
|
|
|
|
|
|
upper = (FAR struct btuart_upperhalf_s *)
|
|
|
|
kmm_zalloc(sizeof(struct btuart_upperhalf_s));
|
|
|
|
|
|
|
|
if (upper == NULL)
|
|
|
|
{
|
|
|
|
wlerr("ERROR: Failed to allocate upper-half state\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the upper half driver state */
|
|
|
|
|
|
|
|
upper->dev.head_reserve = H4_HEADER_SIZE;
|
|
|
|
upper->dev.open = btuart_open;
|
|
|
|
upper->dev.send = btuart_send;
|
2022-10-01 21:20:15 +02:00
|
|
|
upper->dev.close = btuart_close;
|
2022-10-01 21:34:17 +02:00
|
|
|
upper->dev.ioctl = btuart_ioctl;
|
2018-04-20 01:48:04 +02:00
|
|
|
upper->lower = lower;
|
|
|
|
|
|
|
|
/* And register the driver with the network and the Bluetooth stack. */
|
|
|
|
|
|
|
|
ret = bt_netdev_register(&upper->dev);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-12-31 16:30:44 +01:00
|
|
|
wlerr("ERROR: bt_netdev_registe failed: %d\n", ret);
|
2018-04-20 01:48:04 +02:00
|
|
|
kmm_free(upper);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|