2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
51 + ISRcode is pulled inline and portTICKisr() is therefore
\r
52 deleted from this file.
\r
54 + Prescaler logic for Timer1 added to allow for a wider
\r
60 #include <FreeRTOS.h>
\r
63 /* IO port constants. */
\r
64 #define portBIT_SET (1)
\r
65 #define portBIT_CLEAR (0)
\r
68 * Hardware setup for the tick.
\r
69 * We use a compare match on timer1. Depending on MPU-frequency
\r
70 * and requested tickrate, a prescaled value with a matching
\r
71 * prescaler are determined.
\r
73 #define portTIMER_COMPARE_BASE ((APROCFREQ/4)/configTICK_RATE_HZ)
\r
75 #if portTIMER_COMPARE_BASE < 0x10000
\r
76 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE)
\r
77 #define portTIMER_COMPARE_PS1 (portBIT_CLEAR)
\r
78 #define portTIMER_COMPARE_PS0 (portBIT_CLEAR)
\r
79 #elif portTIMER_COMPARE_BASE < 0x20000
\r
80 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 2)
\r
81 #define portTIMER_COMPARE_PS1 (portBIT_CLEAR)
\r
82 #define portTIMER_COMPARE_PS0 (portBIT_SET)
\r
83 #elif portTIMER_COMPARE_BASE < 0x40000
\r
84 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 4)
\r
85 #define portTIMER_COMPARE_PS1 (portBIT_SET)
\r
86 #define portTIMER_COMPARE_PS0 (portBIT_CLEAR)
\r
87 #elif portTIMER_COMPARE_BASE < 0x80000
\r
88 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 8)
\r
89 #define portTIMER_COMPARE_PS1 (portBIT_SET)
\r
90 #define portTIMER_COMPARE_PS0 (portBIT_SET)
\r
92 #error "TickRate out of range"
\r
95 /*-----------------------------------------------------------*/
\r
98 * Setup a timer for a regular tick.
\r
100 void portSetupTick( void )
\r
103 * Interrupts are disabled when this function is called.
\r
108 * Provide the tick interrupt using a compare match on timer1.
\r
112 * Set the compare match value.
\r
114 CCPR1H = ( unsigned char ) ( ( portTIMER_COMPARE_VALUE >> 8 ) & 0xff );
\r
115 CCPR1L = ( unsigned char ) ( portTIMER_COMPARE_VALUE & 0xff );
\r
118 * Set Compare Special Event Trigger Mode
\r
120 bCCP1M3 = portBIT_SET;
\r
121 bCCP1M2 = portBIT_CLEAR;
\r
122 bCCP1M1 = portBIT_SET;
\r
123 bCCP1M0 = portBIT_SET;
\r
126 * Enable CCP1 interrupt
\r
128 bCCP1IE = portBIT_SET;
\r
131 * We are only going to use the global interrupt bit, so disable
\r
132 * interruptpriorities and enable peripheral interrupts.
\r
134 bIPEN = portBIT_CLEAR;
\r
135 bPEIE = portBIT_SET;
\r
139 * It will produce the system tick.
\r
143 * Clear the time count
\r
145 TMR1H = ( unsigned char ) 0x00;
\r
146 TMR1L = ( unsigned char ) 0x00;
\r
151 bRD16 = portBIT_SET; // 16-bit
\r
152 bT1CKPS1 = portTIMER_COMPARE_PS1; // prescaler
\r
153 bT1CKPS0 = portTIMER_COMPARE_PS0; // prescaler
\r
154 bT1OSCEN = portBIT_SET; // Oscillator enable
\r
155 bT1SYNC = portBIT_SET; // No external clock sync
\r
156 bTMR1CS = portBIT_CLEAR; // Internal clock
\r
158 bTMR1ON = portBIT_SET; // Start timer1
\r