240 lines
5.7 KiB
C
240 lines
5.7 KiB
C
/* microkernel/base_api.h */
|
|
|
|
/*
|
|
* Copyright (c) 1997-2014 Wind River Systems, Inc.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions are met:
|
|
*
|
|
* 1) Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
*
|
|
* 2) Redistributions in binary form must reproduce the above copyright notice,
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
* and/or other materials provided with the distribution.
|
|
*
|
|
* 3) Neither the name of Wind River Systems nor the names of its contributors
|
|
* may be used to endorse or promote products derived from this software without
|
|
* specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#ifndef _BASE_API_H
|
|
#define _BASE_API_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef int32_t ktask_t;
|
|
typedef uint32_t ktask_group_t;
|
|
typedef uint32_t kmutex_t;
|
|
typedef uint32_t kmemory_map_t;
|
|
typedef uint32_t kfifo_t;
|
|
typedef uint32_t kmbox_t;
|
|
typedef uint32_t kpipe_t;
|
|
typedef int32_t ksem_t;
|
|
typedef ksem_t *ksemg_t;
|
|
typedef uint32_t ktimer_t;
|
|
typedef uint32_t kpriority_t;
|
|
typedef uint32_t kmemory_pool_t;
|
|
typedef unsigned int kevent_t;
|
|
typedef uint32_t kirq_t;
|
|
|
|
typedef int (*kevent_handler_t)(int event);
|
|
|
|
#define RC_OK 0
|
|
#define RC_FAIL 1
|
|
#define RC_TIME 2
|
|
#define RC_ALIGNMENT 3
|
|
#define RC_INCOMPLETE 4
|
|
|
|
/** for mail sender or receiver parameter */
|
|
#define ANYTASK (-1)
|
|
/** this value terminates a semaphore list */
|
|
#define ENDLIST (-1)
|
|
|
|
struct k_args;
|
|
|
|
struct k_block {
|
|
kmemory_pool_t poolid;
|
|
void *address_in_pool;
|
|
void *pointer_to_data;
|
|
uint32_t req_size;
|
|
};
|
|
|
|
struct k_msg {
|
|
/** Mailbox ID */
|
|
kmbox_t mailbox;
|
|
/** size of message (bytes) */
|
|
uint32_t size;
|
|
/** information field, free for user */
|
|
uint32_t info;
|
|
/** pointer to message data at sender side */
|
|
void *tx_data;
|
|
/** pointer to message data at receiver */
|
|
void *rx_data;
|
|
/** for async message posting */
|
|
struct k_block tx_block;
|
|
/** sending task */
|
|
ktask_t tx_task;
|
|
/** receiving task */
|
|
ktask_t rx_task;
|
|
/** internal use only */
|
|
union {
|
|
/** for 2-steps data transfer operation */
|
|
struct k_args *transfer;
|
|
/** semaphore to signal when asynchr. call */
|
|
ksem_t sema;
|
|
} extra;
|
|
};
|
|
|
|
/* Task control block */
|
|
|
|
struct k_proc {
|
|
struct k_proc *Forw;
|
|
struct k_proc *Back;
|
|
kpriority_t Prio;
|
|
ktask_t Ident;
|
|
uint32_t State;
|
|
uint32_t Group;
|
|
void (*fstart)(void);
|
|
char *workspace;
|
|
int worksize;
|
|
void (*fabort)(void);
|
|
struct k_args *Args;
|
|
};
|
|
|
|
struct _k_mbox_struct {
|
|
struct k_args *Writers;
|
|
struct k_args *Readers;
|
|
int Count;
|
|
};
|
|
|
|
struct _k_mutex_struct {
|
|
ktask_t Owner;
|
|
kpriority_t OwnerCurrentPrio;
|
|
kpriority_t OwnerOriginalPrio;
|
|
int Level;
|
|
struct k_args *Waiters;
|
|
int Count;
|
|
int Confl;
|
|
};
|
|
|
|
struct _k_sem_struct {
|
|
struct k_args *Waiters;
|
|
int Level;
|
|
int Count;
|
|
};
|
|
|
|
struct _k_fifo_struct {
|
|
int Nelms;
|
|
int Esize;
|
|
char *Base;
|
|
char *Endp;
|
|
char *Enqp;
|
|
char *Deqp;
|
|
struct k_args *Waiters;
|
|
int Nused;
|
|
int Hmark;
|
|
int Count;
|
|
};
|
|
|
|
/* Pipe-related structures */
|
|
|
|
#define MAXNBR_PIPE_MARKERS 10 /* 1==disable parallel transfers */
|
|
|
|
struct _k_pipe_marker {
|
|
unsigned char *pointer; /* NULL == non valid marker == free */
|
|
int size;
|
|
bool bXferBusy;
|
|
int Prev; /* -1 == no predecessor */
|
|
int Next; /* -1 == no successor */
|
|
};
|
|
|
|
struct _k_pipe_marker_list {
|
|
int iNbrMarkers; /* Only used if STORE_NBR_MARKERS is defined */
|
|
int iFirstMarker;
|
|
int iLastMarker;
|
|
int iAWAMarker; /* -1 means no AWAMarkers */
|
|
struct _k_pipe_marker aMarkers[MAXNBR_PIPE_MARKERS];
|
|
};
|
|
|
|
typedef enum {
|
|
BUFF_EMPTY, /* buffer is empty, disregarding the pending data Xfers
|
|
(reads) still finishing up */
|
|
BUFF_FULL, /* buffer is full, disregarding the pending data Xfers
|
|
(writes) still finishing up */
|
|
BUFF_OTHER
|
|
} _K_PIPE_BUFF_STATE;
|
|
|
|
struct _k_pipe_desc {
|
|
int iBuffSize;
|
|
unsigned char *pBegin;
|
|
unsigned char *pWrite;
|
|
unsigned char *pRead;
|
|
unsigned char *pWriteGuard; /* can be NULL --> invalid */
|
|
unsigned char *pReadGuard; /* can be NULL --> invalid */
|
|
int iFreeSpaceCont;
|
|
int iFreeSpaceAWA;
|
|
int iNbrPendingReads;
|
|
int iAvailDataCont;
|
|
int iAvailDataAWA; /* AWA == After Wrap Around */
|
|
int iNbrPendingWrites;
|
|
bool bWriteWA;
|
|
bool bReadWA;
|
|
_K_PIPE_BUFF_STATE BuffState;
|
|
struct _k_pipe_marker_list WriteMarkers;
|
|
struct _k_pipe_marker_list ReadMarkers;
|
|
unsigned char *pEnd;
|
|
unsigned char *pEndOrig;
|
|
};
|
|
|
|
struct _k_pipe_struct {
|
|
int iBufferSize; /* size in bytes, must be first for sysgen */
|
|
char *Buffer; /* pointer to statically allocated buffer */
|
|
struct k_args *Writers;
|
|
struct k_args *Readers;
|
|
struct _k_pipe_desc desc;
|
|
int Count;
|
|
};
|
|
|
|
typedef enum {
|
|
_0_TO_N = 0x00000001,
|
|
_1_TO_N = 0x00000002,
|
|
_ALL_N = 0x00000004
|
|
} K_PIPE_OPTION;
|
|
|
|
/* Memory map related structure */
|
|
|
|
struct _k_mem_map_struct {
|
|
int Nelms;
|
|
int Esize;
|
|
char *Base;
|
|
char *Free;
|
|
struct k_args *Waiters;
|
|
int Nused;
|
|
int Hmark;
|
|
int Count;
|
|
};
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _BASE_API_H */
|