Skip to content

Commit 267a5ac

Browse files
authored
Merge pull request ARMmbed#13538 from sparkfun/ambiq-apollo3-dev-squash
Ambiq AMA3B1KK and SparkFun Artemis Boards Target Update
2 parents 5940b16 + c2bddbb commit 267a5ac

File tree

195 files changed

+113138
-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.

195 files changed

+113138
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 2020 SparkFun Electronics
3+
* SPDX-License-Identifier: MIT
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
#include "AP3CordioHCIDriver.h"
25+
#include "AP3CordioHCITransportDriver.h"
26+
#include "am_mcu_apollo.h"
27+
#include "stdio.h"
28+
#include <cstring>
29+
30+
#include "wsf_types.h"
31+
#include "wsf_timer.h"
32+
#include "bstream.h"
33+
#include "wsf_msg.h"
34+
#include "wsf_cs.h"
35+
36+
#include "hci_drv_apollo3.h"
37+
38+
using namespace ble;
39+
40+
AP3CordioHCIDriver::AP3CordioHCIDriver(CordioHCITransportDriver &transport_driver)
41+
: CordioHCIDriver(transport_driver)
42+
{
43+
AP3CordioHCITransportDriver *p_trspt_drv = (AP3CordioHCITransportDriver *)&transport_driver;
44+
_ptr_to_handle = &p_trspt_drv->handle;
45+
}
46+
47+
AP3CordioHCIDriver::~AP3CordioHCIDriver() {}
48+
49+
void AP3CordioHCIDriver::do_initialize()
50+
{
51+
#ifdef USE_AMBIQ_DRIVER
52+
HciDrvRadioBoot(true);
53+
#else
54+
MBED_ASSERT(*_ptr_to_handle);
55+
_ble_config = am_hal_ble_default_config;
56+
MBED_ASSERT(am_hal_ble_power_control(*_ptr_to_handle, AM_HAL_BLE_POWER_ACTIVE) == AM_HAL_STATUS_SUCCESS);
57+
MBED_ASSERT(am_hal_ble_config(*_ptr_to_handle, &_ble_config) == AM_HAL_STATUS_SUCCESS);
58+
MBED_ASSERT(am_hal_ble_boot(*_ptr_to_handle) == AM_HAL_STATUS_SUCCESS);
59+
MBED_ASSERT(am_hal_ble_tx_power_set(*_ptr_to_handle, 0x0F) == AM_HAL_STATUS_SUCCESS);
60+
MBED_ASSERT(am_hal_ble_sleep_set(*_ptr_to_handle, false) == AM_HAL_STATUS_SUCCESS);
61+
am_hal_ble_int_enable(*_ptr_to_handle, (AP3_STUPID_DEF_OF_BLECIRQ_BIT | AM_HAL_BLE_INT_ICMD | AM_HAL_BLE_INT_BLECSSTAT));
62+
NVIC_EnableIRQ(BLE_IRQn);
63+
#endif
64+
}
65+
void AP3CordioHCIDriver::do_terminate()
66+
{
67+
#ifdef USE_AMBIQ_DRIVER
68+
HciDrvRadioShutdown();
69+
#else
70+
am_hal_ble_power_control(*_ptr_to_handle, AM_HAL_BLE_POWER_OFF);
71+
#endif
72+
}
73+
74+
ble::buf_pool_desc_t AP3CordioHCIDriver::get_buffer_pool_description()
75+
{
76+
static union {
77+
uint8_t buffer[9000];
78+
uint64_t align;
79+
};
80+
static const wsfBufPoolDesc_t pool_desc[] = {
81+
{16, 64},
82+
{32, 64},
83+
{64, 32},
84+
{128, 16},
85+
{272, 4}};
86+
return buf_pool_desc_t(buffer, pool_desc);
87+
}
88+
89+
ble::CordioHCIDriver &ble_cordio_get_hci_driver()
90+
{
91+
static AP3CordioHCITransportDriver transport_driver;
92+
93+
static AP3CordioHCIDriver hci_driver(transport_driver);
94+
95+
return hci_driver;
96+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2020 SparkFun Electronics
3+
* SPDX-License-Identifier: MIT
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
#ifndef APOLLO3_CORDIO_HCI_DRIVER_H_
25+
#define APOLLO3_CORDIO_HCI_DRIVER_H_
26+
27+
#include "CordioHCIDriver.h"
28+
#include "am_mcu_apollo.h"
29+
30+
namespace ble
31+
{
32+
class AP3CordioHCIDriver : public CordioHCIDriver
33+
{
34+
public:
35+
AP3CordioHCIDriver(
36+
CordioHCITransportDriver &transport_driver
37+
/* specific constructor arguments*/);
38+
39+
virtual ~AP3CordioHCIDriver();
40+
41+
virtual void do_initialize();
42+
43+
virtual void do_terminate();
44+
45+
virtual ble::buf_pool_desc_t get_buffer_pool_description();
46+
47+
private:
48+
void **_ptr_to_handle;
49+
am_hal_ble_config_t _ble_config;
50+
};
51+
} // namespace ble
52+
53+
#endif /* APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_ */
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright (c) 2020 SparkFun Electronics
3+
* SPDX-License-Identifier: MIT
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
#include "AP3CordioHCITransportDriver.h"
25+
#include "am_mcu_apollo.h"
26+
#include "stdio.h"
27+
#include <cstring>
28+
29+
#include "wsf_types.h"
30+
#include "wsf_timer.h"
31+
#include "bstream.h"
32+
#include "wsf_msg.h"
33+
#include "wsf_cs.h"
34+
35+
#include "hci_drv_apollo3.h"
36+
37+
#define PRINT_DEBUG_HCI 0
38+
39+
using namespace ble;
40+
41+
#ifndef USE_AMBIQ_DRIVER
42+
static uint8_t ample_buffer[256];
43+
void *ble_handle = NULL;
44+
#endif
45+
46+
AP3CordioHCITransportDriver::~AP3CordioHCITransportDriver() {}
47+
48+
void AP3CordioHCITransportDriver::initialize()
49+
{
50+
#ifdef USE_AMBIQ_DRIVER
51+
wsfHandlerId_t handlerId = WsfOsSetNextHandler(HciDrvHandler);
52+
HciDrvHandlerInit(handlerId);
53+
#else
54+
am_hal_ble_initialize(0, &handle);
55+
ble_handle = handle;
56+
#endif
57+
}
58+
59+
void AP3CordioHCITransportDriver::terminate()
60+
{
61+
#ifdef USE_AMBIQ_DRIVER
62+
#else
63+
am_hal_ble_deinitialize(handle);
64+
handle = NULL;
65+
ble_handle = NULL;
66+
#endif
67+
}
68+
69+
uint16_t AP3CordioHCITransportDriver::write(uint8_t packet_type, uint16_t len, uint8_t *data)
70+
{
71+
#if PRINT_DEBUG_HCI
72+
printf("sent tx packet_type: %02X data: ", packet_type);
73+
for (int i = 0; i < len; i++)
74+
{
75+
printf(" %02X", data[i]);
76+
}
77+
printf("\r\n");
78+
#endif
79+
80+
//Temporary workaround, random address not working, suppress it.
81+
if (data[0] == 0x06 && data[1] == 0x20)
82+
{
83+
#if PRINT_DEBUG_HCI
84+
printf("LE Set Advertising Params\r\n");
85+
#endif
86+
data[8] = 0;
87+
}
88+
89+
uint16_t retLen = 0;
90+
#ifdef USE_AMBIQ_DRIVER
91+
retLen = ap3_hciDrvWrite(packet_type, len, data);
92+
#else
93+
if (handle)
94+
{
95+
uint16_t retVal = (uint16_t)am_hal_ble_blocking_hci_write(handle, packet_type, (uint32_t *)data, (uint16_t)len);
96+
if (retVal == AM_HAL_STATUS_SUCCESS)
97+
{
98+
retLen = len;
99+
}
100+
}
101+
#endif
102+
103+
#if CORDIO_ZERO_COPY_HCI
104+
WsfMsgFree(data);
105+
#endif
106+
107+
return retLen;
108+
}
109+
110+
#ifdef USE_AMBIQ_DRIVER
111+
//Ugly Mutlifile implementation
112+
void CordioHCITransportDriver_on_data_received(uint8_t *data, uint16_t len)
113+
{
114+
#if PRINT_DEBUG_HCI
115+
printf("data rx: ");
116+
for (int i = 0; i < len; i++)
117+
{
118+
printf("%02X ", data[i]);
119+
}
120+
printf("\r\n");
121+
#endif
122+
CordioHCITransportDriver::on_data_received(data, len);
123+
}
124+
#else
125+
extern "C" void HciDrvIntService(void)
126+
{
127+
uint32_t status = am_hal_ble_int_status(ble_handle, false);
128+
if (status & AM_HAL_BLE_INT_BLECIRQ)
129+
{
130+
uint32_t len = 0;
131+
am_hal_ble_blocking_hci_read(ble_handle, (uint32_t *)ample_buffer, &len);
132+
CordioHCITransportDriver::on_data_received(ample_buffer, len);
133+
}
134+
am_hal_ble_int_clear(ble_handle, 0xFFFF);
135+
}
136+
#endif
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2020 SparkFun Electronics
3+
* SPDX-License-Identifier: MIT
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
#ifndef APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_
25+
#define APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_
26+
27+
#include "CordioHCITransportDriver.h"
28+
29+
#define AP3_STUPID_DEF_OF_BLECIRQ_BIT 0x00000080 // AM_BLEIF_INT_BLECIRQ
30+
31+
namespace ble
32+
{
33+
class AP3CordioHCITransportDriver : public CordioHCITransportDriver
34+
{
35+
public:
36+
//AP3CordioHCITransportDriver(/* specific constructor arguments*/);
37+
38+
virtual ~AP3CordioHCITransportDriver();
39+
40+
virtual void initialize();
41+
42+
virtual void terminate();
43+
44+
virtual uint16_t write(uint8_t packet_type, uint16_t len, uint8_t *data);
45+
46+
void *handle;
47+
48+
private:
49+
// private driver declarations
50+
};
51+
} // namespace ble
52+
53+
extern "C" void CordioHCITransportDriver_on_data_received(uint8_t *data, uint16_t len);
54+
55+
#endif /* APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_ */

0 commit comments

Comments
 (0)