]> git.sur5r.net Git - freertos/blob - Source/portable/WizC/PIC18/Drivers/Tick/Tick.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Source / portable / WizC / PIC18 / Drivers / Tick / Tick.c
1 /*\r
2     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     This file is part of the FreeRTOS distribution.\r
5 \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
14     license details.\r
15 \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
19     more details.\r
20 \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
24 \r
25 \r
26     ***************************************************************************\r
27     *                                                                         *\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
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 /* \r
50 Changes from V3.0.0\r
51         + ISRcode is pulled inline and portTICKisr() is therefore\r
52           deleted from this file.\r
53 \r
54         + Prescaler logic for Timer1 added to allow for a wider\r
55           range of TickRates.\r
56 \r
57 Changes from V3.0.1\r
58 */\r
59 \r
60 #include <FreeRTOS.h>\r
61 #include <task.h>\r
62 \r
63 /* IO port constants. */\r
64 #define portBIT_SET             (1)\r
65 #define portBIT_CLEAR   (0)\r
66 \r
67 /* \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
72  */\r
73 #define portTIMER_COMPARE_BASE                  ((APROCFREQ/4)/configTICK_RATE_HZ)\r
74 \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
91 #else\r
92         #error "TickRate out of range"\r
93 #endif\r
94 \r
95 /*-----------------------------------------------------------*/\r
96 \r
97 /*\r
98  * Setup a timer for a regular tick.\r
99  */\r
100 void portSetupTick( void )\r
101 {\r
102         /*\r
103          * Interrupts are disabled when this function is called.\r
104          */\r
105 \r
106         /*\r
107          * Setup CCP1\r
108          * Provide the tick interrupt using a compare match on timer1.\r
109          */\r
110 \r
111         /*\r
112          * Set the compare match value.\r
113          */\r
114         CCPR1H = ( unsigned char ) ( ( portTIMER_COMPARE_VALUE >> 8 ) & 0xff );\r
115         CCPR1L = ( unsigned char )   ( portTIMER_COMPARE_VALUE & 0xff );\r
116 \r
117         /*\r
118          * Set Compare Special Event Trigger Mode\r
119          */\r
120         bCCP1M3         = portBIT_SET;\r
121         bCCP1M2         = portBIT_CLEAR;\r
122         bCCP1M1         = portBIT_SET;\r
123         bCCP1M0         = portBIT_SET;\r
124 \r
125         /*\r
126          * Enable CCP1 interrupt\r
127          */\r
128         bCCP1IE         = portBIT_SET;\r
129 \r
130         /*\r
131          * We are only going to use the global interrupt bit, so disable\r
132          * interruptpriorities and enable peripheral interrupts.\r
133          */\r
134         bIPEN           = portBIT_CLEAR;\r
135         bPEIE           = portBIT_SET;\r
136 \r
137         /*\r
138          * Set up timer1\r
139          * It will produce the system tick.\r
140          */\r
141 \r
142         /*\r
143          * Clear the time count\r
144          */\r
145         TMR1H = ( unsigned char ) 0x00;\r
146         TMR1L = ( unsigned char ) 0x00;\r
147 \r
148         /*\r
149          * Setup the timer\r
150          */\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
157         \r
158         bTMR1ON         = portBIT_SET;                          // Start timer1\r
159 }\r