📄 almapi.c.svn-base
字号:
/*
* ***********************************************************
* OSEK
* COUNTER AND ALARM
*FILE : almapi.c
*BY : mrchen
*************************************************************
*/
#include"almapi.h"
//int alm_auto; /*the number of aotustart alarm,decided by OIL.*/
/*whether it is needed is also decided by OIL.*/
int alm_now=0; //id of the alarm which can be used now
//int cntid=0;
//int tempnum=0; //it is used by test.record the number of actions.
/*
* ******************************************************************
* COUNTER AND ALARM ARRAY DEFINE
********************************************************************
*/
struct COUNTER CntArrary[cnt_num];
struct ALARM AlmArrary[alm_num];
/*return the information about the counter of alarms*/
enum statetype Getalarmbase(alarmtype alarmid ,alarmbasereftype temp_cont)
{
if(alarmid != NULL)
{
temp_cont = &CntArrary[alarmid->counter];
return E_OK;
}
else
return E_OS_ID;
}
/*return the relative alarm value of alarms*/
enum statetype Getalarm(alarmtype alarmid,tickreftype ticktemp)
{
if(alarmid->state == 0)
return E_OS_NOFUNC;
if(alarmid->almnum >= CntArrary[alarmid->counter].cntcurrent)
*ticktemp = alarmid->almnum - CntArrary[alarmid->counter].cntcurrent;
else
*ticktemp = alarmid->almnum + CntArrary[alarmid->counter].maxallowvalue
- CntArrary[alarmid->counter].cntcurrent;
return E_OK;
}
/*set relative alarm and start it*/
enum statetype Setrelalarm(alarmtype alarmid, ticktype increment,ticktype cycle)
{
int temp;
tickreftype tickreftemp;//init the reference of tick value
ticktype ticktemp;
tickreftemp =&ticktemp;
if(alarmid == NULL)
return E_OS_ID;
if(alarmid->state == 1)
return E_OS_STATE;
if(increment < 0 || increment > CntArrary[alarmid->counter].maxallowvalue)
return E_OS_VALUE;
if(!(cycle == 0 || CntArrary[alarmid->counter].mincycle <= cycle
<= CntArrary[alarmid->counter].maxallowvalue))
return E_OS_VALUE;
temp = increment + CntArrary[alarmid->counter].cntcurrent;//relative value ,so cann't exceed maxvalue.
if(temp > CntArrary[alarmid->counter].maxallowvalue)//if exceed ,it must count cycle to zero.
alarmid->almnum = temp - CntArrary[alarmid->counter].maxallowvalue;
else
alarmid->almnum = temp;
alarmid->cycle = cycle;
alarmid->state = 1;//start work
alm_now++;
return E_OK;
}
/*set abslute alarm and start it,this api is different from the up one,it doesn't need
the current value of COUNTER depended by the ALARM */
enum statetype Setabsalarm(alarmtype alarmid, ticktype start,ticktype cycle)
{
if(alarmid == NULL)
return E_OS_ID;
if(alarmid->state == 1)
return E_OS_STATE;
if(start < 0 || start > CntArrary[alarmid->counter].maxallowvalue)
return E_OS_VALUE;
if(!(cycle == 0 || (CntArrary[alarmid->counter].mincycle <= cycle
<= CntArrary[alarmid->counter].maxallowvalue)))
return E_OS_VALUE;
alarmid->almnum = start;
alarmid->cycle = cycle;
alarmid->state = 1;//start work
alm_now++;
return E_OK;
}
/*cancel the ALARM*/
enum statetype Cancelalarm(alarmtype alarmid)
{
if(alarmid == NULL)
return E_OS_ID;
if(alarmid->state == 0)
return E_OS_NOFUNC;
alarmid->state = 0;
return E_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -