2727 */
2828
2929/*
30- * Changes from V3.0.0
31- + ISRcode is pulled inline and portTICKisr() is therefore
32- + deleted from this file.
33- +
34- + Prescaler logic for Timer1 added to allow for a wider
35- + range of TickRates.
36- +
37- + Changes from V3.0.1
38- */
30+ Changes from V3.0.0
31+ + ISRcode is pulled inline and portTICKisr() is therefore
32+ deleted from this file.
33+
34+ + Prescaler logic for Timer1 added to allow for a wider
35+ range of TickRates.
36+
37+ Changes from V3.0.1
38+ */
3939
4040#include <FreeRTOS.h>
4141#include <task.h>
4242
4343/* IO port constants. */
44- #define portBIT_SET ( 1 )
45- #define portBIT_CLEAR ( 0 )
44+ #define portBIT_SET (1 )
45+ #define portBIT_CLEAR (0 )
4646
4747/*
4848 * Hardware setup for the tick.
4949 * We use a compare match on timer1. Depending on MPU-frequency
5050 * and requested tickrate, a prescaled value with a matching
5151 * prescaler are determined.
5252 */
53- #define portTIMER_COMPARE_BASE ( ( APROCFREQ / 4 ) / configTICK_RATE_HZ )
53+ #define portTIMER_COMPARE_BASE (( APROCFREQ/4)/ configTICK_RATE_HZ)
5454
55- #if portTIMER_COMPARE_BASE < 0x10000
56- #define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE )
57- #define portTIMER_COMPARE_PS1 ( portBIT_CLEAR )
58- #define portTIMER_COMPARE_PS0 ( portBIT_CLEAR )
55+ #if portTIMER_COMPARE_BASE < 0x10000
56+ #define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE)
57+ #define portTIMER_COMPARE_PS1 ( portBIT_CLEAR)
58+ #define portTIMER_COMPARE_PS0 ( portBIT_CLEAR)
5959#elif portTIMER_COMPARE_BASE < 0x20000
60- #define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE / 2 )
61- #define portTIMER_COMPARE_PS1 ( portBIT_CLEAR )
62- #define portTIMER_COMPARE_PS0 ( portBIT_SET )
60+ #define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE / 2)
61+ #define portTIMER_COMPARE_PS1 ( portBIT_CLEAR)
62+ #define portTIMER_COMPARE_PS0 ( portBIT_SET)
6363#elif portTIMER_COMPARE_BASE < 0x40000
64- #define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE / 4 )
65- #define portTIMER_COMPARE_PS1 ( portBIT_SET )
66- #define portTIMER_COMPARE_PS0 ( portBIT_CLEAR )
64+ #define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE / 4)
65+ #define portTIMER_COMPARE_PS1 ( portBIT_SET)
66+ #define portTIMER_COMPARE_PS0 ( portBIT_CLEAR)
6767#elif portTIMER_COMPARE_BASE < 0x80000
68- #define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE / 8 )
69- #define portTIMER_COMPARE_PS1 ( portBIT_SET )
70- #define portTIMER_COMPARE_PS0 ( portBIT_SET )
71- #else /* if portTIMER_COMPARE_BASE < 0x10000 */
68+ #define portTIMER_COMPARE_VALUE ( portTIMER_COMPARE_BASE / 8)
69+ #define portTIMER_COMPARE_PS1 ( portBIT_SET)
70+ #define portTIMER_COMPARE_PS0 ( portBIT_SET)
71+ #else
7272 #error "TickRate out of range"
73- #endif /* if portTIMER_COMPARE_BASE < 0x10000 */
73+ #endif
7474
7575/*-----------------------------------------------------------*/
7676
@@ -92,27 +92,27 @@ void portSetupTick( void )
9292 * Set the compare match value.
9393 */
9494 CCPR1H = ( uint8_t ) ( ( portTIMER_COMPARE_VALUE >> 8 ) & 0xff );
95- CCPR1L = ( uint8_t ) ( portTIMER_COMPARE_VALUE & 0xff );
95+ CCPR1L = ( uint8_t ) ( portTIMER_COMPARE_VALUE & 0xff );
9696
9797 /*
9898 * Set Compare Special Event Trigger Mode
9999 */
100- bCCP1M3 = portBIT_SET ;
101- bCCP1M2 = portBIT_CLEAR ;
102- bCCP1M1 = portBIT_SET ;
103- bCCP1M0 = portBIT_SET ;
100+ bCCP1M3 = portBIT_SET ;
101+ bCCP1M2 = portBIT_CLEAR ;
102+ bCCP1M1 = portBIT_SET ;
103+ bCCP1M0 = portBIT_SET ;
104104
105105 /*
106106 * Enable CCP1 interrupt
107107 */
108- bCCP1IE = portBIT_SET ;
108+ bCCP1IE = portBIT_SET ;
109109
110110 /*
111111 * We are only going to use the global interrupt bit, so disable
112112 * interruptpriorities and enable peripheral interrupts.
113113 */
114- bIPEN = portBIT_CLEAR ;
115- bPEIE = portBIT_SET ;
114+ bIPEN = portBIT_CLEAR ;
115+ bPEIE = portBIT_SET ;
116116
117117 /*
118118 * Set up timer1
@@ -128,12 +128,12 @@ void portSetupTick( void )
128128 /*
129129 * Setup the timer
130130 */
131- bRD16 = portBIT_SET ; /* 16-bit */
132- bT1CKPS1 = portTIMER_COMPARE_PS1 ; /* prescaler */
133- bT1CKPS0 = portTIMER_COMPARE_PS0 ; /* prescaler */
134- bT1OSCEN = portBIT_SET ; /* Oscillator enable */
135- bT1SYNC = portBIT_SET ; /* No external clock sync */
136- bTMR1CS = portBIT_CLEAR ; /* Internal clock */
137-
138- bTMR1ON = portBIT_SET ; /* Start timer1 */
131+ bRD16 = portBIT_SET ; // 16-bit
132+ bT1CKPS1 = portTIMER_COMPARE_PS1 ; // prescaler
133+ bT1CKPS0 = portTIMER_COMPARE_PS0 ; // prescaler
134+ bT1OSCEN = portBIT_SET ; // Oscillator enable
135+ bT1SYNC = portBIT_SET ; // No external clock sync
136+ bTMR1CS = portBIT_CLEAR ; // Internal clock
137+
138+ bTMR1ON = portBIT_SET ; // Start timer1
139139}
0 commit comments