-
Notifications
You must be signed in to change notification settings - Fork 3k
Ambiq AMA3B1KK and SparkFun Artemis Boards Target Update #13538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
...ectivity/drivers/ble/FEATURE_BLE/TARGET_Ambiq_Micro/TARGET_Apollo3/AP3CordioHCIDriver.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| * Copyright (c) 2020 SparkFun Electronics | ||
| * SPDX-License-Identifier: MIT | ||
| * | ||
| * 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 THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS 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. | ||
| */ | ||
|
|
||
| #include "AP3CordioHCIDriver.h" | ||
| #include "AP3CordioHCITransportDriver.h" | ||
| #include "am_mcu_apollo.h" | ||
| #include "stdio.h" | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
| #include <cstring> | ||
|
|
||
| #include "wsf_types.h" | ||
| #include "wsf_timer.h" | ||
| #include "bstream.h" | ||
| #include "wsf_msg.h" | ||
| #include "wsf_cs.h" | ||
|
|
||
| #include "hci_drv_apollo3.h" | ||
|
|
||
| using namespace ble; | ||
|
|
||
| AP3CordioHCIDriver::AP3CordioHCIDriver(CordioHCITransportDriver &transport_driver) | ||
| : CordioHCIDriver(transport_driver) | ||
| { | ||
| AP3CordioHCITransportDriver *p_trspt_drv = (AP3CordioHCITransportDriver *)&transport_driver; | ||
| _ptr_to_handle = &p_trspt_drv->handle; | ||
| } | ||
|
|
||
| AP3CordioHCIDriver::~AP3CordioHCIDriver() {} | ||
|
|
||
| void AP3CordioHCIDriver::do_initialize() | ||
| { | ||
| #ifdef USE_AMBIQ_DRIVER | ||
| HciDrvRadioBoot(true); | ||
| #else | ||
| MBED_ASSERT(*_ptr_to_handle); | ||
| _ble_config = am_hal_ble_default_config; | ||
| MBED_ASSERT(am_hal_ble_power_control(*_ptr_to_handle, AM_HAL_BLE_POWER_ACTIVE) == AM_HAL_STATUS_SUCCESS); | ||
| MBED_ASSERT(am_hal_ble_config(*_ptr_to_handle, &_ble_config) == AM_HAL_STATUS_SUCCESS); | ||
| MBED_ASSERT(am_hal_ble_boot(*_ptr_to_handle) == AM_HAL_STATUS_SUCCESS); | ||
| MBED_ASSERT(am_hal_ble_tx_power_set(*_ptr_to_handle, 0x0F) == AM_HAL_STATUS_SUCCESS); | ||
| MBED_ASSERT(am_hal_ble_sleep_set(*_ptr_to_handle, false) == AM_HAL_STATUS_SUCCESS); | ||
| am_hal_ble_int_enable(*_ptr_to_handle, (AP3_STUPID_DEF_OF_BLECIRQ_BIT | AM_HAL_BLE_INT_ICMD | AM_HAL_BLE_INT_BLECSSTAT)); | ||
| NVIC_EnableIRQ(BLE_IRQn); | ||
| #endif | ||
| } | ||
| void AP3CordioHCIDriver::do_terminate() | ||
| { | ||
| #ifdef USE_AMBIQ_DRIVER | ||
| HciDrvRadioShutdown(); | ||
| #else | ||
| am_hal_ble_power_control(*_ptr_to_handle, AM_HAL_BLE_POWER_OFF); | ||
| #endif | ||
| } | ||
|
|
||
| ble::buf_pool_desc_t AP3CordioHCIDriver::get_buffer_pool_description() | ||
| { | ||
| static union { | ||
| uint8_t buffer[9000]; | ||
| uint64_t align; | ||
| }; | ||
| static const wsfBufPoolDesc_t pool_desc[] = { | ||
| {16, 64}, | ||
| {32, 64}, | ||
| {64, 32}, | ||
| {128, 16}, | ||
| {272, 4}}; | ||
| return buf_pool_desc_t(buffer, pool_desc); | ||
| } | ||
|
|
||
| ble::CordioHCIDriver &ble_cordio_get_hci_driver() | ||
| { | ||
| static AP3CordioHCITransportDriver transport_driver; | ||
|
|
||
| static AP3CordioHCIDriver hci_driver(transport_driver); | ||
|
|
||
| return hci_driver; | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
connectivity/drivers/ble/FEATURE_BLE/TARGET_Ambiq_Micro/TARGET_Apollo3/AP3CordioHCIDriver.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright (c) 2020 SparkFun Electronics | ||
| * SPDX-License-Identifier: MIT | ||
| * | ||
| * 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 THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS 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. | ||
| */ | ||
|
|
||
| #ifndef APOLLO3_CORDIO_HCI_DRIVER_H_ | ||
| #define APOLLO3_CORDIO_HCI_DRIVER_H_ | ||
|
|
||
| #include "CordioHCIDriver.h" | ||
| #include "am_mcu_apollo.h" | ||
|
|
||
| namespace ble | ||
| { | ||
| class AP3CordioHCIDriver : public CordioHCIDriver | ||
| { | ||
| public: | ||
| AP3CordioHCIDriver( | ||
| CordioHCITransportDriver &transport_driver | ||
| /* specific constructor arguments*/); | ||
|
|
||
| virtual ~AP3CordioHCIDriver(); | ||
|
|
||
| virtual void do_initialize(); | ||
|
|
||
| virtual void do_terminate(); | ||
|
|
||
| virtual ble::buf_pool_desc_t get_buffer_pool_description(); | ||
|
|
||
| private: | ||
| void **_ptr_to_handle; | ||
| am_hal_ble_config_t _ble_config; | ||
| }; | ||
| } // namespace ble | ||
|
|
||
| #endif /* APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_ */ |
136 changes: 136 additions & 0 deletions
136
...drivers/ble/FEATURE_BLE/TARGET_Ambiq_Micro/TARGET_Apollo3/AP3CordioHCITransportDriver.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /* | ||
| * Copyright (c) 2020 SparkFun Electronics | ||
| * SPDX-License-Identifier: MIT | ||
| * | ||
| * 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 THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS 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. | ||
| */ | ||
|
|
||
| #include "AP3CordioHCITransportDriver.h" | ||
| #include "am_mcu_apollo.h" | ||
| #include "stdio.h" | ||
| #include <cstring> | ||
|
|
||
| #include "wsf_types.h" | ||
| #include "wsf_timer.h" | ||
| #include "bstream.h" | ||
| #include "wsf_msg.h" | ||
| #include "wsf_cs.h" | ||
|
|
||
| #include "hci_drv_apollo3.h" | ||
|
|
||
| #define PRINT_DEBUG_HCI 0 | ||
|
|
||
| using namespace ble; | ||
|
|
||
| #ifndef USE_AMBIQ_DRIVER | ||
| static uint8_t ample_buffer[256]; | ||
| void *ble_handle = NULL; | ||
| #endif | ||
|
|
||
| AP3CordioHCITransportDriver::~AP3CordioHCITransportDriver() {} | ||
|
|
||
| void AP3CordioHCITransportDriver::initialize() | ||
| { | ||
| #ifdef USE_AMBIQ_DRIVER | ||
| wsfHandlerId_t handlerId = WsfOsSetNextHandler(HciDrvHandler); | ||
| HciDrvHandlerInit(handlerId); | ||
| #else | ||
| am_hal_ble_initialize(0, &handle); | ||
| ble_handle = handle; | ||
| #endif | ||
| } | ||
|
|
||
| void AP3CordioHCITransportDriver::terminate() | ||
| { | ||
| #ifdef USE_AMBIQ_DRIVER | ||
| #else | ||
| am_hal_ble_deinitialize(handle); | ||
| handle = NULL; | ||
| ble_handle = NULL; | ||
| #endif | ||
| } | ||
|
|
||
| uint16_t AP3CordioHCITransportDriver::write(uint8_t packet_type, uint16_t len, uint8_t *data) | ||
| { | ||
| #if PRINT_DEBUG_HCI | ||
| printf("sent tx packet_type: %02X data: ", packet_type); | ||
| for (int i = 0; i < len; i++) | ||
| { | ||
| printf(" %02X", data[i]); | ||
| } | ||
| printf("\r\n"); | ||
| #endif | ||
|
|
||
| //Temporary workaround, random address not working, suppress it. | ||
| if (data[0] == 0x06 && data[1] == 0x20) | ||
| { | ||
| #if PRINT_DEBUG_HCI | ||
| printf("LE Set Advertising Params\r\n"); | ||
| #endif | ||
| data[8] = 0; | ||
| } | ||
|
|
||
| uint16_t retLen = 0; | ||
| #ifdef USE_AMBIQ_DRIVER | ||
| retLen = ap3_hciDrvWrite(packet_type, len, data); | ||
| #else | ||
| if (handle) | ||
| { | ||
| uint16_t retVal = (uint16_t)am_hal_ble_blocking_hci_write(handle, packet_type, (uint32_t *)data, (uint16_t)len); | ||
| if (retVal == AM_HAL_STATUS_SUCCESS) | ||
| { | ||
| retLen = len; | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| #if CORDIO_ZERO_COPY_HCI | ||
| WsfMsgFree(data); | ||
| #endif | ||
|
|
||
| return retLen; | ||
| } | ||
|
|
||
| #ifdef USE_AMBIQ_DRIVER | ||
| //Ugly Mutlifile implementation | ||
| void CordioHCITransportDriver_on_data_received(uint8_t *data, uint16_t len) | ||
| { | ||
| #if PRINT_DEBUG_HCI | ||
| printf("data rx: "); | ||
| for (int i = 0; i < len; i++) | ||
| { | ||
| printf("%02X ", data[i]); | ||
| } | ||
| printf("\r\n"); | ||
| #endif | ||
| CordioHCITransportDriver::on_data_received(data, len); | ||
| } | ||
| #else | ||
| extern "C" void HciDrvIntService(void) | ||
| { | ||
| uint32_t status = am_hal_ble_int_status(ble_handle, false); | ||
| if (status & AM_HAL_BLE_INT_BLECIRQ) | ||
| { | ||
| uint32_t len = 0; | ||
| am_hal_ble_blocking_hci_read(ble_handle, (uint32_t *)ample_buffer, &len); | ||
| CordioHCITransportDriver::on_data_received(ample_buffer, len); | ||
| } | ||
| am_hal_ble_int_clear(ble_handle, 0xFFFF); | ||
| } | ||
| #endif |
55 changes: 55 additions & 0 deletions
55
...y/drivers/ble/FEATURE_BLE/TARGET_Ambiq_Micro/TARGET_Apollo3/AP3CordioHCITransportDriver.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright (c) 2020 SparkFun Electronics | ||
| * SPDX-License-Identifier: MIT | ||
| * | ||
| * 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 THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS 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. | ||
| */ | ||
|
|
||
| #ifndef APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_ | ||
| #define APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_ | ||
|
|
||
| #include "CordioHCITransportDriver.h" | ||
|
|
||
| #define AP3_STUPID_DEF_OF_BLECIRQ_BIT 0x00000080 // AM_BLEIF_INT_BLECIRQ | ||
|
|
||
| namespace ble | ||
| { | ||
| class AP3CordioHCITransportDriver : public CordioHCITransportDriver | ||
| { | ||
| public: | ||
| //AP3CordioHCITransportDriver(/* specific constructor arguments*/); | ||
|
|
||
| virtual ~AP3CordioHCITransportDriver(); | ||
|
|
||
| virtual void initialize(); | ||
|
|
||
| virtual void terminate(); | ||
|
|
||
| virtual uint16_t write(uint8_t packet_type, uint16_t len, uint8_t *data); | ||
|
|
||
| void *handle; | ||
|
|
||
| private: | ||
| // private driver declarations | ||
| }; | ||
| } // namespace ble | ||
|
|
||
| extern "C" void CordioHCITransportDriver_on_data_received(uint8_t *data, uint16_t len); | ||
|
|
||
| #endif /* APOLLO3_CORDIO_HCI_TRANSPORT_DRIVER_H_ */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.