📄 pg_os.c
字号:
///////////////////////////////////////////////////////////////
//
//
// PGOS : A Portable,Configable Embedded System Kernel
//
//
//
// This is an open source project under GPL lincence
//
// Version 0.9.0 ---- Development Snopshot
//
// File name : pg_os.c : Main PGOS kernel code
// History :
//
// 2005-07-24 First build by X.K. @ PGOS Team
//
/////////////////////////////////////////////////////////////////
#include "PGOS.H"
#include <stdlib.h>
#define IDLE_TASK_STK 128
BYTE pgos_running ;
REGSZ idle_stk[ IDLE_TASK_STK ] ;
BYTE idle_id ;
DWORD idle_time ;
BYTE schedular ;
extern BYTE task_cur_id ;
extern BYTE task_cur_prio ;
extern BYTE task_nxt_id ;
extern BYTE task_nxt_prio ;
#if PG_TIME_SUPPORT == 1
extern BYTE intn ;
#endif
#if PG_STAT_SUPPORT == 1
DWORD task_sw ;
DWORD idle_run_sec ;
#endif
extern pgTASK* task_nxt ;
extern pgTASK* task_cur ;
extern pgTASKLIST* task_list ;
extern pgTASKLIST* task_freelist ;
extern pgTASKLIST* task_list_head ;
VOID pgos_sys_init()
{
pgos_running = 0 ;
task_nxt_id = 0 ;
task_nxt_prio = PRIO_LOWEST ;
schedular = PG_SCH_UNLOCK ;
pgos_int_disable() ;
task_freelist = pgos_tk_inilist() ;
if( task_freelist == NULL )
{
// Error ! Memory is not enough
for( ;; ) ;
}
if( pgos_tk_initab() == PGOS_FAIL_MEM )
{
// Error ! Memory is not enough
for( ;; ) ;
}
if( pgos_tk_cre( pgos_sys_idle, PRIO_LOWEST, &idle_stk[ IDLE_TASK_STK - 1 ], &idle_id )
!=
PGOS_SUCCESS
)
{
// Error !
for( ;; ) ;
}
// pgos_int_connect( PGOS,pgos_tk_handler ) ;
#if PG_SEM_SUPPORT == 1
pgos_sem_init() ;
#endif // SEM_SUPPORT
#if PG_SCH_ROUNDROBIN == 1
pgos_tk_setruntime( MAX_DEF_TIME ) ;
#endif
#if PG_STAT_SUPPORT == 1
task_sw = 0;
idle_run_sec = 0 ;
#endif
#if PG_TIME_SUPPORT == 1
pgos_tim_clrtime( ) ;
intn = 0 ;
#endif
#if PG_TIMER_SUPPORT == 1
/**************************
/ These codes are not used
/ in the Sunplus Implentions
/**************************/
//pgos_old_timer = _dos_getvect( 0x08 ) ;
//pgos_int_connect( 0x08, pgos_timer_handler ) ;
//pgos_int_connect( 0x81,*pgos_old_timer ) ;
pgos_int_init( ) ;
#endif // TIMER_SUPPORT
#if PG_DRV_SUPPORT == 1
if( pgos_drv_initalize( ) != PGOS_SUCCESS )
printf( "Driver initlaize fail.\nNo driver support\n") ;
#endif
//////////////////////////////////////////
// Install PGOS IO Driver
//
// Bug Bug
//////////////////////////////////////////
//if( pgos_lowio_init( 1024 ) != PGOS_SUCCESS )
//for( ;; ) ;
}
VOID pgos_sys_begin()
{
pgTASKLIST* tlist = task_list_head ;
for( ; tlist ; tlist = tlist->next )
{
if( tlist->pTask->prio > task_nxt_prio )
{
task_nxt_id = tlist->pTask->id ;
task_nxt_prio = tlist->pTask->prio ;
}
}
pgos_running = 1 ;
task_cur_id = task_nxt_id ;
task_cur_prio = task_nxt_prio ;
task_nxt = pgos_tk_lookup( task_nxt_id ) ;
task_cur = task_nxt ;
task_nxt->state = PG_RUN ;
pgos_sys_runhigh() ;
// Will never runs here
for( ;; ) ;
}
VOID pgos_sys_reset()
{
// You can edit this function
}
VOID pgos_sys_idle()
{
for( ;; )
{
pgos_int_disable() ;
#if PG_WDG_CLEAN_KERNEL == 1
*( WORD* )( 0x7012 ) = 0x0001 ;
#endif
idle_time ++ ;
#if PG_DRV_SUPPORT == 1
pgos_call_drv( SYS_KERNEL, NULL ) ;
#endif
pgos_int_enable() ;
}
}
VOID pgos_sch_lock()
{
schedular = PG_SCH_LOCK ;
}
VOID pgos_sch_unlock()
{
schedular = PG_SCH_UNLOCK ;
}
WORD pgos_sys_getver()
{
// Version 0.0.9
return 0x0090 ;
}
#if PG_STAT_SUPPORT == 1
DWORD pgos_sys_swspeed( )
{
if( pgos_tim_getsec( ) == 0 ) return 0 ;
return task_sw / pgos_tim_getsec( ) ;
}
DWORD pgos_sys_idlenum()
{
DWORD ret ;
pgos_int_disable() ;
ret = idle_run_sec ;
pgos_int_enable() ;
return ret ;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -