Skip to content

Commit 9f27b6f

Browse files
committed
Add ambiq apollo3 target and SFE boards
1 parent 9073a48 commit 9f27b6f

File tree

196 files changed

+112879
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+112879
-0
lines changed

.mbedignore

Whitespace-only changes.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "AP3CordioHCIDriver.h"
2+
#include "AP3CordioHCITransportDriver.h"
3+
#include "am_mcu_apollo.h"
4+
#include "stdio.h"
5+
#include <cstring>
6+
7+
#include "wsf_types.h"
8+
#include "wsf_timer.h"
9+
#include "bstream.h"
10+
#include "wsf_msg.h"
11+
#include "wsf_cs.h"
12+
13+
#include "hci_drv_apollo3.h"
14+
15+
using namespace ble;
16+
17+
AP3CordioHCIDriver::AP3CordioHCIDriver(CordioHCITransportDriver &transport_driver)
18+
: CordioHCIDriver(transport_driver)
19+
{
20+
AP3CordioHCITransportDriver *p_trspt_drv = (AP3CordioHCITransportDriver *)&transport_driver;
21+
_ptr_to_handle = &p_trspt_drv->handle;
22+
}
23+
24+
AP3CordioHCIDriver::~AP3CordioHCIDriver() {}
25+
26+
void AP3CordioHCIDriver::do_initialize()
27+
{
28+
#ifdef USE_AMBIQ_DRIVER
29+
HciDrvRadioBoot(true);
30+
#else
31+
MBED_ASSERT(*_ptr_to_handle);
32+
_ble_config = am_hal_ble_default_config;
33+
MBED_ASSERT(am_hal_ble_power_control(*_ptr_to_handle, AM_HAL_BLE_POWER_ACTIVE) == AM_HAL_STATUS_SUCCESS);
34+
MBED_ASSERT(am_hal_ble_config(*_ptr_to_handle, &_ble_config) == AM_HAL_STATUS_SUCCESS);
35+
MBED_ASSERT(am_hal_ble_boot(*_ptr_to_handle) == AM_HAL_STATUS_SUCCESS);
36+
MBED_ASSERT(am_hal_ble_tx_power_set(*_ptr_to_handle, 0x0F) == AM_HAL_STATUS_SUCCESS);
37+
MBED_ASSERT(am_hal_ble_sleep_set(*_ptr_to_handle, false) == AM_HAL_STATUS_SUCCESS);
38+
am_hal_ble_int_enable(*_ptr_to_handle, (AP3_STUPID_DEF_OF_BLECIRQ_BIT | AM_HAL_BLE_INT_ICMD | AM_HAL_BLE_INT_BLECSSTAT));
39+
NVIC_EnableIRQ(BLE_IRQn);
40+
#endif
41+
}
42+
void AP3CordioHCIDriver::do_terminate()
43+
{
44+
#ifdef USE_AMBIQ_DRIVER
45+
HciDrvRadioShutdown();
46+
#else
47+
am_hal_ble_power_control(*_ptr_to_handle, AM_HAL_BLE_POWER_OFF);
48+
#endif
49+
}
50+
51+
ble::buf_pool_desc_t AP3CordioHCIDriver::get_buffer_pool_description()
52+
{
53+
static union {
54+
uint8_t buffer[9000];
55+
uint64_t align;
56+
};
57+
static const wsfBufPoolDesc_t pool_desc[] = {
58+
{16, 64},
59+
{32, 64},
60+
{64, 32},
61+
{128, 16},
62+
{272, 4}};
63+
return buf_pool_desc_t(buffer, pool_desc);
64+
}
65+
66+
ble::CordioHCIDriver &ble_cordio_get_hci_driver()
67+
{
68+
static AP3CordioHCITransportDriver transport_driver;
69+
70+
static AP3CordioHCIDriver hci_driver(transport_driver);
71+
72+
return hci_driver;
73+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef APOLLO3_CORDIO_HCI_DRIVER_H_
2+
#define APOLLO3_CORDIO_HCI_DRIVER_H_
3+
4+
#include "CordioHCIDriver.h"
5+
#include "am_mcu_apollo.h"
6+
7+
namespace ble
8+
{
9+
class AP3CordioHCIDriver : public CordioHCIDriver
10+
{
11+
public:
12+
AP3CordioHCIDriver(
13+
CordioHCITransportDriver &transport_driver
14+
/* specific constructor arguments*/);
15+
16+
virtual ~AP3CordioHCIDriver();
17+
18+
virtual void do_initialize();
19+
20+
virtual void do_terminate();
21+
22+
virtual ble::buf_pool_desc_t get_buffer_pool_description();
23+
24+
private:
25+
void **_ptr_to_handle;
26+
am_hal_ble_config_t _ble_config;
27+
};
28+
} // namespace ble
29+
30+
#endif /* APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_ */
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include "AP3CordioHCITransportDriver.h"
2+
#include "am_mcu_apollo.h"
3+
#include "stdio.h"
4+
#include <cstring>
5+
6+
#include "wsf_types.h"
7+
#include "wsf_timer.h"
8+
#include "bstream.h"
9+
#include "wsf_msg.h"
10+
#include "wsf_cs.h"
11+
12+
#include "hci_drv_apollo3.h"
13+
14+
#define PRINT_DEBUG_HCI 0
15+
16+
#if PRINT_DEBUG_HCI
17+
#include "mbed.h"
18+
DigitalOut debugGPIO(D28, 0);
19+
DigitalOut debugGPIO2(D25, 0);
20+
#endif
21+
22+
using namespace ble;
23+
24+
static uint8_t ample_buffer[256];
25+
void *ble_handle = NULL;
26+
27+
AP3CordioHCITransportDriver::~AP3CordioHCITransportDriver() {}
28+
29+
void AP3CordioHCITransportDriver::initialize()
30+
{
31+
#ifdef USE_AMBIQ_DRIVER
32+
wsfHandlerId_t handlerId = WsfOsSetNextHandler(HciDrvHandler);
33+
HciDrvHandlerInit(handlerId);
34+
#else
35+
am_hal_ble_initialize(0, &handle);
36+
ble_handle = handle;
37+
#endif
38+
}
39+
40+
void AP3CordioHCITransportDriver::terminate()
41+
{
42+
#ifdef USE_AMBIQ_DRIVER
43+
#else
44+
am_hal_ble_deinitialize(handle);
45+
handle = NULL;
46+
ble_handle = NULL;
47+
#endif
48+
}
49+
50+
uint16_t AP3CordioHCITransportDriver::write(uint8_t packet_type, uint16_t len, uint8_t *data)
51+
{
52+
#if PRINT_DEBUG_HCI
53+
printf("sent tx packet_type: %02X data: ", packet_type);
54+
for (int i = 0; i < len; i++)
55+
{
56+
printf(" %02X", data[i]);
57+
}
58+
printf("\r\n");
59+
#endif
60+
61+
//Temporary workaround, random address not working, suppress it.
62+
if (data[0] == 0x06 && data[1] == 0x20)
63+
{
64+
#if PRINT_DEBUG_HCI
65+
printf("LE Set Advertising Params\r\n");
66+
#endif
67+
data[8] = 0;
68+
}
69+
70+
#ifdef USE_AMBIQ_DRIVER
71+
return ap3_hciDrvWrite(packet_type, len, data);
72+
#else
73+
if (handle)
74+
{
75+
uint16_t retVal = (uint16_t)am_hal_ble_blocking_hci_write(handle, packet_type, (uint32_t *)data, (uint16_t)len);
76+
if (retVal == AM_HAL_STATUS_SUCCESS)
77+
{
78+
return len;
79+
}
80+
}
81+
return 0;
82+
#endif
83+
}
84+
85+
#ifdef USE_AMBIQ_DRIVER
86+
//Ugly Mutlifile implementation
87+
void CordioHCITransportDriver_on_data_received(uint8_t *data, uint16_t len)
88+
{
89+
#if PRINT_DEBUG_HCI
90+
printf("data rx: ");
91+
for (int i = 0; i < len; i++)
92+
{
93+
printf("%02X ", data[i]);
94+
}
95+
printf("\r\n");
96+
#endif
97+
CordioHCITransportDriver::on_data_received(data, len);
98+
}
99+
#else
100+
extern "C" void HciDrvIntService(void)
101+
{
102+
uint32_t status = am_hal_ble_int_status(ble_handle, false);
103+
if (status & AM_HAL_BLE_INT_BLECIRQ)
104+
{
105+
uint32_t len = 0;
106+
am_hal_ble_blocking_hci_read(ble_handle, (uint32_t *)ample_buffer, &len);
107+
CordioHCITransportDriver::on_data_received(ample_buffer, len);
108+
}
109+
am_hal_ble_int_clear(ble_handle, 0xFFFF);
110+
}
111+
#endif
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_
2+
#define APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_
3+
4+
#include "CordioHCITransportDriver.h"
5+
6+
#define AP3_STUPID_DEF_OF_BLECIRQ_BIT 0x00000080 // AM_BLEIF_INT_BLECIRQ
7+
8+
namespace ble
9+
{
10+
class AP3CordioHCITransportDriver : public CordioHCITransportDriver
11+
{
12+
public:
13+
//AP3CordioHCITransportDriver(/* specific constructor arguments*/);
14+
15+
virtual ~AP3CordioHCITransportDriver();
16+
17+
virtual void initialize();
18+
19+
virtual void terminate();
20+
21+
virtual uint16_t write(uint8_t packet_type, uint16_t len, uint8_t *data);
22+
23+
void *handle;
24+
25+
private:
26+
// private driver declarations
27+
};
28+
} // namespace ble
29+
30+
extern "C" void CordioHCITransportDriver_on_data_received(uint8_t *data, uint16_t len);
31+
32+
#endif /* APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_ */

0 commit comments

Comments
 (0)