105 #ifndef _NZDEFAULT_TICK_H_
106 #define _NZDEFAULT_TICK_H_
118 #if defined(__PIC24FJ256GB206__) || defined(__PIC24FJ256GB208__) || defined(__PIC24FJ256GB210__) || defined(__PIC24FJ128GB106__) || defined(__PIC24FJ128GB108__) || defined(__PIC24FJ128GB110__)
119 #ifndef NZ_UTICKS_PER_MS
120 #define NZ_UTICKS_PER_MS 2000
122 #elif defined(__PIC32MX__)
124 #ifndef NZ_UTICKS_PER_MS
125 #define NZ_UTICKS_PER_MS 1250
130 #ifndef __INLINE_FUNCTION__
131 #define __INLINE_FUNCTION__ extern inline __attribute__((always_inline))
137 #ifndef nzINT_PRIORITY_TICK
138 #define nzINT_PRIORITY_TICK ( 5 ) //Define the interrupt priority level, 1-7 (7 is highest)
141 #ifndef nzINT_PRIORITY_UTICK
142 #define nzINT_PRIORITY_UTICK ( 6 ) //Define the interrupt priority level, 1-7 (7 is highest)
145 #if !defined(NZSYS_TICK_TMR2AND3_UTICK)
146 #define NZSYS_TICK_TMR2AND3_UTICK ( 0 ) //Use Timer 2 and 3 for a dedicated uTick counter - for utickXxx() functions
150 #elif defined(__PIC32MX__)
152 #define _T1IF IFS0bits.T1IF
158 typedef DWORD TICK32;
171 #define tickService() { \
212 #define tick16TestTmr(tmr) ( (((((tmr) - (tick_val.w[0]) ) & 0x8000))==0) ? 0 : 1)
224 #define tick16SetTmrMS(tmr, msVal) (tmr = (tick16Get() + msVal))
248 #define tick16GetElapsedMS(oldTick) ((WORD)((tick_val.w[0]) - (oldTick)))
266 #define tick16UpdateTmrMS(tmr, msVal) (tmr += msVal)
289 #define tick16ConvertFromMS(msVal) (msVal)
311 #define tick32Get_noDisi() (tick_val.Val)
341 #define tick32SetTmrMS(tmr, msVal) (tmr = (tick32Get() + msVal))
350 #define tick32TestTmr_noDisi(tmr) ((((tmr-tick_val.Val)&0x80000000)==0) ? 0 : 1)
364 #define tick32UpdateTmrMS(tmr, msVal) (tmr += msVal)
376 #define tick32UpdateTmrSec(tmr, secVal) (tmr += (((DWORD)secVal)*1000))
385 #define tick32UpdateTmrMin(tmr, minVal) (tmr += ( ((DWORD)minVal)*60000))
408 #define tick32ConvertFromMS(msVal) ((DWORD)(msVal))
438 #if (NZSYS_TICK_TMR2AND3_UTICK==1)
439 #define utick16Get() (TMR2)
452 #if (NZSYS_TICK_TMR2AND3_UTICK==0)
459 return ((
tick_val.word.LW*NZ_UTICKS_PER_MS) + tmrCpy);
466 #if (NZ_UTICKS_PER_MS==2000)
469 if (tmrCpy==2000) tmrCpy=0;
471 return (((
tick_val.word.LW+1)*NZ_UTICKS_PER_MS) + tmrCpy);
473 #error "NZ_UTICKS_PER_MS not supported!"
491 #if (NZSYS_TICK_TMR2AND3_UTICK==1)
495 ret.word.HW = TMR3HLD;
500 #endif //#if (NZSYS_TICK_TMR2AND3_UTICK==1)
511 #if (NZSYS_TICK_TMR2AND3_UTICK==1)
514 ret.word.HW = TMR3HLD;
523 return (DWORD)( ((DWORD)(
tick_val.Val*NZ_UTICKS_PER_MS)) + tmrCpy);
530 #if (NZ_UTICKS_PER_MS==2000)
533 if (tmrCpy==2000) tmrCpy=0;
535 return (DWORD)( ((DWORD)((
tick_val.Val+1)*NZ_UTICKS_PER_MS)) + tmrCpy);
537 #error "NZ_UTICKS_PER_MS not supported!"
539 #endif //#if (NZSYS_TICK_TMR2AND3_UTICK==1)
555 #define utick16TestTmr(tmr) ( (((((tmr) - (utick16Get()) ) & 0x8000))==0) ? 0 : 1)
582 #define utick16GetElapsedUS(oldTick) utick16ConvertToUS(((WORD)((utick16Get()) - (oldTick))))
592 #define utick16ConvertToUS(utickVal) ( ((WORD)utickVal) / ((WORD)(NZ_UTICKS_PER_MS/1000)) )
604 #define utick16ConvertFromUS(usVal) (WORD)( ((WORD)usVal) * (NZ_UTICKS_PER_MS/1000) )
622 #define utick32TestTmr(tmr) ((((tmr-utick32Get())&0x80000000)==0) ? 0 : 1)
632 #define utick32ConvertToUS(utickVal) ( ((DWORD)utickVal) / ((DWORD)(NZ_UTICKS_PER_MS/1000)) )
644 #define utick32ConvertFromUS(usVal) (DWORD)( ((DWORD)usVal) * (NZ_UTICKS_PER_MS/1000) )
659 #if (NZSYS_TICK_TMR2AND3_UTICK==1)
663 dw.word.HW = TMR3HLD;
664 #if (NZ_UTICKS_PER_MS==2000)
665 return ((WORD)(dw.Val/16));
667 #error "NZ_UTICKS_PER_MS not supported!"
682 #if (NZSYS_TICK_TMR2AND3_UTICK==1)
685 dw.word.HW = TMR3HLD;
686 #if (NZ_UTICKS_PER_MS==2000)
687 return ((WORD)(dw.Val/16));
689 #error "NZ_UTICKS_PER_MS not supported!"
699 #if (NZ_UTICKS_PER_MS==2000)
702 return ((
tick_val.word.LW*125) + (tmrCpy/16));
704 #error "NZ_UTICKS_PER_MS not supported!"
712 #if (NZ_UTICKS_PER_MS==2000)
715 if (tmrCpy==2000) tmrCpy=0;
717 return (( ((WORD)(
tick_val.word.LW+1))*125) + (tmrCpy/16));
719 #error "NZ_UTICKS_PER_MS not supported!"
721 #elif defined(__PIC32MX__)
724 #endif //#if (NZSYS_TICK_TMR2AND3_UTICK==1)
735 #if (NZSYS_TICK_TMR2AND3_UTICK==1)
739 dw.word.HW = TMR3HLD;
740 #if (NZ_UTICKS_PER_MS==2000)
743 #error "NZ_UTICKS_PER_MS not supported!"
760 #if (NZSYS_TICK_TMR2AND3_UTICK==1)
763 dw.word.HW = TMR3HLD;
764 #if (NZ_UTICKS_PER_MS==2000)
767 #error "NZ_UTICKS_PER_MS not supported!"
776 #if (NZ_UTICKS_PER_MS==2000)
777 return (DWORD)( ((DWORD)(
tick_val.Val*125)) + tmrCpy/16);
779 #error "NZ_UTICKS_PER_MS not supported!"
787 #if (NZ_UTICKS_PER_MS==2000)
790 if (tmrCpy==2000) tmrCpy=0;
792 return ( ((DWORD)((
tick_val.Val+1)*125)) + (tmrCpy/16));
794 #error "NZ_UTICKS_PER_MS not supported!"
796 #elif defined(__PIC32MX__)
798 #endif //#if (NZSYS_TICK_TMR2AND3_UTICK==1)
801 #endif //end of #define _NZDEFAULT_TICK_H_