Esempio n. 1
0
//initialise the counter and alarm table
EXPORT void knl_cntalm_init(void)
{
    INT i;
    CCB* ccb;
    ALMCB* almcb;
    for(i=0;i<cfgOSEK_COUNTER_NUM;i++)
    {
        ccb = &knl_ccb_table[i];
        QueInit(&ccb->almque); 
        #if(cfgAR_SCHEDTBL_NUM > 0)
        QueInit(&ccb->tblque);
        #endif
        ccb->curvalue = 0;
    }
    
#if(cfgOSEK_ALARM_NUM >0)
    for(i=0;i<cfgOSEK_ALARM_NUM;i++)
    {
        almcb = &knl_almcb_table[i];
        QueInit(&almcb->almque);
        //almcb->almid = i;
        if((knl_galm_table[i].mode & knl_app_mode) != 0) 
        {
            (void)SetRelAlarm(i,knl_galm_table[i].time,knl_galm_table[i].cycle); 
        }
    }
#endif

#if(cfgAR_SCHEDTBL_NUM > 0)
    knl_init_schedule_table();
#endif
}
Esempio n. 2
0
/*
 * initialize state machine
 */
EXPORT ER kpInitializeStateMachine( void )
{
	ER	err;
	int	i;

        /* key */
	QueInit(&StatMach.useq);
	QueInit(&StatMach.freq);
	for ( i = 0; i < MaxKey; ++i ) {
		err = initAlmStat(&StatMach.key[i].alm, KeyTmoutKind(i));
		if ( err != E_OK ) return err;
		QueInsert((QUEUE*)&StatMach.key[i], &StatMach.freq);
	}
	StatMach.spressMsg.cmd.read = 1;
	StatMach.spressMsg.cmd.cmd = PIC_SPRESS;
	StatMach.keyupMsg.cmd.read = 1;
	StatMach.keyupMsg.cmd.cmd = PIC_KEYUP;

        /* PD button */
	for ( i = 0; i < NumOfPdBut; ++i ) {
		StatMach.pdBut[i].state = BS_RELEASE;
		err = initAlmStat(&StatMach.pdBut[i].alm, PdButTmoutKind(i));
		if ( err != E_OK ) return err;
		StatMach.pdBut[i].button = PdButKind(i);
	}

	return E_OK;
}
Esempio n. 3
0
/*
 * IMACB Initialization 
 */
LOCAL void initIMACB( UINT attr )
{
	IMACB	*imacb = SelIMACB(attr);

	QueInit(&imacb->areaque);
	QueInit(&imacb->freeque);
	imacb->mematr = attr;
}
Esempio n. 4
0
U0 SysGlblsInit()
{
  I64 i,j;
  U8 *m;
  CRAXRBCRCXRDX ee;

  CPUId(0x1,&ee);
  sys_cache_line_width=ee.rbx.u8[1]*8;
  QueInit(&sys_pci_dev_root);
  sys_rnd_seed = 93186752^GetTimeStamp;
  sys_focus_task=Fs;
  QueInit(&sys_macro_root);
  sys_dft_iso_name="::/Temp/CDDVD.ISO";
  MemSet(mp_apic_ids,0,MP_MAX_PROCESSORS*sizeof(U8));

  LBts(&adam_task->task_flags,TASKf_INIT_EXT);//So dbgger doesn't call $LK,"TaskInitExt","MN:TaskInitExt"$().
  InDbg(ON);

  reverse_bits_table=CAlloc(256);
  for (i=0;i<256;i++)
    for (j=0;j<8;j++)
      if (Bt(&i,7-j))
	LBts(reverse_bits_table+i,j);
  set_bits_table=CAlloc(256);
  for (i=0;i<256;i++)
    for (j=0;j<8;j++)
      if (Bt(&i,j))
	set_bits_table[i]++;

  ext=CAlloc(EXT_TABLE_SIZE*sizeof(U8 *));
  fp_mgets=&SysMGetS;

  fp_ctrl_alt_let_cbs=CAlloc(26*sizeof(U8 *));
  ctrl_alt_let_descs=CAlloc(26*sizeof(U8 *));;
  ctrl_alt_let_in_irq_flags=0;

  psect_cache=CAlloc(PSECT_CACHE_SIZE*sizeof(CPSectCache));
  psect_cache_index=0;

  StrCpy(sys_temp_filename,"HOME/Temp.TXT.Z");
  MemSet(&sys_put_key_root,0,sizeof(CKeyDev));
  QueInit(&sys_put_key_root);
  KeyDevAdd(&AKDInputFilterPutKey,&AKDInputFilterPutS,0x40000000,FALSE);
  KeyDevAdd(&AKDRawDisplayPutKey,&AKDRawDisplayPutS,0x60000000,FALSE);
  #exe {
    if (*kernel_cfg->acct_name)
      StreamPrintF("sys_acct=StrNew(\"%C:/TempleOS/Accts/%s\");",kernel_cfg->sys_acct_drv,kernel_cfg->acct_name);
    else
      StreamPrintF("sys_acct=StrNew(\"%C:/TempleOS/Accts\");",kernel_cfg->sys_acct_drv);
    StreamPutS("#exe{OptOff(OPTf_WARN_PAREN);}");
    StreamPrintF("DskCacheInit(%s);",kernel_cfg->dsk_cache_size_exp);
    StreamPutS("#exe{OptOn(OPTf_WARN_PAREN);}");
  };
Esempio n. 5
0
/*
 * Initialization sequence of device input/output-related
 */
EXPORT ER initDevIO( void )
{
	INT	i;
	ER	ercd;

	i = _tk_get_cfn(SCTAG_TMAXOPNDEV, &MaxOpnDev, 1);
	if ( i < 1 ) {
		ercd = E_SYS;
		goto err_ret;
	}
	i = _tk_get_cfn(SCTAG_TMAXREQDEV, &MaxReqDev, 1);
	if ( i < 1 ) {
		ercd = E_SYS;
		goto err_ret;
	}

	/* Generate open management information table */
	OpnCBtbl = Imalloc((UINT)MaxOpnDev * sizeof(OpnCB));
	if ( OpnCBtbl == NULL ) {
		ercd = E_NOMEM;
		goto err_ret;
	}

	QueInit(&FreeOpnCB);
	for ( i = 0; i < MaxOpnDev; ++i ) {
		OpnCBtbl[i].resid = 0;
		QueInsert(&OpnCBtbl[i].q, &FreeOpnCB);
	}

	/* Generate request management information table */
	ReqCBtbl = Imalloc((UINT)MaxReqDev * sizeof(ReqCB));
	if ( ReqCBtbl == NULL ) {
		ercd = E_NOMEM;
		goto err_ret;
	}

	QueInit(&FreeReqCB);
	for ( i = 0; i < MaxReqDev; ++i ) {
		ReqCBtbl[i].opncb = NULL;
		QueInsert(&ReqCBtbl[i].q, &FreeReqCB);
	}

	return E_OK;

err_ret:
	DEBUG_PRINT(("initDevIO ercd = %d\n", ercd));
	return ercd;
}
Esempio n. 6
0
/*
 * Create rendezvous port
 */
SYSCALL ID _tk_cre_por( CONST T_CPOR *pk_cpor )
{
#if CHK_RSATR
	const ATR VALID_PORATR = {
		 TA_TPRI
		|TA_NODISWAI
#if USE_OBJECT_NAME
		|TA_DSNAME
#endif
	};
#endif
	PORCB	*porcb;
	ID	porid;
	ER	ercd;

	CHECK_RSATR(pk_cpor->poratr, VALID_PORATR);
	CHECK_PAR(pk_cpor->maxcmsz >= 0);
	CHECK_PAR(pk_cpor->maxrmsz >= 0);
	CHECK_INTSK();

	BEGIN_CRITICAL_SECTION;
	/* Get control block from FreeQue */
	porcb = (PORCB*)QueRemoveNext(&free_porcb);
	if ( porcb == NULL ) {
		ercd = E_LIMIT;
	} else {
		porid = ID_POR(porcb - porcb_table);

		/* Initialize control block */
		QueInit(&porcb->call_queue);
		porcb->porid = porid;
		porcb->exinf = pk_cpor->exinf;
		porcb->poratr = pk_cpor->poratr;
		QueInit(&porcb->accept_queue);
		porcb->maxcmsz = pk_cpor->maxcmsz;
		porcb->maxrmsz = pk_cpor->maxrmsz;
#if USE_OBJECT_NAME
		if ( (pk_cpor->poratr & TA_DSNAME) != 0 ) {
			strncpy((char*)porcb->name, (char*)pk_cpor->dsname,
				OBJECT_NAME_LENGTH);
		}
#endif
		ercd = porid;
	}
	END_CRITICAL_SECTION;

	return ercd;
}
Esempio n. 7
0
/*
 * Object lock
 *	Do not call from critical section
 */
EXPORT void knl_LockOBJ( OBJLOCK *loc )
{
	BOOL	klocked;

  retry:
	BEGIN_CRITICAL_SECTION;
	klocked = knl_ctxtsk->klocked;
	if ( !klocked ) {
		if ( loc->wtskq.next == NULL ) {
			/* Lock */
			QueInit(&loc->wtskq);

			knl_ctxtsk->klocked = klocked = TRUE;
			knl_ready_queue.klocktsk = knl_ctxtsk;
		} else {
			/* Ready for lock */
			knl_ready_queue_delete(&knl_ready_queue, knl_ctxtsk);
			knl_ctxtsk->klockwait = TRUE;
			QueInsert(&knl_ctxtsk->tskque, &loc->wtskq);

			knl_schedtsk = knl_ready_queue_top(&knl_ready_queue);
			knl_dispatch_request();
		}
	}
	END_CRITICAL_SECTION;
	/* Since wait could be freed without getting lock, 
	   need to re-try if lock is not got */
	if ( !klocked ) {
		goto retry;
	}
}
Esempio n. 8
0
/*
 * Get open management block
 */
LOCAL OpnCB* newOpnCB( DevCB *devcb, INT unitno, UINT omode, ResCB *rescb )
{
	OpnCB	*opncb;

	/* Get space in open management block */
	opncb = (OpnCB*)QueRemoveNext(&knl_FreeOpnCB);
	if ( opncb == NULL ) {
		return NULL; /* No space */
	}

	/* Register as open device */
	QueInsert(&opncb->q, &devcb->openq);
	QueInsert(&opncb->resq, &rescb->openq);

	opncb->devcb  = devcb;
	opncb->unitno = unitno;
	opncb->omode  = omode;
	QueInit(&opncb->requestq);
	opncb->waitone = 0;
	opncb->nwaireq = 0;
	opncb->abort_tskid = 0;

	opncb->resid  = 0; /* Indicate that open processing is not completed */

	return opncb;
}
Esempio n. 9
0
File: mutex.c Progetto: yuki74w/TRON
/*
 * Initialization of mutex control block
 */
EXPORT ER mutex_initialize(void)
{
	MTXCB	*mtxcb, *end;
	W	n;

	/* Get system information */
	n = _tk_get_cfn(SCTAG_TMAXMTXID, &max_mtxid, 1);
	if ( n < 1 || NUM_MTXID < 1 ) {
		return E_SYS;
	}

	/* Create mutex control block */
	mtxcb_table = Imalloc((UINT)NUM_MTXID * sizeof(MTXCB));
	if ( mtxcb_table == NULL ) {
		return E_NOMEM;
	}

	/* Register all control blocks onto FeeQue */
	QueInit(&free_mtxcb);
	end = mtxcb_table + NUM_MTXID;
	for( mtxcb = mtxcb_table; mtxcb < end; mtxcb++ ) {
		mtxcb->mtxid = 0;
		QueInsert(&mtxcb->wait_queue, &free_mtxcb);
	}

	return E_OK;
}
Esempio n. 10
0
/*
 * Initialization of port control block
 */
EXPORT ER rendezvous_initialize( void )
{
	PORCB	*porcb, *end;
	W	n;

	/* Get system information */
	n = _tk_get_cfn(SCTAG_TMAXPORID, &max_porid, 1);
	if ( n < 1 || NUM_PORID < 1 ) {
		return E_SYS;
	}

	/* Create port control block */
	porcb_table = Imalloc((UINT)NUM_PORID * sizeof(PORCB));
	if ( porcb_table == NULL ) {
		return E_NOMEM;
	}

	/* Register all control blocks onto FeeQue */
	QueInit(&free_porcb);
	end = porcb_table + NUM_PORID;
	for ( porcb = porcb_table; porcb < end; porcb++ ) {
		porcb->porid = 0;
		QueInsert(&porcb->call_queue, &free_porcb);
	}

	return E_OK;
}
Esempio n. 11
0
/*
 * Initialization of message buffer control block
 */
EXPORT ER messagebuffer_initialize( void )
{
	MBFCB	*mbfcb, *end;
	W	n;

	/* Get system information */
	n = _tk_get_cfn(SCTAG_TMAXMBFID, &max_mbfid, 1);
	if ( n < 1 || NUM_MBFID < 1 ) {
		return E_SYS;
	}

	/* Create message buffer control block */
	mbfcb_table = Imalloc((UINT)NUM_MBFID * sizeof(MBFCB));
	if ( mbfcb_table == NULL ) {
		return E_NOMEM;
	}

	/* Register all control blocks onto FeeQue */
	QueInit(&free_mbfcb);
	end = mbfcb_table + NUM_MBFID;
	for ( mbfcb = mbfcb_table; mbfcb < end; mbfcb++ ) {
		mbfcb->mbfid = 0;
		QueInsert(&mbfcb->send_queue, &free_mbfcb);
	}

	return E_OK;
}
Esempio n. 12
0
U0 EdRenumAsm(CDoc *doc)
{
  Bool unlock=DocLock(doc);
  I64 num=0;
  CRenum root,*tempr,*tempr1;
  U8 buf[sizeof(CEdFindText.find_text)],
	buf2[sizeof(CEdFindText.find_text)];

  QueInit(&root);
  EdSelectFun(doc,TRUE);
  EdRACollect(doc,&root);

  tempr=root.next;
  while (tempr!=&root) {
    tempr1=tempr->next;
    num+=ASM_RENUM_SPACING;
    SPrintF(buf,"@#%02d",num);
    EdReplace(doc,tempr->label,buf,TRUE,TRUE,TRUE);
    Free(tempr);
    tempr=tempr1;
  }

  while (num) {
    SPrintF(buf, "@#%02d",num);
    SPrintF(buf2,"@@%02d",num);
    EdReplace(doc,buf,buf2,TRUE,TRUE,TRUE);
    num-=ASM_RENUM_SPACING;
  }
  EdSelectAll(doc,FALSE);
  DocRecalc(doc);
  DocCenter(doc);
  if (unlock)
    DocUnlock(doc);
}
Esempio n. 13
0
/* |------------------+------------------------------------------------------------| */
StatusType ReleaseResource ( ResourceType ResID )
{
	StatusType ercd = E_OK;
	RESCB *rescb;
	PRI ceilpri,oldpri;
	OS_CHECK_EXT(!in_indp(),E_OS_CALLEVEL); //add as share resource with ISR was not supported
	OS_CHECK_EXT((ResID < cfgOSEK_RESOURCE_NUM),E_OS_ID);
	rescb = &knl_rescb_table[ResID];	
    OS_CHECK_EXT((knl_ctxtsk->resque.prev == &rescb->resque),E_OS_NOFUNC);  
    oldpri = rescb->tskpri;
    ceilpri = knl_gres_table[ResID];        
    OS_CHECK_EXT((ceilpri <= knl_ctxtsk->itskpri),E_OS_ACCESS);
    
    BEGIN_CRITICAL_SECTION;
    knl_ctxtsk->priority = oldpri; 
    QueRemove(&rescb->resque);
    QueInit(&rescb->resque);    
    if(oldpri > knl_ready_queue.top_priority)
    {
        knl_preempt();
    }
    END_CRITICAL_SECTION;	
Error_Exit:
    #if(cfgOS_ERROR_HOOK == STD_ON)
	if(E_OK != ercd)
	{
    	BEGIN_CRITICAL_SECTION;
    	_errorhook_svcid = OSServiceId_ReleaseResource;
    	_errorhook_par1.resid = ResID;
    	CallErrorHook(ercd);
    	END_CRITICAL_SECTION;
    }
	#endif /* cfgOS_ERROR_HOOK */
	return ercd;
}
Esempio n. 14
0
SYSCALL ER _tk_slp_tsk_u( TMO_U tmout )
{
	ER	ercd = E_OK;

	CHECK_TMOUT(tmout);
	CHECK_DISPATCH();

	BEGIN_CRITICAL_SECTION;
	/* Check wait disable */
	if ( (ctxtsk->waitmask & TTW_SLP) != 0 ) {
		ercd = E_DISWAI;
		goto error_exit;
	}

	if ( ctxtsk->wupcnt > 0 ) {
		ctxtsk->wupcnt--;
	} else {
		ercd = E_TMOUT;
		if ( tmout != TMO_POL ) {
			ctxtsk->wspec = &wspec_slp;
			ctxtsk->wid = 0;
			ctxtsk->wercd = &ercd;
			make_wait(tmout, TA_NULL);
			QueInit(&ctxtsk->tskque);
		}
	}

    error_exit:
	END_CRITICAL_SECTION;

	return ercd;
}
Esempio n. 15
0
/*
 * Initialization of variable size memory pool control block
 */
EXPORT ER memorypool_initialize( void )
{
	MPLCB	*mplcb, *end;
	W	n;

	/* Get system information */
	n = _tk_get_cfn(SCTAG_TMAXMPLID, &max_mplid, 1);
	if ( n < 1 || NUM_MPLID < 1 ) {
		return E_SYS;
	}

	/* Create variable size memory pool control block */
	mplcb_table = Imalloc((UINT)NUM_MPLID * sizeof(MPLCB));
	if ( mplcb_table == NULL ) {
		return E_NOMEM;
	}

	/* Register all control blocks onto FeeQue */
	QueInit(&free_mplcb);
	end = mplcb_table + NUM_MPLID;
	for ( mplcb = mplcb_table; mplcb < end; mplcb++ ) {
		mplcb->mplid = 0;
		QueInsert(&mplcb->wait_queue, &free_mplcb);
	}

	return E_OK;
}
Esempio n. 16
0
StatusType SleepTask ( TickType Timeout )
{
    StatusType ercd = E_OK;
    OS_CHECK_EXT(!in_indp(),E_OS_CALLEVEL);
	OS_CHECK_EXT(isQueEmpty(&knl_ctxtsk->resque),E_OS_RESOURCE);

	BEGIN_CRITICAL_SECTION;

    if ( knl_ctxtsk->wupcnt > 0 ) {
        knl_ctxtsk->wupcnt--;
    } else {
        ercd = E_OS_TMOUT;
        if ( Timeout != 0 ) {
            knl_ctxtsk->wspec = &knl_wspec_slp;
            knl_ctxtsk->wid = 0;
            knl_ctxtsk->wercd = &ercd;
            knl_make_wait(Timeout);
            QueInit(&knl_ctxtsk->tskque);
        }
    }

    END_CRITICAL_SECTION;
Error_Exit:
	return ercd;
}
Esempio n. 17
0
/* |------------------+-------------------------------------------------------------| */
StatusType CancelAlarm ( AlarmType AlarmID )
{
    StatusType ercd = E_OK;
    ALMCB* almcb;
    OS_CHECK_EXT((AlarmID < cfgOSEK_ALARM_NUM),E_OS_ID);
    almcb = &knl_almcb_table[AlarmID];
    OS_CHECK((!isQueEmpty(&almcb->almque)),E_OS_NOFUNC);

    BEGIN_DISABLE_INTERRUPT;
    QueRemove(&almcb->almque);
    QueInit(&almcb->almque);
    END_DISABLE_INTERRUPT;
    Error_Exit:
    #if(cfgOS_ERROR_HOOK == STD_ON)
	if(E_OK != ercd)
	{
    	BEGIN_CRITICAL_SECTION;
    	_errorhook_svcid = OSServiceId_CancelAlarm;
    	_errorhook_par1.almid = AlarmID;
    	CallErrorHook(ercd);
    	END_CRITICAL_SECTION;
    }
	#endif /* cfgOS_ERROR_HOOK */
    	return ercd;
}
Esempio n. 18
0
EXPORT void knl_resource_init(void)
{
    ID i;
    for(i=0;i<cfgOSEK_RESOURCE_NUM;i++)
    {
        QueInit(&(knl_rescb_table[i].resque));
    }
}
Esempio n. 19
0
/*
 * Initialization sequence of device input/output-related
 */
