mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-30 07:21:20 +00:00
max32630-fthr: implement hal_flash_sector for MXC and use in port
This commit is contained in:
parent
944b9f78ad
commit
5efdcd7d20
@ -138,10 +138,12 @@ COMMON = \
|
||||
hci.o \
|
||||
hci_cmd.o \
|
||||
hci_dump.o \
|
||||
btstack_uart_block_embedded.o
|
||||
btstack_uart_block_embedded.o \
|
||||
hal_flash_sector_mxc.o \
|
||||
btstack_tlv_flash_sector.o \
|
||||
|
||||
CLASSIC = \
|
||||
btstack_link_key_db_memory.o \
|
||||
btstack_link_key_db_tlv.o \
|
||||
rfcomm.o \
|
||||
sdp_util.o \
|
||||
spp_server.o \
|
||||
@ -152,7 +154,7 @@ CLASSIC = \
|
||||
BLE = \
|
||||
att_db.o \
|
||||
att_server.o \
|
||||
le_device_db_memory.o \
|
||||
le_device_db_tlv.o \
|
||||
att_dispatch.o \
|
||||
sm.o \
|
||||
ancs_client.o \
|
||||
|
@ -3,11 +3,10 @@
|
||||
#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
|
||||
@ -15,37 +14,33 @@
|
||||
|
||||
#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_LOG_INFO
|
||||
// #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_GATT_CLIENTS 1
|
||||
#define MAX_NR_HCI_CONNECTIONS 1
|
||||
#define MAX_NR_L2CAP_SERVICES 3
|
||||
#define MAX_NR_L2CAP_CHANNELS 3
|
||||
#define MAX_NR_RFCOMM_MULTIPLEXERS 1
|
||||
#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_RFCOMM_CHANNELS 1
|
||||
#define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 2
|
||||
#define MAX_NR_BNEP_SERVICES 1
|
||||
#define MAX_NR_BNEP_CHANNELS 1
|
||||
#define MAX_NR_HFP_CONNECTIONS 1
|
||||
#define MAX_NR_WHITELIST_ENTRIES 1
|
||||
#define MAX_NR_SM_LOOKUP_ENTRIES 3
|
||||
#define MAX_NR_SERVICE_RECORD_ITEMS 1
|
||||
#define MAX_NR_AVDTP_STREAM_ENDPOINTS 1
|
||||
#define MAX_NR_AVDTP_CONNECTIONS 1
|
||||
#define MAX_NR_AVRCP_CONNECTIONS 1
|
||||
|
||||
#define MAX_NR_LE_DEVICE_DB_ENTRIES 1
|
||||
// Link Key DB and LE Device DB using TLV on top of Flash Sector interface
|
||||
#define NVM_NUM_LINK_KEYS 16
|
||||
#define NVM_NUM_DEVICE_DB_ENTRIES 16
|
||||
|
||||
#endif
|
||||
|
@ -275,6 +275,19 @@ void hal_led_on(void){
|
||||
void hal_led_toggle(void){
|
||||
}
|
||||
|
||||
#include "hal_flash_sector_mxc.h"
|
||||
#include "btstack_tlv.h"
|
||||
#include "btstack_tlv_flash_sector.h"
|
||||
#include "btstack_link_key_db_tlv.h"
|
||||
#include "le_device_db_tlv.h"
|
||||
|
||||
#define HAL_FLASH_SECTOR_SIZE 0x2000
|
||||
#define HAL_FLASH_SECTOR_BANK_0_ADDR 0x1FC000
|
||||
#define HAL_FLASH_SECTOR_BANK_1_ADDR 0x1FE000
|
||||
|
||||
static hal_flash_sector_mxc_t hal_flash_sector_context;
|
||||
static btstack_tlv_flash_sector_t btstack_tlv_flash_sector_context;
|
||||
|
||||
int bluetooth_main(void)
|
||||
{
|
||||
bt_comm_init();
|
||||
@ -284,12 +297,28 @@ int bluetooth_main(void)
|
||||
|
||||
/* 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());
|
||||
|
||||
// setup TLV Flash Sector implementation
|
||||
const hal_flash_sector_t * hal_flash_sector_impl = hal_flash_sector_mxc_init_instance(
|
||||
&hal_flash_sector_context,
|
||||
HAL_FLASH_SECTOR_SIZE,
|
||||
HAL_FLASH_SECTOR_BANK_0_ADDR,
|
||||
HAL_FLASH_SECTOR_BANK_1_ADDR);
|
||||
const btstack_tlv_t * btstack_tlv_impl = btstack_tlv_flash_sector_init_instance(
|
||||
&btstack_tlv_flash_sector_context,
|
||||
hal_flash_sector_impl,
|
||||
&hal_flash_sector_context);
|
||||
|
||||
// setup Link Key DB using TLV
|
||||
const btstack_link_key_db_t * btstack_link_key_db = btstack_link_key_db_tlv_get_instance(btstack_tlv_impl, &btstack_tlv_flash_sector_context);
|
||||
hci_set_link_key_db(btstack_link_key_db);
|
||||
|
||||
// setup LE Device DB using TLV
|
||||
le_device_db_tlv_configure(btstack_tlv_impl, &btstack_tlv_flash_sector_context);
|
||||
|
||||
// go
|
||||
btstack_main(0, (void *)NULL);
|
||||
|
||||
return 0;
|
||||
|
@ -35,7 +35,15 @@
|
||||
#ifndef BTSTACK_MAX32630FTHR_PORT_H
|
||||
#define BTSTACK_MAX32630FTHR_PORT_H
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int bluetooth_main(void);
|
||||
void hal_btstack_run_loop_execute_once(void);
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* BTSTACK_MAX32630FTHR_PORT_H */
|
||||
|
104
port/max32630-fthr/src/hal_flash_sector_mxc.c
Normal file
104
port/max32630-fthr/src/hal_flash_sector_mxc.c
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* hal_flash_sector_mxc.c
|
||||
*
|
||||
* HAL abstraction for Flash memory that can be written anywhere
|
||||
* after being erased implemented with memory
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h> // memcpy
|
||||
|
||||
#include "hal_flash_sector_mxc.h"
|
||||
|
||||
#include "flc.h" // Maxim Flash Controller
|
||||
|
||||
static uint32_t hal_flash_sector_mxc_get_size(void * context){
|
||||
hal_flash_sector_mxc_t * self = (hal_flash_sector_mxc_t *) context;
|
||||
return self->sector_size;
|
||||
}
|
||||
|
||||
static uint32_t hal_flash_sector_mxc_get_alignment(void * context){
|
||||
(void)(context);
|
||||
return 4;
|
||||
}
|
||||
|
||||
static void hal_flash_sector_mxc_erase(void * context, int bank){
|
||||
hal_flash_sector_mxc_t * self = (hal_flash_sector_mxc_t *) context;
|
||||
|
||||
if (bank > 1) return;
|
||||
|
||||
// Erase page
|
||||
FLC_PageErase(self->banks[bank], MXC_V_FLC_ERASE_CODE_PAGE_ERASE, MXC_V_FLC_FLSH_UNLOCK_KEY);
|
||||
}
|
||||
|
||||
static void hal_flash_sector_mxc_read(void * context, int bank, uint32_t offset, uint8_t * buffer, uint32_t size){
|
||||
hal_flash_sector_mxc_t * self = (hal_flash_sector_mxc_t *) context;
|
||||
|
||||
if (bank > 1) return;
|
||||
if (offset > self->sector_size) return;
|
||||
if ((offset + size) > self->sector_size) return;
|
||||
|
||||
memcpy(buffer, ((uint8_t *) self->banks[bank]) + offset, size);
|
||||
}
|
||||
|
||||
static void hal_flash_sector_mxc_write(void * context, int bank, uint32_t offset, const uint8_t * data, uint32_t size){
|
||||
hal_flash_sector_mxc_t * self = (hal_flash_sector_mxc_t *) context;
|
||||
|
||||
if (bank > 1) return;
|
||||
if (offset > self->sector_size) return;
|
||||
if ((offset + size) > self->sector_size) return;
|
||||
|
||||
FLC_Write(self->banks[bank] + offset, data, size, MXC_V_FLC_FLSH_UNLOCK_KEY);
|
||||
}
|
||||
|
||||
static const hal_flash_sector_t hal_flash_sector_mxc_impl = {
|
||||
/* uint32_t (*get_size)() */ &hal_flash_sector_mxc_get_size,
|
||||
/* uint32_t (*get_alignment)(..); */ &hal_flash_sector_mxc_get_alignment,
|
||||
/* void (*erase)(..); */ &hal_flash_sector_mxc_erase,
|
||||
/* void (*read)(..); */ &hal_flash_sector_mxc_read,
|
||||
/* void (*write)(..); */ &hal_flash_sector_mxc_write,
|
||||
};
|
||||
|
||||
const hal_flash_sector_t * hal_flash_sector_mxc_init_instance(hal_flash_sector_mxc_t * context, uint32_t sector_size,
|
||||
uintptr_t bank_0_addr, uintptr_t bank_1_addr){
|
||||
context->sector_size = sector_size;
|
||||
context->banks[0] = bank_0_addr;
|
||||
context->banks[1] = bank_1_addr;
|
||||
|
||||
// prepare FLC
|
||||
FLC_Init();
|
||||
|
||||
return &hal_flash_sector_mxc_impl;
|
||||
}
|
||||
|
69
port/max32630-fthr/src/hal_flash_sector_mxc.h
Normal file
69
port/max32630-fthr/src/hal_flash_sector_mxc.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* hal_flash_sector_maxim.h
|
||||
*
|
||||
* HAL abstraction for Flash memory that can be written anywhere
|
||||
* after being erased implemented with memory
|
||||
*/
|
||||
|
||||
#ifndef __HAL_FLASH_SECTOR_MAXIM_H
|
||||
#define __HAL_FLASH_SECTOR_MAXIM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "hal_flash_sector.h"
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint32_t sector_size;
|
||||
uintptr_t banks[2];
|
||||
|
||||
} hal_flash_sector_mxc_t;
|
||||
|
||||
/**
|
||||
* Configure MXC HAL Flash Implementation
|
||||
*
|
||||
* @param context of hal_flash_sector_mxc_t
|
||||
* @param sector_size
|
||||
* @param bank_0_addr
|
||||
* @param bank_1_addr
|
||||
* @return
|
||||
*/
|
||||
const hal_flash_sector_t * hal_flash_sector_mxc_init_instance(hal_flash_sector_mxc_t * context, uint32_t sector_size, uintptr_t bank_0_addr, uintptr_t bank_1_addr);
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user