📄 avt.h
字号:
/*---------------------------------------------------------------------------*/
/* */
/* avt.h */
/* */
/* Standard types, some useful coding macros and API declares. */
/* */
/*---------------------------------------------------------------------------*/
/* */
/* Copyright (C) 2006 YuKanghua, All rights reserved. */
/* */
/*---------------------------------------------------------------------------*/
#ifndef __AVT_H__
#define __AVT_H__
/*
* useful coding macros
*/
#ifndef NULL
#define NULL 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/*
* system call without wait
*/
#define NOWAIT 0
/*
* system call waiting forever
*/
#define FOREVER -1
/*
* system call flags
*/
#define SM_FIFO 0
#define SM_PRIO 1
#define EV_FIFO 0
#define EV_PRIO 1
#define MQ_FIFO 0
#define MQ_PRIO 1
#define RW_FIFO 0
#define RW_PRIO 1
#define MX_FIFO 0
#define MX_PRIO 1
#define RW_READER 0
#define RW_WRITER 1
#define EV_OR 0x0
#define EV_AND 0x1
#define EV_XOR 0x2
#define EV_ANY 0x3
#define EV_MODE_MASK 0x3
#define EV_CLR 0x4
#define EV_EQ 0x8
/*
* New mutex structures
*/
enum pthread_mutextype {
MUTEX_TYPE_STATIC_FAST,
MUTEX_TYPE_FAST,
MUTEX_TYPE_COUNTING_FAST, /* Recursive */
MUTEX_TYPE_METERED,
MUTEX_TYPE_DEBUG, /* This will have lots of options */
MUTEX_TYPE_MAX
};
#define PTHREAD_MUTEXTYPE_FAST 0x01
#define PTHREAD_MUTEXTYPE_DEBUG 0x04
#define PTHREAD_MUTEXTYPE_RECURSIVE 0x02
/*
* Error codes
*/
#define ENOERR 0 /* No error */
#define EPERM 1 /* Not permitted */
#define ENOENT 2 /* No such entity */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Operation interrupted */
#define EIO 5 /* I/O error */
#define EBADF 9 /* Bad file handle */
#define EAGAIN 11 /* Try again later */
#define EWOULDBLOCK EAGAIN
#define ENOMEM 12 /* Out of memory */
#define EBUSY 16 /* Resource busy */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* Too many open files in system */
#define EMFILE 24 /* Too many open files */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EDOM 33 /* Argument to math function outside valid */
/* domain */
#define ERANGE 34 /* Math result cannot be represented */
#define EDEADLK 35 /* Resource deadlock would occur */
#define EDEADLOCK EDEADLK
#define ENOSYS 38 /* Function not implemented */
#define ENAMETOOLONG 60 /* File name too long */
#define ENOTSUP 95 /* Not supported error */
#define ETMOUT 100 /* operation timeout */
#define EEOF 200 /* End of file reached */
#define ENOSUPP 201 /* Operation not supported */
#define EDEVNOSUPP 202 /* Device does not support this operation */
/* Additional errors used by networking */
#define ENXIO 300 /* Device not configured */
#define EACCES 301 /* Permission denied */
#define EEXIST 302 /* File exists */
#define ENOTTY 303 /* Inappropriate ioctl for device */
/*
* Standard types
*/
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
struct datatime {
ushort year;
ushort ms;
uchar month;
uchar day;
uchar hour;
uchar minute;
uchar second;
};
/*
* API prototypes
*/
#ifdef __cplusplus
extern "C" {
#endif
void
avtInit(void *free_memory_start, void *memory_end);
/*
* avt startup
*/
void
avt_start(
void /*void*/
);
/*
* Task control APIs
*/
int
t_create(
const char *name,
int priority,
void (*entry)(void *),
void *argument, /* optional */
uint stack_size, /* optional */
int auto_start,
uint *tid
);
int
t_delete(
uint task_id /* optional */
);
int
t_kill(
uint task_id, /* optional */
int exit_code
);
int
t_suspend(
uint task_id /* optional */
);
int
t_resume(
uint task_id /* optional */
);
int
t_yield(
void /*void*/
);
int
t_get_priority(
uint task_id, /* optional */
int *priority
);
int
t_set_priority(
uint task_id, /* optional */
int new_priority);
int
tls_get(
uint task_id, /* optional */
int key,
ulong *keyval
);
int
tls_set(
uint task_id, /* optional */
int key,
ulong keyval
);
/*
* semaphore control
*/
int
sm_create(
const char *name,
int init,
uint flags,
uint *smid
);
int
sm_delete(
uint sm
);
int
sm_p(
uint sm,
uint wait_opt
);
int
sm_tryp(
uint sm
);
int
sm_v(
uint sm
);
int
ev_create(
const char *name,
uint init_bits,
uint flags,
uint *evid
);
int
ev_delete(
uint evid
);
int
ev_wait(
uint evid,
uint mask,
uint mode,
uint bits,
uint wait_opt,
uint *events
);
int
ev_receive(
uint evid,
uint wait_opt,
uint *events
);
int
ev_notify(
uint evid,
uint bits
);
int
ev_broadcast(
uint evid,
uint bits
);
int
mq_create(
const char *name,
uint msgmax,
uint flags,
uint *mqid
);
int
mq_delete(
uint mqid
);
int
mq_send(
uint mqid,
const void *data,
uint wait_opt
);
int
mq_broadcast(
uint mqid,
const void *data
);
int
mq_receive(
uint mqid,
void *data,
uint wait_opt
);
/*
* read/write lock APIs
*/
int
rw_create(
const char *name,
int init_read,
int init_write,
uint flags,
uint *rid
);
int
rw_delete(
uint rid
);
int
rw_enter(
uint rid,
int mode /* 0 for READER, 1 for WRITER */
);
int
rw_tryenter(
uint rid,
int mode
);
int
rw_exit(
uint rid
);
int
mx_create(
const char *name,
uint type,
uint flags,
uint *mxid
);
int
mx_delete(
uint mxid
);
int
mx_trylock(
uint mxid
);
int
mx_lock(
uint mxid
);
int
mx_unlock(
uint mxid
);
/*
* memory management APIs
*/
int
pt_create(
const char *name,
const void *addr,
uint length,
uint unit_size,
uint *pid
);
int
pt_delete(
uint pid
);
int
pt_get(
uint pid,
void **pptr
);
int
pt_put(
uint pid,
const void *ptr
);
int
rn_create(
const char *name,
const char *addr,
uint length,
uint *rid
);
int
rn_delete(
uint rid
);
int
rn_get(
uint rid,
uint size,
void **pptr
);
int
rn_put(
uint rid,
const void *ptr
);
/*
* time control
*/
int
tm_create(
const char *name,
void (*handler)(void *),
uint flags,
uint *tid
);
int
tm_delete(
uint tid
);
int
tm_start(
uint tid,
uint ticks,
void *argument
);
int
tm_cancel(
uint tid
);
void
tm_delay(
uint ticks
);
void
tm_set(
ulong time
);
ulong
tm_get(
void
);
void
tm_datetime(
struct datatime *retval
);
int
wtd_create(
const char *name,
void (*handler)(void *),
void *argument,
uint flags,
uint *wid
);
int
wtd_delete(
uint wid
);
int
wtd_start(
uint wid,
uint ticks
);
int
wtd_adjust(
uint wid,
int ticks
);
int
wtd_kill(
uint wid
);
#if 0
#define ASSERT(e) do { if(!(e)) __assert(__FILE__, __LINE__, #e); } while(0)
#define CHECK_PTR(ptr) if((uint)ptr < 0x0C084000 || (uint)ptr >= 0x0C800000) { \
interrupts_disable(); \
DbgOut("%s:%u %s(%08x) invalid!\n", __FILE__, __LINE__, #ptr, ptr); \
while(1); \
}
void DbgOut(const char *fmt, ...);
void __assert(const char *f, int l, const char *expr);
void chkstk(void);
#else
#define ASSERT(e) (void)0
#define CHECK_PTR(p)
#define chkstk() (void)0
#endif
#ifdef __cplusplus
}
#endif
#endif /*__AVT_H__*/
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -