Skip to content

Commit

Permalink
lib: system: create a new libmetal API metal_yield
Browse files Browse the repository at this point in the history
Define metal_yield in sys.h files is more flexible to manage this
in libmetal, metal_yield would be managed at the OS level and
dispatched to metal_cpu_yield, metal_sleep_usec, or others.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
  • Loading branch information
wyr-7 authored and arnopo committed Oct 21, 2024
1 parent e2c504f commit 142c403
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/system/freertos/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define __METAL_FREERTOS_SYS__H__

#include <metal/errno.h>
#include <metal/cpu.h>

#ifdef XLNX_PLATFORM
#include <metal/system/freertos/xlnx/sys.h>
Expand All @@ -33,6 +34,8 @@ extern "C" {
#define METAL_MAX_DEVICE_REGIONS 1
#endif

#define metal_yield() metal_cpu_yield()

/** Structure for FreeRTOS libmetal runtime state. */
struct metal_state {

Expand Down
4 changes: 4 additions & 0 deletions lib/system/freertos/template/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
#ifndef __METAL_FREERTOS_TEMPLATE_SYS__H__
#define __METAL_FREERTOS_TEMPLATE_SYS__H__

#include <metal/cpu.h>

#ifdef __cplusplus
extern "C" {
#endif

#define metal_yield() metal_cpu_yield()

#ifdef METAL_INTERNAL

void sys_irq_enable(unsigned int vector);
Expand Down
4 changes: 4 additions & 0 deletions lib/system/freertos/xlnx/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
#ifndef __METAL_FREERTOS_XLNX_SYS__H__
#define __METAL_FREERTOS_XLNX_SYS__H__

#include <metal/cpu.h>

#include "xscugic.h"
#include "FreeRTOS.h"

#ifdef __cplusplus
extern "C" {
#endif

#define metal_yield() metal_cpu_yield()

#if defined(SDT) && defined(PLATFORM_ZYNQ)
#define XPAR_SCUGIC_0_DIST_BASEADDR XPAR_SCUGIC_DIST_BASEADDR
#endif
Expand Down
3 changes: 3 additions & 0 deletions lib/system/linux/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <fcntl.h>
#include <libgen.h>
#include <limits.h>
#include <metal/cpu.h>
#include <metal/errno.h>
#include <pthread.h>
#include <stdio.h>
Expand Down Expand Up @@ -46,6 +47,8 @@ extern "C" {
#define METAL_INVALID_VADDR NULL
#define MAX_PAGE_SIZES 32

#define metal_yield() metal_cpu_yield()

struct metal_device;

/** Structure of shared page or hugepage sized data. */
Expand Down
4 changes: 4 additions & 0 deletions lib/system/nuttx/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
#ifndef __METAL_NUTTX_SYS__H__
#define __METAL_NUTTX_SYS__H__

#include <metal/sleep.h>

#ifdef __cplusplus
extern "C" {
#endif

#define metal_yield() metal_sleep_usec(1000)

#define METAL_INIT_DEFAULTS \
{ \
.log_handler = (metal_log_handler)syslog, \
Expand Down
3 changes: 3 additions & 0 deletions lib/system/zephyr/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
#ifndef __METAL_ZEPHYR_SYS__H__
#define __METAL_ZEPHYR_SYS__H__

#include <metal/cpu.h>
#include <stdlib.h>
#include <zephyr/kernel.h>

#ifdef __cplusplus
extern "C" {
#endif

#define metal_yield() metal_cpu_yield()

#define METAL_INIT_DEFAULTS \
{ \
.log_handler = metal_zephyr_log_handler, \
Expand Down

0 comments on commit 142c403

Please sign in to comment.