avtintl.h
来自「基于ARM7的直流电机的驱动,还有FLASH驱动,LCD驱动等」· C头文件 代码 · 共 299 行
H
299 行
/*---------------------------------------------------------------------------*/
/* */
/* avtintl.h */
/* */
/* Internal used types, some useful coding macros. */
/* */
/*---------------------------------------------------------------------------*/
/* */
/* Copyright (C) 2006 YuKanghua, All rights reserved. */
/* */
/*---------------------------------------------------------------------------*/
#ifndef __AVTINTL_H__
#define __AVTINTL_H__
#if defined(__arm) || defined(__arm__)
#include <avtarm.h>
#endif
#if defined(__i386) || defined(__i386__)
#include <avtx86.h>
#endif
#if defined(__ppc) || defined(__ppc__)
#include <avtppc.h>
#endif
#if defined(__m68k) || defined(__m68k__)
#include <avt68k.h>
#endif
#if defined(__mips) || defined(__mips__)
#include <avtmips.h>
#endif
#define DFLT_STACK 16384
#define CURTASK avt.run
#define TASK_SLEEP 1
#define TASK_TIMERSET 2
#define TASK_TIMEOUT 4
#define offsetof(T, M) ((uint) &((T *)0)->M)
#define container(P, T, M) ((T *)((char *)(P) - offsetof(T, M)))
#define qhead(q) (q)->q_forw
#define qtail(q) (q)->q_back
#define qprev(q) (q)->q_back
#define qnext(q) (q)->q_forw
#define qempty(q) (qhead(q) == (q))
#define initque(q) (q)->q_forw = (q)->q_back = (q)
#define TASK_MAGIC 0x5555aaaa
#define SM_MAGIC 0x6666bbbb
#define TM_MAGIC 0x7777cccc
#define WTD_MAGIC 0x8888dddd
struct qelem {
struct qelem *q_forw;
struct qelem *q_back;
};
typedef struct watchdog {
struct watchdog *next;
void (*handler)(void *);
void *argument;
int ticks;
uint flags;
uint magic;
char name[4];
} watchdog_t;
typedef struct timer {
struct qelem link;
struct timer *next;
void (*handler)(void *);
void *argument;
short ticks;
short ticks_bak;
uint magic;
char name[4];
} timer_t;
typedef struct task {
/*
* machine dependences
*/
uint *stack_pointer;
/*
* Priority of task 0(highest) - 31(lowest)
*/
uchar priority;
/*
* Task flags
*/
uchar flags_suspend;
uchar flags_timeout;
uchar flags_delay;
uchar flags_onwaitq;
uchar time_slice;
uchar slice_base;
uchar pad[1];
uint stktop;
uint stkbot;
/*
* Event control
*/
uint evmask;
uint evmode;
uint evbits;
uint *evptr;
uchar *mqptr;
struct qelem link;
watchdog_t watchdog;
uint magic;
char name[4];
ulong tls[1];
} task_t;
typedef struct sem {
struct qelem tq;
int count;
char name[4];
uint flags;
uint magic;
} sem_t;
typedef struct event {
struct qelem tq;
uint bits;
char name[4];
uint flags;
} event_t;
typedef struct mutex {
struct qelem tq;
task_t *owner;
uint nesting;
uint type;
char name[4];
uint flags;
} mutex_t;
struct mbox_msg {
struct mbox_msg *next;
uchar data[12];
};
typedef struct mbox {
struct qelem rtq;
struct qelem wtq;
char name[4];
uint flags;
struct mbox_msg *msg;
struct mbox_msg *free;
} mbox_t;
typedef struct rwlock {
struct qelem wtq;
struct qelem rtq;
int read_count;
short write_count;
ushort flags;
} rwlock_t;
typedef struct rnBlk {
uint previous;
uint this;
/*
* fields for free block
*/
struct rnBlk *prev;
struct rnBlk *next;
} RnBlk;
typedef struct range {
void *start;
void *end;
uint length;
uint total_blocks;
RnBlk header;
RnBlk *last;
char name[4];
} range_t;
typedef struct ptBlk {
struct ptBlk *next;
} PtBlk;
typedef struct partition {
void *start;
void *end;
uint length;
uint total_units;
uint free_units;
struct ptBlk *first_free;
char name[4];
} partition_t;
struct avtvar {
uint need_resched;
uint sched_count;
task_t *run;
uint hipri;
uint rdybits;
uint ticks;
uint todticks;
ulong systime;
struct datatime tod;
struct qelem timer_list;
timer_t *timer_pending;
watchdog_t *watchdog_list;
watchdog_t *watchdog_pending;
range_t rn0;
uint *rstk; /* root's stack */
uint task_count;
uint sem_count;
uint ev_count;
uint mq_count;
uint mx_count;
uint rn_count;
uint pt_count;
uint tm_count;
uint wtd_count;
uint rw_count;
uint root;
uint tmsvr;
uint idle;
ulong idle_count;
};
/*
* system global variable
*/
extern struct avtvar avt;
#ifdef __cplusplus
extern "C" {
#endif
#define bittst(v, b) ((v) & (1 << (b)))
#define bitclr(v, b) v &= ~(1 << (b))
#define bitset(v, b) v |= 1 << (b)
#define insque(elem, prev) \
do { \
struct qelem *next = (prev)->q_forw; \
(elem)->q_back = prev; \
(elem)->q_forw = next; \
(prev)->q_forw = elem; \
(next)->q_back = elem; \
} while(0)
/* Unlink ELEM from the doubly-linked list that it is in. */
#define remque(elem) \
do { \
struct qelem *next = (elem)->q_forw; \
struct qelem *prev = (elem)->q_back; \
next->q_back = prev; \
prev->q_forw = next; \
} while(0)
/*
* prototypes
*/
task_t *
tq_deq(struct qelem *tq, int priority);
int
tq_enq(struct qelem *tq, uint wait_opt);
void
sched(void);
void *
kmalloc(uint sz);
void
kfree(void *ptr);
void
namcpy(const char *src, char *dest);
void
msgcpy(const uchar *src, uchar *dest);
void
internal_fatal(const char *msg);
void
avtmmInit(void *free_memory_start, void *memory_end);
#ifdef __cplusplus
}
#endif
#endif /*__AVTINTL_H__*/
/* EOF */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?