📄 leonbare_kernel.h
字号:
#ifndef __LEONBARE_KERNEL_H__#define __LEONBARE_KERNEL_H__/* LEON2/3 LIBIO low-level routines Written by Jiri Gaisler. Copyright (C) 2004 Gaisler Research AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include <asm-leon/contextswitch.h>#include <asm-leon/leonbare_debug.h>#include <sys/fsu_pthread_queue.h>#include <reent.h>#define LEONBARE_RUNQ_NR 2#ifndef __ASSEMBLER__#ifndef NULL#define NULL ((void *)0)#endif#define MACRO_BEGIN do {#define MACRO_END } while (0)typedef TAILQ_HEAD(leonbare_thread_queue,leonbare_thread) *leonbare_thread_queue_t;typedef struct leonbare_thread { threadctx_t th_ctx __attribute__((aligned(8))); unsigned int th_flags; int th_account; unsigned int th_runq_idx; unsigned int th_pri_idx; char *th_name; int th_result; int (*th_func)(void *); void *th_arg; char *th_stack_base; unsigned int th_stack_size; struct _reent th_reent; /* reentrant structure for newlib */ struct _reent *th_reentp; /* pointer to eather pt_reent or global reent */ TAILQ_ENTRY(leonbare_thread) th_runq[LEONBARE_RUNQ_NR]; TAILQ_ENTRY(leonbare_thread) th_allq;} * leonbare_thread_t __attribute__((aligned(8)));#define LEONBARE_TH_NAME(c) (c->th_name)#define LEONBARE_TH_NAME_DBG(c) (LEONBARE_TH_NAME(c) ? LEONBARE_TH_NAME(c) : "<unknown>")#define LEONBARE_REENT_SET(p) ((_impure_ptr=(p)->th_reentp)==_impure_ptr)extern struct leonbare_kernel leonbare_kernel;#define KERNEL_GLOBAL leonbare_kerneltypedef struct leonbare_kernel { leonbare_thread_t kr_cur,kr_next; struct leonbare_thread_queue kr_runq[LEONBARE_RUNQ_NR]; struct leonbare_thread_queue kr_allq; int kr_is_inkernel, kr_need_schedule;} * leonbare_kernel_t __attribute__((aligned(8)));#define LEONBARE_KR_CURRENT (KERNEL_GLOBAL.kr_cur)#define LEONBARE_KR_RUNQ(i) (&(KERNEL_GLOBAL.kr_runq[i]))#define LEONBARE_KR_ALLQ (&(KERNEL_GLOBAL.kr_allq))#define LEONBARE_KR_NEXT (KERNEL_GLOBAL.kr_next)#define LEONBARE_KR_IS_IN_KERNEL (KERNEL_GLOBAL.kr_is_inkernel)#define LEONBARE_KR_NEED_SCHEDULE (KERNEL_GLOBAL.kr_need_schedule)#define LEONBARE_STACKALIGN(sp) ((((unsigned int)sp) + 7) & ~7)/* context switching macros, implemented via setjmp/longjmp plus saving errno */#define SAVE_CONTEXT(t) ( thread_setjmp((t)->th_ctx, 0) )#define RESTORE_CONTEXT(t) thread_longjmp((t)->th_ctx, 1)#define KERNEL_SCHEDULE \ MACRO_BEGIN \ LEONBARE_KR_IS_IN_KERNEL = 0; \ if (LEONBARE_KR_NEED_SCHEDULE) { \ LEONBARE_KR_IS_IN_KERNEL = 1; \ if (leonbare_sched_tick() && \ !SAVE_CONTEXT(LEONBARE_KR_CURRENT)) \ leonbare_sched(); \ LEONBARE_KR_NEED_SCHEDULE = 0; \ LEONBARE_KR_IS_IN_KERNEL = 0; \ } \ MACRO_END#define KERNEL_ENTER LEONBARE_KR_IS_IN_KERNEL=1;#define KERNEL_EXIT KERNEL_SCHEDULE extern __inline__ leonbare_thread_t leonbare_sched_next() { int i = 0; for (i = 0;i< LEONBARE_RUNQ_NR;i++){ leonbare_thread_t c; if (!TAILQ_EMPTY(LEONBARE_KR_RUNQ(i))) { return TAILQ_FIRST(LEONBARE_KR_RUNQ(i)); } } return 0;} int leonbare_thread_init();int leonbare_thread_create(leonbare_thread_t thread, char *stack, int stacksize);leonbare_thread_t leonbare_sched_paytime();void leonbare_sched_insert(leonbare_thread_t thread);#endif /* __ASSEMBLER__ */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -