-
Couldn't load subscription status.
- Fork 3
drivers: crc: create ambiq crc driver #59
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
base: apollo510-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| zephyr_library() | ||
| zephyr_library_sources_ifdef(CONFIG_CRC_AMBIQ crc_ambiq.c) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # CRC configuration options | ||
|
|
||
| # Copyright (c) 2025, Ambiq | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| menuconfig CRC | ||
| bool "CRC drivers" | ||
| help | ||
| Enable CRC (Cyclic Redundancy Check) driver support. | ||
|
|
||
| if CRC | ||
|
|
||
| # Ensure Ambiq-specific CRC Kconfig is included | ||
| source "drivers/crc/Kconfig.ambiq" | ||
|
|
||
| config CRC_INIT_PRIORITY | ||
| int "CRC devices init priority" | ||
| default 90 | ||
| help | ||
| CRC devices initialization priority. | ||
|
|
||
| module = CRC | ||
| module-str = CRC | ||
| source "subsys/logging/Kconfig.template.log_config" | ||
|
|
||
| endif # CRC |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Ambiq CRC configuration options | ||
|
|
||
| # Copyright (c) 2025 Ambiq | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config CRC_AMBIQ | ||
| bool "Ambiq Apollo4P and Apollo510 CRC support" | ||
| default y | ||
| depends on SOC_SERIES_APOLLO4X || SOC_SERIES_APOLLO5X | ||
| help | ||
| Enable Ambiq Apollo4P and Apollo510 CRC support. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||
| /* | ||||||
| * Copyright (c) 2025 Ambiq Micro, Inc. | ||||||
| * | ||||||
| * SPDX-License-Identifier: Apache-2.0 | ||||||
| */ | ||||||
|
|
||||||
| #define DT_DRV_COMPAT ambiq_hw_crc32 | ||||||
|
|
||||||
| #include <string.h> | ||||||
| #include "soc.h" | ||||||
| #include <zephyr/logging/log.h> | ||||||
| #include <zephyr/device.h> | ||||||
| #include <zephyr/drivers/crc/crc.h> | ||||||
|
|
||||||
| LOG_MODULE_REGISTER(ambiq_hw_crc32, CONFIG_KERNEL_LOG_LEVEL); | ||||||
|
|
||||||
| static int crc_ambiq_get_crc32(const struct device *dev, const void *startAddr, uint32_t sizeBytes, | ||||||
| uint32_t *pCrc) | ||||||
| { | ||||||
| ARG_UNUSED(dev); | ||||||
|
|
||||||
| /* | ||||||
| * Validate input parameters | ||||||
| */ | ||||||
| if (sizeBytes == 0 || startAddr == NULL || pCrc == NULL) { | ||||||
| return -EINVAL; | ||||||
| } | ||||||
|
|
||||||
| /* | ||||||
| * If the CRC is already running then return an error | ||||||
| */ | ||||||
| if (SECURITY->CTRL_b.ENABLE) { | ||||||
| return -EBUSY; | ||||||
| } | ||||||
|
|
||||||
| /* | ||||||
| * Generate the CRC | ||||||
| */ | ||||||
| am_hal_crc32((uint32_t)startAddr, sizeBytes, pCrc); | ||||||
|
|
||||||
| return 0; | ||||||
| } | ||||||
|
|
||||||
| static int crc_ambiq_init(const struct device *dev) | ||||||
| { | ||||||
| ARG_UNUSED(dev); | ||||||
|
|
||||||
| /* Any hardware init can be performed here if needed. */ | ||||||
| return 0; | ||||||
| } | ||||||
|
|
||||||
| static const struct crc_driver_api crc_ambiq_api_funcs = { | ||||||
| .get_crc = crc_ambiq_get_crc32, | ||||||
| }; | ||||||
|
|
||||||
| DEVICE_DT_INST_DEFINE(0, crc_ambiq_init, NULL, NULL, NULL, POST_KERNEL, | ||||||
| CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, | ||||||
|
||||||
| CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, | |
| CONFIG_CRC_INIT_PRIORITY, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Copyright (c) 2025, Ambiq | ||
| # Author, Richard S Wheatley | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| description: | | ||
| Hardware CRC32 Cyclic Redundancy Check Module. | ||
| This module implements a hardware-based CRC32 calculation. | ||
| compatible: "ambiq,hw-crc32" | ||
|
|
||
| include: base.yaml | ||
|
|
||
| properties: | ||
| reg: | ||
| required: true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright (c) 2025, Ambiq Micro Inc. <www.ambiq.com> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #ifndef ZEPHYR_INCLUDE_DRIVERS_CRC_H_ | ||
| #define ZEPHYR_INCLUDE_DRIVERS_CRC_H_ | ||
|
|
||
| #include <zephyr/device.h> | ||
| #include <stdint.h> | ||
| #include <errno.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /* Driver callback: compute CRC32 over a memory region */ | ||
| typedef int (*crc_get_fn)(const struct device *dev, | ||
| const void *start_addr, | ||
| uint32_t size_bytes, | ||
| uint32_t *out_crc); | ||
|
|
||
| /* Public driver API struct */ | ||
| struct crc_driver_api { | ||
| crc_get_fn get_crc; | ||
| }; | ||
|
|
||
| /* Convenience inline wrapper that calls the device API */ | ||
| static inline int crc_driver_get_crc(const struct device *dev, | ||
| const void *start_addr, | ||
| uint32_t size_bytes, | ||
| uint32_t *out_crc) | ||
| { | ||
| const struct crc_driver_api *api; | ||
|
|
||
| if (dev == NULL) { | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| api = (const struct crc_driver_api *)dev->api; | ||
| if (!api || !api->get_crc) { | ||
| return -ENOSYS; | ||
| } | ||
|
|
||
| return api->get_crc(dev, start_addr, size_bytes, out_crc); | ||
| } | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* ZEPHYR_INCLUDE_DRIVERS_CRC_H_ */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| cmake_minimum_required(VERSION 3.20.0) | ||
| find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
| project(crc) | ||
|
|
||
| target_sources(app PRIVATE src/main.c) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| .. _crc-sample: | ||
|
|
||
| CRC Sample | ||
| ########## | ||
|
|
||
| Overview | ||
| ******** | ||
|
|
||
| This sample demonstrates how to use the CRC (Cyclic Redundancy Check) driver API. | ||
| The sample calculates CRC32 checksums over test data and displays the results. | ||
|
|
||
| Building and Running | ||
| ******************** | ||
|
|
||
| This sample can be found under :zephyr_file:`samples/drivers/crc` in the Zephyr tree. | ||
|
|
||
| The sample will work on any board that has a CRC driver enabled and configured. | ||
| For Ambiq Apollo4P and Apollo510 boards, the sample uses the hardware CRC32 module. | ||
|
|
||
| Supported boards: | ||
| - apollo4p_evb | ||
| - apollo4p_blue_kxr_evb | ||
| - apollo510_evb | ||
| - apollo510_eb | ||
|
|
||
| .. zephyr-app-commands:: | ||
| :zephyr-app: samples/drivers/crc | ||
| :board: apollo4p_evb | ||
| :goals: build flash | ||
| :compact: | ||
|
|
||
| Sample Output | ||
| ============= | ||
|
|
||
| .. code-block:: console | ||
| *** Booting Zephyr OS build v3.x.x *** | ||
| [00:00:00.000,000] <inf> crc_sample: CRC Sample starting... | ||
| [00:00:00.000,000] <inf> crc_sample: Testing CRC device: crc32@40030030 | ||
| [00:00:00.001,000] <inf> crc_sample: CRC32 of 256 bytes: 0x12345678 | ||
RichardSWheatley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [00:00:00.002,000] <inf> crc_sample: CRC test completed successfully | ||
| References | ||
| ********** | ||
|
|
||
| - :ref:`crc_api` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| CONFIG_CRC=y | ||
| CONFIG_CRC_AMBIQ=y | ||
| CONFIG_LOG=y |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| sample: | ||
| name: CRC Sample | ||
| description: Sample application demonstrating CRC driver usage | ||
| common: | ||
| tags: crc drivers | ||
| platform_allow: | ||
| - apollo4p_evb | ||
| - apollo4p_blue_kxr_evb | ||
| - apollo510_evb | ||
| - apollo510_eb | ||
| integration_platforms: | ||
| - apollo4p_evb | ||
| tests: | ||
| sample.drivers.crc: | ||
| tags: crc drivers | ||
| platform_allow: | ||
| - apollo4p_evb | ||
| - apollo4p_blue_kxr_evb | ||
| - apollo510_evb | ||
| - apollo510_eb |
Uh oh!
There was an error while loading. Please reload this page.