eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dlcdhw_common.c
Go to the documentation of this file.
1 /**************************************************************************
2 *
3 * Copyright 2014 by Petr Gargulak. eGUI Community.
4 * Copyright 2009-2013 by Petr Gargulak. Freescale Semiconductor, Inc.
5 *
6 ***************************************************************************
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License Version 3
9 * or later (the "LGPL").
10 *
11 * As a special exception, the copyright holders of the eGUI project give you
12 * permission to link the eGUI sources with independent modules to produce an
13 * executable, regardless of the license terms of these independent modules,
14 * and to copy and distribute the resulting executable under terms of your
15 * choice, provided that you also meet, for each linked independent module,
16 * the terms and conditions of the license of that module.
17 * An independent module is a module which is not derived from or based
18 * on this library.
19 * If you modify the eGUI sources, you may extend this exception
20 * to your version of the eGUI sources, but you are not obligated
21 * to do so. If you do not wish to do so, delete this
22 * exception statement from your version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 *
28 * You should have received a copy of the GNU General Public License
29 * and the GNU Lesser General Public License along with this program.
30 * If not, see <http://www.gnu.org/licenses/>.
31 *
32 ***************************************************************************/
48 #include "d4d.h"
51 
53 
54  /******************************************************************************
55  * Macros
56  ******************************************************************************/
57 
58 
59  /******************************************************************************
60  * Functions definitions
61  ******************************************************************************/
62 
63  /**************************************************************/
69  /**************************************************************/
75  /**************************************************************/
82  {
83 
84  }
85 
86 
87 
88 
89 
90 
91 
92  #define MCU_BUS_CYCLES_100US (D4D_MCU_BUS_CLOCK / 10000)
93 
94  #ifdef MQX_CPU
95  // do nothing
96  #elif (D4D_MCU_TYPE == D4D_HCS08)
97 
98  #define MCU_BUS_CYCLES_100US_WITHOUT_OVERHEAD (MCU_BUS_CYCLES_100US - 18)
99  #define DELAY_LOOP_CNT (MCU_BUS_CYCLES_100US_WITHOUT_OVERHEAD / 5)
100 
101  static void Cpu_Delay100US(unsigned short us100)
102  {
103  (void)us100;
104  /* Total irremovable overhead: 16 cycles */
105  /* ldhx: 5 cycles overhead (load parameter into register) */
106  /* jsr: 5 cycles overhead (jump to subroutine) */
107  /* rts: 6 cycles overhead (return from subroutine) */
108 
109  /* aproximate irremovable overhead for each 100us cycle (counted) : 8 cycles */
110  /* aix: 2 cycles overhead */
111  /* cphx: 3 cycles overhead */
112  /* bne: 3 cycles overhead */
113  asm {
114  loop:
115  /* 100 us delay block begin */
116  /*
117  * Delay
118  * - requested : 100 us @ 25.165824MHz,
119  * - possible : 2517 c, 100016.59 ns, delta 16.59 ns
120  * - without removable overhead : 2509 c, 99698.7 ns
121  */
122  pshh /* (2 c: 79.47 ns) backup H */
123  pshx /* (2 c: 79.47 ns) backup X */
124  ldhx #DELAY_LOOP_CNT /* (3 c: 119.21 ns) number of iterations */
125  label0:
126  aix #-1 /* (2 c: 79.47 ns) decrement H:X */
127  cphx #0 /* (3 c: 119.21 ns) compare it to zero */
128  bne label0 /* (3 c: 119.21 ns) repeat 312x */
129  pulx /* (3 c: 119.21 ns) restore X */
130  pulh /* (3 c: 119.21 ns) restore H */
131  /* 100 us delay block end */
132  aix #-1 /* us100 parameter is passed via H:X registers */
133  cphx #0
134  bne loop /* next loop */
135  rts /* return from subroutine */
136  }
137  }
138 
139 
140  #elif (D4D_MCU_TYPE == D4D_HCS12) || (D4D_MCU_TYPE == D4D_HCS12X)
141 
142 
143  #define MCU_BUS_CYCLES_100US_WITHOUT_OVERHEAD (MCU_BUS_CYCLES_100US - 13)
144  #define DELAY_LOOP_CNT (MCU_BUS_CYCLES_100US_WITHOUT_OVERHEAD /3)
145 
146  #pragma CODE_SEG __NEAR_SEG NON_BANKED
147  #pragma NO_ENTRY
148  #pragma NO_EXIT
149  #pragma MESSAGE DISABLE C5703
150 
151  static void Cpu_Delay100US(unsigned short us100)
152  {
153  /* irremovable overhead (ignored): 13 cycles */
154  /* ldd: 2 cycles overhead (load parameter into register) */
155  /* jsr: 4 cycles overhead (call this function) */
156  /* rts: 7 cycles overhead (return from this function) */
157 
158  /* irremovable overhead for each 100us cycle (counted): 13 cycles */
159  /* dbne: 3 cycles overhead (return from this function) */
160 
161  asm {
162  loop:
163  /* 100 us delay block begin */
164  /*
165  * Delay
166  * - requested : 100 us @ 40MHz,
167  * - possible : 4000 c, 100000 ns
168  * - without removable overhead : 3997 c, 99925 ns
169  */
170  pshd /* (2 c: 50 ns) backup D */
171  ldd #DELAY_LOOP_CNT /* (2 c: 50 ns) number of iterations */
172  label0:
173  dbne d, label0 /* (3 c: 75 ns) repeat 1330x */
174  puld /* (3 c: 75 ns) restore D */
175  /* 100 us delay block end */
176  dbne d, loop /* us100 parameter is passed via D register */
177  rts /* return from subroutine */
178  }
179  }
180  #pragma CODE_SEG DEFAULT
181  //===========================================================================
182 
183 
184  #elif (D4D_MCU_TYPE == D4D_MCF51) || (D4D_MCU_TYPE == D4D_MCF52)
185 
186  #define MCU_BUS_CYCLES_100US_WITHOUT_OVERHEAD (MCU_BUS_CYCLES_100US - 9)
187  #define DELAY_LOOP_CNT (unsigned int)(MCU_BUS_CYCLES_100US_WITHOUT_OVERHEAD / 3)
188 
189  __declspec(register_abi) static void Cpu_Delay100US(unsigned int us100:__D0)
190  {
191  /* Total irremovable overhead: 9 cycles */
192  /* move: 1 cycles overhead (load parameter into register) */
193  /* jsr: 3 cycles overhead (jump to subroutine) */
194  /* rts: 5 cycles overhead (return from subroutine) */
195 
196  #pragma unused(us100)
197  asm {
198  naked
199  loop:
200  /* 100 us delay block begin */
201 
202  /*
203  * Delay
204  * - requested : 100 us @ 25.165824MHz,
205  * - possible : 2517 c, 100016.59 ns, delta 16.59 ns
206  * - without removable overhead : 2508 c, 99658.97 ns
207  */
208  move.l #DELAY_LOOP_CNT,d1 /* (1 c: 39.74 ns) number of iterations */
209  label0:
210  subq.l #0x01,d1 /* (1 c: 39.74 ns) decrement d1 */
211  bne.b label0 /* (2 c: 79.47 ns) repeat DELAY_LOOP_CNT x */
212  tpf /* (1 c: 39.74 ns) wait for 1 c */
213 
214  /* 100 us delay block end */
215  subq.l #0x01,d0 /* parameter is passed via d0 register */
216  bne.b loop /* next loop */
217  rts /* return from subroutine */
218  }
219  }
220 
221  // Kinetis
222  #elif (D4D_MCU_TYPE == D4D_MK)
223 // to do check the clock speed and compute the right value !!!!
224  static void Cpu_Delay100US(unsigned short us100)
225  {
226  unsigned int i;
227  while((us100--)){
228  for(i=0; i < (MCU_BUS_CYCLES_100US/10); i++)
229  {// 10 cycles delay
230  asm("NOP");
231  asm("NOP");
232  asm("NOP");
233  }
234  }
235  }
236 #elif (D4D_MCU_TYPE == D4D_MPC51)
237  //TODO tune length of hardware delay
238  static void Cpu_Delay100US(unsigned short us100)
239  {
240  unsigned int i;
241  while((us100--)){
242  for(i=0; i < (MCU_BUS_CYCLES_100US/10); i++)
243  {// 10 cycles delay
244  asm("nop");
245  asm("nop");
246  asm("nop");
247  }
248  }
249  }
250 
251 
252  #else
253  #error "Unsupported MCU type for delay loop in loe level common driver!"
254 
255 
256 
257  #endif
258 
259  void D4DLCD_Delay_ms_Common(unsigned short period) //delay routine (milliseconds)
260  {
261 
262  #ifdef MQX_CPU
263  _time_delay(period);
264  #else
265 
266  while (period != 0)
267  {
268  Cpu_Delay100US (10);
269  period--;
270  }
271  #endif
272 
273  }
D4D Driver main header file.
void D4DLCDHW_CommonInit(void)
D4D Driver private header file.
D4D driver - common low level driver header file.
static void Cpu_Delay100US(unsigned short us100)
#define MCU_BUS_CYCLES_100US
void D4DLCD_Delay_ms_Common(unsigned short period)
D4D driver - resistive touch screen driver function header file.
#define DELAY_LOOP_CNT