📄 pg_int.c
字号:
///////////////////////////////////////////////////////////////
//
//
// PGOS : A Portable,Configable Embedded System Kernel
//
// Sunplus unSP(TM) Specific Code
//
// This is an open source project under GPL lincence
//
// Version 0.9.0 ---- Development Snopshot
//
// File name : pg_int.c : Interrupt functions implemention
// History :
//
// 2005-07-24 First build by X.K. @ PGOS Team
// 2005-08-09 Update for PG_PRI_SCH support
// 2005-02-21 Rewrite for Sunplus unSP(TM)
//
/////////////////////////////////////////////////////////////////
#include "stdio.h"
#include "pgos.h"
void IRQ6() __attribute__((ISR)) ;
extern BYTE task_cur_id ;
extern BYTE task_cur_prio ;
extern BYTE task_nxt_id ;
extern BYTE task_nxt_prio ;
extern BYTE task_swflag ;
extern pgTASKLIST* task_list_head ;
extern pgTASK* task_cur ;
extern pgTASK* task_nxt ;
extern pgTASK* task_prv ;
extern BYTE tasknum ;
extern DWORD maxtime ;
pgTASK* task ;
pgTASKLIST* tklist ;
BYTE intn ;
#if PG_STAT_SUPPORT == 1
extern DWORD task_sw ;
extern DWORD idle_run_sec ;
extern DWORD idle_time ;
#endif
PGOS_STATUS pgos_int_init()
{
// Note : You can edit these codes.
// pgos_int_rate( PG_RATE ) ;
//*( WORD * )( 0x7010 ) = 0x0001 ;
asm("
r1 = 0x0001
[0x7010] = r1
int irq
") ;
return PGOS_SUCCESS ;
}
VOID pgos_int_connect( BYTE intnum, VOID ( *int_handler )() )
{
// setvect( intnum,int_handler ) ;
// _dos_setvect( intnum, int_handler ) ;
return ;
}
VOID pgos_timer_handler()
{
*( WORD * )( 0x7011 ) = 0x0001 ;
pgos_int_disable() ;
#if PG_TIME_SUPPORT == 1
intn ++ ;
if( intn >= PG_RATE )
{
intn = 0 ;
#if PG_STAT_SUPPORT == 1
idle_run_sec = idle_time ;
idle_time = 0 ;
#endif // end if STAT Support
pgos_tim_process( ) ;
}
#endif // end of TIME Support
#if PG_SCH_ROUNDROBIN == 1
if( task_cur->state == PG_RUN && task_cur->id != PRIO_LOWEST )
{
task_cur->runtime ++ ;
if( task_cur->runtime >= maxtime )
{
task_cur->runtime = 0 ;
task_cur->state = PG_SLEEP ;
task_cur->delay = 10 ;
}
}
task_nxt_prio = 0 ;
#else
task_nxt_prio = task_cur_prio ;
#endif // end of PG_SCH_ROUNDROBIN
#if PG_PRI_SCH == 1
task_nxt_id = task_cur_id ;
tklist = task_list_head ;
for( ; tklist ; tklist = tklist->next )
{
task = tklist->pTask ;
if( task->state == PG_SLEEP )
{
task->delay-- ;
if( task->delay == 0 )
{
task->state = PG_READY ;
}
}
if( task->state == PG_READY )
{
if( task->prio > task_nxt_prio )
{
task_nxt_prio = task->prio ;
task_nxt_id = task->id ;
task_nxt = task ;
}
}
}
#endif // end of PG_PRI_SCH
if( task_nxt_id != task_cur_id )
{
task_prv = task_cur ;
task_cur = task_nxt ;
task_cur_id = task_nxt_id ;
task_cur_prio = task_nxt_prio ;
task_prv->state = PG_READY ;
task_nxt->state = PG_RUN ;
#if PG_STAT_SUPPORT == 1
task_sw++ ;
#endif
#if PG_DRV_SUPPORT == 1
pgos_call_drv( SYS_INT, NULL ) ;
#endif
// Now we will switch to new task ...
asm("
sp += 0x0A
r2 = [_task_prv]
[r2] = sp
r1 = [_task_nxt]
r1 = [r1]
sp = r1
pop bp,r1 from [sp]
reti
") ;
}
}
void IRQ6()
{
if( ( *( WORD * )( 0x7010 ) ) == 0x0001 )
{
pgos_timer_handler() ;
}
*( WORD * )( 0x7011 ) = 0x0001 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -