初始化版本
This commit is contained in:
67
osal/include/osal.h
Normal file
67
osal/include/osal.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* OSAL (Operating System Abstraction Layer) Main Header
|
||||
*/
|
||||
|
||||
#ifndef __OSAL_H__
|
||||
#define __OSAL_H__
|
||||
|
||||
#include "osal_config.h"
|
||||
#include "osal_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* System Control */
|
||||
osal_err_t osal_init(void);
|
||||
osal_err_t osal_start(void);
|
||||
|
||||
/* Error Handling */
|
||||
osal_err_t osal_get_errno(int native_err);
|
||||
|
||||
/* System Service */
|
||||
osal_tick_t osal_tick_get(void);
|
||||
osal_err_t osal_delay(osal_tick_t tick);
|
||||
osal_err_t osal_mdelay(osal_int32_t ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Include Modules */
|
||||
|
||||
#if OSAL_USING_THREAD
|
||||
#include "osal_thread.h"
|
||||
#endif
|
||||
|
||||
#if OSAL_USING_SEMAPHORE
|
||||
#include "osal_sem.h"
|
||||
#endif
|
||||
|
||||
#if OSAL_USING_MUTEX
|
||||
#include "osal_mutex.h"
|
||||
#endif
|
||||
|
||||
#if OSAL_USING_EVENT
|
||||
#include "osal_event.h"
|
||||
#endif
|
||||
|
||||
#if OSAL_USING_MESSAGEQUEUE
|
||||
#include "osal_mq.h"
|
||||
#endif
|
||||
|
||||
#if OSAL_USING_TIMER
|
||||
#include "osal_timer.h"
|
||||
#endif
|
||||
|
||||
#if OSAL_USING_HEAP
|
||||
#include "osal_mem.h"
|
||||
#endif
|
||||
|
||||
#include "osal_irq.h"
|
||||
|
||||
#if OSAL_USING_LOG
|
||||
#include "osal_log.h"
|
||||
#endif
|
||||
|
||||
#endif /* __OSAL_H__ */
|
||||
34
osal/include/osal_config.h
Normal file
34
osal/include/osal_config.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef __OSAL_CONFIG_H__
|
||||
#define __OSAL_CONFIG_H__
|
||||
|
||||
/* Enable/Disable OSAL modules */
|
||||
#define OSAL_USING_THREAD 1
|
||||
#define OSAL_USING_SEMAPHORE 1
|
||||
#define OSAL_USING_MUTEX 1
|
||||
#define OSAL_USING_EVENT 1
|
||||
#define OSAL_USING_MESSAGEQUEUE 1
|
||||
#define OSAL_USING_TIMER 1
|
||||
#define OSAL_USING_HEAP 1
|
||||
#define OSAL_USING_LOG 1
|
||||
|
||||
/* Log Levels */
|
||||
#define OSAL_LOG_LEVEL_NONE 0
|
||||
#define OSAL_LOG_LEVEL_ERROR 1
|
||||
#define OSAL_LOG_LEVEL_WARN 2
|
||||
#define OSAL_LOG_LEVEL_INFO 3
|
||||
#define OSAL_LOG_LEVEL_DEBUG 4
|
||||
|
||||
/* Current Log Level */
|
||||
#ifndef OSAL_LOG_LEVEL
|
||||
#define OSAL_LOG_LEVEL OSAL_LOG_LEVEL_DEBUG
|
||||
#endif
|
||||
|
||||
/* Log Buffer Size */
|
||||
#ifndef OSAL_LOG_BUF_SIZE
|
||||
#define OSAL_LOG_BUF_SIZE 256
|
||||
#endif
|
||||
|
||||
/* Assert */
|
||||
#define OSAL_USING_ASSERT 1
|
||||
|
||||
#endif /* __OSAL_CONFIG_H__ */
|
||||
80
osal/include/osal_def.h
Normal file
80
osal/include/osal_def.h
Normal file
@ -0,0 +1,80 @@
|
||||
#ifndef __OSAL_DEF_H__
|
||||
#define __OSAL_DEF_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Error codes */
|
||||
typedef int osal_err_t;
|
||||
|
||||
#define OSAL_OK 0 /* Operation successful */
|
||||
#define OSAL_ERROR (-1) /* Operation failed */
|
||||
#define OSAL_ETIMEOUT (-2) /* Timeout */
|
||||
#define OSAL_EFULL (-3) /* Resource full */
|
||||
#define OSAL_EEMPTY (-4) /* Resource empty */
|
||||
#define OSAL_ENOMEM (-5) /* No memory */
|
||||
#define OSAL_ENOSYS (-6) /* No system */
|
||||
#define OSAL_EBUSY (-7) /* Busy */
|
||||
#define OSAL_EIO (-8) /* IO error */
|
||||
#define OSAL_EINTR (-9) /* Interrupted */
|
||||
#define OSAL_INVAL (-10) /* Invalid argument */
|
||||
|
||||
/* Backward compatibility */
|
||||
#define OSAL_TIMEOUT OSAL_ETIMEOUT
|
||||
#define OSAL_NO_MEMORY OSAL_ENOMEM
|
||||
|
||||
/* Wait Forever */
|
||||
#define OSAL_WAIT_FOREVER ((osal_tick_t)-1)
|
||||
|
||||
/* Assert */
|
||||
#ifndef OSAL_ASSERT
|
||||
#ifdef OSAL_DEBUG
|
||||
#define OSAL_ASSERT(EX) \
|
||||
if (!(EX)) \
|
||||
{ \
|
||||
extern void osal_kprintf(const char *fmt, ...); \
|
||||
osal_kprintf("(%s) has assert failed at %s:%d.\n", #EX, __FUNCTION__, __LINE__); \
|
||||
while (1); \
|
||||
}
|
||||
#else
|
||||
#define OSAL_ASSERT(EX)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Priority */
|
||||
typedef unsigned char osal_priority_t;
|
||||
|
||||
#define OSAL_PRIORITY_LOWEST 255 /* Lowest priority */
|
||||
#define OSAL_PRIORITY_HIGHEST 0 /* Highest priority */
|
||||
|
||||
/* Basic Types */
|
||||
typedef unsigned int osal_tick_t;
|
||||
typedef unsigned int osal_size_t;
|
||||
typedef int osal_int32_t;
|
||||
typedef unsigned int osal_uint32_t;
|
||||
typedef unsigned char osal_uint8_t;
|
||||
typedef unsigned short osal_uint16_t;
|
||||
typedef void* osal_handle_t;
|
||||
|
||||
/* IPC Flags */
|
||||
#define OSAL_FLAG_FIFO 0x00 /* FIFO scheduling */
|
||||
#define OSAL_FLAG_PRIO 0x01 /* Priority scheduling */
|
||||
|
||||
/* Event Flags */
|
||||
#define OSAL_EVENT_AND 0x01 /* Logic AND */
|
||||
#define OSAL_EVENT_OR 0x02 /* Logic OR */
|
||||
#define OSAL_EVENT_CLEAR 0x04 /* Clear event */
|
||||
|
||||
/* Timer Flags */
|
||||
#define OSAL_TIMER_FLAG_ONE_SHOT 0x00 /* One shot */
|
||||
#define OSAL_TIMER_FLAG_PERIODIC 0x01 /* Periodic */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OSAL_DEF_H__ */
|
||||
26
osal/include/osal_event.h
Normal file
26
osal/include/osal_event.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef __OSAL_EVENT_H__
|
||||
#define __OSAL_EVENT_H__
|
||||
|
||||
#include "osal_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* osal_event_t;
|
||||
|
||||
/* Event API */
|
||||
osal_event_t osal_event_create(const char* name);
|
||||
osal_err_t osal_event_delete(osal_event_t event);
|
||||
osal_err_t osal_event_send(osal_event_t event, osal_uint32_t set);
|
||||
osal_err_t osal_event_recv(osal_event_t event,
|
||||
osal_uint32_t set,
|
||||
osal_uint8_t opt,
|
||||
osal_int32_t timeout,
|
||||
osal_uint32_t* recved);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OSAL_EVENT_H__ */
|
||||
19
osal/include/osal_irq.h
Normal file
19
osal/include/osal_irq.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef __OSAL_IRQ_H__
|
||||
#define __OSAL_IRQ_H__
|
||||
|
||||
#include "osal_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* IRQ/Critical Section API */
|
||||
void osal_enter_critical(void);
|
||||
void osal_exit_critical(void);
|
||||
osal_uint8_t osal_interrupt_get_nest(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OSAL_IRQ_H__ */
|
||||
44
osal/include/osal_log.h
Normal file
44
osal/include/osal_log.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef __OSAL_LOG_H__
|
||||
#define __OSAL_LOG_H__
|
||||
|
||||
#include "osal_def.h"
|
||||
#include "osal_config.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Log API */
|
||||
void osal_kprintf(const char *fmt, ...);
|
||||
|
||||
/* Log Macros */
|
||||
#if (OSAL_LOG_LEVEL >= OSAL_LOG_LEVEL_ERROR)
|
||||
#define osal_log_e(fmt, ...) osal_kprintf("[Error] " fmt "\n", ##__VA_ARGS__)
|
||||
#else
|
||||
#define osal_log_e(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if (OSAL_LOG_LEVEL >= OSAL_LOG_LEVEL_WARN)
|
||||
#define osal_log_w(fmt, ...) osal_kprintf("[Warning] " fmt "\n", ##__VA_ARGS__)
|
||||
#else
|
||||
#define osal_log_w(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if (OSAL_LOG_LEVEL >= OSAL_LOG_LEVEL_INFO)
|
||||
#define osal_log_i(fmt, ...) osal_kprintf("[Info] " fmt "\n", ##__VA_ARGS__)
|
||||
#else
|
||||
#define osal_log_i(fmt, ...)
|
||||
#endif
|
||||
|
||||
#if (OSAL_LOG_LEVEL >= OSAL_LOG_LEVEL_DEBUG)
|
||||
#define osal_log_d(fmt, ...) osal_kprintf("[Debug] " fmt "\n", ##__VA_ARGS__)
|
||||
#else
|
||||
#define osal_log_d(fmt, ...)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OSAL_LOG_H__ */
|
||||
23
osal/include/osal_mem.h
Normal file
23
osal/include/osal_mem.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef __OSAL_MEM_H__
|
||||
#define __OSAL_MEM_H__
|
||||
|
||||
#include "osal_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Memory API */
|
||||
void* osal_malloc(osal_size_t size);
|
||||
void* osal_calloc(osal_size_t count, osal_size_t size);
|
||||
void* osal_realloc(void* ptr, osal_size_t size);
|
||||
void osal_free(void* ptr);
|
||||
|
||||
void* osal_malloc_align(osal_size_t size, osal_size_t align);
|
||||
void osal_free_align(void* ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OSAL_MEM_H__ */
|
||||
25
osal/include/osal_mq.h
Normal file
25
osal/include/osal_mq.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __OSAL_MQ_H__
|
||||
#define __OSAL_MQ_H__
|
||||
|
||||
#include "osal_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* osal_mq_t;
|
||||
|
||||
/* Message Queue API */
|
||||
osal_mq_t osal_mq_create(const char* name,
|
||||
osal_size_t msg_size,
|
||||
osal_size_t max_msgs);
|
||||
osal_err_t osal_mq_delete(osal_mq_t mq);
|
||||
osal_err_t osal_mq_send(osal_mq_t mq, const void* buffer, osal_size_t size);
|
||||
osal_err_t osal_mq_urgent(osal_mq_t mq, const void* buffer, osal_size_t size);
|
||||
osal_err_t osal_mq_recv(osal_mq_t mq, void* buffer, osal_size_t size, osal_int32_t timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OSAL_MQ_H__ */
|
||||
23
osal/include/osal_mutex.h
Normal file
23
osal/include/osal_mutex.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef __OSAL_MUTEX_H__
|
||||
#define __OSAL_MUTEX_H__
|
||||
|
||||
#include "osal_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* osal_mutex_t;
|
||||
|
||||
/* Mutex API */
|
||||
osal_mutex_t osal_mutex_create(const char* name);
|
||||
osal_err_t osal_mutex_delete(osal_mutex_t mutex);
|
||||
osal_err_t osal_mutex_take(osal_mutex_t mutex, osal_int32_t timeout);
|
||||
osal_err_t osal_mutex_trytake(osal_mutex_t mutex);
|
||||
osal_err_t osal_mutex_release(osal_mutex_t mutex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OSAL_MUTEX_H__ */
|
||||
23
osal/include/osal_sem.h
Normal file
23
osal/include/osal_sem.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef __OSAL_SEM_H__
|
||||
#define __OSAL_SEM_H__
|
||||
|
||||
#include "osal_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* osal_sem_t;
|
||||
|
||||
/* Semaphore API */
|
||||
osal_sem_t osal_sem_create(const char* name, osal_uint32_t value);
|
||||
osal_err_t osal_sem_delete(osal_sem_t sem);
|
||||
osal_err_t osal_sem_take(osal_sem_t sem, osal_int32_t timeout);
|
||||
osal_err_t osal_sem_trytake(osal_sem_t sem);
|
||||
osal_err_t osal_sem_release(osal_sem_t sem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OSAL_SEM_H__ */
|
||||
34
osal/include/osal_thread.h
Normal file
34
osal/include/osal_thread.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef __OSAL_THREAD_H__
|
||||
#define __OSAL_THREAD_H__
|
||||
|
||||
#include "osal_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* osal_thread_t;
|
||||
typedef void (*osal_thread_entry)(void* parameter);
|
||||
|
||||
/* Thread API */
|
||||
osal_thread_t osal_thread_create(const char* name,
|
||||
osal_thread_entry entry,
|
||||
void* parameter,
|
||||
osal_size_t stack_size,
|
||||
osal_priority_t priority);
|
||||
|
||||
osal_err_t osal_thread_delete(osal_thread_t thread);
|
||||
osal_err_t osal_thread_start(osal_thread_t thread);
|
||||
osal_err_t osal_thread_suspend(osal_thread_t thread);
|
||||
osal_err_t osal_thread_resume(osal_thread_t thread);
|
||||
osal_err_t osal_thread_yield(void);
|
||||
osal_err_t osal_thread_control(osal_thread_t thread, int cmd, void* arg);
|
||||
osal_thread_t osal_thread_self(void);
|
||||
osal_err_t osal_thread_delay(osal_tick_t tick);
|
||||
osal_err_t osal_thread_mdelay(osal_int32_t ms);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OSAL_THREAD_H__ */
|
||||
27
osal/include/osal_timer.h
Normal file
27
osal/include/osal_timer.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef __OSAL_TIMER_H__
|
||||
#define __OSAL_TIMER_H__
|
||||
|
||||
#include "osal_def.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void* osal_timer_t;
|
||||
typedef void (*osal_timer_callback)(void* parameter);
|
||||
|
||||
/* Timer API */
|
||||
osal_timer_t osal_timer_create(const char* name,
|
||||
osal_timer_callback timeout,
|
||||
void* parameter,
|
||||
osal_tick_t time,
|
||||
osal_uint8_t flag);
|
||||
osal_err_t osal_timer_delete(osal_timer_t timer);
|
||||
osal_err_t osal_timer_start(osal_timer_t timer);
|
||||
osal_err_t osal_timer_stop(osal_timer_t timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __OSAL_TIMER_H__ */
|
||||
Reference in New Issue
Block a user