📄 user.c
字号:
break;
#endif
#if (VB_ISR_EINT2 != 0)
case VB_ISR_EINT2:
CLR_IRQ(BIT_EINT2);
(enable) ? UNMK_INT(BIT_EINT2) : MASK_INT(BIT_EINT2);
break;
#endif
#if (VB_ISR_EINT1 != 0)
case VB_ISR_EINT1:
CLR_IRQ(BIT_EINT1);
(enable) ? UNMK_INT(BIT_EINT1) : MASK_INT(BIT_EINT1);
break;
#endif
#if (VB_ISR_EINT0 != 0)
case VB_ISR_EINT0:
CLR_IRQ(BIT_EINT0);
(enable) ? UNMK_INT(BIT_EINT0) : MASK_INT(BIT_EINT0);
break;
#endif
default: return FALSE;
}
return TRUE;
}
/*/////////////////////////设备函数/////////////////////////////
***************************************************************/
BOOL VB_RequestDevie(VB_HTASK htask, uint devnum, BOOL isblock)
{
Visby_Task *pTask = (Visby_Task *)htask;
Visby_List *pList;
if( devnum > VB_DEV_NUM )return FALSE;
if( TST(pVisby_Device[devnum].Type, VB_DEV_SHARE)==FALSE )
{
if( pVisby_Device[devnum].pUser )
{
if( isblock )//阻塞自己,一直到得到设备才调度运行
{
if( pVisby_Device[devnum].pWaitTask )
{
pList = pVisby_Device[devnum].pWaitTask;
while( pList->pNext )pList = pList->pNext;
pList->pNext = (Visby_List *)heapalloc(sizeof(Visby_List));
pList->pNext->pNext = NULL;
pList->pNext->pData = (void *)pTask;
}
else
{
pList = (Visby_List *)heapalloc(sizeof(Visby_List));
pList->pNext = NULL;
pList->pData = (void *)pTask;
pVisby_Device[devnum].pWaitTask = pList;
}
Visby_KReqWaiTask( pTask, VB_MSG(MSG_WAIT_DEV,devnum) );
//任务被唤醒后继续执行.等到任务被唤醒,这表示已经得到了请求的设备
}
else
return FALSE;
}
else
pVisby_Device[devnum].pUser = pTask;
}
//将设备句柄放到任务的占用资源链表中
if( pTask->pUsedDev )
{
pList = pTask->pUsedDev;
while( pList->pNext )pList = pList->pNext;
pList->pNext = (Visby_List *)heapalloc(sizeof(Visby_List));
pList->pNext->pNext = NULL;
pList->pNext->pData = (void *)(&pVisby_Device[devnum]);
}
else
{
pTask->pUsedDev = (Visby_List *)heapalloc(sizeof(Visby_List));
pTask->pUsedDev->pNext = NULL;
pTask->pUsedDev->pData = (void *)(&pVisby_Device[devnum]);
}
return TRUE;
}
//共享型设备一律返回FALSE。独占设备返回 TRUE说明设备更换了使用者;否则,设备空闲。
BOOL VB_FreeDevice(uint devnum)
{
Visby_List *pList;
Visby_List *pTmpList;
Visby_Msg *pMsg;
Visby_Device *pDev = &pVisby_Device[devnum];
Visby_Task *pTask = pDev->pUser;
if( devnum > VB_DEV_NUM )return FALSE;
//释放任务块中的占用设备链表
pList = pTask->pUsedDev;
if( pList->pData == pDev )
{
pTask->pUsedDev = pList->pNext;
heapfree(pList);
}
else
{
while( (pList->pNext != NULL) && (pList->pNext->pData != pDev) )pList = pList->pNext;
pTmpList = pList->pNext;
pList->pNext = pTmpList->pNext;
heapfree(pTmpList);
}
//修改设备描述块
pDev->pUser = NULL;
if( TST(pDev->Type, VB_DEV_SHARE)==FALSE && pDev->pWaitTask )
{
pDev->pUser = (Visby_Task *)(pDev->pWaitTask->pData);
pList = pDev->pWaitTask;
pDev->pWaitTask = pDev->pWaitTask->pNext;
heapfree(pList);
pMsg = (Visby_Msg *)heapalloc(sizeof(Visby_Msg));
pMsg->Type = VB_MSG(MSG_WAIT_DEV,devnum);
pMsg->pDetail = NULL;
pMsg->pNext = NULL;
Visby_KUrgtMsg( pDev->pUser, pMsg);
return TRUE;
}
else
return FALSE;
}
/*///////////////////////资源管理函数///////////////////////////
***************************************************************/
BOOL VB_SetTimer0123(uint index, float duty_ms, VB_HISR isr, VB_HISR *oldisr)
{
float coff;
if( index < VB_TIMER0 || index > VB_TIMER3 )return FALSE;
if( Visby_Resouce[index] == TRUE )return FALSE;
if( isr )
{
*oldisr = VB_InstallISR(isr, index-VB_TIMER0+VB_ISR_TIMER0 );
if( *oldisr == 0xFFFFFFFF )return FALSE;
}
coff = (1000*duty_ms);
if( coff > 4194240 )
{
if( isr )VB_InstallISR(*oldisr, index-VB_TIMER0+VB_ISR_TIMER0 );
return FALSE;
}
else if( coff > 2097120 )
{
switch( index )
{
case VB_TIMER0:VB_MUX_Timer(0,TIMER_1_32);VB_TimerPrescale(01,132);break;
case VB_TIMER1:VB_MUX_Timer(1,TIMER_1_32);VB_TimerPrescale(01,132);break;
case VB_TIMER2:VB_MUX_Timer(2,TIMER_1_32);VB_TimerPrescale(23,132);break;
case VB_TIMER3:VB_MUX_Timer(3,TIMER_1_32);VB_TimerPrescale(23,132);break;
default: return FALSE;//couldn't run here
}
coff /= 64;
}
else if( coff > 1048560 )
{
switch( index )
{
case VB_TIMER0:VB_MUX_Timer(0,TIMER_1_32);VB_TimerPrescale(01,66);break;
case VB_TIMER1:VB_MUX_Timer(1,TIMER_1_32);VB_TimerPrescale(01,66);break;
case VB_TIMER2:VB_MUX_Timer(2,TIMER_1_32);VB_TimerPrescale(23,66);break;
case VB_TIMER3:VB_MUX_Timer(3,TIMER_1_32);VB_TimerPrescale(23,66);break;
default: return FALSE;//couldn't run here
}
coff /= 32;
}
else if( coff > 524280 )
{
switch( index )
{
case VB_TIMER0:VB_MUX_Timer(0,TIMER_1_32);VB_TimerPrescale(01,33);break;
case VB_TIMER1:VB_MUX_Timer(1,TIMER_1_32);VB_TimerPrescale(01,33);break;
case VB_TIMER2:VB_MUX_Timer(2,TIMER_1_32);VB_TimerPrescale(23,33);break;
case VB_TIMER3:VB_MUX_Timer(3,TIMER_1_32);VB_TimerPrescale(23,33);break;
default: return FALSE;//couldn't run here
}
coff /= 16;
}
else if( coff > 262140 )
{
switch( index )
{
case VB_TIMER0:VB_MUX_Timer(0,TIMER_1_16);VB_TimerPrescale(01,33);break;
case VB_TIMER1:VB_MUX_Timer(1,TIMER_1_16);VB_TimerPrescale(01,33);break;
case VB_TIMER2:VB_MUX_Timer(2,TIMER_1_16);VB_TimerPrescale(23,33);break;
case VB_TIMER3:VB_MUX_Timer(3,TIMER_1_16);VB_TimerPrescale(23,33);break;
default: return FALSE;//couldn't run here
}
coff /= 8;
}
else if( coff > 131070 )
{
switch( index )
{
case VB_TIMER0:VB_MUX_Timer(0,TIMER_1_8);VB_TimerPrescale(01,33);break;
case VB_TIMER1:VB_MUX_Timer(1,TIMER_1_8);VB_TimerPrescale(01,33);break;
case VB_TIMER2:VB_MUX_Timer(2,TIMER_1_8);VB_TimerPrescale(23,33);break;
case VB_TIMER3:VB_MUX_Timer(3,TIMER_1_8);VB_TimerPrescale(23,33);break;
default: return FALSE;//couldn't run here
}
coff /= 4;
}
else if( coff > 65535 )
{
switch( index )
{
case VB_TIMER0:VB_MUX_Timer(0,TIMER_1_4);VB_TimerPrescale(01,33);break;
case VB_TIMER1:VB_MUX_Timer(1,TIMER_1_4);VB_TimerPrescale(01,33);break;
case VB_TIMER2:VB_MUX_Timer(2,TIMER_1_4);VB_TimerPrescale(23,33);break;
case VB_TIMER3:VB_MUX_Timer(3,TIMER_1_4);VB_TimerPrescale(23,33);break;
default: return FALSE;//couldn't run here
}
coff /= 2;
}
else
{
switch( index )
{
case VB_TIMER0:VB_MUX_Timer(0,TIMER_1_2);VB_TimerPrescale(01,33);break;
case VB_TIMER1:VB_MUX_Timer(1,TIMER_1_2);VB_TimerPrescale(01,33);break;
case VB_TIMER2:VB_MUX_Timer(2,TIMER_1_2);VB_TimerPrescale(23,33);break;
case VB_TIMER3:VB_MUX_Timer(3,TIMER_1_2);VB_TimerPrescale(23,33);break;
default: return FALSE;//couldn't run here
}
}
switch( index )
{
case VB_TIMER0:
VB_TimerCount(0,(ushort)(coff+0.5));VB_TimerUpdate(0);VB_TimerAuto(0);VB_TimerStart(0);break;
case VB_TIMER1:
VB_TimerCount(1,(ushort)(coff+0.5));VB_TimerUpdate(1);VB_TimerAuto(1);VB_TimerStart(1);break;
case VB_TIMER2:
VB_TimerCount(2,(ushort)(coff+0.5));VB_TimerUpdate(2);VB_TimerAuto(2);VB_TimerStart(2);break;
case VB_TIMER3:
VB_TimerCount(3,(ushort)(coff+0.5));VB_TimerUpdate(3);VB_TimerAuto(3);VB_TimerStart(3);break;
default: return FALSE;//couldn't run here
}
Visby_Resouce[index] = TRUE;
return TRUE;
}
/*/////////////////////////系统函数/////////////////////////////
***************************************************************/
void VB_Start()
{
uint i;
if(Visby_Started)
{
return;
}
Visby_Started = true;
Visby_KStart();
//////////////////////////////////////////////////////////// 初始化内核无关的设备
LCD_Init();
/////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////// 初始化系统任务
/////////////////////////////////////////////////////////////////////////////////
// enable Vector irq
ENA_VECTINT;
// enable IRQ
ENA_IRQ;
// unmask global int
UNMK_GLOBAL;
CLR_IRQ(BIT_TIMER2);
UNMK_INT(BIT_TIMER2);
/////////////////////////////////////////////////////////////// Azbo Test UsrMode
i = 0x00000010;
__asm
{
MSR CPSR_cxsf, i
}
/////////////////////////////////////////////////////////////////////////////////
while(true)
{
VB_ENCRIT;
Uart_Printf("Idle...\n");
VB_DECRIT;
for(i = 0; i < 500000; i++);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -