2 FreeRTOS.org V5.1.2 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
31 * This is a concise, step by step, 'hands on' guide that describes both *
\r
32 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
33 * explains numerous examples that are written using the FreeRTOS API. *
\r
34 * Full source code for all the examples is provided in an accompanying *
\r
37 ***************************************************************************
\r
38 ***************************************************************************
\r
40 Please ensure to read the configuration and relevant port sections of the
\r
41 online documentation.
\r
43 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
46 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
49 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
50 licensing and training services.
\r
55 + ISRcode is pulled inline and portTICKisr() is therefore
\r
56 deleted from this file.
\r
58 + Prescaler logic for Timer1 added to allow for a wider
\r
64 #include <FreeRTOS.h>
\r
67 /* IO port constants. */
\r
68 #define portBIT_SET (1)
\r
69 #define portBIT_CLEAR (0)
\r
72 * Hardware setup for the tick.
\r
73 * We use a compare match on timer1. Depending on MPU-frequency
\r
74 * and requested tickrate, a prescaled value with a matching
\r
75 * prescaler are determined.
\r
77 #define portTIMER_COMPARE_BASE ((APROCFREQ/4)/configTICK_RATE_HZ)
\r
79 #if portTIMER_COMPARE_BASE < 0x10000
\r
80 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE)
\r
81 #define portTIMER_COMPARE_PS1 (portBIT_CLEAR)
\r
82 #define portTIMER_COMPARE_PS0 (portBIT_CLEAR)
\r
83 #elif portTIMER_COMPARE_BASE < 0x20000
\r
84 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 2)
\r
85 #define portTIMER_COMPARE_PS1 (portBIT_CLEAR)
\r
86 #define portTIMER_COMPARE_PS0 (portBIT_SET)
\r
87 #elif portTIMER_COMPARE_BASE < 0x40000
\r
88 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 4)
\r
89 #define portTIMER_COMPARE_PS1 (portBIT_SET)
\r
90 #define portTIMER_COMPARE_PS0 (portBIT_CLEAR)
\r
91 #elif portTIMER_COMPARE_BASE < 0x80000
\r
92 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 8)
\r
93 #define portTIMER_COMPARE_PS1 (portBIT_SET)
\r
94 #define portTIMER_COMPARE_PS0 (portBIT_SET)
\r
96 #error "TickRate out of range"
\r
99 /*-----------------------------------------------------------*/
\r
102 * Setup a timer for a regular tick.
\r
104 void portSetupTick( void )
\r
107 * Interrupts are disabled when this function is called.
\r
112 * Provide the tick interrupt using a compare match on timer1.
\r
116 * Set the compare match value.
\r
118 CCPR1H = ( unsigned portCHAR ) ( ( portTIMER_COMPARE_VALUE >> 8 ) & 0xff );
\r
119 CCPR1L = ( unsigned portCHAR ) ( portTIMER_COMPARE_VALUE & 0xff );
\r
122 * Set Compare Special Event Trigger Mode
\r
124 bCCP1M3 = portBIT_SET;
\r
125 bCCP1M2 = portBIT_CLEAR;
\r
126 bCCP1M1 = portBIT_SET;
\r
127 bCCP1M0 = portBIT_SET;
\r
130 * Enable CCP1 interrupt
\r
132 bCCP1IE = portBIT_SET;
\r
135 * We are only going to use the global interrupt bit, so disable
\r
136 * interruptpriorities and enable peripheral interrupts.
\r
138 bIPEN = portBIT_CLEAR;
\r
139 bPEIE = portBIT_SET;
\r
143 * It will produce the system tick.
\r
147 * Clear the time count
\r
149 TMR1H = ( unsigned portCHAR ) 0x00;
\r
150 TMR1L = ( unsigned portCHAR ) 0x00;
\r
155 bRD16 = portBIT_SET; // 16-bit
\r
156 bT1CKPS1 = portTIMER_COMPARE_PS1; // prescaler
\r
157 bT1CKPS0 = portTIMER_COMPARE_PS0; // prescaler
\r
158 bT1OSCEN = portBIT_SET; // Oscillator enable
\r
159 bT1SYNC = portBIT_SET; // No external clock sync
\r
160 bTMR1CS = portBIT_CLEAR; // Internal clock
\r
162 bTMR1ON = portBIT_SET; // Start timer1
\r