Skip to content

Commit

Permalink
lib: processor: hosted: Fix compilation warning in metal_cpu_yield
Browse files Browse the repository at this point in the history
Fix cross inclusion between metal/sys.h and /processor/hosted/cpu.h

The fix consists in creating a cpu.c file to avoid inline declaration.

Issue reported by Zephyr twister CI test:

libmetal/lib/include/metal/processor/hosted/cpu.h:19:9:
error: implicit declaration of function ‘metal_wait_usec’
   19 |         metal_wait_usec(10);
      |         ^~~~~~~~~~~~~~~
libmetal/lib/include/metal/system/zephyr/sys.h:46:20:
error: conflicting types for ‘metal_wait_usec’; have ‘void(uint32_t)’
   46 | static inline void metal_wait_usec(uint32_t usec_to_wait)
      |                    ^~~~~~~~~~~~~~~
libmetal/lib/include/metal/processor/hosted/cpu.h:19:9:
note: previous implicit declaration of ‘metal_wait_usec’ with
type ‘void(uint32_t)’ {aka ‘void(unsigned int)’}
   19 |         metal_wait_usec(10);
      |         ^~~~~~~~~~~~~~~

Signed-off-by: Arnaud Pouliquen <[email protected]>
  • Loading branch information
arnopo committed Oct 25, 2024
1 parent 7f351a5 commit 4a6b337
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/processor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ else()
collect (PROJECT_LIB_HEADERS generic/cpu.h)
endif()

if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_PROCESSOR}/cpu.c")
collect (PROJECT_LIB_SOURCES ${PROJECT_PROCESSOR}/cpu.c)
endif()

if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_PROCESSOR}/atomic.h")
collect (PROJECT_LIB_HEADERS ${PROJECT_PROCESSOR}/atomic.h)
set(HAVE_PROCESSOR_ATOMIC_H 1 CACHE INTERNAL "Have include ${PROJECT_PROCESSOR}/atomic.h")
else()
collect (PROJECT_LIB_HEADERS generic/atomic.h)
endif()

17 changes: 17 additions & 0 deletions lib/processor/hosted/cpu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2024, STMicroelectronics.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

/*
* @file zephyr/cpu.c
* @brief hosted libmetal cpu routines.
*/

#include <metal/sys.h>

void metal_cpu_yield(void)
{
metal_wait_usec(10);
}
7 changes: 1 addition & 6 deletions lib/processor/hosted/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@
* @brief Hosted environment CPU specific primitives
*/

#include <metal/sys.h>

#ifndef __METAL_HOSTED_CPU__H__
#define __METAL_HOSTED_CPU__H__

static inline void metal_cpu_yield(void)
{
metal_wait_usec(10);
}
void metal_cpu_yield(void);

#endif /* __METAL_HOSTED_CPU__H__ */

0 comments on commit 4a6b337

Please sign in to comment.