📄 ma_tmr.c
字号:
case 2:
/*--- Reset timer first? ---*/
if( Reset )
{
TCNT2 = 0;
}
/*--- Start channel 2 ---*/
TCCR2 = MA_TCCR2_TMR;
break;
case 3:
/*--- Reset timer first? ---*/
if( Reset )
{
TCNT3 = 0;
}
/*--- Start channel 3 ---*/
TCCR3B = MA_TCCR3B_TMR;
break;
default:
/*--- Handle user code on function exit ---*/
// EXIT_MA_START_TMR;
/*--- Illegal channel ---*/
return MA_ERROR;
}
/*--- Handle user code on function exit ---*/
// EXIT_MA_START_TMR;
return MA_OK;
} /* MA_START_TMR */
S8 MA_Stop_TMR( U8 Channel )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Stops the selected timer channel.
**
** Parameters:
** Channel The timer channel to stop (0-3)
**
** Returns:
** MA_ERROR If illegal channel number was given
** MA_OK Otherwise
**
**---------------------------------------------------------------------------
*/
{
/*--- Handle user code on function entry ---*/
// ENTER_MA_STOP_TMR;
/*--- Handle correct channel ---*/
switch( Channel )
{
case 0:
/*--- Stop channel 0 ---*/
TCCR0 &= ~0x07;
break;
case 1:
/*--- Stop channel 1 ---*/
TCCR1B &= ~0x07;
break;
case 2:
/*--- Stop channel 2 ---*/
TCCR2 &= ~0x07;
break;
case 3:
/*--- Stop channel 3 ---*/
TCCR3B &= ~0x07;
break;
default:
/*--- Handle user code on function exit ---*/
// EXIT_MA_STOP_TMR;
/*--- Illegal channel ---*/
return MA_ERROR;
}
/*--- Handle user code on function exit ---*/
// EXIT_MA_STOP_TMR;
return MA_OK;
} /* MA_STOP_TMR */
S8 MA_SetCompareMatch_TMR( U8 Channel, U16 ValueA, U16 ValueB, U16 ValueC )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** Sets new compare match values for selected channel. Please note that
** only some channels have support for B and C values. For channels
** with support for one compare match value only, use Value A.
*
** Parameters:
** Channel The timer channel to change
** ValueA The new compare match value (A) (all channels)
** ValueB The new compare match value (B) (channels 1 and 3)
** ValueC The new compare match value (C) (channels 1 and 3)
**
** Returns:
** MA_ERROR If illegal channel number was given
** MA_OK Otherwise
**
**---------------------------------------------------------------------------
*/
{
/*--- Handle user code on function entry ---*/
// ENTER_MA_SETCOMPAREMATCH_TMR;
/*--- Handle correct channel ---*/
switch( Channel )
{
case 0:
/*--- Update channel 0 ---*/
OCR0 = (U8)ValueA;
break;
case 1:
/*--- Update channel 1 ---*/
OCR1A = ValueA;
OCR1B = ValueB;
OCR1C = ValueC;
break;
case 2:
/*--- Update channel 2 ---*/
OCR2 = (U8)ValueA;
break;
case 3:
/*--- Update channel 3 ---*/
OCR3A = ValueA;
OCR3B = ValueB;
OCR3C = ValueC;
break;
default:
/*--- Handle user code on function exit ---*/
// EXIT_MA_SETCOMPAREMATCH_TMR;
/*--- Illegal channel ---*/
return MA_ERROR;
}
/*--- Handle user code on function exit ---*/
// EXIT_MA_SETCOMPAREMATCH_TMR;
return MA_OK;
} /* MA_SETCOMPAREMATCH_TMR */
extern unsigned int inc;
#pragma vector=MA_TIMER0_OVF_vect
__interrupt void MA_IntHandler_OVF0_TMR( void )
//__task void MA_IntHandler_OVF0_TMR( void )
/*
**---------------------------------------------------------------------------
**
** Abstract:
** This function is the high level language interrupt handler for the
** timer 0 overflow interrupt.
**
** Parameters:
** None
**
** Returns:
** None
**
**---------------------------------------------------------------------------
*/
//nou: comutarea modificata pentru a permite lucrul cu semafoare
{
/*--- Handle user code on function entry ---*/
// ENTER_MA_INTHANDLER_OVF0_TMR;
__disable_interrupt();
asm(" ST -Y, R4");
asm(" ST -Y, R5");
asm(" ST -Y, R6");
asm(" ST -Y, R7");
asm(" ST -Y, R8");
asm(" ST -Y, R9");
asm(" ST -Y, R10");
asm(" ST -Y, R11");
asm(" ST -Y, R12");
asm(" ST -Y, R13");
asm(" ST -Y, R14");
asm(" ST -Y, R15");
asm(" ST -Y, R26");
//salvare registru stare
// xxx=R26;
// if(b_start_so)//numai daca a fost pornit sistemul de operare
// {
// }
/*--- Handle user code ---*/
// INSIDE_MA_INTHANDLER_OVF0_TMR;
global_inc++;//incrementare contor task
global_inc_g++;//pentru functia delay generala
inc++;
/* if(sstare)
{
// MA_WritePort_IO(MA_PORTB,0X00,0x01);
sstare=0;
}
else
{
sstare=1;
// MA_WritePort_IO(MA_PORTB,0X01,0x01);
}
*/
//test comutare intre task-uri
if(b_start_so)//numai daca a fost pornit sistemul de operare!
{
if(global_inc>=(task_time*TICK_TIME))//are loc comutarea intre task-uri??
{
global_inc=0;
t_sph=0;
t_spl=0;
t_r29=0;
t_r28=0;
get_tsp();//initializare variabile t_sp si t_r
//salvare adrese - folosit pointer-ul X (este deja salvat)
asm(" LDS R30,t_r28");//R26 <- t_r28
asm(" LDS R31,t_r29");//R27 <- t_r29
asm(" ST -Z, R28");//salvare pointer Y
asm(" ST -Z, R29");
//salvare stiva
asm(" LDS R30,t_spl");//salvarea stivei se face folosind pointer-ul Y
asm(" LDS R31,t_sph");
asm(" IN R16,0x3d");//salvare SPH
asm(" ST -Z,R16");
asm(" IN R16,0x3e");//salvare SPL
asm(" ST -Z,R16");
// PushSP();
push_var();//salveaza variabilele
comuta_task();//comuta task-ul urmator
pop_var();//restaureaza noile variabile
// PopSP();
/*--- Handle user code on function exit ---*/
// EXIT_MA_INTHANDLER_OVF0_TMR;
asm(" LDS R28,t_spl");
asm(" LDS R29,t_sph");
asm(" LD R16,-Y");
asm(" OUT 0x3d,R16");
asm(" LD R16,-Y");
asm(" OUT 0x3e,R16");
//in plus setare pointer y pentru stiva soft!
//restaurare adrese - folosit pointer-ul X (va fi si el restaurat)
asm(" LDS R30,t_r28");
asm(" LDS R31,t_r29");
asm(" LD R28,-Z");
asm(" LD R29,-Z");
}
//intfunct();
//reactualizeaza pointerii noi calculati
}
// SREG=xxx;
asm(" LD R26,Y+");
asm(" LD R15,Y+");
asm(" LD R14,Y+");
asm(" LD R13,Y+");
asm(" LD R12,Y+");
asm(" LD R11,Y+");
asm(" LD R10,Y+");
asm(" LD R9,Y+");
asm(" LD R8,Y+");
asm(" LD R7,Y+");
asm(" LD R6,Y+");
asm(" LD R5,Y+");
asm(" LD R4,Y+");
} /* MA_IntHandler_OVF0_TMR */
/*
**===========================================================================
** 5. INTERNAL FUNCTIONS (declared in Section 3.5)
**===========================================================================
*/
void intfunct(void)
{
//tratarea intrerperii timer pentru rtos
/* if(global_inc>=63)//pasul de 1 milisecunda
{
task_time++;//timpul taskului curent
if(task_time>=v_task[task_curent].nr_timpi)//testeaza daca s-a terminat timpul unui task
{
task_time=0;//timpul taskului curent devine 0
task_curent++;//incrementeaza taskul curent
if(task_curent==task_ultim)//daca a ajuns la ultimul task reia de la primul task
task_curent=0;
//calculeaza pointerul la stiva task-ului urmator
p_taskurmator=v_task[task_curent].adr_task+OSTaskStkSize;
OSCtxSw();//comuta contextul la cele doua task-uri
}
}*/
//OSCtxSw();
}
/*
**===========================================================================
** END OF FILE
**===========================================================================
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -