|
1 /* |
|
2 This file is part of CanFestival, a library implementing CanOpen Stack. |
|
3 |
|
4 Copyright (C): Edouard TISSERANT and Francis DUPIN |
|
5 |
|
6 See COPYING file for copyrights details. |
|
7 |
|
8 This library is free software; you can redistribute it and/or |
|
9 modify it under the terms of the GNU Lesser General Public |
|
10 License as published by the Free Software Foundation; either |
|
11 version 2.1 of the License, or (at your option) any later version. |
|
12 |
|
13 This library is distributed in the hope that it will be useful, |
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 Lesser General Public License for more details. |
|
17 |
|
18 You should have received a copy of the GNU Lesser General Public |
|
19 License along with this library; if not, write to the Free Software |
|
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 */ |
|
22 |
|
23 #ifndef __APPLICFG_HC12__ |
|
24 #define __APPLICFG_HC12__ |
|
25 |
|
26 #include <string.h> |
|
27 #include <stdio.h> |
|
28 |
|
29 #include <../include/hcs12/asm-m68hc12/portsaccess.h> |
|
30 #include <../include/hcs12/asm-m68hc12/ports_def.h> |
|
31 #include <../include/hcs12/asm-m68hc12/ports.h> |
|
32 #include <../include/hcs12/interrupt.h> |
|
33 |
|
34 |
|
35 /// Define the architecture : little_endian or big_endian |
|
36 // ----------------------------------------------------- |
|
37 // Test : |
|
38 // UNS32 v = 0x1234ABCD; |
|
39 // char *data = &v; |
|
40 // |
|
41 // Result for a little_endian architecture : |
|
42 // data[0] = 0xCD; |
|
43 // data[1] = 0xAB; |
|
44 // data[2] = 0x34; |
|
45 // data[3] = 0x12; |
|
46 // |
|
47 // Result for a big_endian architecture : |
|
48 // data[0] = 0x12; |
|
49 // data[1] = 0x34; |
|
50 // data[2] = 0xAB; |
|
51 // data[3] = 0xCD; |
|
52 |
|
53 |
|
54 #define CANOPEN_BIG_ENDIAN |
|
55 |
|
56 // Use or not the PLL |
|
57 //#define USE_PLL |
|
58 |
|
59 #ifdef USE_PLL |
|
60 # define BUS_CLOCK 24 // If the quartz on the board is 16 MHz. If different, change this value |
|
61 #else |
|
62 # define BUS_CLOCK 8 // If the quartz on the board is 16 MHz. If different, change this value |
|
63 #endif |
|
64 |
|
65 /// Configuration of the serials port SCI0 and SCI1 |
|
66 // Tested : |
|
67 // SERIAL_SCI0_BAUD_RATE 9600 BUS_CLOCK 8 Send OK Receive not tested |
|
68 // SERIAL_SCI0_BAUD_RATE 19200 BUS_CLOCK 8 Send OK Receive not tested |
|
69 // SERIAL_SCI0_BAUD_RATE 38400 BUS_CLOCK 8 Send OK Receive not tested |
|
70 // SERIAL_SCI0_BAUD_RATE 57600 BUS_CLOCK 8 Send Failed Receive not tested |
|
71 // SERIAL_SCI0_BAUD_RATE 115200 BUS_CLOCK 8 Send Failed Receive not tested |
|
72 |
|
73 // SERIAL_SCI0_BAUD_RATE 9600 BUS_CLOCK 24 Send OK Receive not tested |
|
74 // SERIAL_SCI0_BAUD_RATE 19200 BUS_CLOCK 24 Send OK Receive not tested |
|
75 // SERIAL_SCI0_BAUD_RATE 38400 BUS_CLOCK 24 Send OK but init problems Receive not tested |
|
76 // SERIAL_SCI0_BAUD_RATE 57600 BUS_CLOCK 24 Send Failed Receive not tested |
|
77 // SERIAL_SCI0_BAUD_RATE 115200 BUS_CLOCK 24 Send Failed Receive not tested |
|
78 |
|
79 #define SERIAL_SCI0_BAUD_RATE 19200 |
|
80 #define SERIAL_SCI1_BAUD_RATE 9600 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 // Several hardware definitions functions |
|
88 // -------------------------------------- |
|
89 |
|
90 |
|
91 /// Initialisation of the serial port 0 |
|
92 extern void initSCI_0 (void); |
|
93 |
|
94 /// Initialisation of the serial port 1 |
|
95 extern void initSCI_1 (void); |
|
96 |
|
97 /// Convert an integer to a string in hexadecimal format |
|
98 /// If you do not wants to use a lastCar, put lastCar = '\0' (end of string) |
|
99 /// ex : value = 0XABCDEF and lastCar = '\n' |
|
100 /// buf[0] = '0' |
|
101 /// buf[1] = 'X' |
|
102 /// buf[2] = 'A' |
|
103 /// .... |
|
104 /// buf[7] = 'F' |
|
105 /// buf[8] = '\n' |
|
106 /// buf[9] = '\0' |
|
107 extern char * |
|
108 hex_convert (char *buf, unsigned long value, char lastCar); |
|
109 |
|
110 /// Print the string to the serial port sci |
|
111 /// (sci takes the values SCI0 or SCI1) |
|
112 extern void printSCI_str (char sci, const char * str); |
|
113 |
|
114 /// Print the number in hexadecimal to the serial port sci |
|
115 /// (sci takes the values SCI0 or SCI1) |
|
116 extern void printSCI_nbr (char sci, unsigned long nbr, char lastCar); |
|
117 |
|
118 /// to start using the PLL. Bus clock becomes 24 MHz if the quartz |
|
119 /// on the board is at 16 MHz |
|
120 extern void initPLL (void); |
|
121 |
|
122 /// Put here all the code to init the HCS12 |
|
123 extern void initHCS12 (void); |
|
124 |
|
125 // Integers |
|
126 #define INTEGER8 signed char |
|
127 #define INTEGER16 short |
|
128 #define INTEGER24 |
|
129 #define INTEGER32 long |
|
130 #define INTEGER40 |
|
131 #define INTEGER48 |
|
132 #define INTEGER56 |
|
133 #define INTEGER64 |
|
134 |
|
135 // Unsigned integers |
|
136 #define UNS8 unsigned char |
|
137 #define UNS16 unsigned short |
|
138 #define UNS32 unsigned long |
|
139 #define UNS24 |
|
140 #define UNS40 |
|
141 #define UNS48 |
|
142 #define UNS56 |
|
143 #define UNS64 |
|
144 |
|
145 // Whatever your microcontroller, the timer wont work if |
|
146 // TIMEVAL is not at least on 32 bits |
|
147 #define TIMEVAL UNS32 |
|
148 |
|
149 // The timer of the hcs12 counts from 0000 to 0xFFFF |
|
150 #define TIMEVAL_MAX 0xFFFF |
|
151 |
|
152 // The timer is incrementing every 4 us. |
|
153 #define MS_TO_TIMEVAL(ms) (ms * 250) |
|
154 #define US_TO_TIMEVAL(us) (us>>2) |
|
155 |
|
156 |
|
157 // Reals |
|
158 #define REAL32 float |
|
159 #define REAL64 double |
|
160 |
|
161 #include "can.h" |
|
162 |
|
163 |
|
164 /// Definition of MSG_ERR |
|
165 // --------------------- |
|
166 #ifdef DEBUG_ERR_CONSOLE_ON |
|
167 # define MSG_ERR(num, str, val) \ |
|
168 initSCI_0(); \ |
|
169 printSCI_nbr(SCI0, num, ' '); \ |
|
170 /* large printing on console */ \ |
|
171 printSCI_str(SCI0, str); \ |
|
172 printSCI_nbr(SCI0, val, '\n'); |
|
173 #else |
|
174 # define MSG_ERR(num, str, val) |
|
175 #endif |
|
176 |
|
177 /// Definition of MSG_WAR |
|
178 // --------------------- |
|
179 #ifdef DEBUG_WAR_CONSOLE_ON |
|
180 # define MSG_WAR(num, str, val) \ |
|
181 initSCI_0(); \ |
|
182 printSCI_nbr(SCI0, num, ' '); \ |
|
183 /* large printing on console */ \ |
|
184 printSCI_str(SCI0, str); \ |
|
185 printSCI_nbr(SCI0, val, '\n'); |
|
186 #else |
|
187 # define MSG_WAR(num, str, val) |
|
188 #endif |
|
189 |
|
190 |
|
191 #endif |
|
192 |
|
193 |