cc2564b: support Maxim max32630fthr board

max32630fthr uses PAN1326B based TI CC2564B TI Controller

Board Link:
https://www.maximintegrated.com/en/products/digital/microcontrollers/MAX32630FTHR.html
This commit is contained in:
Ismail H. Kose 2017-05-26 11:37:16 -07:00 committed by Matthias Ringwald
parent c573ae3327
commit 91b4ef4e10
20 changed files with 2066 additions and 0 deletions

View File

@ -21,6 +21,7 @@ SUBDIRS = \
posix-h4 \
posix-h5 \
stm32-f103rb-nucleo \
max32630-fthr-cc2564b \
EXCLUDED = \
pic32-harmony/app.X \

17
port/max32630-fthr-cc2564b/.gitignore vendored Normal file
View File

@ -0,0 +1,17 @@
.swp
.*.sw[op]
*~
*.o
*.a
*.xml
*.d
*.map
*.elf
build/
GPATH
GRTAGS
GTAGS
tags
*.txt
*.log
core

View File

@ -0,0 +1,200 @@
################################################################################
# Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
# Ismail H. Kose <ismail.kose@maximintegrated.com>
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name of Maxim Integrated
# Products, Inc. shall not be used except as stated in the Maxim Integrated
# Products, Inc. Branding Policy.
#
# The mere transfer of this software does not imply any licenses
# of trade secrets, proprietary technology, copyrights, patents,
# trademarks, maskwork rights, or any other form of intellectual
# property whatsoever. Maxim Integrated Products, Inc. retains all
# ownership rights.
#
# $Date: 2016-03-23 13:28:53 -0700 (Wed, 23 Mar 2016) $
# $Revision: 22067 $
#
###############################################################################
# Maxim ARM Toolchain and Libraries
# https://www.maximintegrated.com/en/products/digital/microcontrollers/MAX32630.html
# This is the name of the build output file
PROJECT=max3263x
# Specify the target processor
TARGET=MAX3263x
PROJ_CFLAGS+=-DRO_FREQ=96000000
# Create Target name variables
TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z)
TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z)
CC2564B = bluetooth_init_cc2564B_1.6_BT_Spec_4.1.o
# Select 'GCC' or 'IAR' compiler
COMPILER=GCC
ifeq "$(MAXIM_PATH)" ""
LIBS_DIR=/$(subst \,/,$(subst :,,$(HOME))/Maxim/Firmware/$(TARGET_UC)/Libraries)
$(warning "MAXIM_PATH need to be set. Please run setenv bash file in the Maxim Toolchain directory.")
else
LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries)
endif
CMSIS_ROOT=$(LIBS_DIR)/CMSIS
# Where to find source files for this test
VPATH=.
# Where to find header files for this test
IPATH=.
BOARD_DIR=$(LIBS_DIR)/Boards
IPATH += board/
VPATH += board/
# Source files for this test (add path to VPATH below)
SRCS = main.c
SRCS += hal_tick.c
SRCS += btstack_port.c
SRCS += spp_and_le_streamer.c
SRCS += board.c
SRCS += stdio.c
SRCS += led.c
SRCS += pb.c
SRCS += max14690n.c
# Where to find BSP source files
VPATH += $(BOARD_DIR)/Source
# Where to find BSP header files
IPATH += $(BOARD_DIR)/Include
# Btstack
BTSTACK_ROOT = ../..
VPATH += $(BTSTACK_ROOT)/src
VPATH += $(BTSTACK_ROOT)/src/ble
VPATH += $(BTSTACK_ROOT)/src/classic
VPATH += $(BTSTACK_ROOT)/chipset/cc256x
VPATH += ${BTSTACK_ROOT}/platform/embedded
VPATH += ${BTSTACK_ROOT}/src/ble/gatt-service/
VPATH += $(BTSTACK_ROOT)/port/pegasus-max3263x
VPATH += $(BTSTACK_ROOT)/example
PROJ_CFLAGS += \
-I$(BTSTACK_ROOT)/src \
-I$(BTSTACK_ROOT)/src/ble \
-I$(BTSTACK_ROOT)/src/classic \
-I$(BTSTACK_ROOT)/chipset/cc256x \
-I$(BTSTACK_ROOT)/platform/embedded \
-I${BTSTACK_ROOT}/port/pegasus-max3263x \
-I${BTSTACK_ROOT}/src/ble/gatt-service/ \
-I${BTSTACK_ROOT}/example
CORE = \
ad_parser.o \
btstack_linked_list.o \
btstack_memory.o \
btstack_memory_pool.o \
btstack_run_loop.o \
btstack_util.o \
l2cap.o \
l2cap_signaling.o \
btstack_run_loop_embedded.o \
$(CC2564B) \
hci_transport_h4.o
COMMON = \
btstack_chipset_cc256x.o \
hci.o \
hci_cmd.o \
hci_dump.o \
btstack_uart_block_embedded.o
CLASSIC = \
btstack_link_key_db_memory.o \
rfcomm.o \
sdp_util.o \
spp_server.o \
sdp_server.o \
sdp_client.o \
sdp_client_rfcomm.o
BLE = \
att_db.o \
att_server.o \
le_device_db_memory.o \
att_dispatch.o \
sm.o
ADDITION =
CORE_OBJ = $(CORE:.c=.o)
COMMON_OBJ = $(COMMON:.c=.o)
BLE_OBJ = $(BLE:.c=.o)
CLASSIC_OBJ = $(CLASSIC:.c=.o)
SRCS += $(CORE_OBJ)
SRCS += $(COMMON_OBJ)
SRCS += $(BLE_OBJ)
SRCS += $(CLASSIC_OBJ)
# Enable assertion checking for development
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE
# Use this variables to specify and alternate tool path
#TOOL_DIR=/opt/gcc-arm-none-eabi-4_8-2013q4/bin
# Use these variables to add project specific tool options
#PROJ_CFLAGS+=--specs=nano.specs
#PROJ_LDFLAGS+=--specs=nano.specs
# Point this variable to a startup file to override the default file
#STARTUPFILE=start.S
# Point this variable to a linker file to override the default file
# LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld
# Include the peripheral driver
PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET_UC)PeriphDriver
include $(PERIPH_DRIVER_DIR)/periphdriver.mk
################################################################################
# Include the rules for building for this target. All other makefiles should be
# included before this one.
include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk
# fetch and convert init scripts
# use bluetooth_init_cc2564B_1.6_BT_Spec_4.1.c
include ${BTSTACK_ROOT}/chipset/cc256x/Makefile.inc
#include ${BTSTACK_ROOT}/example/Makefile.inc
spp_and_le_streamer.h: spp_and_le_streamer.gatt
python ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@
generate_header_file: spp_and_le_streamer.h
# The rule to clean out all the build products.
distclean: clean
$(MAKE) -C ${PERIPH_DRIVER_DIR} clean

View File

@ -0,0 +1,76 @@
# BTstack Port for the Maxim MAX32630FTHR ARM Cortex-M4F
This port uses the MAX32630FTHR ARM Cortex M4F Board onboard TI's CC2564B Bluetooth controller.
Maxim ARM Toolchain is free software that provides peripheral libraries, linker files, initial code and some board files.
The toolchain also provides Eclipse Neon and Maxim modified OpenOCD to program the microcontroller.
It also provides various examples for Maxim Cortex M4F ARM processors. Maxim released OpenOCD was used to flash and debug the max32630fthr port.
The port uses non-blocking polling UART communication with hardware flow control for Bluetooth controller. It was tested and achieved up to 1.8Mbps bandwidth between two Max32630FTHR boards.
## Hardware
- [MAX32630FTHR Board] (https://www.maximintegrated.com/en/products/digital/microcontrollers/MAX32630FTHR.html)
## Software
You need to install Maxim ARM Toolchain. The Libraries and the toolchain can be downloaded from [Maxim Toolchains] (https://www.maximintegrated.com/en/products/digital/microcontrollers/MAX32630.html/tb_tab2) page. Regular openocd does not support Maxim ARM microcontrollers yet. Maxim modified OpenOCD can be found in the toolchain.
In the Maxim Toolchain installation directory, there is a setenv.sh file that sets the MAXIM_PATH. This file needs to run at the beginning and set the enviromental variables.
## Usage
The example can be compiled using GNU ARM Toolchain and the firmware binary can be flashed using OpenOCD or eclipse.
## Build
Go to port/max32630fthr folder and run "make" command in terminal. You can also open the project using Eclipse and build it.
MAXIM_PATH needs to point to the root directory where the tool chain installed. Or makefile could be modified to point to the libraries.
"make" command will build and generate .elf file which is convenient for debugging using Eclipse or GDB.
$ make
"make release" command will generate .bin file that can be used to program using Daplink adapter.
## Eclipse
Toolchain and Eclipse guide can be found in README.pdf file where the Maxim Toolchain installed.
Please note that this development was not made with eclipse.
## Flashing Max32630 ARM Processor
There are two ways to program the board. The simplest way is drag and drop the max3263x.bin file to DAPLINK mass storage drive. Once the file is copied to the mass storage device, it should program and then run the new firmware.
OpenOcd also can be used for developing and especially for debugging. Eclipse or GDB could be used for step by step debugging.
The programming script can be found in the scripts folder.
To flash the microcontroller, 'flash_Max32630_hdk.sh' script needs to be run in the max32630fthr directory.
## Debug output
printf messages are redirected to UART2.
To get the console output, connect P3_1 (UART TX) of the MAX32630FTHR board to a USB-to-UART adapter and open a terminal at 115200 baudrate with no hardware/software flow control.
In src/btstack_config.h resp. in example/btstack_config.h of the generated projects, additional debug information can be enabled by uncommenting ENABLE_LOG_INFO.
## Modifications to the GATT Database
In BTstack, the GATT Database is defined via the .gatt file in the example folder. Before it can be used, run the following command in max32630fthr directory.
$ make generate_header_file
or
$ python ../../tool/compile_gatt.py spp_and_le_streamer.gatt spp_and_le_streamer.h
## Notes
- bluetooth_init_cc2564B_1.6_BT_Spec_4.1.c file added as default. If "include ${BTSTACK_ROOT}/chipset/cc256x/Makefile.inc" is enabled in the Makefile, it will automatically download the bts files and convert it to a c file.
## TODOs
- Add Eclipse project for max32630fthr
- link to sources instead of copying into every example project
- support link-key-db for on flash memory

View File

@ -0,0 +1,143 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2016-03-17 14:27:29 -0700 (Thu, 17 Mar 2016) $
* $Revision: 21966 $
*
******************************************************************************/
#include <stdio.h>
#include "mxc_config.h"
#include "mxc_assert.h"
#include "board.h"
#include "gpio.h"
#include "uart.h"
#include "spim.h"
#include "max14690n.h"
/***** Global Variables *****/
// LEDs
// Note: EvKit board uses 3.3v supply so these must be open-drain.
const gpio_cfg_t led_pin[] = {
{ PORT_2, PIN_4, GPIO_FUNC_GPIO, GPIO_PAD_OPEN_DRAIN },
{ PORT_2, PIN_5, GPIO_FUNC_GPIO, GPIO_PAD_OPEN_DRAIN },
{ PORT_2, PIN_6, GPIO_FUNC_GPIO, GPIO_PAD_OPEN_DRAIN },
};
const unsigned int num_leds = (sizeof(led_pin) / sizeof(gpio_cfg_t));
// Pushbuttons
const gpio_cfg_t pb_pin[] = {
{ PORT_2, PIN_3, GPIO_FUNC_GPIO, GPIO_PAD_INPUT_PULLUP },
};
const unsigned int num_pbs = (sizeof(pb_pin) / sizeof(gpio_cfg_t));
// Console UART configuration
const uart_cfg_t console_uart_cfg = {
.parity = UART_PARITY_DISABLE,
.size = UART_DATA_SIZE_8_BITS,
.extra_stop = 0,
.cts = 0,
.rts = 0,
.baud = CONSOLE_BAUD,
};
const sys_cfg_uart_t console_sys_cfg = {
.clk_scale = CLKMAN_SCALE_AUTO,
.io_cfg = IOMAN_UART(CONSOLE_UART, IOMAN_MAP_A, IOMAN_MAP_UNUSED, IOMAN_MAP_UNUSED, 1, 0, 0)
};
// MAX14690 PMIC
const ioman_cfg_t max14690_io_cfg = IOMAN_I2CM2(IOMAN_MAP_A, 1);
const gpio_cfg_t max14690_int = { PORT_3, PIN_7, GPIO_FUNC_GPIO, GPIO_PAD_INPUT_PULLUP };
const gpio_cfg_t max14690_mpc0 = { PORT_2, PIN_7, GPIO_FUNC_GPIO, GPIO_PAD_NORMAL };
/***** File Scope Variables *****/
/******************************************************************************/
void mxc_assert(const char *expr, const char *file, int line)
{
printf("MXC_ASSERT %s #%d: (%s)\n", file, line, expr);
while (1);
}
/******************************************************************************/
int Board_Init(void)
{
int err;
if ((err = Console_Init()) != E_NO_ERROR) {
MXC_ASSERT_FAIL();
return err;
}
if ((err = LED_Init()) != E_NO_ERROR) {
MXC_ASSERT_FAIL();
return err;
}
if ((err = PB_Init()) != E_NO_ERROR) {
MXC_ASSERT_FAIL();
return err;
}
/* On the Pegasus board MPC1 is connected to CAP which is high when VBUS is present.
* The LDO_OUTPUT_MPC1 setting will automatically enable the output when VBUS is present.
* The LDO_OUTPUT_MPC1 setting will also disable the output when powered from the battery.
* The Pegasus board uses LDO2 for VDDB (USB), LEDs and the SD card connector.
* Use the MAX14690_LDO2setMode(mode) function to enable LDO2 when needed.
*/
if ((err = MAX14690N_Init(3.3, LDO_OUTPUT_MPC1, 3.3, LDO_OUTPUT_DISABLED)) != E_NO_ERROR) {
MXC_ASSERT_FAIL();
return err;
}
return E_NO_ERROR;
}
/******************************************************************************/
int Console_Init(void)
{
int err;
if ((err = UART_Init(MXC_UART_GET_UART(CONSOLE_UART), &console_uart_cfg, &console_sys_cfg)) != E_NO_ERROR) {
MXC_ASSERT_FAIL();
return err;
}
return E_NO_ERROR;
}
/******************************************************************************/
int Console_PrepForSleep(void)
{
fflush(stdout);
return UART_PrepForSleep(MXC_UART_GET_UART(CONSOLE_UART));
}

View File

@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2016-03-11 10:46:02 -0700 (Fri, 11 Mar 2016) $
* $Revision: 21838 $
*
******************************************************************************/
/**
* @file board.h
* @brief Board support package API.
*/
#ifndef _BOARD_H
#define _BOARD_H
#include "gpio.h"
#include "spim.h"
#include "ioman.h"
#include "led.h"
#include "pb.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef CONSOLE_UART
#define CONSOLE_UART 1 /// UART instance to use for console
#endif
#ifndef CONSOLE_BAUD
#define CONSOLE_BAUD 115200 /// Console baud rate
#endif
// Pushbutton Indices
#define SW1 0 /// Pushbutton index for SW1
#define LED_OFF 1 /// Inactive state of LEDs
#define LED_ON 0 /// Active state of LEDs
// Console UART configuration
extern const uart_cfg_t console_uart_cfg;
extern const sys_cfg_uart_t console_sys_cfg;
// MAX14690 PMIC
#define MAX14690_I2CM_INST 0
#define MAX14690_I2CM MXC_I2CM2
extern const ioman_cfg_t max14690_io_cfg;
extern const gpio_cfg_t max14690_int;
extern const gpio_cfg_t max14690_mpc0;
/**
* \brief Initialize the BSP and board interfaces.
* \returns #E_NO_ERROR if everything is successful
*/
int Board_Init(void);
/**
* \brief Initialize or reinitialize the console. This may be necessary if the
* system clock rate is changed.
* \returns #E_NO_ERROR if everything is successful
*/
int Console_Init(void);
/**
* \brief Attempt to prepare the console for sleep.
* \returns #E_NO_ERROR if ready to sleep, #E_BUSY if not ready for sleep.
*/
int Console_PrepForSleep(void);
#ifdef __cplusplus
}
#endif
#endif /* _BOARD_H */

View File

@ -0,0 +1,232 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2016-03-11 10:46:37 -0700 (Fri, 11 Mar 2016) $
* $Revision: 21839 $
*
******************************************************************************/
/***** Includes *****/
#include <stddef.h>
#include "mxc_config.h"
#include "mxc_sys.h"
#include "max14690n.h"
#include "board.h"
#include "i2cm.h"
#include "lp.h"
/***** Definitions *****/
#define MAX14690_I2C_ADDR (0x50 >> 1)
#define MAX14690_ADDR_ID 0x00
#define MAX14690_ADDR_LDO2 0x14
#define MAX14690_LDO_EN 0x02
/***** Function Prototypes *****/
static void VBUS_Interrupt(void *unused);
/******************************************************************************/
int MAX14690N_Init(float ldo2v, ldo_enable_mode_t ldo2en, float ldo3v, ldo_enable_mode_t ldo3en)
{
uint8_t addr;
uint8_t data[2];
/* Setup the I2CM Peripheral to talk to the MAX14690 */
sys_cfg_i2cm_t cfg;
cfg.clk_scale = CLKMAN_SCALE_DIV_1;
cfg.io_cfg = max14690_io_cfg;
I2CM_Init(MAX14690_I2CM, &cfg, I2CM_SPEED_100KHZ);
/* Attempt to read the ID from the device */
addr = MAX14690_ADDR_ID;
if (I2CM_Read(MAX14690_I2CM, MAX14690_I2C_ADDR, &addr, 1, data, 2) != 2) {
return E_COMM_ERR;
}
/* Configure the initial state of LDO2 */
if ((0.8 <= ldo2v)&&(ldo2v <= 3.6)){
data[0] = MAX14690_REG_LDO2_VSET;
data[1] = (10 * ldo2v) - 8;
if (I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2) != 2) {
return -1;
}
}
data[0] = MAX14690_REG_LDO2_CFG;
data[1] = ldo2en;
if (I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2) != 2) {
return -1;
}
/* Configure the initial state of LDO3 */
if ((0.8 <= ldo3v)&&(ldo3v <= 3.6)){
data[0] = MAX14690_REG_LDO3_VSET;
data[1] = (10 * ldo3v) - 8;
if (I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2) != 2) {
return -1;
}
} else {
return -1;
}
data[0] = MAX14690_REG_LDO3_CFG;
data[1] = ldo3en;
if (I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2) != 2) {
return -1;
}
VBUS_Interrupt(NULL);
/* Configure GPIO for interrupt pin from PMIC */
if (GPIO_Config(&max14690_int) != E_NO_ERROR) {
return E_UNKNOWN;
}
/* Configure and enable interrupt */
GPIO_RegisterCallback(&max14690_int, VBUS_Interrupt, NULL);
GPIO_IntConfig(&max14690_int, GPIO_INT_FALLING_EDGE);
GPIO_IntEnable(&max14690_int);
NVIC_EnableIRQ(MXC_GPIO_GET_IRQ(max14690_int.port));
/* Configure interrupt wakeup */
if (LP_ConfigGPIOWakeUpDetect(&max14690_int, 0, LP_WEAK_PULL_UP) != E_NO_ERROR) {
return E_UNKNOWN;
}
/* Enable the VBUS interrupt */
data[0] = 0x07; /* IntMaskA */
data[1] = 0x08; /* UsbOk */
if (I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2) != 2) {
return -1;
}
return E_NO_ERROR;
}
/******************************************************************************/
static void VBUS_Interrupt(void *unused)
{
uint8_t addr = 0x02; /* StatusA */
uint8_t data[5];
if (I2CM_Read(MAX14690_I2CM, MAX14690_I2C_ADDR, &addr, 1, data, sizeof(data)) == sizeof(data)) {
if (data[1] & 0x08) { /* UsbOk */
/* VBUS is present. Enable LDO2 */
// MAX14690_EnableLDO2(1);
} else {
/* VBUS is not present. Disable LDO2 */
// MAX14690_EnableLDO2(0);
}
}
}
/******************************************************************************/
int MAX14690_LDO2setMode(ldo_enable_mode_t mode)
{
int retval;
uint8_t data[2] = {MAX14690_REG_LDO2_CFG, mode};
retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2);
if(retval != 2) {
return retval;
}
return E_NO_ERROR;
}
/******************************************************************************/
int MAX14690_LDO2setV(float voltage)
{
int retval;
uint8_t data[2] = {MAX14690_REG_LDO2_VSET, 0};
if ((0.8 <= voltage)&&(voltage <= 3.6)){
data[1] = (10 * voltage) - 8;
} else {
return -1;
}
retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2);
if(retval != 2) {
return retval;
}
return E_NO_ERROR;
}
/******************************************************************************/
int MAX14690_LDO3setMode(ldo_enable_mode_t mode)
{
int retval;
uint8_t data[2] = {MAX14690_REG_LDO3_CFG, mode};
retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2);
if(retval != 2) {
return retval;
}
return E_NO_ERROR;
}
/******************************************************************************/
int MAX14690_LDO3setV(float voltage)
{
int retval;
uint8_t data[2] = {MAX14690_REG_LDO3_VSET, 0};
if ((0.8 <= voltage)&&(voltage <= 3.6)){
data[1] = (10 * voltage) - 8;
} else {
return -1;
}
retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2);
if(retval != 2) {
return retval;
}
return E_NO_ERROR;
}
/******************************************************************************/
int MAX14690_MuxSet(max14690_mux_ch_t ch, max14690_mux_div_t div)
{
int retval;
uint8_t data[2] = {MAX14690_REG_MON_CFG, 0};
data[1] = (div << 4) + ch;
retval = I2CM_Write(MAX14690_I2CM, MAX14690_I2C_ADDR, NULL, 0, data, 2);
if(retval != 2) {
return retval;
}
return E_NO_ERROR;
}

View File

@ -0,0 +1,148 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2016-03-11 10:46:37 -0700 (Fri, 11 Mar 2016) $
* $Revision: 21839 $
*
******************************************************************************/
/**
* @file max14690n.h
* @brief MAX14690 PMIC driver API.
*/
#ifndef _MAX14690_H_
#define _MAX14690_H_
#ifdef __cplusplus
extern "C" {
#endif
/***** Definitions *****/
typedef enum { // I2C Register Addresses
MAX14690_REG_CHIP_ID,
MAX14690_REG_CHIP_REV,
MAX14690_REG_STATUS_A,
MAX14690_REG_STATUS_B,
MAX14690_REG_STATUS_C,
MAX14690_REG_INT_A,
MAX14690_REG_INT_B,
MAX14690_REG_INT_MASK_A,
MAX14690_REG_INT_MASK_B,
MAX14690_REG_ILIM_CNTL,
MAX14690_REG_CHG_CNTL_A,
MAX14690_REG_CHG_CNTL_B,
MAX14690_REG_CHG_TMR,
MAX14690_REG_BUCK1_CFG,
MAX14690_REG_BUCK1_VSET,
MAX14690_REG_BUCK2_CFG,
MAX14690_REG_BUCK2_VSET,
MAX14690_REG_RSVD_11,
MAX14690_REG_LDO1_CFG,
MAX14690_REG_LDO1_VSET,
MAX14690_REG_LDO2_CFG,
MAX14690_REG_LDO2_VSET,
MAX14690_REG_LDO3_CFG,
MAX14690_REG_LDO3_VSET,
MAX14690_REG_THRM_CFG,
MAX14690_REG_MON_CFG,
MAX14690_REG_BOOT_CFG,
MAX14690_REG_PIN_STAT,
MAX14690_REG_BUCK_EXTRA,
MAX14690_REG_PWR_CFG,
MAX14690_REG_RSVD_1E,
MAX14690_REG_PWR_OFF,
} max14690_reg_map_t;
typedef enum {
LDO_OUTPUT_DISABLED,
SW_OUTPUT_DISABLED,
LDO_OUTPUT_ENABLED,
SW_OUTPUT_ENABLED,
LDO_OUTPUT_MPC0,
SW_OUTPUT_MPC0,
LDO_OUTPUT_MPC1,
SW_OUTPUT_MPC1,
LDO_OUTPUT_DISABLED_ACT_DIS,
SW_OUTPUT_DISABLED_ACT_DIS,
LDO_OUTPUT_ENABLED_ACT_DIS,
SW_OUTPUT_ENABLED_ACT_DIS,
LDO_OUTPUT_MPC0_ACT_DIS,
SW_OUTPUT_MPC0_ACT_DIS,
LDO_OUTPUT_MPC1_ACT_DIS,
SW_OUTPUT_MPC1_ACT_DIS,
} ldo_enable_mode_t;
typedef enum {
MAX14690_MUX_SEL_PULLDOWN,
MAX14690_MUX_SEL_BAT,
MAX14690_MUX_SEL_SYS,
MAX14690_MUX_SEL_BUCK1,
MAX14690_MUX_SEL_BUCK2,
MAX14690_MUX_SEL_LDO1,
MAX14690_MUX_SEL_LDO2,
MAX14690_MUX_SEL_LDO3,
MAX14690_MUX_SEL_HIZ,
} max14690_mux_ch_t;
typedef enum {
MAX14690_MUX_DIV_4,
MAX14690_MUX_DIV_3,
MAX14690_MUX_DIV_2,
MAX14690_MUX_DIV_1,
} max14690_mux_div_t;
/***** Function Prototypes *****/
/**
* @brief Initialize the MAX14690.
* @returns #E_NO_ERROR if everything is successful, error if unsuccessful.
*/
int MAX14690N_Init(float ldo2v, ldo_enable_mode_t ldo2en, float ldo3v, ldo_enable_mode_t ldo3en);
/**
* @brief Enable or disable LDO2.
* @param enable 1 to enable, 0 to disable LDO2.
* @returns #E_NO_ERROR if everything is successful, error if unsuccessful.
*/
int MAX14690_LDO2setMode(ldo_enable_mode_t mode);
int MAX14690_LDO2setV(float voltage);
int MAX14690_LDO3setMode(ldo_enable_mode_t mode);
int MAX14690_LDO3setV(float voltage);
int MAX14690_MuxSet(max14690_mux_ch_t ch, max14690_mux_div_t div);
#ifdef __cplusplus
}
#endif
#endif /* _MAX14690_H_ */

View File

@ -0,0 +1,51 @@
// Maxim Max32630FTHR Port
//
#ifndef __BTSTACK_CONFIG
#define __BTSTACK_CONFIG
#include <stdint.h>
// Port related features
#define HAVE_INIT_SCRIPT
#define HAVE_EMBEDDED_TIME_MS
//#define HAVE_POSIX_TIME
//#define HAVE_MALLOC
// BTstack features that can be enabled
#define ENABLE_BLE
#define ENABLE_CLASSIC
#define ENABLE_LE_PERIPHERAL
#define ENABLE_LE_CENTRAL
//#define ENABLE_LOG_INTO_HCI_DUMP
//#define ENABLE_LOG_DEBUG
#define ENABLE_LOG_ERROR
//#define ENABLE_LOG_INFO
//#define ENABLE_SDP_DES_DUMP
//#define ENABLE_SDP_EXTRA_QUERIES
// #define ENABLE_LE_SECURE_CONNECTIONS
// BTstack configuration. buffers, sizes, ...
// BTstack configuration. buffers, sizes, ...
//#define HCI_INCOMING_PRE_BUFFER_SIZE 6
#define HCI_ACL_PAYLOAD_SIZE 1021
#define MAX_SPP_CONNECTIONS 1
#define MAX_NR_HCI_CONNECTIONS MAX_SPP_CONNECTIONS
#define MAX_NR_GATT_CLIENTS 0
#define MAX_NR_GATT_SUBCLIENTS 0
#define MAX_NR_HFP_CONNECTIONS 0
#define MAX_NR_L2CAP_SERVICES 2
#define MAX_NR_L2CAP_CHANNELS (1+MAX_SPP_CONNECTIONS)
#define MAX_NR_RFCOMM_MULTIPLEXERS MAX_SPP_CONNECTIONS
#define MAX_NR_RFCOMM_SERVICES 1
#define MAX_NR_RFCOMM_CHANNELS MAX_SPP_CONNECTIONS
#define MAX_NR_BNEP_SERVICES 1
#define MAX_NR_BNEP_CHANNELS MAX_SPP_CONNECTIONS
#define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 2
#define MAX_NR_WHITELIST_ENTRIES 1
#define MAX_NR_SM_LOOKUP_ENTRIES 3
#define MAX_NR_SERVICE_RECORD_ITEMS 1
#define MAX_NR_LE_DEVICE_DB_ENTRIES 1
#endif

View File

@ -0,0 +1,287 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
* Author: Ismail H. Kose <ismail.kose@maximintegrated.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*******************************************************************************
*/
#include "hal_tick.h"
#include <stdio.h>
#include <string.h>
#include "lp.h"
#include "uart.h"
#include "board.h"
#include "btstack_debug.h"
#include "btstack.h"
#include "btstack_config.h"
#include "btstack_run_loop_embedded.h"
#include "btstack_chipset_cc256x.h"
#include "btstack_port.h"
#define CC256X_UART_ID 0
#define UART_RXFIFO_USABLE (MXC_UART_FIFO_DEPTH-3)
static uint32_t baud_rate;
// rx state
static int bytes_to_read = 0;
static uint8_t * rx_buffer_ptr = 0;
// tx state
static int bytes_to_write = 0;
static uint8_t * tx_buffer_ptr = 0;
const gpio_cfg_t PAN1326_SLOW_CLK = { PORT_1, PIN_7, GPIO_FUNC_GPIO,
GPIO_PAD_NORMAL };
const gpio_cfg_t PAN1326_nSHUTD = { PORT_1, PIN_6, GPIO_FUNC_GPIO,
GPIO_PAD_NORMAL };
const gpio_cfg_t PAN1326_HCIRTS = { PORT_0, PIN_3, GPIO_FUNC_GPIO,
GPIO_PAD_NORMAL };
static void dummy_handler(void) {};
static void (*rx_done_handler)(void) = dummy_handler;
static void (*tx_done_handler)(void) = dummy_handler;
void hal_cpu_disable_irqs(void)
{
__disable_irq();
}
void hal_cpu_enable_irqs(void)
{
__enable_irq();
}
void hal_cpu_enable_irqs_and_sleep(void)
{
}
void hal_uart_dma_send_block(const uint8_t *buffer, uint16_t len)
{
tx_buffer_ptr = (uint8_t *)buffer;
bytes_to_write = len;
}
void hal_uart_dma_receive_block(uint8_t *buffer, uint16_t len)
{
rx_buffer_ptr = buffer;
bytes_to_read = len;
}
void hal_btstack_run_loop_execute_once(void)
{
int rx_avail;
int num_rx_bytes;
int tx_avail;
int rx_bytes;
int tx_bytes;
int ret;
while (bytes_to_read) {
rx_avail = UART_NumReadAvail(MXC_UART_GET_UART(CC256X_UART_ID));
if (!rx_avail)
break;
if (bytes_to_read > rx_avail)
num_rx_bytes = rx_avail;
else
num_rx_bytes = bytes_to_read;
ret = UART_Read(MXC_UART_GET_UART(CC256X_UART_ID), rx_buffer_ptr, num_rx_bytes, &rx_bytes);
if (ret < 0)
break;
rx_buffer_ptr += rx_bytes;
bytes_to_read -= rx_bytes;
if (bytes_to_read < 0) {
bytes_to_read = 0;
}
if (bytes_to_read == 0){
(*rx_done_handler)();
}
}
while (bytes_to_write) {
tx_avail = UART_NumWriteAvail(MXC_UART_GET_UART(CC256X_UART_ID));
if (!tx_avail)
break;
if (bytes_to_write > tx_avail)
tx_bytes = tx_avail;
else
tx_bytes = bytes_to_write;
ret = UART_Write(MXC_UART_GET_UART(CC256X_UART_ID), tx_buffer_ptr, tx_bytes);
if (ret < 0)
break;
bytes_to_write -= tx_bytes;
tx_buffer_ptr += tx_bytes;
if (bytes_to_write < 0) {
bytes_to_write = 0;
}
if (bytes_to_write == 0){
(*tx_done_handler)();
}
}
btstack_run_loop_embedded_execute_once();
}
void hal_uart_init(void)
{
int error = 0;
uart_cfg_t cfg;
cfg.parity = UART_PARITY_DISABLE;
cfg.size = UART_DATA_SIZE_8_BITS;
cfg.extra_stop = 0;
cfg.cts = 1;
cfg.rts = 1;
cfg.baud = baud_rate;
sys_cfg_uart_t sys_cfg;
sys_cfg.clk_scale = CLKMAN_SCALE_AUTO;
sys_cfg.io_cfg = (ioman_cfg_t )IOMAN_UART(0,
IOMAN_MAP_B, // io_map
IOMAN_MAP_B, // cts_map
IOMAN_MAP_B, // rts_map
1, // io_en
1, // cts_en
1); //rts_en
if ((error = UART_Init(MXC_UART_GET_UART(CC256X_UART_ID), &cfg, &sys_cfg)) != E_NO_ERROR) {
printf("Error initializing UART %d\n", error);
while (1);
} else {
printf("BTSTACK UART Initialized\n");
}
MXC_UART_GET_UART(CC256X_UART_ID)->ctrl |= MXC_F_UART_CTRL_CTS_POLARITY | MXC_F_UART_CTRL_RTS_POLARITY;
MXC_UART_GET_UART(CC256X_UART_ID)->ctrl &= ~((MXC_UART_FIFO_DEPTH - 4) << (MXC_F_UART_CTRL_RTS_LEVEL_POS));
MXC_UART_GET_UART(CC256X_UART_ID)->ctrl |= ((UART_RXFIFO_USABLE) << MXC_F_UART_CTRL_RTS_LEVEL_POS);
}
int hal_uart_dma_set_baud(uint32_t baud){
baud_rate = baud;
printf("BAUD RATE IS = %d \n", baud);
hal_uart_init();
return baud_rate;
}
void hal_uart_dma_init(void){
bytes_to_write = 0;
bytes_to_read = 0;
hal_uart_dma_set_baud(115200);
}
void hal_uart_dma_set_block_received( void (*block_handler)(void)){
rx_done_handler = block_handler;
}
void hal_uart_dma_set_block_sent( void (*block_handler)(void)){
tx_done_handler = block_handler;
}
void hal_uart_dma_set_csr_irq_handler( void (*csr_irq_handler)(void)){
}
void hal_uart_dma_set_sleep(uint8_t sleep){
}
void init_slow_clock(void)
{
MXC_PWRSEQ->reg0 &= ~(MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN | MXC_F_PWRSEQ_REG0_PWR_RTCEN_SLP);
MXC_PWRSEQ->reg4 &= ~MXC_F_PWRSEQ_REG4_PWR_PSEQ_32K_EN;
MXC_PWRSEQ->reg0 |= MXC_F_PWRSEQ_REG0_PWR_RTCEN_RUN | MXC_F_PWRSEQ_REG0_PWR_RTCEN_SLP; // Enable RTC
hal_delay_us(1);
MXC_PWRSEQ->reg4 |= MXC_F_PWRSEQ_REG4_PWR_PSEQ_32K_EN; // Enable the RTC out of P1.7
}
int bt_comm_init() {
int error = 0;
int cnt = 0;
hal_tick_init();
hal_delay_us(1);
if ((error = GPIO_Config(&PAN1326_HCIRTS)) != E_NO_ERROR) {
printf("Error setting PAN1326_HCIRTS %d\n", error);
}
GPIO_OutSet(&PAN1326_HCIRTS);
init_slow_clock();
/*
* when enabling the P1.7 RTC output, P1.6 will be hardcoded to an input with 25k pullup enabled.
* There is an internal pullup, so when it is set as an input, it will float high.
* The PAN1326B data sheet says the NSHUTD pin is pulled down, but the input impedance is stated at 1Meg Ohm,
* The so the 25k pullup should be enough to reach the minimum 1.42V to enable the device.
* */
while (GPIO_InGet(&PAN1326_HCIRTS)) {
cnt++;
}
printf("%s CC256X init completed. cnt: %d \n", __func__, cnt);
return 0;
}
static hci_transport_config_uart_t config = {
HCI_TRANSPORT_CONFIG_UART,
115200,
4000000,
1, // flow control
"max32630fthr",
};
int bluetooth_main(void)
{
bt_comm_init();
/* BT Stack Initialization */
btstack_memory_init();
btstack_run_loop_init(btstack_run_loop_embedded_get_instance());
/* Init HCI */
const hci_transport_t * transport = hci_transport_h4_instance(btstack_uart_block_embedded_instance());
const btstack_link_key_db_t *link_key_db = NULL;
hci_init(transport, &config);
hci_set_link_key_db(link_key_db);
hci_set_chipset(btstack_chipset_cc256x_instance());
btstack_main(0, (void *)NULL);
return 0;
}

View File

@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
* Author: Ismail H. Kose <ismail.kose@maximintegrated.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*******************************************************************************
*/
#ifndef BTSTACK_MAX32630FTHR_PORT_H
#define BTSTACK_MAX32630FTHR_PORT_H
int bluetooth_main(void);
void hal_btstack_run_loop_execute_once(void);
int btstack_main(int argc, const char * argv[]);
#endif /* BTSTACK_MAX32630FTHR_PORT_H */

View File

@ -0,0 +1,128 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
* Author: Ismail H. Kose <ismail.kose@maximintegrated.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*******************************************************************************
*/
#include <stdio.h>
#include "board.h"
/***** Definitions *****/
#define USE_RTC_SYSTEM_CLK 0
#define SYSTICK_PERIOD_EXT_CLK 32767
/* Trigger interrupt every second */
static const uint32_t sysTicks = SYSTICK_PERIOD_EXT_CLK;
static volatile uint32_t sys_tick_sec = 0;
int32_t hal_tick_init(void)
{
uint32_t ret;
ret = SYS_SysTick_Config(sysTicks, USE_RTC_SYSTEM_CLK);
printf("SysTick Clock = %d Hz\n", SYS_SysTick_GetFreq());
if(ret != E_NO_ERROR) {
printf("ERROR: Ticks is not valid");
}
return ret;
}
void SysTick_Handler(void)
{
sys_tick_sec++;
}
uint64_t hal_get_tick(void)
{
uint32_t usec_tick;
uint64_t tick_sec;
uint32_t systick_val = SysTick->VAL;
uint32_t _sys_tick_sec = sys_tick_sec;
uint32_t sys_freq = SYS_SysTick_GetFreq();
usec_tick = ((uint64_t)(sysTicks - systick_val) * 1000000) / sys_freq;
if (systick_val == 0) // to protect time overflow
_sys_tick_sec -= 1;
tick_sec = _sys_tick_sec * 1000000 + usec_tick;
return tick_sec;
}
void hal_delay_ms(unsigned int ms)
{
uint64_t prev_tick = hal_get_tick();
uint64_t wait_time = ms * 1000;
uint64_t curr_tick;
int64_t diff;
while(1) {
curr_tick = hal_get_tick();
diff = curr_tick - prev_tick;
if (diff > wait_time) {
break;
}
}
}
void hal_delay_us(unsigned int us)
{
uint64_t prev_tick = hal_get_tick();
uint64_t wait_time = us;
uint64_t curr_tick;
int64_t diff;
while(1) {
curr_tick = hal_get_tick();
diff = curr_tick - prev_tick;
if (diff > wait_time) {
break;
}
}
}
uint32_t hal_get_time_ms(void)
{
uint32_t usec_tick;
uint64_t tick_sec;
uint32_t systick_val = SysTick->VAL;
uint32_t _sys_tick_sec = sys_tick_sec;
uint32_t sys_freq = SYS_SysTick_GetFreq();
usec_tick = ((uint64_t)(sysTicks - systick_val) * 1000) / sys_freq;
if (systick_val == 0) // to protect time overflow
_sys_tick_sec -= 1;
tick_sec = _sys_tick_sec * 1000 + usec_tick;
return tick_sec;
}
uint32_t hal_time_ms(void)
{
return hal_get_time_ms();
}

View File

@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
* Author: Ismail H. Kose <ismail.kose@maximintegrated.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*******************************************************************************
*/
#ifndef MAX32630FTHR_HAL_TICK_H_
#define MAX32630FTHR_HAL_TICK_H_
#include <stdint.h>
void hal_delay_us(unsigned int us);
void hal_delay_ms(unsigned int ms);
uint32_t hal_time_ms(void);
uint32_t hal_get_time_ms(void);
uint64_t hal_get_tick(void);
int32_t hal_tick_init(void);
#endif /* MAX32630FTHR_HAL_TICK_H_ */

View File

@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
* Author: Ismail H. Kose <ismail.kose@maximintegrated.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2016-03-11 10:46:02 -0700 (Fri, 11 Mar 2016) $
* $Revision: 21838 $
*
******************************************************************************/
/**
* @file main.c
* @brief Max32630 CC2564B btstack Example
*/
/***** Includes *****/
#include <stdio.h>
#include <stdint.h>
#include "led.h"
#include "tmr_utils.h"
#include "btstack_port.h"
/***** Definitions *****/
/***** Globals *****/
/***** Functions *****/
// *****************************************************************************
int main(void)
{
printf("max32630fthr btstack example\n");
bluetooth_main();
while(1) {
hal_btstack_run_loop_execute_once();
}
}

View File

@ -0,0 +1,3 @@
file="./build/max3263x.elf"
openocd -f scripts/max3263x_hdk.cfg -c "program $file verify reset exit"

View File

@ -0,0 +1,27 @@
define connect
set trace-commands on
set remotetimeout 1000000000
set logging on
target remote localhost:3333
end
define reset
monitor reset halt
c
end
define settings
# set unlimited string size while print
set print elements 0
end
define program
monitor reset halt
load build/max3263x.elf
monitor reset halt
end
connect
settings
program
c

View File

@ -0,0 +1,25 @@
# MAX3263x HDK CMSIS-DAP SWD firmware load script
interface cmsis-dap
# adapter speed
adapter_khz 2000
# reset pin configuration
reset_config srst_only
# SWD DAP
swd newdap max32630 cpu -irlen 4 -irmask 0xf -ircapture 0x1 -expected-id 0x07f67197 -ignore-version
# target configuration
target create max32630.cpu cortex_m -chain-position max32630.cpu
max32630.cpu configure -work-area-phys 0x20005000 -work-area-size 0x2000
# Config Command: flash bank name driver base size chip_width bus_width target [driver_options]
# flash bank <name> maxim <base> <size> 0 0 <target> <flc base> <sector> <clk> <burst>
# max32630 flash base address 0x00000000
# max32630 flash size 0x200000 (2MB)
# max32630 FLC base address 0x40002000
# max32630 sector (page) size 0x2000 (8kB)
# max32630 clock speed 96 (MHz)
flash bank max32630.flash maxim 0x00000000 0x200000 0 0 max32630.cpu 0x40002000 0x2000 96

View File

@ -0,0 +1,400 @@
/*
* Copyright (C) 2014 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
// *****************************************************************************
/* EXAMPLE_START(spp_and_le_streamer): Dual mode example
*
* @text The SPP and LE Streamer example combines the Bluetooth Classic SPP Streamer
* and the Bluetooth LE Streamer into a single application.
*
* In this Section, we only point out the differences to the individual examples
* and how how the stack is configured.
*/
// *****************************************************************************
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "btstack.h"
#include "spp_and_le_streamer.h"
int btstack_main(int argc, const char * argv[]);
#define RFCOMM_SERVER_CHANNEL 1
#define HEARTBEAT_PERIOD_MS 1000
#define TEST_COD 0x1234
#define NUM_ROWS 25
#define NUM_COLS 40
#define DATA_VOLUME (10 * 1000 * 1000)
/*
* @section Advertisements
*
* @text The Flags attribute in the Advertisement Data indicates if a device is in dual-mode or not.
* Flag 0x06 indicates LE General Discoverable, BR/EDR not supported although we're actually using BR/EDR.
* In the past, there have been problems with Anrdoid devices when the flag was not set.
* Setting it should prevent the remote implementation to try to use GATT over LE/EDR, which is not
* implemented by BTstack. So, setting the flag seems like the safer choice (while it's technically incorrect).
*/
/* LISTING_START(advertisements): Advertisement data: Flag 0x06 indicates LE-only device */
const uint8_t adv_data[] = {
// Flags general discoverable, BR/EDR not supported
0x02, 0x01, 0x06,
// Name
0x0c, 0x09, 'L', 'E', ' ', 'S', 't', 'r', 'e', 'a', 'm', 'e', 'r',
};
static btstack_packet_callback_registration_t hci_event_callback_registration;
uint8_t adv_data_len = sizeof(adv_data);
static uint8_t test_data[NUM_ROWS * NUM_COLS];
// SPP
static uint8_t spp_service_buffer[150];
static uint16_t spp_test_data_len;
static uint16_t rfcomm_mtu;
static uint16_t rfcomm_cid = 0;
// static uint32_t data_to_send = DATA_VOLUME;
// LE
static uint16_t att_mtu;
static int counter = 'A';
static int le_notification_enabled;
static uint16_t le_test_data_len;
static hci_con_handle_t le_connection_handle;
/*
* @section Track throughput
* @text We calculate the throughput by setting a start time and measuring the amount of
* data sent. After a configurable REPORT_INTERVAL_MS, we print the throughput in kB/s
* and reset the counter and start time.
*/
/* LISTING_START(tracking): Tracking throughput */
#define REPORT_INTERVAL_MS 3000
static uint32_t test_data_transferred;
static uint32_t test_data_start;
static void test_reset(void){
test_data_start = btstack_run_loop_get_time_ms();
test_data_transferred = 0;
}
static void test_track_transferred(int bytes_sent){
test_data_transferred += bytes_sent;
// evaluate
uint32_t now = btstack_run_loop_get_time_ms();
uint32_t time_passed = now - test_data_start;
if (time_passed < REPORT_INTERVAL_MS) return;
// print speed
int bytes_per_second = test_data_transferred * 1000 / time_passed;
printf("%u bytes -> %u.%03u kB/s\n", (int) test_data_transferred, (int) bytes_per_second / 1000, bytes_per_second % 1000);
// restart
test_data_start = now;
test_data_transferred = 0;
}
/* LISTING_END(tracking): Tracking throughput */
static void spp_create_test_data(void){
int x,y;
for (y=0;y<NUM_ROWS;y++){
for (x=0;x<NUM_COLS-2;x++){
test_data[y*NUM_COLS+x] = '0' + (x % 10);
}
test_data[y*NUM_COLS+NUM_COLS-2] = '\n';
test_data[y*NUM_COLS+NUM_COLS-1] = '\r';
}
}
static void spp_send_packet(void){
rfcomm_send(rfcomm_cid, (uint8_t*) test_data, spp_test_data_len);
test_track_transferred(spp_test_data_len);
#if 0
if (data_to_send <= spp_test_data_len){
printf("SPP Streamer: enough data send, closing channel\n");
rfcomm_disconnect(rfcomm_cid);
rfcomm_cid = 0;
return;
}
data_to_send -= spp_test_data_len;
#endif
rfcomm_request_can_send_now_event(rfcomm_cid);
}
static void le_streamer(void){
// check if we can send
if (!le_notification_enabled) return;
// create test data
counter++;
if (counter > 'Z') counter = 'A';
memset(test_data, counter, sizeof(test_data));
// send
att_server_notify(le_connection_handle, ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE, (uint8_t*) test_data, le_test_data_len);
// track
test_track_transferred(le_test_data_len);
// request next send event
att_server_request_can_send_now_event(le_connection_handle);
}
/*
* @section Packet Handler
*
* @text The packet handler of the combined example is just the combination of the individual packet handlers.
*/
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
UNUSED(channel);
bd_addr_t event_addr;
uint8_t rfcomm_channel_nr;
switch (packet_type) {
case HCI_EVENT_PACKET:
switch (hci_event_packet_get_type(packet)) {
case HCI_EVENT_PIN_CODE_REQUEST:
// inform about pin code request
printf("Pin code request - using '0000'\n");
hci_event_pin_code_request_get_bd_addr(packet, event_addr);
gap_pin_code_response(event_addr, "0000");
break;
case HCI_EVENT_USER_CONFIRMATION_REQUEST:
// inform about user confirmation request
printf("SSP User Confirmation Request with numeric value '%06"PRIu32"'\n", little_endian_read_32(packet, 8));
printf("SSP User Confirmation Auto accept\n");
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
le_notification_enabled = 0;
break;
case HCI_EVENT_LE_META:
switch (hci_event_le_meta_get_subevent_code(packet)) {
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
le_test_data_len = ATT_DEFAULT_MTU - 3;
le_connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
break;
}
break;
case ATT_EVENT_MTU_EXCHANGE_COMPLETE:
att_mtu = att_event_mtu_exchange_complete_get_MTU(packet);
printf("ATT MTU = %u\n", att_mtu);
le_test_data_len = att_mtu - 3;
if (le_test_data_len > sizeof(test_data)){
le_test_data_len = sizeof(test_data);
}
break;
case ATT_EVENT_CAN_SEND_NOW:
le_streamer();
break;
case RFCOMM_EVENT_INCOMING_CONNECTION:
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr);
rfcomm_channel_nr = rfcomm_event_incoming_connection_get_server_channel(packet);
rfcomm_cid = rfcomm_event_incoming_connection_get_rfcomm_cid(packet);
printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr));
rfcomm_accept_connection(rfcomm_cid);
break;
case RFCOMM_EVENT_CHANNEL_OPENED:
// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
if (rfcomm_event_channel_opened_get_status(packet)) {
printf("RFCOMM channel open failed, status %u\n", rfcomm_event_channel_opened_get_status(packet));
} else {
rfcomm_cid = rfcomm_event_channel_opened_get_rfcomm_cid(packet);
rfcomm_mtu = rfcomm_event_channel_opened_get_max_frame_size(packet);
printf("RFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n", rfcomm_cid, rfcomm_mtu);
spp_test_data_len = rfcomm_mtu;
if (spp_test_data_len > sizeof(test_data)){
spp_test_data_len = sizeof(test_data);
}
test_reset();
rfcomm_request_can_send_now_event(rfcomm_cid);
}
break;
case RFCOMM_EVENT_CAN_SEND_NOW:
spp_send_packet();
break;
case RFCOMM_EVENT_CHANNEL_CLOSED:
printf("RFCOMM channel closed\n");
rfcomm_cid = 0;
break;
default:
break;
}
break;
case RFCOMM_DATA_PACKET:
test_track_transferred(size);
#if 0
printf("RCV: '");
for (i=0;i<size;i++){
putchar(packet[i]);
}
printf("'\n");
#endif
break;
default:
break;
}
}
// ATT Client Read Callback for Dynamic Data
// - if buffer == NULL, don't copy data, just return size of value
// - if buffer != NULL, copy data and return number bytes copied
// @param offset defines start of attribute value
static uint16_t att_read_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
UNUSED(con_handle);
UNUSED(att_handle);
UNUSED(offset);
UNUSED(buffer);
UNUSED(buffer_size);
return 0;
}
// write requests
static int att_write_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size){
UNUSED(con_handle);
UNUSED(offset);
UNUSED(buffer_size);
// printf("att_write_callback att_handle %04x, transaction mode %u\n", att_handle, transaction_mode);
if (transaction_mode != ATT_TRANSACTION_MODE_NONE) return 0;
switch(att_handle){
case ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_CLIENT_CONFIGURATION_HANDLE:
le_notification_enabled = little_endian_read_16(buffer, 0) == GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION;
printf("Notifications enabled %u\n", le_notification_enabled);
if (le_notification_enabled){
att_server_request_can_send_now_event(le_connection_handle);
}
test_reset();
break;
default:
break;
}
return 0;
}
/*
* @section Main Application Setup
*
* @text As with the packet and the heartbeat handlers, the combined app setup contains the code from the individual example setups.
*/
/* LISTING_START(MainConfiguration): Init L2CAP RFCOMM SDO SM ATT Server and start heartbeat timer */
int btstack_main(int argc, const char * argv[])
{
UNUSED(argc);
(void)argv;
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
rfcomm_init();
rfcomm_register_service(packet_handler, RFCOMM_SERVER_CHANNEL, 0xffff);
// init SDP, create record for SPP and register with SDP
sdp_init();
memset(spp_service_buffer, 0, sizeof(spp_service_buffer));
spp_create_sdp_record(spp_service_buffer, 0x10001, RFCOMM_SERVER_CHANNEL, "SPP Streamer");
sdp_register_service(spp_service_buffer);
// printf("SDP service record size: %u\n", de_get_len(spp_service_buffer));
gap_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO);
// short-cut to find other SPP Streamer
gap_set_class_of_device(TEST_COD);
gap_discoverable_control(1);
// setup le device db
le_device_db_init();
// setup SM: Display only
sm_init();
// setup ATT server
att_server_init(profile_data, att_read_callback, att_write_callback);
att_server_register_packet_handler(packet_handler);
// setup advertisements
uint16_t adv_int_min = 0x0030;
uint16_t adv_int_max = 0x0030;
uint8_t adv_type = 0;
bd_addr_t null_addr;
memset(null_addr, 0, 6);
gap_advertisements_set_params(adv_int_min, adv_int_max, adv_type, 0, null_addr, 0x07, 0x00);
gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data);
gap_advertisements_enable(1);
spp_create_test_data();
// turn on!
hci_power_control(HCI_POWER_ON);
return 0;
}
/* LISTING_END */
/* EXAMPLE_END */

View File

@ -0,0 +1,12 @@
PRIMARY_SERVICE, GAP_SERVICE
CHARACTERISTIC, GAP_DEVICE_NAME, READ, "Max32630FTHR LE Streamer"
PRIMARY_SERVICE, GATT_SERVICE
CHARACTERISTIC, GATT_SERVICE_CHANGED, READ,
// Test Service
PRIMARY_SERVICE, 0000FF10-0000-1000-8000-00805F9B34FB
// Test Characteristic, only notify
CHARACTERISTIC, 0000FF11-0000-1000-8000-00805F9B34FB, NOTIFY,
// Test Characterisitic, only write_without_response
CHARACTERISTIC, 0000FF12-0000-1000-8000-00805F9B34FB, WRITE_WITHOUT_RESPONSE | DYNAMIC,

View File

@ -0,0 +1,63 @@
// spp_and_le_streamer.h generated from spp_and_le_streamer.gatt for BTstack
// binary representation
// attribute size in bytes (16), flags(16), handle (16), uuid (16/128), value(...)
#include <stdint.h>
const uint8_t profile_data[] =
{
// 0x0001 PRIMARY_SERVICE-GAP_SERVICE
0x0a, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x28, 0x00, 0x18,
// 0x0002 CHARACTERISTIC-GAP_DEVICE_NAME-READ
0x0d, 0x00, 0x02, 0x00, 0x02, 0x00, 0x03, 0x28, 0x02, 0x03, 0x00, 0x00, 0x2a,
// 0x0003 VALUE-GAP_DEVICE_NAME-READ-'Max32630FTHR LE Streamer'
0x20, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x2a, 0x4d, 0x61, 0x78, 0x33, 0x32, 0x36, 0x33, 0x30, 0x46, 0x54, 0x48, 0x52, 0x20, 0x4c, 0x45, 0x20, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x65, 0x72,
// 0x0004 PRIMARY_SERVICE-GATT_SERVICE
0x0a, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x28, 0x01, 0x18,
// 0x0005 CHARACTERISTIC-GATT_SERVICE_CHANGED-READ
0x0d, 0x00, 0x02, 0x00, 0x05, 0x00, 0x03, 0x28, 0x02, 0x06, 0x00, 0x05, 0x2a,
// 0x0006 VALUE-GATT_SERVICE_CHANGED-READ-''
0x08, 0x00, 0x02, 0x00, 0x06, 0x00, 0x05, 0x2a,
// Test Service
// 0x0007 PRIMARY_SERVICE-0000FF10-0000-1000-8000-00805F9B34FB
0x18, 0x00, 0x02, 0x00, 0x07, 0x00, 0x00, 0x28, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x10, 0xff, 0x00, 0x00,
// Test Characteristic, only notify
// 0x0008 CHARACTERISTIC-0000FF11-0000-1000-8000-00805F9B34FB-NOTIFY
0x1b, 0x00, 0x02, 0x00, 0x08, 0x00, 0x03, 0x28, 0x10, 0x09, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x11, 0xff, 0x00, 0x00,
// 0x0009 VALUE-0000FF11-0000-1000-8000-00805F9B34FB-NOTIFY-''
0x16, 0x00, 0x10, 0x02, 0x09, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x11, 0xff, 0x00, 0x00,
// 0x000a CLIENT_CHARACTERISTIC_CONFIGURATION
0x0a, 0x00, 0x0a, 0x01, 0x0a, 0x00, 0x02, 0x29, 0x00, 0x00,
// Test Characterisitic, only write_without_response
// 0x000b CHARACTERISTIC-0000FF12-0000-1000-8000-00805F9B34FB-WRITE_WITHOUT_RESPONSE | DYNAMIC
0x1b, 0x00, 0x02, 0x00, 0x0b, 0x00, 0x03, 0x28, 0x04, 0x0c, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x12, 0xff, 0x00, 0x00,
// 0x000c VALUE-0000FF12-0000-1000-8000-00805F9B34FB-WRITE_WITHOUT_RESPONSE | DYNAMIC-''
0x16, 0x00, 0x04, 0x03, 0x0c, 0x00, 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x12, 0xff, 0x00, 0x00,
// END
0x00, 0x00,
}; // total size 126 bytes
//
// list service handle ranges
//
#define ATT_SERVICE_GAP_SERVICE_START_HANDLE 0x0001
#define ATT_SERVICE_GAP_SERVICE_END_HANDLE 0x0003
#define ATT_SERVICE_GATT_SERVICE_START_HANDLE 0x0004
#define ATT_SERVICE_GATT_SERVICE_END_HANDLE 0x0006
#define ATT_SERVICE_0000FF10_0000_1000_8000_00805F9B34FB_START_HANDLE 0x0007
#define ATT_SERVICE_0000FF10_0000_1000_8000_00805F9B34FB_END_HANDLE 0x000c
//
// list mapping between characteristics and handles
//
#define ATT_CHARACTERISTIC_GAP_DEVICE_NAME_01_VALUE_HANDLE 0x0003
#define ATT_CHARACTERISTIC_GATT_SERVICE_CHANGED_01_VALUE_HANDLE 0x0006
#define ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE 0x0009
#define ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_CLIENT_CONFIGURATION_HANDLE 0x000a
#define ATT_CHARACTERISTIC_0000FF12_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE 0x000c