建立工程,成功创建两个虚拟串口

This commit is contained in:
ranchuan
2023-06-21 18:00:56 +08:00
commit 3604192d8f
872 changed files with 428764 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
collect (PROJECT_LIB_HEADERS alloc.h)
collect (PROJECT_LIB_HEADERS assert.h)
collect (PROJECT_LIB_HEADERS cache.h)
collect (PROJECT_LIB_HEADERS condition.h)
collect (PROJECT_LIB_HEADERS io.h)
collect (PROJECT_LIB_HEADERS irq.h)
collect (PROJECT_LIB_HEADERS log.h)
collect (PROJECT_LIB_HEADERS mutex.h)
collect (PROJECT_LIB_HEADERS sleep.h)
collect (PROJECT_LIB_HEADERS sys.h)
collect (PROJECT_LIB_SOURCES alloc.c)
collect (PROJECT_LIB_SOURCES condition.c)
collect (PROJECT_LIB_SOURCES device.c)
collect (PROJECT_LIB_SOURCES init.c)
collect (PROJECT_LIB_SOURCES irq.c)
collect (PROJECT_LIB_SOURCES log.c)
collect (PROJECT_LIB_SOURCES shmem.c)
collect (PROJECT_LIB_SOURCES time.c)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE})
add_subdirectory(${PROJECT_MACHINE})
endif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE})
# vim: expandtab:ts=2:sw=2:smartindent

View File

@@ -0,0 +1,28 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/alloc.c
* @brief Zephyr libmetal memory allocation handling.
*/
#include <metal/alloc.h>
#include <metal/compiler.h>
#if (CONFIG_HEAP_MEM_POOL_SIZE <= 0)
void* metal_weak metal_zephyr_allocate_memory(unsigned int size)
{
(void)size;
return NULL;
}
void metal_weak metal_zephyr_free_memory(void *ptr)
{
(void)ptr;
}
#endif /* CONFIG_HEAP_MEM_POOL_SIZE */

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/alloc.h
* @brief zephyr libmetal memory allocattion definitions.
*/
#ifndef __METAL_ALLOC__H__
#error "Include metal/alloc.h instead of metal/zephyr/alloc.h"
#endif
#ifndef __METAL_ZEPHYR_ALLOC__H__
#define __METAL_ZEPHYR_ALLOC__H__
#include <kernel.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
#if (CONFIG_HEAP_MEM_POOL_SIZE > 0)
static inline void *metal_allocate_memory(unsigned int size)
{
return k_malloc(size);
}
static inline void metal_free_memory(void *ptr)
{
k_free(ptr);
}
#else
void *metal_zephyr_allocate_memory(unsigned int size);
void metal_zephyr_free_memory(void *ptr);
static inline void *metal_allocate_memory(unsigned int size)
{
return metal_zephyr_allocate_memory(size);
}
static inline void metal_free_memory(void *ptr)
{
metal_zephyr_free_memory(ptr);
}
#endif /* CONFIG_HEAP_MEM_POOL_SIZE */
#ifdef __cplusplus
}
#endif
#endif /* __METAL_ZEPHYR_ALLOC__H__ */

View File

@@ -0,0 +1,28 @@
/*
* Copyright (c) 2018, Xilinx Inc. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file assert.h
* @brief Zephyr assertion support.
*/
#ifndef __METAL_ASSERT__H__
#error "Include metal/assert.h instead of metal/zephyr/assert.h"
#endif
#ifndef __METAL_ZEPHYR_ASSERT__H__
#define __METAL_ZEPHYR_ASSERT__H__
#include <zephyr.h>
/**
* @brief Assertion macro for Zephyr-based applications.
* @param cond Condition to evaluate.
*/
#define metal_sys_assert(cond) __ASSERT_NO_MSG(cond)
#endif /* __METAL_ZEPHYR_ASSERT__H__ */

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2018, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/cache.h
* @brief Zephyr cache operation primitives for libmetal.
*/
#ifndef __METAL_CACHE__H__
#error "Include metal/cache.h instead of metal/zephyr/cache.h"
#endif
#ifndef __METAL_ZEPHYR_CACHE__H__
#define __METAL_ZEPHYR_CACHE__H__
#include <cache.h>
#include <metal/utilities.h>
#ifdef __cplusplus
extern "C" {
#endif
static inline void __metal_cache_flush(void *addr, unsigned int len)
{
sys_cache_flush((vaddr_t) addr, len);
}
static inline void __metal_cache_invalidate(void *addr, unsigned int len)
{
metal_unused(addr);
metal_unused(len);
return;
}
#ifdef __cplusplus
}
#endif
#endif /* __METAL_ZEPHYR_CACHE__H__ */

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/condition.c
* @brief Zephyr libmetal condition variable handling.
*/
#include <metal/condition.h>
#include <metal/irq.h>
extern void metal_generic_default_poll(void);
int metal_condition_wait(struct metal_condition *cv,
metal_mutex_t *m)
{
metal_mutex_t *tmpm = 0;
int v;
unsigned int flags;
/* Check if the mutex has been acquired */
if (!cv || !m || !metal_mutex_is_acquired(m))
return -EINVAL;
if (!atomic_compare_exchange_strong(&cv->m, &tmpm, m)) {
if (m != tmpm)
return -EINVAL;
}
v = atomic_load(&cv->v);
/* Release the mutex first. */
metal_mutex_release(m);
do {
flags = metal_irq_save_disable();
if (atomic_load(&cv->v) != v) {
metal_irq_restore_enable(flags);
break;
}
metal_generic_default_poll();
metal_irq_restore_enable(flags);
} while(1);
/* Acquire the mutex again. */
metal_mutex_acquire(m);
return 0;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/condition.h
* @brief Zephyr condition variable primitives for libmetal.
*/
#ifndef __METAL_CONDITION__H__
#error "Include metal/condition.h instead of metal/generic/condition.h"
#endif
#ifndef __METAL_ZEPHYR_CONDITION__H__
#define __METAL_ZEPHYR_CONDITION__H__
#include <metal/errno.h>
#include <metal/atomic.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
struct metal_condition {
metal_mutex_t *m; /**< mutex.
The condition variable is attached to
this mutex when it is waiting.
It is also used to check correctness
in case there are multiple waiters. */
atomic_int v; /**< condition variable value. */
};
/** Static metal condition variable initialization. */
#define METAL_CONDITION_INIT { NULL, ATOMIC_VAR_INIT(0) }
static inline void metal_condition_init(struct metal_condition *cv)
{
cv->m = NULL;
atomic_init(&cv->v, 0);
}
static inline int metal_condition_signal(struct metal_condition *cv)
{
if (!cv)
return -EINVAL;
/** wake up waiters if there are any. */
atomic_fetch_add(&cv->v, 1);
return 0;
}
static inline int metal_condition_broadcast(struct metal_condition *cv)
{
return metal_condition_signal(cv);
}
#ifdef __cplusplus
}
#endif
#endif /* __METAL_ZEPHYR_CONDITION__H__ */

View File

@@ -0,0 +1,5 @@
collect (PROJECT_LIB_HEADERS sys.h)
collect (PROJECT_LIB_SOURCES sys.c)
# vim: expandtab:ts=2:sw=2:smartindent

View File

@@ -0,0 +1,22 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/qemu_cortex_m3/sys.c
* @brief machine specific system primitives implementation.
*/
#include <metal/io.h>
#include <metal/sys.h>
#include <stdint.h>
/**
* @brief poll function until some event happens
*/
void metal_weak metal_generic_default_poll(void)
{
__asm__ __volatile__("wfi");
}

View File

@@ -0,0 +1,27 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/qemu_cortex_m3/sys.h
* @brief Zephyr QEMU Cortex M3 system primitives for libmetal.
*/
#ifndef __METAL_ZEPHYR_SYS__H__
#error "Include metal/sys.h instead of metal/generic/@PROJECT_MACHINE@/sys.h"
#endif
#ifndef __METAL_ZEPHYR_CORTEXM_SYS__H__
#define __METAL_ZEPHYR_CORTEXM_SYS__H__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* __METAL_ZEPHYR_CORTEXM_SYS__H__ */

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/device.c
* @brief Zephyr libmetal device definitions.
*/
#include <metal/device.h>
#include <metal/sys.h>
#include <metal/utilities.h>
int metal_generic_dev_sys_open(struct metal_device *dev)
{
metal_unused(dev);
/* Since Zephyr runs bare-metal there is no mapping that needs to be
* done of IO regions
*/
return 0;
}
struct metal_bus metal_generic_bus = {
.name = "generic",
.ops = {
.bus_close = NULL,
.dev_open = metal_generic_dev_open,
.dev_close = NULL,
.dev_irq_ack = NULL,
.dev_dma_map = NULL,
.dev_dma_unmap = NULL,
},
};

View File

@@ -0,0 +1,27 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/init.c
* @brief Zephyr libmetal initialization.
*/
#include <metal/device.h>
#include <metal/sys.h>
#include <metal/utilities.h>
struct metal_state _metal;
int metal_sys_init(const struct metal_init_params *params)
{
metal_bus_register(&metal_generic_bus);
return 0;
}
void metal_sys_finish(void)
{
metal_bus_unregister(&metal_generic_bus);
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/io.h
* @brief Zephyr specific io definitions.
*/
#ifndef __METAL_IO__H__
#error "Include metal/io.h instead of metal/zephyr/io.h"
#endif
#ifndef __METAL_ZEPHYR_IO__H__
#define __METAL_ZEPHYR_IO__H__
#include <stdlib.h>
#include <metal/utilities.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef METAL_INTERNAL
/**
* @brief memory mapping for an I/O region
*/
static inline void metal_sys_io_mem_map(struct metal_io_region *io)
{
metal_unused(io);
}
/**
* @brief memory mapping
*/
static inline void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa,
size_t size, unsigned int flags)
{
metal_unused(pa);
metal_unused(size);
metal_unused(flags);
return va;
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* __METAL_ZEPHYR_IO__H__ */

View File

@@ -0,0 +1,280 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/irq.c
* @brief Zephyr libmetal irq definitions.
*/
#include <metal/errno.h>
#include <metal/irq.h>
#include <metal/sys.h>
#include <metal/log.h>
#include <metal/mutex.h>
#include <metal/list.h>
#include <metal/utilities.h>
#include <metal/alloc.h>
#include <irq.h>
/** IRQ handlers descriptor structure */
struct metal_irq_hddesc {
metal_irq_handler hd; /**< irq handler */
void *drv_id; /**< id to identify the driver
of the irq handler */
struct metal_device *dev; /**< device identifier */
struct metal_list node; /**< node on irq handlers list */
};
/** IRQ descriptor structure */
struct metal_irq_desc {
int irq; /**< interrupt number */
struct metal_list hdls; /**< interrupt handlers */
struct metal_list node; /**< node on irqs list */
};
/** IRQ state structure */
struct metal_irqs_state {
struct metal_list irqs; /**< interrupt descriptors */
metal_mutex_t irq_lock; /**< access lock */
};
static struct metal_irqs_state _irqs = {
.irqs = METAL_INIT_LIST(_irqs.irqs),
.irq_lock = METAL_MUTEX_INIT(_irqs.irq_lock),
};
int metal_irq_register(int irq,
metal_irq_handler hd,
struct metal_device *dev,
void *drv_id)
{
struct metal_irq_desc *irq_p = NULL;
struct metal_irq_hddesc *hdl_p;
struct metal_list *node;
unsigned int irq_flags_save;
if (irq < 0) {
metal_log(METAL_LOG_ERROR,
"%s: irq %d need to be a positive number\n",
__func__, irq);
return -EINVAL;
}
if ((drv_id == NULL) || (hd == NULL)) {
metal_log(METAL_LOG_ERROR, "%s: irq %d need drv_id and hd.\n",
__func__, irq);
return -EINVAL;
}
/* Search for irq in list */
metal_mutex_acquire(&_irqs.irq_lock);
metal_list_for_each(&_irqs.irqs, node) {
irq_p = metal_container_of(node, struct metal_irq_desc, node);
if (irq_p->irq == irq) {
struct metal_list *h_node;
/* Check if drv_id already exist */
metal_list_for_each(&irq_p->hdls, h_node) {
hdl_p = metal_container_of(h_node,
struct metal_irq_hddesc,
node);
/* if drv_id already exist reject */
if ((hdl_p->drv_id == drv_id) &&
((dev == NULL) || (hdl_p->dev == dev))) {
metal_log(METAL_LOG_ERROR,
"%s: irq %d already registered."
"Will not register again.\n",
__func__, irq);
metal_mutex_release(&_irqs.irq_lock);
return -EINVAL;
}
}
/* irq found and drv_id not used, get out of metal_list_for_each */
break;
}
}
/* Either need to add handler to an existing list or to a new one */
hdl_p = metal_allocate_memory(sizeof(struct metal_irq_hddesc));
if (hdl_p == NULL) {
metal_log(METAL_LOG_ERROR,
"%s: irq %d cannot allocate mem for drv_id %d.\n",
__func__, irq, drv_id);
metal_mutex_release(&_irqs.irq_lock);
return -ENOMEM;
}
hdl_p->hd = hd;
hdl_p->drv_id = drv_id;
hdl_p->dev = dev;
/* interrupt already registered, add handler to existing list*/
if ((irq_p != NULL) && (irq_p->irq == irq)) {
irq_flags_save = metal_irq_save_disable();
metal_list_add_tail(&irq_p->hdls, &hdl_p->node);
metal_irq_restore_enable(irq_flags_save);
metal_log(METAL_LOG_DEBUG, "%s: success, irq %d add drv_id %p \n",
__func__, irq, drv_id);
metal_mutex_release(&_irqs.irq_lock);
return 0;
}
/* interrupt was not already registered, add */
irq_p = metal_allocate_memory(sizeof(struct metal_irq_desc));
if (irq_p == NULL) {
metal_log(METAL_LOG_ERROR, "%s: irq %d cannot allocate mem.\n",
__func__, irq);
metal_mutex_release(&_irqs.irq_lock);
return -ENOMEM;
}
irq_p->irq = irq;
metal_list_init(&irq_p->hdls);
metal_list_add_tail(&irq_p->hdls, &hdl_p->node);
irq_flags_save = metal_irq_save_disable();
metal_list_add_tail(&_irqs.irqs, &irq_p->node);
metal_irq_restore_enable(irq_flags_save);
metal_log(METAL_LOG_DEBUG, "%s: success, added irq %d\n", __func__, irq);
metal_mutex_release(&_irqs.irq_lock);
return 0;
}
/* helper function for metal_irq_unregister() */
static void metal_irq_delete_node(struct metal_list *node, void *p_to_free)
{
unsigned int irq_flags_save;
irq_flags_save=metal_irq_save_disable();
metal_list_del(node);
metal_irq_restore_enable(irq_flags_save);
metal_free_memory(p_to_free);
}
int metal_irq_unregister(int irq,
metal_irq_handler hd,
struct metal_device *dev,
void *drv_id)
{
struct metal_irq_desc *irq_p;
struct metal_list *node;
if (irq < 0) {
metal_log(METAL_LOG_ERROR, "%s: irq %d need to be a positive number\n",
__func__, irq);
return -EINVAL;
}
/* Search for irq in list */
metal_mutex_acquire(&_irqs.irq_lock);
metal_list_for_each(&_irqs.irqs, node) {
irq_p = metal_container_of(node, struct metal_irq_desc, node);
if (irq_p->irq == irq) {
struct metal_list *h_node, *h_prenode;
struct metal_irq_hddesc *hdl_p;
unsigned int delete_count = 0;
metal_log(METAL_LOG_DEBUG, "%s: found irq %d\n",
__func__, irq);
/* Search through handlers */
metal_list_for_each(&irq_p->hdls, h_node) {
hdl_p = metal_container_of(h_node,
struct metal_irq_hddesc,
node);
if (((hd == NULL) || (hdl_p->hd == hd)) &&
((drv_id == NULL) || (hdl_p->drv_id == drv_id)) &&
((dev == NULL) || (hdl_p->dev == dev))) {
metal_log(METAL_LOG_DEBUG,
"%s: unregister hd=%p drv_id=%p dev=%p\n",
__func__, hdl_p->hd, hdl_p->drv_id, hdl_p->dev);
h_prenode = h_node->prev;
metal_irq_delete_node(h_node, hdl_p);
h_node = h_prenode;
delete_count++;
}
}
/* we did not find any handler to delete */
if (!delete_count) {
metal_log(METAL_LOG_DEBUG, "%s: No matching entry\n",
__func__);
metal_mutex_release(&_irqs.irq_lock);
return -ENOENT;
}
/* if interrupt handlers list is empty, unregister interrupt */
if (metal_list_is_empty(&irq_p->hdls)) {
metal_log(METAL_LOG_DEBUG,
"%s: handlers list empty, unregister interrupt\n",
__func__);
metal_irq_delete_node(node, irq_p);
}
metal_log(METAL_LOG_DEBUG, "%s: success\n", __func__);
metal_mutex_release(&_irqs.irq_lock);
return 0;
}
}
metal_log(METAL_LOG_DEBUG, "%s: No matching IRQ entry\n", __func__);
metal_mutex_release(&_irqs.irq_lock);
return -ENOENT;
}
unsigned int metal_irq_save_disable(void)
{
return irq_lock();
}
void metal_irq_restore_enable(unsigned int flags)
{
irq_unlock(flags);
}
void metal_irq_enable(unsigned int vector)
{
irq_enable(vector);
}
void metal_irq_disable(unsigned int vector)
{
irq_disable(vector);
}
/**
* @brief default handler
*/
void metal_irq_isr(unsigned int vector)
{
struct metal_list *node;
struct metal_irq_desc *irq_p;
metal_list_for_each(&_irqs.irqs, node) {
irq_p = metal_container_of(node, struct metal_irq_desc, node);
if ((unsigned int)irq_p->irq == vector) {
struct metal_list *h_node;
struct metal_irq_hddesc *hdl_p;
metal_list_for_each(&irq_p->hdls, h_node) {
hdl_p = metal_container_of(h_node,
struct metal_irq_hddesc,
node);
(hdl_p->hd)(vector, hdl_p->drv_id);
}
}
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/irq.c
* @brief Zephyr libmetal irq definitions.
*/
#ifndef __METAL_IRQ__H__
#error "Include metal/irq.h instead of metal/zephyr/irq.h"
#endif
#ifndef __METAL_ZEPHYR_IRQ__H__
#define __METAL_ZEPHYR_IRQ__H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief default interrupt handler
* @param[in] vector interrupt vector
*/
void metal_irq_isr(unsigned int vector);
#ifdef __cplusplus
}
#endif
#endif /* __METAL_ZEPHYR_IRQ__H__ */

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2018, Xilinx Inc. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/log.c
* @brief Zephyr libmetal log handler.
*/
#include <stdarg.h>
#include <metal/log.h>
#include <zephyr.h>
static const char *level_strs[] = {
"metal: emergency: ",
"metal: alert: ",
"metal: critical: ",
"metal: error: ",
"metal: warning: ",
"metal: notice: ",
"metal: info: ",
"metal: debug: ",
};
void metal_zephyr_log_handler(enum metal_log_level level,
const char *format, ...)
{
va_list args;
if (level <= METAL_LOG_EMERGENCY || level > METAL_LOG_DEBUG)
level = METAL_LOG_EMERGENCY;
printk("%s", level_strs[level]);
va_start(args, format);
vprintk(format, args);
va_end(args);
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright (c) 2018, Xilinx Inc. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/log.h
* @brief Zephyr libmetal log handler definition.
*/
#ifndef __METAL_METAL_LOG__H__
#error "Include metal/log.h instead of metal/zephyr/log.h"
#endif
#ifndef __METAL_ZEPHYR_LOG__H__
#define __METAL_ZEPHYR_LOG__H__
#ifdef __cplusplus
extern "C" {
#endif
void metal_zephyr_log_handler(enum metal_log_level level,
const char *format, ...);
#ifdef __cplusplus
}
#endif
#endif /* __METAL_ZEPHYR_LOG__H__ */

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/mutex.h
* @brief Zephyr mutex primitives for libmetal.
*/
#ifndef __METAL_MUTEX__H__
#error "Include metal/mutex.h instead of metal/zephyr/mutex.h"
#endif
#ifndef __METAL_ZEPHYR_MUTEX__H__
#define __METAL_ZEPHYR_MUTEX__H__
#include <metal/atomic.h>
#include <kernel.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct k_sem metal_mutex_t;
/*
* METAL_MUTEX_INIT - used for initializing an mutex elmenet in a static struct
* or global
*/
#define METAL_MUTEX_INIT(m) _K_SEM_INITIALIZER(m, 1, 1)
/*
* METAL_MUTEX_DEFINE - used for defining and initializing a global or
* static singleton mutex
*/
#define METAL_MUTEX_DEFINE(m) K_SEM_DEFINE(m, 1, 1)
static inline void __metal_mutex_init(metal_mutex_t *m)
{
k_sem_init(m, 1, 1);
}
static inline void __metal_mutex_deinit(metal_mutex_t *m)
{
(void)m;
}
static inline int __metal_mutex_try_acquire(metal_mutex_t *m)
{
int key = irq_lock(), ret = 1;
if (m->count) {
m->count = 0;
ret = 0;
}
irq_unlock(key);
return ret;
}
static inline int __metal_mutex_is_acquired(metal_mutex_t *m)
{
int key = irq_lock(), ret;
ret = m->count;
irq_unlock(key);
return ret;
}
static inline void __metal_mutex_acquire(metal_mutex_t *m)
{
k_sem_take(m, K_FOREVER);
}
static inline void __metal_mutex_release(metal_mutex_t *m)
{
k_sem_give(m);
}
#ifdef __cplusplus
}
#endif
#endif /* __METAL_ZEPHYR_MUTEX__H__ */

View File

@@ -0,0 +1,18 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/shmem.c
* @brief Zephyr libmetal shared memory handling.
*/
#include <metal/shmem.h>
int metal_shmem_open(const char *name, size_t size,
struct metal_io_region **io)
{
return metal_shmem_open_generic(name, size, io);
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/sleep.h
* @brief Zephyr sleep primitives for libmetal.
*/
#ifndef __METAL_SLEEP__H__
#error "Include metal/sleep.h instead of metal/zephyr/sleep.h"
#endif
#ifndef __METAL_ZEPHYR_SLEEP__H__
#define __METAL_ZEPHYR_SLEEP__H__
#include <metal/utilities.h>
#ifdef __cplusplus
extern "C" {
#endif
static inline int __metal_sleep_usec(unsigned int usec)
{
metal_unused(usec);
/* Fix me */
return 0;
}
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* __METAL_ZEPHYR_SLEEP__H__ */

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/sys.h
* @brief Zephyr system primitives for libmetal.
*/
#ifndef __METAL_SYS__H__
#error "Include metal/sys.h instead of metal/zephyr/sys.h"
#endif
#ifndef __METAL_ZEPHYR_SYS__H__
#define __METAL_ZEPHYR_SYS__H__
#include <stdlib.h>
#include "./@PROJECT_MACHINE@/sys.h"
#ifdef __cplusplus
extern "C" {
#endif
#define METAL_INIT_DEFAULTS \
{ \
.log_handler = metal_zephyr_log_handler, \
.log_level = METAL_LOG_INFO, \
}
#ifndef METAL_MAX_DEVICE_REGIONS
#define METAL_MAX_DEVICE_REGIONS 1
#endif
/** Structure of zephyr libmetal runtime state. */
struct metal_state {
/** Common (system independent) data. */
struct metal_common_state common;
};
#ifdef __cplusplus
}
#endif
#endif /* __METAL_ZEPHYR_SYS__H__ */

View File

@@ -0,0 +1,21 @@
/*
* Copyright (c) 2017, Linaro Limited. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*
* @file zephyr/time.c
* @brief Zephyr libmetal time handling.
*/
#include <metal/time.h>
#include <sys_clock.h>
extern volatile u64_t _sys_clock_tick_count;
unsigned long long metal_get_timestamp(void)
{
return (unsigned long long)_sys_clock_tick_count;
}