EXPORT ER knl_initDevIO( void )
{
	INT	i;

	QueInit(&knl_FreeOpnCB);
	for ( i = 0; i < CFN_MAX_OPNDEV; ++i ) {
		knl_OpnCBtbl[i].resid = 0;
		QueInsert(&knl_OpnCBtbl[i].q, &knl_FreeOpnCB);
	}

	QueInit(&knl_FreeReqCB);
	for ( i = 0; i < CFN_MAX_REQDEV; ++i ) {
		knl_ReqCBtbl[i].opncb = NULL;
		QueInsert(&knl_ReqCBtbl[i].q, &knl_FreeReqCB);
	}

	return E_OK;
}
Esempio n. 20
0
/*
 * Memory pool initial setting
 */
LOCAL void init_mempool( MPLCB *mplcb, void *mempool, INT mempsz )
{
	QUEUE	*tp, *ep;

	QueInit(&mplcb->areaque);
	QueInit(&mplcb->freeque);

	/* Register onto AreaQue */
	tp = (QUEUE*)mempool;
	ep = (QUEUE*)((VB*)mempool + mempsz) - 1;
	insertAreaQue(&mplcb->areaque, ep);
	insertAreaQue(&mplcb->areaque, tp);

	/* Set AREA_USE for locations that must not be free area */
	setAreaFlag(&mplcb->areaque, AREA_USE);
	setAreaFlag(ep, AREA_USE);

	/* Register onto FreeQue */
	appendFreeArea(mplcb, tp);
}
Esempio n. 21
0
CQue *QueCopy(CQue *root,CTask *mem_task=NULL)
{
  CQue *result=MAllocIdentical(root,mem_task),*tempq=root->next,*tempq1;
  QueInit(result);
  while (tempq!=root) {
    tempq1=MAllocIdentical(tempq,mem_task);
    QueIns(tempq1,result->last);
    tempq=tempq->next;
  }
  return result;
}
Esempio n. 22
0
/*
 * Device management startup function
 */
EXPORT void knl_devmgr_startup( void )
{
	LockDM();

	/* Initialization of open device management queue */
	QueInit(&(knl_resource_control_block.openq));
	knl_resource_control_block.dissus = 0;
	
	UnlockDM();

	return;
}
Esempio n. 23
0
File: mutex.c Progetto: yuki74w/TRON
/*
 * Create mutex
 */
SYSCALL ID _tk_cre_mtx( CONST T_CMTX *pk_cmtx )
{
#if CHK_RSATR
	const ATR VALID_MTXATR = {
		 TA_CEILING
		|TA_NODISWAI
#if USE_OBJECT_NAME
		|TA_DSNAME
#endif
	};
#endif
	MTXCB	*mtxcb;
	ID	mtxid;
	INT	ceilpri;
	ER	ercd;

	CHECK_RSATR(pk_cmtx->mtxatr, VALID_MTXATR);

	if ( (pk_cmtx->mtxatr & TA_CEILING) == TA_CEILING ) {
		CHECK_PRI(pk_cmtx->ceilpri);
		ceilpri = int_priority(pk_cmtx->ceilpri);
	} else {
		ceilpri = 0;
	}

	BEGIN_CRITICAL_SECTION;
	/* Get control block from FreeQue */
	mtxcb = (MTXCB*)QueRemoveNext(&free_mtxcb);
	if ( mtxcb == NULL ) {
		ercd = E_LIMIT;
	} else {
		mtxid = ID_MTX(mtxcb - mtxcb_table);

		/* Initialize control block */
		QueInit(&mtxcb->wait_queue);
		mtxcb->mtxid   = mtxid;
		mtxcb->exinf   = pk_cmtx->exinf;
		mtxcb->mtxatr  = pk_cmtx->mtxatr;
		mtxcb->ceilpri = ceilpri;
		mtxcb->mtxtsk  = NULL;
		mtxcb->mtxlist = NULL;
#if USE_OBJECT_NAME
		if ( (pk_cmtx->mtxatr & TA_DSNAME) != 0 ) {
			strncpy((char*)mtxcb->name, (char*)pk_cmtx->dsname,
				(UINT)OBJECT_NAME_LENGTH);
		}
#endif
		ercd = mtxid;
	}
	END_CRITICAL_SECTION;

	return ercd;
}
Esempio n. 24
0
/* |------------------+------------------------------------------------------------| */
StatusType ReleaseResource ( ResourceType ResID )
{
	StatusType ercd = E_OK;
	RESCB *rescb;
	PRI newpri,oldpri;
	OS_CHECK_EXT((ResID < cfgOSEK_RESOURCE_NUM),E_OS_ID);
	rescb = &knl_rescb_table[ResID];
    	
    if(in_indp())  /* Interrupt level */
    {
        /* not supported */
    }
    else
    {
        OS_CHECK_EXT((knl_ctxtsk->resque.prev == &rescb->resque),E_OS_NOFUNC);
        oldpri = knl_gres_table[ResID];
        newpri = rescb->tskpri;
         
        OS_CHECK_EXT((newpri > oldpri),E_OS_ACCESS);
        
        BEGIN_CRITICAL_SECTION;
        if(oldpri < 0)
        {
            /* Task share resource with ISR */
            /* should change IPL */
            /* not supported */           
        }
        else
        {
            knl_ctxtsk->priority = newpri; 
            QueRemove(&rescb->resque);
            QueInit(&rescb->resque);    
            if(newpri > knl_ready_queue.top_priority)
            {
                knl_preempt();
            }
        }
        END_CRITICAL_SECTION;	
    }
Error_Exit:
    #if(cfgOS_ERROR_HOOK == STD_ON)
	if(E_OK != ercd)
	{
    	BEGIN_CRITICAL_SECTION;
    	_errorhook_svcid = OSServiceId_ReleaseResource;
    	_errorhook_par1.resid = ResID;
    	CallErrorHook(ercd);
    	END_CRITICAL_SECTION;
    }
	#endif /* cfgOS_ERROR_HOOK */
	return ercd;
}
Esempio n. 25
0
/*
 * Set timeout event
 *	Register the timer event 'event' onto the timer queue to
 *	start after the timeout 'tmout'. At timeout, start with the
 *	argument 'arg' on the callback function 'callback'.
 *	When 'tmout' is TMO_FEVR, do not register onto the timer
 *	queue, but initialize queue area in case 'timer_delete' 
 *	is called later.
 *
 *	"include/tk/typedef.h"
 *	typedef	W		TMO;
 *	typedef UW		RELTIM;
 *	#define TMO_FEVR	(-1)
 */
EXPORT void knl_timer_insert( TMEB *event, TickType tmout, CBACK callback, VP arg )
{
	event->callback = callback;
	event->arg = arg;

	if ( tmout == TMO_FEVR ) {
		QueInit(&event->queue);
	} else {
		/* To guarantee longer wait time specified by 'tmout',
		   add TIMER_PERIOD on wait time */
		event->time = knl_current_time + tmout;
		knl_enqueue_tmeb(event);
	}
}
Esempio n. 26
0
/*
 * Get resource management information
 */
EXPORT ResCB* knl_GetResCB( void )
{
	LockDM();

	/* If the startup function is not called, initialize at this point */
	if ( knl_resource_control_block.openq.next == NULL ) {
		/* Initialization of open device management queue */
		QueInit(&(knl_resource_control_block.openq));
	}

	UnlockDM();

	return &knl_resource_control_block;
}
Esempio n. 27
0
/*
 * Set timeout event
 *	Register the timer event 'event' onto the timer queue to
 *	start after the timeout 'tmout'. At timeout, start with the
 *	argument 'arg' on the callback function 'callback'.
 *	When 'tmout' is TMO_FEVR, do not register onto the timer
 *	queue, but initialize queue area in case 'timer_delete'
 *	is called later.
 *
 *	"include/tk/typedef.h"
 *	typedef	W		TMO;
 *	typedef UW		RELTIM;
 *	#define TMO_FEVR	(-1)
 */
EXPORT void knl_timer_insert( TMEB *event, TMO tmout, CBACK callback, VP arg )
{
    event->callback = callback;
    event->arg = arg;

    if ( tmout == TMO_FEVR ) {
        QueInit(&event->queue);
    } else {
        /* To guarantee longer wait time specified by 'tmout',
           add TIMER_PERIOD on wait time */
        event->time = ll_add( ll_add(knl_current_time, ltoll(tmout)),
                              uitoll(CFN_TIMER_PERIOD) );
        knl_enqueue_tmeb(event);
    }
}
Esempio n. 28
0
/*
 * Initialization of timer module
 */
EXPORT ER knl_timer_initialize( void )
{
    if ( CFN_TIMER_PERIOD < MIN_TIMER_PERIOD
            || CFN_TIMER_PERIOD > MAX_TIMER_PERIOD ) {
        return E_SYS;
    }

    knl_current_time = knl_real_time_ofs = ltoll(0);
    QueInit(&knl_timer_queue);

    /* Start timer interrupt */
    knl_start_hw_timer();

    return E_OK;
}
Esempio n. 29
0
/*
 * TCB Initialization
 */
EXPORT ER task_initialize( void )
{
	INT	i;
	TCB	*tcb;
	ID	tskid;

	/* Get system information */
	i = _tk_get_cfn(SCTAG_TMAXTSKID, &max_tskid, 1);
	if ( i < 1 || NUM_TSKID < 1 ) {
		return E_SYS;
	}
	i = _tk_get_cfn(SCTAG_TSYSSTKSZ, &default_sstksz, 1);
	if ( i < 1 || default_sstksz < MIN_SYS_STACK_SIZE ) {
		return E_SYS;
	}
	i = _tk_get_cfn(SCTAG_TSVCLIMIT, &svc_call_limit, 1);
	if ( i < 1 || svc_call_limit < 0 || svc_call_limit > 3 ) {
		return E_SYS;
	}

	/* Allocate TCB area */
	tcb_table = Imalloc((UINT)NUM_TSKID * sizeof(TCB));
	if ( tcb_table == NULL ) {
		return E_NOMEM;
	}
	
	/* Initialize task execution control information */
	ctxtsk = schedtsk = NULL;
	ready_queue_initialize(&ready_queue);
	dispatch_disabled = DDS_ENABLE;

	/* Register all TCBs onto FreeQue */
	QueInit(&free_tcb);
	for ( tcb = tcb_table, i = 0; i < NUM_TSKID; tcb++, i++ ) {
		tskid = ID_TSK(i);
		tcb->tskid = tskid;
		tcb->state = TS_NONEXIST;
#ifdef NUM_PORID
		tcb->wrdvno = tskid;
#endif
		InitSVCLOCK(&tcb->svclock);
		tcb->svclocked = NULL;

		QueInsert(&tcb->tskque, &free_tcb);
	}

	return E_OK;
}
Esempio n. 30
0
/*
 * Create semaphore
 */
SYSCALL ID tk_cre_sem_impl( T_CSEM *pk_csem )
{
#if CHK_RSATR
	const ATR VALID_SEMATR = {
		 TA_TPRI
		|TA_CNT
#if USE_OBJECT_NAME
		|TA_DSNAME
#endif
	};
#endif
	SEMCB	*semcb;
	ID	semid;
	ER	ercd;

	CHECK_RSATR(pk_csem->sematr, VALID_SEMATR);
	CHECK_PAR(pk_csem->isemcnt >= 0);
	CHECK_PAR(pk_csem->maxsem > 0);
	CHECK_PAR(pk_csem->maxsem >= pk_csem->isemcnt);

	BEGIN_CRITICAL_SECTION;
	/* Get control block from FreeQue */
	semcb = (SEMCB*)QueRemoveNext(&knl_free_semcb);
	if ( semcb == NULL ) {
		ercd = E_LIMIT;
	} else {
		semid = ID_SEM(semcb - knl_semcb_table);

		/* Initialize control block */
		QueInit(&semcb->wait_queue);
		semcb->semid = semid;
		semcb->exinf = pk_csem->exinf;
		semcb->sematr = pk_csem->sematr;
		semcb->semcnt = pk_csem->isemcnt;
		semcb->maxsem = pk_csem->maxsem;
#if USE_OBJECT_NAME
		if ( (pk_csem->sematr & TA_DSNAME) != 0 ) {
			strncpy((char*)semcb->name, (char*)pk_csem->dsname,
				OBJECT_NAME_LENGTH);
		}
#endif
		ercd = semid;
	}
	END_CRITICAL_SECTION;

	return ercd;
}