summaryrefslogtreecommitdiff
path: root/source/hal/profiles/bare-metal
diff options
context:
space:
mode:
authorKshitij Sisodia <kshitij.sisodia@arm.com>2022-03-14 09:26:48 +0000
committerKshitij Sisodia <kshitij.sisodia@arm.com>2022-03-14 17:18:25 +0000
commitc22e80e25521bdd291fdef9ba20194ce9d2a8544 (patch)
treeb8ffe314220d4d04e84dbd6a240f77271c1e5e70 /source/hal/profiles/bare-metal
parent1716efd0b35889b580276e27c8b6f661c9858cd0 (diff)
downloadml-embedded-evaluation-kit-c22e80e25521bdd291fdef9ba20194ce9d2a8544.tar.gz
MLECO-2919: Restructuring to standardise HAL APIs
* LCD module component created (removed from individual platform packs). * retarget.c moved out into its own component that wraps the uart module. It also have the native stub for GetLine => paved the way for removing data_acq module from profiles. * shortened names for components' dir for npu and ta * remove peripheral_memmap and peripheral_irqs headers from platform_drivers.h. There should be no need for these to be included in the top level now. These should be private headers. * cmsis_device moved in as a component. * Pyenv created by set_up_default_resource.py will also install packages that CMake's source generator needs. TODO's: * Remove timer from profiles (MLECO-3096) Change-Id: I9d6ea2f4f291788f40a16ed507019563c8d7f205
Diffstat (limited to 'source/hal/profiles/bare-metal')
-rw-r--r--source/hal/profiles/bare-metal/bsp/retarget.c278
-rw-r--r--source/hal/profiles/bare-metal/data_acquisition/data_acq.c62
-rw-r--r--source/hal/profiles/bare-metal/data_presentation/data_psn.c46
-rw-r--r--source/hal/profiles/bare-metal/data_presentation/lcd/include/lcd_img.h90
-rw-r--r--source/hal/profiles/bare-metal/data_presentation/lcd/lcd_img.c160
-rw-r--r--source/hal/profiles/bare-metal/timer/include/platform_timer.h38
-rw-r--r--source/hal/profiles/bare-metal/timer/platform_timer.c351
7 files changed, 0 insertions, 1025 deletions
diff --git a/source/hal/profiles/bare-metal/bsp/retarget.c b/source/hal/profiles/bare-metal/bsp/retarget.c
deleted file mode 100644
index ac9b282..0000000
--- a/source/hal/profiles/bare-metal/bsp/retarget.c
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Copyright (c) 2022 Arm Limited. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#if !defined(USE_SEMIHOSTING)
-
-#include "uart_stdout.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-
-#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
-/* Arm compiler re-targeting */
-
-#include <rt_misc.h>
-#include <rt_sys.h>
-
-
-/* Standard IO device handles. */
-#define STDIN 0x8001
-#define STDOUT 0x8002
-#define STDERR 0x8003
-
-#define RETARGET(fun) _sys##fun
-
-#else
-/* GNU compiler re-targeting */
-
-/*
- * This type is used by the _ I/O functions to denote an open
- * file.
- */
-typedef int FILEHANDLE;
-
-/*
- * Open a file. May return -1 if the file failed to open.
- */
-extern FILEHANDLE _open(const char * /*name*/, int /*openmode*/);
-
-/* Standard IO device handles. */
-#define STDIN 0x00
-#define STDOUT 0x01
-#define STDERR 0x02
-
-#define RETARGET(fun) fun
-
-#endif
-
-/* Standard IO device name defines. */
-const char __stdin_name[] __attribute__((aligned(4))) = "STDIN";
-const char __stdout_name[] __attribute__((aligned(4))) = "STDOUT";
-const char __stderr_name[] __attribute__((aligned(4))) = "STDERR";
-
-__attribute__((noreturn)) static void UartEndSimulation(int code)
-{
- UartPutc((char) 0x4); // End of simulation
- UartPutc((char) code); // Exit code
- while(1);
-}
-
-void _ttywrch(int ch) {
- (void)fputc(ch, stdout);
-}
-
-FILEHANDLE RETARGET(_open)(const char *name, int openmode)
-{
- (void)(openmode);
-
- if (strcmp(name, __stdin_name) == 0) {
- return (STDIN);
- }
-
- if (strcmp(name, __stdout_name) == 0) {
- return (STDOUT);
- }
-
- if (strcmp(name, __stderr_name) == 0) {
- return (STDERR);
- }
-
- return -1;
-}
-
-int RETARGET(_write)(FILEHANDLE fh, const unsigned char *buf, unsigned int len, int mode)
-{
- (void)(mode);
-
- switch (fh) {
- case STDOUT:
- case STDERR: {
- int c;
-
- while (len-- > 0) {
- c = fputc(*buf++, stdout);
- if (c == EOF) {
- return EOF;
- }
- }
-
- return 0;
- }
- default:
- return EOF;
- }
-}
-
-int RETARGET(_read)(FILEHANDLE fh, unsigned char *buf, unsigned int len, int mode)
-{
- (void)(mode);
-
- switch (fh) {
- case STDIN: {
- int c;
-
- while (len-- > 0) {
- c = fgetc(stdin);
- if (c == EOF) {
- return EOF;
- }
-
- *buf++ = (unsigned char)c;
- }
-
- return 0;
- }
- default:
- return EOF;
- }
-}
-
-int RETARGET(_istty)(FILEHANDLE fh)
-{
- switch (fh) {
- case STDIN:
- case STDOUT:
- case STDERR:
- return 1;
- default:
- return 0;
- }
-}
-
-int RETARGET(_close)(FILEHANDLE fh)
-{
- if (RETARGET(_istty(fh))) {
- return 0;
- }
-
- return -1;
-}
-
-int RETARGET(_seek)(FILEHANDLE fh, long pos)
-{
- (void)(fh);
- (void)(pos);
-
- return -1;
-}
-
-int RETARGET(_ensure)(FILEHANDLE fh)
-{
- (void)(fh);
-
- return -1;
-}
-
-long RETARGET(_flen)(FILEHANDLE fh)
-{
- if (RETARGET(_istty)(fh)) {
- return 0;
- }
-
- return -1;
-}
-
-int RETARGET(_tmpnam)(char *name, int sig, unsigned int maxlen)
-{
- (void)(name);
- (void)(sig);
- (void)(maxlen);
-
- return 1;
-}
-
-char *RETARGET(_command_string)(char *cmd, int len)
-{
- (void)(len);
-
- return cmd;
-}
-
-void RETARGET(_exit)(int return_code)
-{
- UartEndSimulation(return_code);
- while(1);
-}
-
-int system(const char *cmd)
-{
- (void)(cmd);
-
- return 0;
-}
-
-time_t time(time_t *timer)
-{
- time_t current;
-
- current = 0; // To Do !! No RTC implemented
-
- if (timer != NULL) {
- *timer = current;
- }
-
- return current;
-}
-
-void _clock_init(void) {}
-
-clock_t clock(void)
-{
- return (clock_t)-1;
-}
-
-int remove(const char *arg) {
- (void)(arg);
-
- return 0;
-}
-
-int rename(const char *oldn, const char *newn)
-{
- (void)(oldn);
- (void)(newn);
-
- return 0;
-}
-
-int fputc(int ch, FILE *f)
-{
- (void)(f);
-
- return UartPutc(ch);
-}
-
-int fgetc(FILE *f)
-{
- (void)(f);
-
- return UartPutc(UartGetc());
-}
-
-#ifndef ferror
-
-/* arm-none-eabi-gcc with newlib uses a define for ferror */
-int ferror(FILE *f)
-{
- (void)(f);
-
- return EOF;
-}
-
-#endif /* #ifndef ferror */
-
-#endif /* !defined(USE_SEMIHOSTING) */
diff --git a/source/hal/profiles/bare-metal/data_acquisition/data_acq.c b/source/hal/profiles/bare-metal/data_acquisition/data_acq.c
deleted file mode 100644
index 84d80a6..0000000
--- a/source/hal/profiles/bare-metal/data_acquisition/data_acq.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2022 Arm Limited. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "data_acq.h"
-
-#include "log_macros.h"
-#include "platform_drivers.h"
-#include "uart_stdout.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-
-/**
- * @brief Get the user input from USART.
- * @param[out] user_input String read from the UART block.
- * @param[in] size String read length.
- * @return 0 if successful, error code otherwise.
- **/
-static int get_uart_user_input(char* user_input, int size)
-{
- if (1 != GetLine(user_input, size - 1)) {
- return 1;
- }
- return 0;
-}
-
-int data_acq_channel_init(data_acq_module* module)
-{
- assert(module);
-
- /* UART should have been initialised with low level initialisation
- * routines. */
- module->system_init = NULL;
-
- strncpy(module->system_name, "UART", sizeof(module->system_name));
- module->get_input = get_uart_user_input;
- module->inited = 1;
-
- return !(module->inited);
-}
-
-int data_acq_channel_release(data_acq_module* module)
-{
- assert(module);
- module->inited = 0;
- module->get_input = NULL;
- return 0;
-}
diff --git a/source/hal/profiles/bare-metal/data_presentation/data_psn.c b/source/hal/profiles/bare-metal/data_presentation/data_psn.c
deleted file mode 100644
index de088d7..0000000
--- a/source/hal/profiles/bare-metal/data_presentation/data_psn.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2022 Arm Limited. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "data_psn.h"
-
-#include "lcd_img.h"
-#include "platform_drivers.h"
-
-#include <assert.h>
-#include <string.h>
-
-int data_psn_system_init(data_psn_module* module)
-{
- assert(module);
-
- /* LCD output supported. */
- module->system_init = lcd_init;
- module->present_data_image = lcd_display_image;
- module->present_data_text = lcd_display_text;
- module->present_box = lcd_display_box;
- module->set_text_color = lcd_set_text_color;
- module->clear = lcd_clear;
- strncpy(module->system_name, "lcd", sizeof(module->system_name));
- module->inited = !module->system_init();
- return !module->inited;
-}
-
-int data_psn_system_release(data_psn_module* module)
-{
- assert(module);
- module->inited = 0;
- return 0;
-}
diff --git a/source/hal/profiles/bare-metal/data_presentation/lcd/include/lcd_img.h b/source/hal/profiles/bare-metal/data_presentation/lcd/include/lcd_img.h
deleted file mode 100644
index b447767..0000000
--- a/source/hal/profiles/bare-metal/data_presentation/lcd/include/lcd_img.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2021-2022 Arm Limited. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef LCD_IMG_H
-#define LCD_IMG_H
-
-#include <stdint.h>
-#include <stddef.h>
-#include <stdbool.h>
-
-/**
- * @brief Initialise the LCD
- * @return 0 if successful, error code otherwise.
- **/
-int lcd_init(void);
-
-/**
- * @brief Display a given image on the LCD. This allows displaying 8 bit
- * single or multi-channel images on the LCD.
- * @param[in] data Pointer to start of the image.
- * @param[in] width Width of this image.
- * @param[in] height Image height.
- * @param[in] channels Number of channels.
- * @param[in] pos_x Screen position x co-ordinate.
- * @param[in] pos_y Screen position y co-ordinate.
- * @param[in] downsample_factor Factor by which the image needs to be
- * downsampled.
- * @return 0 if successful, non-zero otherwise.
- **/
-int lcd_display_image(const uint8_t* data, const uint32_t width,
- const uint32_t height, const uint32_t channels,
- const uint32_t pos_x, const uint32_t pos_y,
- const uint32_t downsample_factor);
-
-/**
- * @brief Display a given image on the LCD. This allows displaying 8 bit
- * single or multi-channel images on the LCD.
- * @param[in] str Pointer to a null terminated string.
- * @param[in] str_sz Length of the string.
- * @param[in] pos_x Screen position x co-ordinate.
- * @param[in] pos_y Screen position y co-ordinate.
- * @param[in] allow_multiple_lines The function will try and spread
- * the string into multiple lines if
- * they don't fit in one.
- * @return 0 if successful, non-zero otherwise.
- **/
-int lcd_display_text(const char* str, const size_t str_sz,
- const uint32_t pos_x, const uint32_t pos_y,
- const bool allow_multiple_lines);
-
-/**
- * @brief Display a box with given color on LCD.
- * @param[in] pos_x Screen position x co-ordinate.
- * @param[in] pos_y Screen position y co-ordinate.
- * @param[in] width Width.
- * @param[in] height Height.
- * @param[in] color Fill color.
- * @return 0 if successful, non-zero otherwise.
- **/
-int lcd_display_box(const uint32_t pos_x, const uint32_t pos_y,
- const uint32_t width, const uint32_t height, const uint16_t color);
-
-/**
- * @brief Clear LCD.
- * @param[in] color Fill color.
- * @return 0 if successful, non-zero otherwise.
- **/
-int lcd_clear(const uint16_t color);
-
-/**
- * @brief Set text color.
- * @param[in] color Fill color.
- * @return 0 if successful, non-zero otherwise.
- **/
-int lcd_set_text_color(const uint16_t color);
-
-#endif /* LCD_IMG_H */
diff --git a/source/hal/profiles/bare-metal/data_presentation/lcd/lcd_img.c b/source/hal/profiles/bare-metal/data_presentation/lcd/lcd_img.c
deleted file mode 100644
index 6e05f29..0000000
--- a/source/hal/profiles/bare-metal/data_presentation/lcd/lcd_img.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright (c) 2022 Arm Limited. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "lcd_img.h"
-
-#include "log_macros.h"
-#include "platform_drivers.h"
-
-#include <string.h>
-#include <assert.h>
-
-static int show_title(void)
-{
- char title[128];
- int status = 0;
-
- /* LCD title string */
-#if defined(CPU_CORTEX_M55)
- const char* cpu_name = "Arm Cortex-M55";
-#else /* defined(CPU_CORTEX_M55) */
- const char* cpu_name = "Arm CPU";
-#endif /* defined(CPU_CORTEX_M55) */
-
- lcd_set_text_color(White);
-
- /* First line */
- snprintf(title, sizeof(title), "Arm ML embedded code samples");
-
- if (0 != (status = lcd_display_text(
- title, strlen(title), 10, 0, false))) {
- return status;
- }
-
- /* Second line */
-#if defined (ARM_NPU)
- snprintf(title, sizeof(title), "%s + Arm Ethos-U NPU", cpu_name);
-#else /* defined (ARM_NPU) */
- snprintf(title, sizeof(title), "%s", cpu_name);
-#endif /* defined (ARM_NPU) */
-
- return lcd_display_text(title, strlen(title), 10, 20, false);
-}
-
-int lcd_init(void)
-{
- GLCD_Initialize();
- GLCD_Clear(Black);
- return show_title();
-}
-
-int lcd_display_image(const uint8_t* data, const uint32_t width,
- const uint32_t height, const uint32_t channels,
- const uint32_t pos_x, const uint32_t pos_y,
- const uint32_t downsample_factor)
-{
- /* Sanity checks */
- assert(data);
- if ((pos_x + width/downsample_factor > GLCD_WIDTH) ||
- (pos_y + height/downsample_factor > GLCD_HEIGHT)) {
- printf_err("Invalid image size for given location!\n");
- return 1;
- }
-
- if (1 == channels || 3 == channels) {
- GLCD_Image(data, width, height, channels, pos_x, pos_y,
- downsample_factor);
- } else {
- printf_err("Only single and three channel images are supported!\n");
- return 1;
- }
-
- return 0;
-}
-
-int lcd_display_text(const char* str, const size_t str_sz,
- const uint32_t pos_x, const uint32_t pos_y,
- const bool allow_multiple_lines)
-{
- /* We use a font 0 which is 9x15. */
- const uint32_t x_span = 9; /* Each character is this 9 pixels "wide". */
- const uint32_t y_span = 15; /* Each character is this 15 pixels "high". */
-
- if (str_sz == 0) {
- return 1;
- }
-
- /* If not within the LCD bounds, return error. */
- if (pos_x + x_span > GLCD_WIDTH || pos_y + y_span > GLCD_HEIGHT) {
- return 1;
- } else {
- const unsigned char font_idx = 0; /* We are using the custom font = 0 */
-
- const uint32_t col = pos_x/x_span;
- const uint32_t max_cols = GLCD_WIDTH/x_span - 1;
- const uint32_t max_lines = GLCD_HEIGHT/y_span - 1;
-
- uint32_t i = 0;
- uint32_t current_line = pos_y/y_span;
- uint32_t current_col = col;
-
- /* Display the string on the LCD. */
- for (i = 0; i < str_sz; ++i) {
-
- if (allow_multiple_lines) {
-
- /* If the next character won't fit. */
- if (current_col > max_cols) {
- current_col = col;
-
- /* If the next line won't fit. */
- if (++current_line > max_lines) {
- return 1;
- }
- }
- }
-
- GLCD_DisplayChar(current_line, current_col++, font_idx, str[i]);
- }
- }
- return 0;
-}
-
-int lcd_display_box(const uint32_t pos_x, const uint32_t pos_y,
- const uint32_t width, const uint32_t height, const uint16_t color)
-{
- /* If not within the LCD bounds, return error. */
- if (pos_x > GLCD_WIDTH || pos_y > GLCD_HEIGHT) {
- return 1;
- }
- else {
- GLCD_Box(pos_x, pos_y, width, height, color);
- }
- return 0;
-}
-
-int lcd_clear(const uint16_t color)
-{
- GLCD_Clear(color);
- GLCD_SetTextColor(White);
- return show_title();
-}
-
-int lcd_set_text_color(const uint16_t color)
-{
- GLCD_SetTextColor(color);
- return 0;
-}
diff --git a/source/hal/profiles/bare-metal/timer/include/platform_timer.h b/source/hal/profiles/bare-metal/timer/include/platform_timer.h
deleted file mode 100644
index dd3934e..0000000
--- a/source/hal/profiles/bare-metal/timer/include/platform_timer.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2022 Arm Limited. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef BAREMETAL_TIMER_H
-#define BAREMETAL_TIMER_H
-
-#include "platform_drivers.h"
-
-#include <stdint.h>
-#include <time.h>
-
-typedef struct bm_time_counter {
- base_time_counter counter;
-
-#if defined (ARM_NPU)
- uint64_t npu_total_ccnt;
- uint32_t npu_idle_ccnt;
- uint32_t npu_axi0_read_beats;
- uint32_t npu_axi0_write_beats;
- uint32_t npu_axi1_read_beats;
-#endif /* ARM_NPU */
-
-} time_counter;
-
-#endif /* BAREMETAL_TIMER_H */
diff --git a/source/hal/profiles/bare-metal/timer/platform_timer.c b/source/hal/profiles/bare-metal/timer/platform_timer.c
deleted file mode 100644
index 0388198..0000000
--- a/source/hal/profiles/bare-metal/timer/platform_timer.c
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
- * Copyright (c) 2022 Arm Limited. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "timer.h"
-#include "log_macros.h"
-#include "platform_drivers.h"
-
-#include <assert.h>
-#include <string.h>
-#include <inttypes.h>
-
-#if defined (ARM_NPU)
-
-#include "pmu_ethosu.h"
-
-extern struct ethosu_driver ethosu_drv; /* Default Ethos-U55 device driver */
-
-/**
- * @brief Initialises the PMU and enables the cycle counter.
- **/
-static void _init_ethosu_cyclecounter(void);
-
-/**
- * @brief Gets the difference of total NPU cycle counts.
- * (includes active and idle)
- * @param[in] st Pointer to time_counter value at start time.
- * @param[in] end Pointer to time_counter value at end.
- * @return Total NPU cycle counts difference between the arguments expressed
- * as unsigned 64 bit integer.
- **/
-static uint64_t bm_get_npu_total_cycle_diff(time_counter *st,
- time_counter *end);
-
-/**
- * @brief Gets the difference in active NPU cycle counts.
- * @param[in] st Pointer to time_counter value at start time.
- * @param[in] end Pointer to time_counter value at end.
- * @return Active NPU cycle counts difference between the arguments expressed
- * as unsigned 64 bit integer.
- **/
-static uint64_t bm_get_npu_active_cycle_diff(time_counter *st,
- time_counter *end);
-
-/** @brief Gets the difference in idle NPU cycle counts
- * @param[in] st Pointer to time_counter value at start time.
- * @param[in] end Pointer to time_counter value at end.
- * @return Idle NPU cycle counts difference between the arguments expressed
- * as unsigned 64 bit integer.
- **/
-static uint64_t bm_get_npu_idle_cycle_diff(time_counter *st,
- time_counter *end);
-
-/** @brief Gets the difference in axi0 bus reads cycle counts
- * @param[in] st Pointer to time_counter value at start time.
- * @param[in] end Pointer to time_counter value at end.
- * @return NPU AXI0 read cycle counts difference between the arguments expressed
- * as unsigned 64 bit integer.
- **/
-static uint64_t bm_get_npu_axi0_read_cycle_diff(time_counter *st,
- time_counter *end);
-
-/** @brief Gets the difference in axi0 bus writes cycle counts
- * @param[in] st Pointer to time_counter value at start time.
- * @param[in] end Pointer to time_counter value at end.
- * @return NPU AXI0 write cycle counts difference between the arguments expressed
- * as unsigned 64 bit integer.
- **/
-static uint64_t bm_get_npu_axi0_write_cycle_diff(time_counter *st,
- time_counter *end);
-
-/** @brief Gets the difference in axi1 bus reads cycle counts
- * @param[in] st Pointer to time_counter value at start time.
- * @param[in] end Pointer to time_counter value at end.
- * @return NPU AXI1 read cycle counts difference between the arguments expressed
- * as unsigned 64 bit integer.
- **/
-static uint64_t bm_get_npu_axi1_read_cycle_diff(time_counter *st,
- time_counter *end);
-
-/** @brief Gets the difference for 6 collected cycle counts:
- * 1) total NPU
- * 2) active NPU
- * 3) idle NPU
- * 4) axi0 read
- * 5) axi0 write
- * 6) axi1 read
- * */
-static int bm_get_npu_cycle_diff(time_counter *st, time_counter *end,
- uint64_t* pmu_counters_values, const size_t size);
-
-#endif /* defined (ARM_NPU) */
-
-#if defined(MPS3_PLATFORM)
-/**
- * @brief Wrapper for getting milliseconds duration between time counters
- * @param[in] st Pointer to time_counter value at start time.
- * @param[in] end Pointer to time_counter value at end.
- * @return Difference in milliseconds between given time counters.
- **/
-static time_t bm_get_duration_ms(time_counter *st, time_counter *end);
-
-/**
- * @brief Wrapper for getting microseconds duration between time counters
- * @param[in] st Pointer to time_counter value at start time.
- * @param[in] end Pointer to time_counter value at end.
- * @return Difference in microseconds between given time counters.
- **/
-static time_t bm_get_duration_us(time_counter *st, time_counter *end);
-#endif /* defined(MPS3_PLATFORM) */
-
-/**
- * @brief Wrapper for resetting timer.
- **/
-static void bm_timer_reset(void);
-
-/**
- * @brief Wrapper for getting the current timer counter.
- * @return Current time counter value.
- **/
-static time_counter bm_get_time_counter(void);
-
-/**
- * @brief Wrapper for profiler start.
- * @return Current profiler start timer counter.
- **/
-static time_counter bm_start_profiling(void);
-
-/**
- * @brief Wrapper for profiler end.
- * @return Current profiler end timer counter.
- **/
-static time_counter bm_stop_profiling(void);
-
-/**
- * @brief Wrapper for getting CPU cycle difference between time counters.
- * @return CPU cycle difference between given time counters expressed
- * as unsigned 32 bit integer.
- **/
-static uint64_t bm_get_cpu_cycles_diff(time_counter *st, time_counter *end);
-
-/**
- * @brief Initialiser for bare metal timer.
- * @param[in] timer Platform timer to initialize.
- **/
-void init_timer(platform_timer *timer)
-{
- assert(timer);
- memset(timer, 0, sizeof(*timer));
-
- timer->reset = bm_timer_reset;
- timer->get_time_counter = bm_get_time_counter;
- timer->start_profiling = bm_start_profiling;
- timer->stop_profiling = bm_stop_profiling;
- timer->get_cpu_cycle_diff = bm_get_cpu_cycles_diff;
- timer->cap.cpu_cycles = 1;
-
-#if defined (MPS3_PLATFORM)
- timer->cap.duration_ms = 1;
- timer->cap.duration_us = 1;
- timer->get_duration_ms = bm_get_duration_ms;
- timer->get_duration_us = bm_get_duration_us;
-#endif /* defined (MPS3_PLATFORM) */
-
-#if defined (ARM_NPU)
- /* We are capable of reporting npu cycle counts. */
- timer->cap.npu_cycles = 1;
- timer->get_npu_cycles_diff = bm_get_npu_cycle_diff;
- _init_ethosu_cyclecounter();
-#endif /* defined (ARM_NPU) */
-
- timer->reset();
- timer->inited = 1;
-}
-
-#if defined (ARM_NPU)
-static void _reset_ethosu_counters()
-{
- /* Reset all cycle and event counters. */
- ETHOSU_PMU_CYCCNT_Reset(&ethosu_drv);
- ETHOSU_PMU_EVCNTR_ALL_Reset(&ethosu_drv);
-}
-static void _init_ethosu_cyclecounter()
-{
- /* Reset overflow status. */
- ETHOSU_PMU_Set_CNTR_OVS(&ethosu_drv, ETHOSU_PMU_CNT1_Msk | ETHOSU_PMU_CCNT_Msk);
- /* We can retrieve only 4 PMU counters: */
- ETHOSU_PMU_Set_EVTYPER(&ethosu_drv, 0, ETHOSU_PMU_NPU_IDLE);
- ETHOSU_PMU_Set_EVTYPER(&ethosu_drv, 1, ETHOSU_PMU_AXI0_RD_DATA_BEAT_RECEIVED);
- ETHOSU_PMU_Set_EVTYPER(&ethosu_drv, 2, ETHOSU_PMU_AXI0_WR_DATA_BEAT_WRITTEN);
- ETHOSU_PMU_Set_EVTYPER(&ethosu_drv, 3, ETHOSU_PMU_AXI1_RD_DATA_BEAT_RECEIVED);
- /* Enable PMU. */
- ETHOSU_PMU_Enable(&ethosu_drv);
- /* Enable counters for cycle and counter# 0. */
- ETHOSU_PMU_CNTR_Enable(&ethosu_drv, ETHOSU_PMU_CNT1_Msk | ETHOSU_PMU_CNT2_Msk | ETHOSU_PMU_CNT3_Msk | ETHOSU_PMU_CNT4_Msk| ETHOSU_PMU_CCNT_Msk);
- _reset_ethosu_counters();
-}
-
-static int bm_get_npu_cycle_diff(time_counter *st, time_counter *end,
- uint64_t* pmu_counters_values, const size_t size)
-{
- if (size == 6) {
- pmu_counters_values[0] = bm_get_npu_total_cycle_diff(st, end);
- pmu_counters_values[1] = bm_get_npu_active_cycle_diff(st, end);
- pmu_counters_values[2] = bm_get_npu_idle_cycle_diff(st, end);
- pmu_counters_values[3] = bm_get_npu_axi0_read_cycle_diff(st, end);
- pmu_counters_values[4] = bm_get_npu_axi0_write_cycle_diff(st, end);
- pmu_counters_values[5] = bm_get_npu_axi1_read_cycle_diff(st, end);
- return 0;
- } else {
- return 1;
- }
-}
-
-static uint64_t bm_get_npu_total_cycle_diff(time_counter *st, time_counter *end)
-{
- return end->npu_total_ccnt - st->npu_total_ccnt;
-}
-
-static uint32_t counter_overflow(uint32_t pmu_counter_mask)
-{
- /* Check for overflow: The idle counter is 32 bit while the
- total cycle count is 64 bit. */
- const uint32_t overflow_status = ETHOSU_PMU_Get_CNTR_OVS(&ethosu_drv);
- return pmu_counter_mask & overflow_status;
-}
-
-static uint64_t bm_get_npu_idle_cycle_diff(time_counter *st, time_counter *end)
-{
- if (counter_overflow(ETHOSU_PMU_CNT1_Msk)) {
- printf_err("EthosU PMU idle counter overflow.\n");
- return 0;
- }
- return (uint64_t)(end->npu_idle_ccnt - st->npu_idle_ccnt);
-}
-
-static uint64_t bm_get_npu_active_cycle_diff(time_counter *st, time_counter *end)
-{
- /* Active NPU time = total time - idle time */
- return bm_get_npu_total_cycle_diff(st, end) - bm_get_npu_idle_cycle_diff(st, end);
-}
-
-static uint64_t bm_get_npu_axi0_read_cycle_diff(time_counter *st, time_counter *end)
-{
- if (counter_overflow(ETHOSU_PMU_CNT2_Msk)) {
- printf_err("EthosU PMU axi0 read counter overflow.\n");
- return 0;
- }
- return (uint64_t)(end->npu_axi0_read_beats - st->npu_axi0_read_beats);
-}
-
-static uint64_t bm_get_npu_axi0_write_cycle_diff(time_counter *st, time_counter *end)
-{
- if (counter_overflow(ETHOSU_PMU_CNT3_Msk)) {
- printf_err("EthosU PMU axi0 write counter overflow.\n");
- return 0;
- }
- return (uint64_t)(end->npu_axi0_write_beats - st->npu_axi0_write_beats);
-}
-
-static uint64_t bm_get_npu_axi1_read_cycle_diff(time_counter *st, time_counter *end)
-{
- if (counter_overflow(ETHOSU_PMU_CNT4_Msk)) {
- printf_err("EthosU PMU axi1 read counter overflow.\n");
- return 0;
- }
- return (uint64_t)(end->npu_axi1_read_beats - st->npu_axi1_read_beats);
-}
-
-#endif /* defined (ARM_NPU) */
-
-static void bm_timer_reset(void)
-{
-#if defined (ARM_NPU)
- _init_ethosu_cyclecounter();
-#endif /* defined (ARM_NPU) */
-
- timer_reset();
-}
-
-static time_counter bm_get_time_counter(void)
-{
- time_counter t = {
- .counter = get_time_counter(),
-
-#if defined (ARM_NPU)
- .npu_total_ccnt = ETHOSU_PMU_Get_CCNTR(&ethosu_drv),
- .npu_idle_ccnt = ETHOSU_PMU_Get_EVCNTR(&ethosu_drv, 0),
- .npu_axi0_read_beats = ETHOSU_PMU_Get_EVCNTR(&ethosu_drv, 1),
- .npu_axi0_write_beats = ETHOSU_PMU_Get_EVCNTR(&ethosu_drv, 2),
- .npu_axi1_read_beats = ETHOSU_PMU_Get_EVCNTR(&ethosu_drv, 3)
-#endif /* defined (ARM_NPU) */
-
- };
-
-#if defined (ARM_NPU)
- debug("NPU total cc: %" PRIu64
- "; NPU idle cc: %" PRIu32
- "; NPU axi0 read beats: %" PRIu32
- "; NPU axi0 write beats: %" PRIu32
- "; NPU axi1 read beats: %" PRIu32 "\n",
- t.npu_total_ccnt,
- t.npu_idle_ccnt,
- t.npu_axi0_read_beats,
- t.npu_axi0_write_beats,
- t.npu_axi1_read_beats);
-#endif /* defined (ARM_NPU) */
-
- return t;
-}
-
-static time_counter bm_start_profiling(void)
-{
- start_cycle_counter();
- return bm_get_time_counter();
-}
-
-static time_counter bm_stop_profiling(void)
-{
- stop_cycle_counter();
- return bm_get_time_counter();
-}
-
-static uint64_t bm_get_cpu_cycles_diff(time_counter *st, time_counter *end)
-{
- return get_cycle_count_diff(&(st->counter), &(end->counter));
-}
-
-#if defined(MPS3_PLATFORM)
-static time_t bm_get_duration_ms(time_counter *st, time_counter *end)
-{
- return get_duration_milliseconds(&(st->counter), &(end->counter));
-}
-
-static time_t bm_get_duration_us(time_counter *st, time_counter *end)
-{
- return get_duration_microseconds(&(st->counter), &(end->counter));
-}
-#endif /* defined(MPS3_PLATFORM) */