📄 lld_eft.c
字号:
/*____________________________________________________________________________| FILE: lld_eft.c| PROJECT: OS20_ACCORDO+| SW-COMPONENT: |_____________________________________________________________________________| DESCRIPTION: timer function|_____________________________________________________________________________| COPYRIGHT: (c) 2005 STMicroelectronics, Arzano (ITALY)| HISTORY:| Date | Modification | Author|_____________________________________________________________________________| 05.10.27 | Initial revision | M. De Martino|____________________________________________________________________________*/#include "lld_eft.h"#include "lld_eic.h"#ifdef __cplusplusextern "C" {#endif/************************************************************************|defines and macros (scope: module-local)|-----------------------------------------------------------------------*/typedef struct rEft{ tU16 Icar; /* addr offset = 0x00 */ intra16; tU16 Icbr; /* addr offset = 0x04 */ intra16; tU16 Ocar; /* addr offset = 0x08 */ intra16; tU16 Ocbr; /* addr offset = 0x0C */ intra16; tU16 Cntr; /* addr offset = 0x10 */ intra16; struct { tU16 ecken:1; tU16 exedg:1; tU16 iedga:1; tU16 iedgb:1; tU16 pwm:1; tU16 opm:1; tU16 ocae:1; tU16 ocbe:1; tU16 olvla:1; tU16 olvlb:1; tU16 folva:1; tU16 folvb:1; tU16 dma:2; tU16 pwmi:1; tU16 en:1; } Cr1; /* addr offset = 0x14 */ intra16; struct { tU16 cc:8; tU16 reserved:2; tU16 dmaie:1; tU16 ocbie:1; tU16 icbie:1; tU16 toe:1; tU16 ocaie:1; tU16 icaie:1; } Cr2; /* addr offset = 0x18 */ intra16; struct { tU16 reserved:11; tU16 ocfb:1; tU16 icfb:1; tU16 tof:1; tU16 ocfa:1; tU16 icfa:1; } sr; /* addr offset = 0x1C */} rEft;#ifdef OS20_USE_TIMER1/* [RB] removed since it is not used by OS20. In the Application *//* we use our own access method *//* Place Eft1 pheripheral according to scatter file */#pragma arm section zidata = "Eft1_map" volatile rEft Eft1;#endif // OS20_USE_TIMER1 #pragma arm section zidata/* Place Eft0 pheripheral according to scatter file */#pragma arm section zidata = "Eft0_map" volatile rEft Eft0; #pragma arm section zidata#define TIMER_SET_PWM 0x0010 /* Set PWM mode */#define TIMER_SET_OPM 0x0020 /* Set One Pulse mode */#define INCA_MSK 0x8000#define INCB_MSK 0x1000#define OCFA_MSK 0x4000#define OCFB_MSK 0x0800#define TMR_OVF 0x2000#define TIMER_MAIN#define ResetCounter(id) wr16_reg(id,Cntr,0); \ { \ tU16 temp = rd16_reg(id,Cr2); \ wr16_reg(id,Cr2,0x00FF); \ wr16(id,Cr1,en,1); \ while (!rd16(id,sr,tof)) \ ; \ wr16(id,Cr1,en,0); \ wr16_reg(id,Cr2,temp); \ } \ wr16_reg(id,sr,0xDFFF); \/************************************************************************|typedefs (scope: module-local)|-----------------------------------------------------------------------*//************************************************************************| variable definition (scope: global)|-----------------------------------------------------------------------*//************************************************************************| variable definition (scope: module-local)|-----------------------------------------------------------------------*/#if 0 // [RB] not usedstatic tU16 Eft_TimValueA;static tU16 Eft_TimValueB;/* Timer accumulator for Timer A */static tSInt Eft_TimAccuValA;static tSInt Eft_TimAccuA;#endif/*****************-*******************************************************|function prototype inclusion (scope: module-local)|-----------------------------------------------------------------------*//************************************************************************|function prototype (scope: module-local)|-----------------------------------------------------------------------*/#if 0 // [RB] unuesedstatic tVoid EFT_Timer0TofMgm (void);static tU16 EFT_ConvTime2EftVal_ns (tU32 u32Time);static tU32 EFT_ConvTime2EftVal_us (tU32 u32Time);#endif/* Al: custom interrupt manager */static tVoid INT_EFT_Default_manager (void);/* Al *//************************************************************************ | variable definition (scope: module-local) |-----------------------------------------------------------------------*//* Al: custom interrupt manager */t_EFT_FctPtr INT_EFT_EndTr_Mgr_Str [EFT_TYPE_NUM] = { DEFAULT_EFT_MGR, DEFAULT_EFT_MGR, DEFAULT_EFT_MGR, DEFAULT_EFT_MGR};/* Al *//************************************************************************|function implementation (scope: module-local)|-----------------------------------------------------------------------*//* Al: custom interrupt manager */static tVoid INT_EFT_Default_manager (void) {}/* Al */#if 0 // [RB] commented out to save ROM space/************************************************************************* ** FUNCTIONS ** ** EFT_Timer0TofMgm ** ** DESCRIPTION ** ** Timer0 overflow management ** ** CALLS ** ** Odometer counter overflow function ** ** INPUTS ** ** None ** OUTPUTS ** ** None ** *************************************************************************/static tVoid EFT_Timer0TofMgm (void){}/************************************************************************|function implementation (scope: global)|-----------------------------------------------------------------------*//* Al: custom interrupt manager */tBool EFT_Install_Manager (tU8 type, t_EFT_FctPtr MgrPtr){ if (EFT_TYPE_NUM <= type) { return FALSE ; } INSTALL_EFT_MANAGER(type, MgrPtr); return TRUE ; } /* Al */#endif/************************************************************************* ** FUNCTIONS ** ** EFT_TimerConfig ** ** DESCRIPTION ** ** Config EFT in required mode ** ** CALLS ** ** LLD macros ** ** INPUTS ** ** tU8 TimerId: Timer identificator ** tU8 TimerMode: Timer mode ** ** OUTPUTS ** ** None ** *************************************************************************/#if 0 // [RB] commented out to recover ROM space, seems unusedtVoid EFT_TimerConfig (tU8 TimerId, tU8 TimerMode, tU32 TimerCompValueA, tU32 TimerCompValueB, tU8 dmasource, tBool dma_int){ if (0 != TimerCompValueA && TimerMode == OUTPUT_COM_MODE) { Eft_TimAccuValA = (tU32)EFT_ConvTime2EftVal_us (TimerCompValueA); if (Eft_TimAccuValA > EFT_MAX_TIMER_PROGRAMMATION) { TimerCompValueA = EFT_MAX_TIMER_PROGRAMMATION; Eft_TimAccuA = Eft_TimAccuValA - EFT_MAX_TIMER_PROGRAMMATION; } else { TimerCompValueA = Eft_TimAccuValA; Eft_TimAccuA = 0; } } else if (0 != TimerCompValueA) { TimerCompValueA = (tU32)EFT_ConvTime2EftVal_ns (TimerCompValueA); Eft_TimAccuA = 0; Eft_TimAccuValA = 0; } else { Eft_TimAccuA = 0; Eft_TimAccuValA = 0; } if (0 != TimerCompValueB) { TimerCompValueB = (tU16)EFT_ConvTime2EftVal_us (TimerCompValueB); } if(EFT1 == TimerId) {#ifdef OS20_USE_TIMER1 wr16_reg(Eft1,Cr1,0x0000); /* Disable timer */ wr16_reg(Eft1,Cr2,0x0000); /* Reset control reg Cr2 */ switch(TimerMode){ case PWM_MODE: wr16_reg(Eft1,Ocar,TimerCompValueA);/* Program OutputCompare Reg A */ wr16_reg(Eft1,Ocbr,TimerCompValueB);/* Program OutputCompare Reg B (for reload value) */ wr16_reg(Eft1,Cr2,TIMER_PRES_VAL); /* Program Control Reg 2 (prescaler) */ wr16(Eft1,Cr2,ocbie,1); /* Enable IRQ */ wr16_reg(Eft1,Cr1,TIMER_SET_PWM); /* Set PWM mode */ break; case OUTPUT_COM_MODE: wr16_reg(Eft1,Ocar,TimerCompValueA);/* Program OutputCompare Reg A */ wr16_reg(Eft1,Ocbr,TimerCompValueB);/* Program OutputCompare Reg B */ wr16(Eft1,Cr2,cc,TIMER_PRES_VAL); /* Program Control Reg 2 (prescaler) */ wr16(Eft1,Cr1,dma,dmasource); /* Program DMA source select */ if(0 != TimerCompValueA) /* Enable IRQ only if output comapare != 0 */ { Eft_TimValueA = (tU16)TimerCompValueA; wr16(Eft1,Cr2,ocaie,1); /* Enable IRQ */ } if(0 != TimerCompValueB) { Eft_TimValueB = (tU16)TimerCompValueB; wr16(Eft1,Cr2,ocbie,1); /* Enable IRQ */ } if (dma_int) { wr16(Eft1,Cr2,dmaie,1); /* Enable DMA IRQ */ } else { wr16(Eft1,Cr2,dmaie,0); /* Enable DMA IRQ */ } break; case PULSE_MODE: wr16_reg(Eft1,Ocar,TimerCompValueA);/* Program OutputCompare Reg A */ wr16_reg(Eft1,Cr2,TIMER_PRES_VAL); /* Program Control Reg 2 (prescaler) */ wr16_reg(Eft1,Cr1,TIMER_SET_OPM); /* Set PWM mode */ wr16(Eft1,Cr1,olvlb,1); /* Level 1 in the OCMPA pin */ wr16(Eft1,Cr1,olvla,0); /* Level 0 in the OCMPA pin */ wr16(Eft1,Cr1,iedga,1); /* Rising edge in the ICAPA */ break; case COUNTER_MODE: wr16(Eft1,Cr1,ecken,1); /* Use external clock */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -