2 FreeRTOS V5.4.2 - 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 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
50 + ISRcode is pulled inline and portTICKisr() is therefore
\r
51 deleted from this file.
\r
53 + Prescaler logic for Timer1 added to allow for a wider
\r
59 #include <FreeRTOS.h>
\r
62 /* IO port constants. */
\r
63 #define portBIT_SET (1)
\r
64 #define portBIT_CLEAR (0)
\r
67 * Hardware setup for the tick.
\r
68 * We use a compare match on timer1. Depending on MPU-frequency
\r
69 * and requested tickrate, a prescaled value with a matching
\r
70 * prescaler are determined.
\r
72 #define portTIMER_COMPARE_BASE ((APROCFREQ/4)/configTICK_RATE_HZ)
\r
74 #if portTIMER_COMPARE_BASE < 0x10000
\r
75 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE)
\r
76 #define portTIMER_COMPARE_PS1 (portBIT_CLEAR)
\r
77 #define portTIMER_COMPARE_PS0 (portBIT_CLEAR)
\r
78 #elif portTIMER_COMPARE_BASE < 0x20000
\r
79 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 2)
\r
80 #define portTIMER_COMPARE_PS1 (portBIT_CLEAR)
\r
81 #define portTIMER_COMPARE_PS0 (portBIT_SET)
\r
82 #elif portTIMER_COMPARE_BASE < 0x40000
\r
83 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 4)
\r
84 #define portTIMER_COMPARE_PS1 (portBIT_SET)
\r
85 #define portTIMER_COMPARE_PS0 (portBIT_CLEAR)
\r
86 #elif portTIMER_COMPARE_BASE < 0x80000
\r
87 #define portTIMER_COMPARE_VALUE (portTIMER_COMPARE_BASE / 8)
\r
88 #define portTIMER_COMPARE_PS1 (portBIT_SET)
\r
89 #define portTIMER_COMPARE_PS0 (portBIT_SET)
\r
91 #error "TickRate out of range"
\r
94 /*-----------------------------------------------------------*/
\r
97 * Setup a timer for a regular tick.
\r
99 void portSetupTick( void )
\r
102 * Interrupts are disabled when this function is called.
\r
107 * Provide the tick interrupt using a compare match on timer1.
\r
111 * Set the compare match value.
\r
113 CCPR1H = ( unsigned portCHAR ) ( ( portTIMER_COMPARE_VALUE >> 8 ) & 0xff );
\r
114 CCPR1L = ( unsigned portCHAR ) ( portTIMER_COMPARE_VALUE & 0xff );
\r
117 * Set Compare Special Event Trigger Mode
\r
119 bCCP1M3 = portBIT_SET;
\r
120 bCCP1M2 = portBIT_CLEAR;
\r
121 bCCP1M1 = portBIT_SET;
\r
122 bCCP1M0 = portBIT_SET;
\r
125 * Enable CCP1 interrupt
\r
127 bCCP1IE = portBIT_SET;
\r
130 * We are only going to use the global interrupt bit, so disable
\r
131 * interruptpriorities and enable peripheral interrupts.
\r
133 bIPEN = portBIT_CLEAR;
\r
134 bPEIE = portBIT_SET;
\r
138 * It will produce the system tick.
\r
142 * Clear the time count
\r
144 TMR1H = ( unsigned portCHAR ) 0x00;
\r
145 TMR1L = ( unsigned portCHAR ) 0x00;
\r
150 bRD16 = portBIT_SET; // 16-bit
\r
151 bT1CKPS1 = portTIMER_COMPARE_PS1; // prescaler
\r
152 bT1CKPS0 = portTIMER_COMPARE_PS0; // prescaler
\r
153 bT1OSCEN = portBIT_SET; // Oscillator enable
\r
154 bT1SYNC = portBIT_SET; // No external clock sync
\r
155 bTMR1CS = portBIT_CLEAR; // Internal clock
\r
157 bTMR1ON = portBIT_SET; // Start timer1
\r