1 /* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
2 /* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
3 /* ELIGIBILITY FOR ANY PURPOSES. */
4 /* (C) Fujitsu Microelectronics Europe GmbH */
5 ;=========================================================================================
7 ;=========================================================================================
14 ; 4.1 Controller device
15 ; 4.2 Boot / flash security
16 ; 4.3 Stack type and stack size
17 ; 4.4 Copy code from flash to I-RAM
19 ; 4.6 Low-level library interface
20 ; 4.7 Clock Configuration
21 ; 4.7.1 Clock selection
22 ; 4.7.2 Select Clock Modulator
23 ; 4.8 External bus interface
24 ; 4.8.1 Select chipselect
25 ; 4.8.2 Set memory addressing for chipselects
26 ; 4.8.3 Configure chipselect area
27 ; 4.8.4 Set wait cycles for chipselects
28 ; 4.8.5 Configure chipselects SDRAM memory only
29 ; 4.8.6 Referesh control register RCR
30 ; 4.8.7 Terminal and timing control register
31 ; 4.8.8 Enable / disable I-cache
32 ; 4.8.9 Enable CACHE for chipselect
33 ; 4.8.10 Select external bus mode (data lines)
34 ; 4.8.11 Select external bus mode (address lines)
35 ; 4.8.12 Select external bus mode (control signals)
37 ; 5 Definitions of Configurations
39 ; 6 Section and data declaration
40 ; 6.1 Define stack size
44 ; 7.1 Initialise stack pointer and table base register
45 ; 7.2 Check for CSV reset and set CSV
46 ; 7.3 Check clock condition
47 ; 7.4 Restore default settings after reset
48 ; 7.4.1 Disable clock modulator
49 ; 7.4.2 Check if running on sub clock, change to main clock
50 ; 7.4.3 Disable sub clock
51 ; 7.4.4 Check if running on PLL, gear down PLL
53 ; 7.4.6 Set to main clock
54 ; 7.5 Set memory controller
56 ; 7.6.1 Set Voltage Regulator Settings
57 ; 7.6.2 Power on clock modulator - clock modulator part I
58 ; 7.6.3 Set CLKR register w/o clock mode
60 ; 7.6.5 Wait for PLL oscillation stabilisation
62 ; 7.6.6.1 Set CPU and peripheral clock
63 ; 7.6.6.2 Set external bus interface clock
64 ; 7.6.6.3 Set CAN clock prescaler
65 ; 7.6.6.4 Switch main clock mode
66 ; 7.6.6.5 Switch sub clock mode
67 ; 7.6.6.6 Switch to PLL mode
68 ; 7.6.7 Enable frequncy modulation - clock modulator part II
69 ; 7.7 Set BusInterface
70 ; 7.7.1 Disable all CS
71 ; 7.7.2 Clear TCR register
80 ; 7.7.11 Set special SDRAM config register
81 ; 7.7.12 set Port function register
82 ; 7.7.13 Set TCR register
83 ; 7.7.14 Enable cache for selected CS
84 ; 7.7.15 Set SDRAM referesh control register
85 ; 7.7.16 Enable used CS
86 ; 7.7.17 I-cache on/off
87 ; 7.7.18 Set port function register to general as I/O-port
88 ; 7.8 Copy code from flash to I-RAM
91 ; 7.11 Copy Init section from ROM to RAM
92 ; 7.12 C library initialization
93 ; 7.13 Call C++ constructors
94 ; 7.14 Call main routine
95 ; 7.15 Return from main function
97 ;=========================================================================================
99 ;=========================================================================================
100 ; Fujitsu Microelectronics Europe GmbH
101 ; http://emea.fujitsu.com/microelectronics
103 ; The following software is for demonstration purposes only. It is not fully
104 ; tested, nor validated in order to fullfill its task under all circumstances.
105 ; Therefore, this software or any part of it must only be used in an evaluation
106 ; laboratory environment.
107 ; This software is subject to the rules of our standard DISCLAIMER, that is
108 ; delivered with our SW-tools on the Fujitsu Microcontrollers CD/DVD (V3.4 or
109 ; higher "\START.HTM") or on our Internet Pages:
110 ; http://www.fme.gsdc.de/gsdc.htm
111 ; http://emea.fujitsu.com/microelectronics
113 ;=========================================================================================
115 ;=========================================================================================
117 ;=========================================================================================
118 ; MB914xx (FR60 CORE ONLY) Series C Compiler's
120 ; Startup file for memory and basic controller initialisation
121 ;=========================================================================================
124 ; 2005-04-18 V1.0 UMa Release first version
125 ; 2005-06-17 V1.1 UMa Added bus interface, modified c++ startup
126 ; 2005-06-28 V1.2 UMa minor changes
127 ; 2005-07-27 V1.3 UMa default values changed
128 ; 2005-10-04 V1.4 UMa changed code 'Call main Routine'
129 ; Added secutiy section for MB91F467D
130 ; Added Flash Access Read Timing setting section;
131 ; 2005-10-04 V1.5 UMa Added Flash Controller Section
132 ; 2005-10-28 V1.6 UMa Check for CSV reset
133 ; 2005-11.16 V1.7 UMa Monitor Debugger support added: Copy of intvect Table
134 ; Ext. Int 0 as abort function
135 ; Changed PLL-Startup, Reset HWWD added
136 ; 2005-11-16 V1.7 UMa Examples for MUL_G changed
137 ; 2006-02-14 V1.8 UMa mb91464a added
138 ; Settings for Clock Spervisor added
139 ; Name of Section SECURITY changed to SECURITY_VECTORS
140 ; Example values for gear-up changed
141 ; 2006-03-17 V1.9 UMa Changed Startup for Monitor Debugger
142 ; 2006-04-24 v2.0 UMa Added MB91465K and MB91469G
143 ; 2006-05-03 v2.1 UMa Added MB91461R; removed MB91V460A
144 ; Added settings for the external bus-interface
145 ; 2006-07-28 v2.2 UMa Added I-RAM copy function (ROM -> IRAM)
146 ; Added default settings for FLASH Access Read Timing
148 ; Changed default settings for FLASH cache configuration
150 ; Changed check for clock startup
151 ; 2006-08-16 v2.3 MVo Corrected Boot Security Sector Addresses for MB91469G
152 ; 2006-10-06 v2.4 UMa Added new devices
153 ; Corrected typo in I_RAM to flash copy function
154 ; Changed default settings for flash cache configuration
155 ; Changed comments for SDRAM bus interface configuration
156 ; Changed comments and default setting of CAN Prescaler
158 ; Added Settings for REGSEL Register
159 ; 2007-02-13 v2.5 UMa Introduction of default configurations
160 ; Changed I_RAM to flash copy function
163 ;=========================================================================================
165 ;=========================================================================================
167 ; CHECK ALL OPTIONS WHETHER THEY FIT TO THE APPLICATION;
169 ; Configure this startup file in the "Settings" section. Search for
170 ; comments with leading "; <<<". This points to the items to be set.
171 ;=========================================================================================
178 ;=========================================================================================
179 ; 4.1 Controller Device
180 ;=========================================================================================
181 #set MB91464A 2 ; MB91460 series
183 #set MB91467B 10 ; MB91460 series
185 #set MB91467C 11 ; MB91460 series
187 #set MB91467D 4 ; MB91460 series
189 #set MB91469G 6 ; MB91460 series
191 #set MB91465K 3 ; MB91460 series
193 #set MB91463N 8 ; MB91460 series
195 #set MB91461R 1 ; MB91460 series
196 #set MB91467R 5 ; MB91460 series
198 #set MB91465X 9 ; MB91460 series
200 #set others 7 ; MB91460 series
204 #set DEVICE MB91465K ; <<< select device
206 ;=========================================================================================
207 ; 4.2 Boot / Flash Security
208 ;=========================================================================================
210 #set BOOT_FLASH_SEC OFF ; <<< BOOT and Flash Security Vector
212 ; The flash devices have two flash and two boot security vectors. It is important to set
213 ; the four vectors correctly. Otherwise it might be possible, that the flash device is
214 ; not accessible any more via the bootrom. Please read carefully the hardware manual.
216 ; OFF: The security feature is switch off. The section SECURITY_VECTORS is reserved and
217 ; the vectors are set.
218 ; ON: IMPORTANT! The security vectors are not set. But the section SECURITY_VECTORS
221 ; Note: This feature is not supported by every device. Please check the data sheet. This
222 ; feature is not available on MB91461R.
224 ;=========================================================================================
225 ; 4.3 Stack Type and Stack Size
226 ;=========================================================================================
228 #set USRSTACK 0 ; user stack: for main program
229 #set SYSSTACK 1 ; system stack: for main program and
233 #set STACKUSE SYSSTACK ; <<< set active stack
235 #set STACK_RESERVE ON ; <<< reserve stack area in
237 #set STACK_SYS_SIZE 0x400-4 ; <<< byte size of System stack
238 #set STACK_USR_SIZE 0x2 ; <<< byte size of User stack
240 ; - If the active stack is set to SYSSTACK, it is used for main program and interrupts.
241 ; In this case, the user stack could be set to a dummy size. If the active stack is
242 ; set to user stack, it is used for the main program but the system stack is
243 ; automatically activated, if an interrupt is serviced. Both stack areas must have a
245 ; - If STACK_RESERVE is ON, the sections USTACK and SSTACK are reserved in this module.
246 ; Otherwise, they have to be reserved in other modules. If STACK_RESERVE is OFF, the
247 ; size definitions STACK_SYS_SIZE and STACK_USR_SIZE have no meaning.
248 ; - Even if they are reverved in other modules, they are still initialised in this
251 ; Note: Several library functions require quite a big stack (due to ANSI).
252 ; Check the stack information files (*.stk) in the LIB\911 directory.
254 ;=========================================================================================
255 ; 4.4 Copy code from Flash to I-RAM
256 ;=========================================================================================
258 #set I_RAM ON ; <<< select if code in section IRAM
261 ; If this option is activated code located in the section IRAM is copied during startup
262 ; from ROM to the instruction-RAM. The code is linked for the instruction-RAM.
264 ;=========================================================================================
265 ; 4.7 Clock Configuration
266 ;=========================================================================================
267 ;=========================================================================================
268 ; 4.7.1 Clock Selection
269 ;=========================================================================================
274 ; Sub-oscillation input: 32 kHz
275 #set SUB_32KHZ_CPU__32KHZ_PER_32KHZ_EXT_32KHZ_CAN__2MHZ 0x11
277 ; Oscillation input: 4 MHz
278 #set MAIN_4MHZ_CPU___2MHZ_PER__1MHZ_EXT__1MHZ_CAN__2MHZ 0x21
279 #set PLL_4MHZ__CPU__48MHZ_PER_16MHZ_EXT_24MHZ_CAN_16MHZ 0x22
280 #set PLL_4MHZ__CPU__64MHZ_PER_16MHZ_EXT_32MHZ_CAN_16MHZ 0x23
281 #set PLL_4MHZ__CPU__80MHZ_PER_20MHZ_EXT_27MHZ_CAN_20MHZ 0x24
282 #set PLL_4MHZ__CPU__80MHZ_PER_20MHZ_EXT_40MHZ_CAN_20MHZ 0x25
283 #set PLL_4MHZ__CPU__96MHZ_PER_16MHZ_EXT_48MHZ_CAN_16MHZ 0x26 ;not MB91V460, ...
284 #set PLL_4MHZ__CPU_100MHZ_PER_20MHZ_EXT_50MHZ_CAN_20MHZ 0x27 ;not MB91V460, ...
286 ; MB91461R only: Oscillation input: 10 MHz
287 #set PLL_10MHZ_CPU__60MHZ_PER_20MHZ_EXT_30MHZ_CAN_20MHZ 0x41
289 ; MB91461R only: Oscillation input: 20 MHz
290 #set PLL_20MHZ_CPU__60MHZ_PER_20MHZ_EXT_30MHZ_CAN_20MHZ 0x51
297 #set CLOCKSPEED PLL_4MHZ__CPU__64MHZ_PER_16MHZ_EXT_32MHZ_CAN_16MHZ
298 ; ; <<< Select clock configuration
300 ; There are different default configurations available, where all necessary settings for
301 ; clocks and the related registers are made. Beside this configurations, there is the
302 ; possibility to define a user configuration in the chapter "Definition of
306 ; The clock registers are not set by the start-up file.
308 ; - PLL_4MHZ__CPU__64MHZ_PER_16MHZ_EXT_32MHZ_CAN_16MHZ means:
309 ; Main oszillation = 4 MHz, PLL is activated
310 ; CPU clock (CLKB) = 64 MHZ
311 ; Peripheral clock (CLKP) = 16 MHZ
312 ; Ext. bus clock (CLKT) = 32 MHZ
313 ; CAN clock (CLKCAN) = 16 MHz, using PLLx
316 ; The user configuration definded in the chapter "Definition of Configurations" is set.
318 ; Note: Not all frequencies are supported by every device. Please see the hardware
321 ;=========================================================================================
322 ; 4.7.2 Select Clock Modulator
323 ;=========================================================================================
325 #set CLOMO OFF ; <<< Enable /disable clock modulator
327 #set CMPR 0x026F ; <<< Ref. to the data sheet, CMPR
329 ; Please refer to the data sheet of the device if you enable clock modulation. The
330 ; register CMPR dependant on the PLL-Clock.
332 ; Note: If the CLKCAN source is set either to main oscillator or to PLL output then the
333 ; clock for the CAN is not influenced by the clock modulation. If the CLKCAN
334 ; source is set CPU clock (CLKB) then the clock for the CAN is also modulated (if
335 ; the clock modulator is enabled).
337 ; Note: If the clock modulator is enabled, the wait states of the internal flash wait
338 ; states must be adapted to maximum frequency. Please check the wait states
341 ; Note: This feature is not supported by every device, e.g. MB91461. Please check the
344 ;=========================================================================================
345 ; 4.8 External Bus Interface
347 ; The rest of the configuration is only applicable for devices with an external bus
350 ; If the device does not offer an external bus interface, the configuration can be
351 ; stoped at this point.
353 ;=========================================================================================
354 ; 5 Definition of Configurations
355 ;=========================================================================================
357 #set NOCLOCK 0 ; do not touch CKSCR register
358 #set MAINCLOCK 1 ; select main clock
359 ; ; MB91461R : 1/4 of oscillation input
360 ; ; Others: 1/2 of oscillation input
361 #set MAINPLLCLOCK 2 ; select main clock with PLL
362 #set SUBCLOCK 3 ; select subclock (if available)
364 #set PSCLOCK_CLKB 0x00 ; select core clock (initial)
365 #set PSCLOCK_PLL 0x10 ; select PLL output (x)
366 #set PSCLOCK_MAIN 0x30 ; select Main Oscillation
368 ;=========================================================================================
369 ; 5.1 CLOCKSPEED == CLOCK_USER <<<
370 ;=========================================================================================
371 ; Must be configured only in the case of CLOCKSPEED is set to CLOCK_USER. Please see the
372 ; corresponding application note.
374 #if (CLOCKSPEED == CLOCK_USER )
375 #set CLOCKSOURCE MAINPLLCLOCK ; <<< Clocksource
376 #set ENABLE_SUBCLOCK OFF ; <<< Subclock: ON/OFF
377 #set PLLSPEED 0x010F ; <<< 0x48Ch, 0x48Dh: PLLDIVM/N ; 64 MHz
378 #set DIV_G 0x0F ; <<< 0x48Eh: PLLDIVG;
379 #set MUL_G 0x0F ; <<< 0x48Fh: PLLMULG;
381 #set CPUCLOCK 0x00 ; <<< 0x486h: DIV0R_B; => /1 ; 64 MHz
382 #set PERCLOCK 0x03 ; <<< 0x486h: DIV0R_P; => /4 ; 16 MHz
383 #set EXTBUSCLOCK 0x01 ; <<< 0x487h: DIV1R_T; => /2 ; 32 MHz
385 #set PSCLOCKSOURCE PSCLOCK_PLL ; <<< 0x4C0h: CANPRE; => PLLx;128 MHz
386 #set PSDVC 0x07 ; <<< 0x4C0h: CANPRE_DVC;=> /8 ; 16 MHz
387 #set CANCLOCK 0x00 ; <<< 0x4C1h: CANCKD;
389 #set REGULATORSEL 0x06 ; <<< 0x4CEh: REGSEL;
390 #set REGULATORCTRL 0x00 ; <<< 0x4CFh: REGCTR;
392 #set FLASHCONTROL 0x032 ; <<< 0x7002h: FCHCR;
393 #set FLASHREADT 0xC413 ; <<< 0x7004h: FMWT;
394 #set FLASHMWT2 0x10 ; <<< 0x7006h: FMWT2;
397 ;=========================================================================================
398 ; 5.2 CLOCKSPEED == NO_CLOCK
399 ;=========================================================================================
401 #if (CLOCKSPEED == NO_CLOCK )
402 #set CLOCKSOURCE NOCLOCK
405 ;=========================================================================================
406 ; 5.2 CLOCKSPEED == SUB_32KHZ_CPU__32KHZ_PER_32KHZ_EXT_32KHZ_CAN__2MHZ
407 ;=========================================================================================
409 #if (CLOCKSPEED == SUB_32KHZ_CPU__32KHZ_PER_32KHZ_EXT_32KHZ_CAN__2MHZ )
411 ; Start restriction; Maximum frequency
412 #if (DEVICE == MB91463N) || (DEVICE == MB91461R)
413 #error: Frequency is not supported by this device.
417 #set CLOCKSOURCE SUBCLOCK ; Clocksource
418 #set ENABLE_SUBCLOCK ON ; Subclock: ON/OFF
419 #set PLLSPEED 0x010F ; 0x48Ch, 0x48Dh: PLLDIVM/N ; n. a.
420 #set DIV_G 0x0F ; 0x48Eh: PLLDIVG;
421 #set MUL_G 0x0F ; 0x48Fh: PLLMULG;
423 #set CPUCLOCK 0x00 ; 0x486h: DIV0R_B; => /1 ; 32 KHz
424 #set PERCLOCK 0x00 ; 0x486h: DIV0R_P; => /1 ; 32 KHz
425 #set EXTBUSCLOCK 0x00 ; 0x487h: DIV1R_T; => /1 ; 32 KHz
427 #set PSCLOCKSOURCE PSCLOCK_MAIN ; 0x4C0h: CANPRE; => MAIN ; 4 MHz
428 #set PSDVC 0x01 ; 0x4C0h: CANPRE_DVC; => /2 ; 2 MHz
429 #set CANCLOCK 0x00 ; 0x4C1h: CANCKD; all CAN Clocks enabled
431 #set REGULATORSEL 0x06 ; 0x4CEh: REGSEL;
432 #set REGULATORCTRL 0x00 ; 0x4CFh: REGCTR;
434 #set FLASHCONTROL 0x032 ; 0x7002h: FCHCR;
435 #set FLASHREADT 0xC100 ; 0x7004h: FMWT;
436 #set FLASHMWT2 0x00 ; 0x7006h: FMWT2;
439 ;=========================================================================================
440 ; 5.3 CLOCKSPEED == MAIN__4MHZ_CPU___2MHZ_PER__1MHZ_EXT__1MHZ_CAN__2MHZ
441 ;=========================================================================================
443 #if (CLOCKSPEED == MAIN_4MHZ_CPU___2MHZ_PER__1MHZ_EXT__1MHZ_CAN__2MHZ )
445 ; Start restriction; Maximum frequency
446 #if (DEVICE == MB91461R)
447 #error: Frequency is not supported by this device.
451 #set CLOCKSOURCE MAINCLOCK ; Clocksource
452 #set ENABLE_SUBCLOCK OFF ; Subclock: ON/OFF
453 #set PLLSPEED 0x010F ; 0x48Ch, 0x48Dh: PLLDIVM/N ; n. a.
454 #set DIV_G 0x0F ; 0x48Eh: PLLDIVG;
455 #set MUL_G 0x0F ; 0x48Fh: PLLMULG;
457 #set CPUCLOCK 0x00 ; 0x486h: DIV0R_B; => /1 ; 2 MHz
458 #set PERCLOCK 0x01 ; 0x486h: DIV0R_P; => /2 ; 1 MHz
459 #set EXTBUSCLOCK 0x01 ; 0x487h: DIV1R_T; => /2 ; 1 MHz
461 #set PSCLOCKSOURCE PSCLOCK_MAIN ; 0x4C0h: CANPRE; => PLLx ; 4 MHz
462 #set PSDVC 0x01 ; 0x4C0h: CANPRE_DVC; => /2 ; 2 MHz
463 #set CANCLOCK 0x00 ; 0x4C1h: CANCKD; all CAN Clocks enabled
465 #set REGULATORSEL 0x06 ; 0x4CEh: REGSEL;
466 #set REGULATORCTRL 0x00 ; 0x4CFh: REGCTR;
468 #set FLASHCONTROL 0x032 ; 0x7002h: FCHCR;
469 #set FLASHREADT 0xC100 ; 0x7004h: FMWT;
470 #set FLASHMWT2 0x00 ; 0x7006h: FMWT2;
473 ;=========================================================================================
474 ; 5.4 CLOCKSPEED == PLL_4MHZ__CPU__48MHZ_PER_16MHZ_EXT_24MHZ_CAN_16MHZ
475 ;=========================================================================================
477 #if (CLOCKSPEED == PLL_4MHZ__CPU__48MHZ_PER_16MHZ_EXT_24MHZ_CAN_16MHZ )
479 ; Start restriction; Maximum frequency
480 #if (DEVICE == MB91461R)
481 #error: Frequency is not supported by this device.
485 #set CLOCKSOURCE MAINPLLCLOCK ; Clocksource
486 #set ENABLE_SUBCLOCK OFF ; Subclock: ON/OFF
487 #set PLLSPEED 0x010B ; 0x48Ch, 0x48Dh: PLLDIVM/N ; 48 MHz
488 #set DIV_G 0x0F ; 0x48Eh: PLLDIVG;
489 #set MUL_G 0x0B ; 0x48Fh: PLLMULG;
491 #set CPUCLOCK 0x00 ; 0x486h: DIV0R_B; => /1 ; 48 MHz
492 #set PERCLOCK 0x02 ; 0x486h: DIV0R_P; => /3 ; 16 MHz
493 #set EXTBUSCLOCK 0x01 ; 0x487h: DIV1R_T; => /2 ; 24 MHz
495 #set PSCLOCKSOURCE PSCLOCK_PLL ; 0x4C0h: CANPRE; => PLLx ; 96 MHz
496 #set PSDVC 0x05 ; 0x4C0h: CANPRE_DVC; => /6 ; 16 MHz
497 #set CANCLOCK 0x00 ; 0x4C1h: CANCKD; all CAN Clocks enabled
499 #if (DEVICE == MB91469G)
500 #set REGULATORSEL 0x36 ; 0x4CEh: REGSEL;
502 #set REGULATORSEL 0x06 ; 0x4CEh: REGSEL;
504 #set REGULATORCTRL 0x00 ; 0x4CFh: REGCTR;
506 #set FLASHCONTROL 0x032 ; 0x7002h: FCHCR;
507 #set FLASHREADT 0xC201 ; 0x7004h: FMWT;
508 #set FLASHMWT2 0x00 ; 0x7006h: FMWT2;
511 ;=========================================================================================
512 ; 5.5 CLOCKSPEED == PLL_4MHZ__CPU__64MHZ_PER_16MHZ_EXT_32MHZ_CAN_16MHZ
513 ;=========================================================================================
515 #if (CLOCKSPEED == PLL_4MHZ__CPU__64MHZ_PER_16MHZ_EXT_32MHZ_CAN_16MHZ )
517 ; Start restriction; Maximum frequency
518 #if (DEVICE == MB91461R)
519 #error: Frequency is not supported by this device.
523 #set CLOCKSOURCE MAINPLLCLOCK ; Clocksource
524 #set ENABLE_SUBCLOCK OFF ; Subclock: ON/OFF
525 #set PLLSPEED 0x010F ; 0x48Ch, 0x48Dh: PLLDIVM/N ; 64 MHz
526 #set DIV_G 0x0F ; 0x48Eh: PLLDIVG;
527 #set MUL_G 0x0F ; 0x48Fh: PLLMULG;
529 #set CPUCLOCK 0x00 ; 0x486h: DIV0R_B; => /1 ; 64 MHz
530 #set PERCLOCK 0x03 ; 0x486h: DIV0R_P; => /4 ; 16 MHz
531 #set EXTBUSCLOCK 0x01 ; 0x487h: DIV1R_T; => /2 ; 32 MHz
533 #set PSCLOCKSOURCE PSCLOCK_PLL ; 0x4C0h: CANPRE; => PLLx ; 128 MHz
534 #set PSDVC 0x07 ; 0x4C0h: CANPRE_DVC; => /8 ; 16 MHz
535 #set CANCLOCK 0x00 ; 0x4C1h: CANCKD; all CAN Clocks enabled
537 #set REGULATORSEL 0x06 ; 0x4CEh: REGSEL;
538 #set REGULATORCTRL 0x00 ; 0x4CFh: REGCTR;
540 #set FLASHCONTROL 0x032 ; 0x7002h: FCHCR;
541 #set FLASHREADT 0xC413 ; 0x7004h: FMWT;
542 #set FLASHMWT2 0x10 ; 0x7006h: FMWT2;
545 ;=========================================================================================
546 ; 5.6 CLOCKSPEED == PLL_4MHZ__CPU__80MHZ_PER_20MHZ_EXT_27MHZ_CAN_20MHZ
547 ;=========================================================================================
549 #if (CLOCKSPEED == PLL_4MHZ__CPU__80MHZ_PER_20MHZ_EXT_27MHZ_CAN_20MHZ )
551 ; Start restriction; Maximum frequency
552 #if (DEVICE == MB91461R)
553 #error: Frequency is not supported by this device.
557 #set CLOCKSOURCE MAINPLLCLOCK ; Clocksource
558 #set ENABLE_SUBCLOCK OFF ; Subclock: ON/OFF
559 #set PLLSPEED 0x0113 ; 0x48Ch, 0x48Dh: PLLDIVM/N ; 80 MHz
560 #set DIV_G 0x0F ; 0x48Eh: PLLDIVG;
561 #set MUL_G 0x13 ; 0x48Fh: PLLMULG;
563 #set CPUCLOCK 0x00 ; 0x486h: DIV0R_B; => /1 ; 80 MHz
564 #set PERCLOCK 0x03 ; 0x486h: DIV0R_P; => /4 ; 20 MHz
565 #set EXTBUSCLOCK 0x02 ; 0x487h: DIV1R_T; => /3 ; 27 MHz
567 #set PSCLOCKSOURCE PSCLOCK_PLL ; 0x4C0h: CANPRE; => PLLx ; 160 MHz
568 #set PSDVC 0x07 ; 0x4C0h: CANPRE_DVC; => /8 ; 8 MHz
569 #set CANCLOCK 0x00 ; 0x4C1h: CANCKD; all CAN Clocks enabled
571 #set REGULATORSEL 0x06 ; 0x4CEh: REGSEL;
572 #set REGULATORCTRL 0x00 ; 0x4CFh: REGCTR;
574 #set FLASHCONTROL 0x032 ; 0x7002h: FCHCR;
575 #set FLASHREADT 0xC413 ; 0x7004h: FMWT;
576 #set FLASHMWT2 0x10 ; 0x7006h: FMWT2;
579 ;=========================================================================================
580 ; 5.7 CLOCKSPEED == PLL_4MHZ__CPU__80MHZ_PER_20MHZ_EXT_40MHZ_CAN_20MHZ
581 ;=========================================================================================
583 #if (CLOCKSPEED == PLL_4MHZ__CPU__80MHZ_PER_20MHZ_EXT_40MHZ_CAN_20MHZ )
585 ; Start restriction; Maximum frequency
586 #if (DEVICE == MB91461R)
587 #error: Frequency is not supported by this device.
591 #set CLOCKSOURCE MAINPLLCLOCK ; Clocksource
592 #set ENABLE_SUBCLOCK OFF ; Subclock: ON/OFF
593 #set PLLSPEED 0x0113 ; 0x48Ch, 0x48Dh: PLLDIVM/N ; 80 MHz
594 #set DIV_G 0x0F ; 0x48Eh: PLLDIVG;
595 #set MUL_G 0x13 ; 0x48Fh: PLLMULG;
597 #set CPUCLOCK 0x00 ; 0x486h: DIV0R_B; => /1 ; 80 MHz
598 #set PERCLOCK 0x03 ; 0x486h: DIV0R_P; => /4 ; 20 MHz
599 #set EXTBUSCLOCK 0x01 ; 0x487h: DIV1R_T; => /2 ; 40 MHz
601 #set PSCLOCKSOURCE PSCLOCK_PLL ; 0x4C0h: CANPRE; => PLLx ; 160 MHz
602 #set PSDVC 0x07 ; 0x4C0h: CANPRE_DVC; => /8 ; 8 MHz
603 #set CANCLOCK 0x00 ; 0x4C1h: CANCKD; all CAN Clocks enabled
605 #set REGULATORSEL 0x06 ; 0x4CEh: REGSEL;
606 #set REGULATORCTRL 0x00 ; 0x4CFh: REGCTR;
608 #set FLASHCONTROL 0x032 ; 0x7002h: FCHCR;
609 #set FLASHREADT 0xC413 ; 0x7004h: FMWT;
610 #set FLASHMWT2 0x10 ; 0x7006h: FMWT2;
613 ;=========================================================================================
614 ; 5.8 CLOCKSPEED == PLL_4MHZ__CPU__96MHZ_PER_16MHZ_EXT_48MHZ_CAN_16MHZ
615 ;=========================================================================================
617 #if (CLOCKSPEED == PLL_4MHZ__CPU__96MHZ_PER_16MHZ_EXT_48MHZ_CAN_16MHZ )
619 ; Start restriction; Maximum frequency
620 #if (DEVICE == MB91464A) || (DEVICE == MB91465K) || (DEVICE == MB91463N) ||\
621 (DEVICE == MB91461R) || (DEVICE == MB91467R)
622 #error: Frequency is not supported by this device.
626 #set CLOCKSOURCE MAINPLLCLOCK ; Clocksource
627 #set ENABLE_SUBCLOCK OFF ; Subclock: ON/OFF
628 #set PLLSPEED 0x0117 ; 0x48Ch, 0x48Dh: PLLDIVM/N ; 96 MHz
629 #set DIV_G 0x0F ; 0x48Eh: PLLDIVG;
630 #set MUL_G 0x17 ; 0x48Fh: PLLMULG;
632 #set CPUCLOCK 0x00 ; 0x486h: DIV0R_B; => /1 ; 64 MHz
633 #set PERCLOCK 0x05 ; 0x486h: DIV0R_P; => /6 ; 16 MHz
634 #set EXTBUSCLOCK 0x01 ; 0x487h: DIV1R_T; => /2 ; 32 MHz
636 #set PSCLOCKSOURCE PSCLOCK_PLL ; 0x4C0h: CANPRE; => PLLx ; 192 MHz
637 #set PSDVC 0x0B ; 0x4C0h: CANPRE_DVC; => /12 ; 16 MHz
638 #set CANCLOCK 0x00 ; 0x4C1h: CANCKD; all CAN Clocks enabled
640 #if (DEVICE == MB91469G)
641 #set REGULATORSEL 0x36 ; 0x4CEh: REGSEL;
643 #set REGULATORSEL 0x06 ; 0x4CEh: REGSEL;
645 #set REGULATORCTRL 0x00 ; 0x4CFh: REGCTR;
647 #set FLASHCONTROL 0x032 ; 0x7002h: FCHCR;
648 #set FLASHREADT 0xC413 ; 0x7004h: FMWT;
649 #set FLASHMWT2 0x10 ; 0x7006h: FMWT2;
652 ;=========================================================================================
653 ; 5.9 CLOCKSPEED == PLL_4MHZ__CPU_100MHZ_PER_20MHZ_EXT_50MHZ_CAN_20MHZ
654 ;=========================================================================================
656 #if (CLOCKSPEED == PLL_4MHZ__CPU_100MHZ_PER_20MHZ_EXT_50MHZ_CAN_20MHZ )
658 ; Start restriction; Maximum frequency
659 #if (DEVICE == MB91464A) || (DEVICE == MB91465K) || (DEVICE == MB91463N) ||\
660 (DEVICE == MB91461R) || (DEVICE == MB91467R) || (DEVICE == MB91467D)
661 #error: Frequency is not supported by this device.
665 #set CLOCKSOURCE MAINPLLCLOCK ; Clocksource
666 #set ENABLE_SUBCLOCK OFF ; Subclock: ON/OFF
667 #set PLLSPEED 0x0118 ; 0x48Ch, 0x48Dh: PLLDIVM/N ; 100 MHz
668 #set DIV_G 0x0F ; 0x48Eh: PLLDIVG;
669 #set MUL_G 0x17 ; 0x48Fh: PLLMULG;
671 #set CPUCLOCK 0x00 ; 0x486h: DIV0R_B; => /1 ; 100 MHz
672 #set PERCLOCK 0x04 ; 0x486h: DIV0R_P; => /5 ; 20 MHz
673 #set EXTBUSCLOCK 0x01 ; 0x487h: DIV1R_T; => /2 ; 50 MHz
675 #set PSCLOCKSOURCE PSCLOCK_PLL ; 0x4C0h: CANPRE; => PLLx ; 200 MHz
676 #set PSDVC 0x09 ; 0x4C0h: CANPRE_DVC; => /10 ; 20 MHz
677 #set CANCLOCK 0x00 ; 0x4C1h: CANCKD; all CAN Clocks enabled
679 #if (DEVICE == MB91469G)
680 #set REGULATORSEL 0x36 ; 0x4CEh: REGSEL;
682 #set REGULATORSEL 0x06 ; 0x4CEh: REGSEL;
684 #set REGULATORCTRL 0x00 ; 0x4CFh: REGCTR;
686 #set FLASHCONTROL 0x032 ; 0x7002h: FCHCR;
687 #set FLASHREADT 0xC413 ; 0x7004h: FMWT;
688 #set FLASHMWT2 0x10 ; 0x7006h: FMWT2;
691 ;=========================================================================================
692 ; 5.10 CLOCKSPEED == PLL_10MHZ_CPU__60MHZ_PER_20MHZ_EXT_30MHZ_CAN_20MHZ
693 ;=========================================================================================
695 #if (CLOCKSPEED == PLL_10MHZ_CPU__60MHZ_PER_20MHZ_EXT_30MHZ_CAN_20MHZ )
697 ; Start restriction; Maximum frequency
698 #if (DEVICE == MB91464A) || (DEVICE == MB91467B) || (DEVICE == MB91467C) ||\
699 (DEVICE == MB91467D) || (DEVICE == MB91469G) || (DEVICE == MB91465K) ||\
700 (DEVICE == MB91463N) || (DEVICE == MB91467R) || (DEVICE == MB91465X)
701 #error: Frequency is not supported by this device.
705 #set CLOCKSOURCE MAINPLLCLOCK ; Clocksource
706 #set ENABLE_SUBCLOCK OFF ; Subclock: ON/OFF
707 #set PLLSPEED 0x0105 ; 0x48Ch, 0x48Dh: PLLDIVM/N ; 60 MHz
708 #set DIV_G 0x0B ; 0x48Eh: PLLDIVG;
709 #set MUL_G 0x1F ; 0x48Fh: PLLMULG;
711 #set CPUCLOCK 0x00 ; 0x486h: DIV0R_B; => /1 ; 60 MHz
712 #set PERCLOCK 0x02 ; 0x486h: DIV0R_P; => /3 ; 20 MHz
713 #set EXTBUSCLOCK 0x01 ; 0x487h: DIV1R_T; => /2 ; 30 MHz
715 #set PSCLOCKSOURCE PSCLOCK_PLL ; 0x4C0h: CANPRE; => PLLx ; 120 MHz
716 #set PSDVC 0x05 ; 0x4C0h: CANPRE_DVC; => /6 ; 20 MHz
717 #set CANCLOCK 0x00 ; 0x4C1h: CANCKD; all CAN Clocks enabled
724 ;=========================================================================================
725 ; 5.11 CLOCKSPEED == PLL_20MHZ_CPU__60MHZ_PER_20MHZ_EXT_30MHZ_CAN_20MHZ
726 ;=========================================================================================
728 #if (CLOCKSPEED == PLL_20MHZ_CPU__60MHZ_PER_20MHZ_EXT_30MHZ_CAN_20MHZ )
730 ; Start restriction; Maximum frequency
731 #if (DEVICE == MB91464A) || (DEVICE == MB91467B) || (DEVICE == MB91467C) ||\
732 (DEVICE == MB91467D) || (DEVICE == MB91469G) || (DEVICE == MB91465K) ||\
733 (DEVICE == MB91463N) || (DEVICE == MB91467R) || (DEVICE == MB91465X)
734 #error: Frequency is not supported by this device.
738 #set CLOCKSOURCE MAINPLLCLOCK ; Clocksource
739 #set ENABLE_SUBCLOCK OFF ; Subclock: ON/OFF
740 #set PLLSPEED 0x0102 ; 0x48Ch, 0x48Dh: PLLDIVM/N ; 60 MHz
741 #set DIV_G 0x0F ; 0x48Eh: PLLDIVG;
742 #set MUL_G 0x1F ; 0x48Fh: PLLMULG;
744 #set CPUCLOCK 0x00 ; 0x486h: DIV0R_B; => /1 ; 60 MHz
745 #set PERCLOCK 0x02 ; 0x486h: DIV0R_P; => /3 ; 20 MHz
746 #set EXTBUSCLOCK 0x01 ; 0x487h: DIV1R_T; => /2 ; 30 MHz
748 #set PSCLOCKSOURCE PSCLOCK_PLL ; 0x4C0h: CANPRE; => PLLx ; 120 MHz
749 #set PSDVC 0x05 ; 0x4C0h: CANPRE_DVC; => /6 ; 20 MHz
750 #set CANCLOCK 0x00 ; 0x4C1h: CANCKD; all CAN Clocks enabled
757 ;=========================================================================================
758 ; 6 Section and Data Declaration
759 ;=========================================================================================
765 ;=========================================================================================
766 ; 6.1 Define Stack Size
767 ;=========================================================================================
768 .SECTION SSTACK, STACK, ALIGN=4
769 #if STACK_RESERVE == ON
770 .EXPORT __systemstack, __systemstack_top
772 .RES.B STACK_SYS_SIZE
776 .SECTION USTACK, STACK, ALIGN=4
777 #if STACK_RESERVE == ON
778 .EXPORT __userstack, __userstack_top
780 .RES.B STACK_USR_SIZE
784 ;=========================================================================================
785 ; 6.2 Define Sections
786 ;=========================================================================================
787 .section DATA, data, align=4
788 .section INIT, data, align=4
789 .section IRAM, code, align=4
790 .section CONST, const, align=4
791 .section INTVECT, const, align=4
798 #if (DEVICE != MB91461R)
799 #if (DEVICE == MB91469G)
800 .section SECURITY_VECTORS, code, locate = 0x248000
802 .section SECURITY_VECTORS, code, locate = 0x148000
805 #if (BOOT_FLASH_SEC == OFF)
815 ;-----------------------------------------------------------------------------------------
816 ; MACRO Clear RC Watchdog
817 ;-----------------------------------------------------------------------------------------
818 #macro ClearRCwatchdog
819 LDI #0x4C7,R7 ; clear RC watchdog
822 ;-----------------------------------------------------------------------------------------
824 ;-----------------------------------------------------------------------------------------
825 #macro wait_loop loop_number
832 .section CODE, code, align=4
833 .section CODE_START, code, align=4
834 #pragma section CODE=IRAM,attr=CODE
837 ;=========================================================================================
839 ;=========================================================================================
840 __start: ; start point
844 ANDCCR #0xEF ; disable interrupts
845 STILM #LOW_PRIOR ; set interrupt level to low prior
846 ClearRCwatchdog ; clear harware watchdog
848 ;=========================================================================================
849 ; 7.1 Initialise Stack Pointer and Table Base Register
850 ;=========================================================================================
851 #if STACKUSE == SYSSTACK
853 LDI #__userstack_top, SP ; initialize SP
855 LDI #__systemstack_top, SP ; initialize SP
858 #if STACKUSE == USRSTACK
860 LDI #__systemstack_top, SP ; initialize SP
862 LDI #__userstack_top, SP ; initialize SP
865 LDI #INTVECT, R0 ; set Table Base
869 #if (CLOCKSOURCE != NOCLOCK)
870 ;=========================================================================================
871 ; 7.2 Check for CSV reset and set CSV
872 ;=========================================================================================
873 ; Start restriction; No clock supervisor (CSV)
874 #if (DEVICE != MB91461R) && (DEVICE != MB91467R) && (DEVICE != MB91463N)
876 LDI:20 #0x04AD, R0 ; CSVCR
877 BORL #0x8, @R0 ; Enable Main Osc CSV
878 BTSTH #0x4, @R0 ; Check for Main Osc missing
879 BEQ NoMAINCSVreset ; Main osc available -> branch
881 BANDL #0x7, @R0 ; Disable Main Osc CSV
883 LDI #noClockStartup, R0 ; Main Clock missing -> no
884 JMP @R0 ; clock startup
889 BORL #0x4, @R0 ; Enable Sub Osc CSV
890 BTSTH #0x2, @R0 ; Check for Sub Osc missing
891 BEQ NoSUBCSVreset ; Sub osc available -> branch
893 BANDL #0xB, @R0 ; Disable Sub Osc SCSV
894 #if (CLOCKSOURCE == SUBCLOCK)
895 LDI #noClockStartup, R0 ; Sub Clock missing -> no
896 JMP @R0 ; clock startup
900 ;=========================================================================================
901 ; 7.3 Check Clock Condition
902 ;=========================================================================================
903 LDI #0x484, R0 ; Check for Default Values
908 ;=========================================================================================
909 ; 7.4 Restore Default Settings after Reset
910 ;=========================================================================================
911 ;=========================================================================================
912 ; 7.4.1 Disable Clock Modulator
913 ;=========================================================================================
914 LDI #0x04BB, R0 ; Clock Modulator Control Reg
915 BANDL #0xD, @R0 ; Disable Frequency modulation
917 BTSTL #8, @R0 ; Wait until Frequency modulation
918 BNE FMODwait ; is disabled
920 BANDL #0xE, @R0 ; Power down clock modulator
922 ;=========================================================================================
923 ; 7.4.2 Check if running on Sub Clock, change to Main Clock
924 ;=========================================================================================
925 LDI:20 #0x0484,R12 ; Check if running on sub clock
932 LDI:20 #0x04CC,R12 ; Check if Main Clock is stopped
936 BANDL #0xE, @R12 ; Start Main Oscillation
938 LDI #0x4C8, R0 ; Main Stabilisation Wait Time
939 LDI #0x04, R1 ; 32.7 ms
943 mainStabTime: ; Wait for stabilisation time
944 ClearRCwatchdog ; clear harware watchdog
951 LDI:20 #0x0484, R12 ; disable sub clock as source
952 BANDL #0xD, @R12 ; Clock source = 0x01 (Main/2)
955 ;=========================================================================================
956 ; 7.4.3 Disable Sub Clock
957 ;=========================================================================================
958 #if ENABLE_SUBCLOCK != ON
959 LDI #0x0484, R0 ; Clock source control reg CLKR
960 BANDL #0x7, @R0 ; Disable PLL
963 ;=========================================================================================
964 ; 7.4.4 Check if running on PLL, Gear Down PLL
965 ;=========================================================================================
966 LDI:20 #0x0484,R12 ; Check if running on PLL
973 LDI:20 #0x0490, R11 ; clear flags
977 STB R1, @R11 ; Set Flag for Simulator; no Effekt on
980 BANDL #0xC, @R12 ; disable PLL as clock source
981 ; Clock Source = 0x00 (Main/2)
983 LDI:20 #0x048E,R12 ; check if DivG != 0
990 ClearRCwatchdog ; clear harware watchdog
991 BTSTL #4, @R11 ; Gear Down
994 LDI #0x00,R1 ; Clear Flags
998 ;=========================================================================================
1000 ;=========================================================================================
1001 LDI #0x0484, R0 ; Clock source control reg CLKR
1002 BANDL #0xB, @R0 ; Disable PLL
1004 ;=========================================================================================
1005 ; 7.4.6 Set to Main Clock
1006 ;=========================================================================================
1007 LDI:20 #0x0484,R12 ; Check if running on PLL
1008 BANDL #0xC, @R12 ; disable PLL as clock source
1009 ; Clock Source = 0x00 (Main/2)
1012 ;=========================================================================================
1013 ; 7.5 Set Memory Controller
1014 ;=========================================================================================
1015 ; Start restriction; No embedded flash
1016 #if DEVICE != MB91461R
1018 LDI #0x7002, R1 ; FLASH Controller Reg.
1019 LDI #FLASHCONTROL, R2 ; Flash Controller Settings
1020 STH R2, @R1 ; set register
1021 LDI #0x7004, R1 ; FLASH Memory Wait Timing Reg.
1022 LDI #FLASHREADT, R2 ; wait settings
1023 STH R2, @R1 ; set register
1024 LDI #0x7006, R1 ; FLASH Memory Wait Timing Reg.
1025 LDI #FLASHMWT2, R2 ; wait settings
1026 STB R2, @R1 ; set register
1030 ;=========================================================================================
1032 ;=========================================================================================
1033 ;=========================================================================================
1034 ; 7.6.1 Set Voltage Regulator Settings
1035 ;=========================================================================================
1036 ; Start restriction; No regulator settings
1037 #if DEVICE != MB91461R
1039 LDI #0x04CF, R0 ; REGCTR
1040 LDI #REGULATORCTRL, R1
1043 LDI #0x04CE, R0 ; REGSEL
1044 LDI #REGULATORSEL, R1
1048 ;=========================================================================================
1049 ; 7.6.2 Power on Clock Modulator - Clock Modulator Part I
1050 ;=========================================================================================
1052 LDI #0x04BB, R0 ; Clock Modulator Control Reg
1053 LDI #0x11, R1 ; Load value to Power on CM
1054 ORB R1, @R0 ; Power on clock modulaor
1057 ;=========================================================================================
1058 ; 7.6.3 Set CLKR Register w/o Clock Mode
1059 ;=========================================================================================
1060 ; Set Clock source (Base Clock) for the three clock tree selections
1061 ; This select Base clock is used to select afterwards the 3
1062 ; Clocks for the diffenrent internal trees.
1063 ; When PLL is used, first pll multiplication ratio is set and PLL is
1064 ; enabled. After waiting the PLL stabilisation time via timebase
1065 ; timer, PLL clock is selected as clock source.
1066 LDI #0x048C, R0 ; PLL Cntl Reg. PLLDIVM/N
1067 LDI:20 #PLLSPEED, R1
1070 LDI #0x048E, R0 ; PLL Cntl Reg. PLLDIVG
1074 LDI #0x048F, R0 ; PLL Cntl Reg. PLLMULG
1078 ;=========================================================================================
1080 ;=========================================================================================
1081 #if ( ( CLOCKSOURCE == MAINPLLCLOCK ) || ( PSCLOCKSOURCE == PSCLOCK_PLL ) )
1082 LDI #0x0484, R0 ; Clock source control reg CLKR
1083 LDI #0x04, R1 ; Use PLL x1, enable PLL
1084 ORB R1, @R0 ; store data to CLKR register
1088 #if ENABLE_SUBCLOCK == ON
1089 LDI #0x0484, R0 ; Clock source control reg CLKR
1090 LDI #0x08, R1 ; enable subclock operation
1091 ORB R1, @R0 ; store data to CLKR register
1092 LDI #0x4CA, R0 ; Sub Clock oszilation
1093 LDI #0x00, R1 ; stabilitsation time = 32 ms
1098 ;=========================================================================================
1099 ; 7.6.5 Wait for PLL oscillation stabilisation
1100 ;=========================================================================================
1101 #if ((CLOCKSOURCE==MAINPLLCLOCK)||(PSCLOCKSOURCE==PSCLOCK_PLL))
1102 LDI #0x0482, R12 ; TimeBaseTimer TBCR
1103 LDI #0x00, R1 ; set 1024 us @ 2 MHz
1106 BANDH #7, @R12 ; clear interrupt flag
1108 LDI #0x0483, R0 ; clearTimeBaseTimer CTBR
1114 BANDH #7, @R12 ; clear interrupt flag
1115 BORH #8, @R12 ; set interrupt flag for simulator
1118 ClearRCwatchdog ; clear harware watchdog
1123 ;=========================================================================================
1125 ;=========================================================================================
1126 ;=========================================================================================
1127 ; 7.6.6.1 Set CPU and peripheral clock
1128 ;=========================================================================================
1129 ; CPU and peripheral clock are set in one register
1130 LDI #0x0486, R2 ; Set DIVR0 (CPU-clock (CLKB)
1131 LDI #((CPUCLOCK << 4) + PERCLOCK), R3 ; Load CPU clock setting
1133 ;=========================================================================================
1134 ; 7.6.6.2 Set External Bus interface clock
1135 ;=========================================================================================
1136 ; set External Bus clock
1137 ; Be aware to do smooth clock setting, to avoid wrong clock setting
1138 ; Take care, always write 0 to the lower 4 bits of DIVR1 register
1139 LDI #0x0487, R2 ; Set DIVR1
1140 LDI #(EXTBUSCLOCK << 4), R3 ; Load Peripheral clock setting
1143 ;=========================================================================================
1144 ; 7.6.6.3 Set CAN clock prescaler
1145 ;=========================================================================================
1146 ; Set CAN Prescaler, only clock relevant parameter
1147 LDI #0x04C0, R0 ; Set CAN ClockParameter Register
1148 LDI #(PSCLOCKSOURCE + PSDVC), R1 ; Load Divider
1149 STB R1, @R0 ; Set Divider
1151 LDI #0x04c1, R0 ; Set CAN Clock enable Register
1152 LDI #CANCLOCK, R1 ; Load CANCLOCK
1153 STB R1, @R0 ; set CANCLOCK
1155 ;=========================================================================================
1156 ; 7.6.6.4 Switch Main Clock Mode
1157 ;=========================================================================================
1158 #if CLOCKSOURCE == MAINCLOCK
1160 ;=========================================================================================
1161 ; 7.6.6.5 Switch Subclock Mode
1162 ;=========================================================================================
1163 #elif ( (CLOCKSOURCE == SUBCLOCK) )
1164 #if ENABLE_SUBCLOCK == ON
1167 ClearRCwatchdog ; clear harware watchdog
1168 BTSTH #8, @R12 ; wait until sub clock stabilisation
1169 BEQ subStabTime ; time is over
1173 LDI #0x0484, R0 ; Clock source control reg CLKR
1174 LDI #0x01, R1 ; load value to select main clock
1175 ORB R1, @R0 ; enable main clock (1/2 external)
1176 LDI #0x03, R1 ; load value to select subclock
1177 ORB R1, @R0 ; enable subclock as clock source
1179 #error: Wrong setting! The clock source is subclock, but the subclock is disabled.
1182 ;=========================================================================================
1183 ; 7.6.7 Switch to PLL Mode
1184 ;=========================================================================================
1185 #elif ( (CLOCKSOURCE == MAINPLLCLOCK) )
1188 LDI #0x0490, R0 ; PLL Ctrl Register
1190 STB R1, @R0 ; Clear Flag
1192 STB R1, @R0 ; Set Flag for Simulator; no Effekt on
1195 LDI #0x0484, R3 ; Clock source control reg CLKR
1196 BORL #0x2, @R3 ; enable PLL as clock source
1200 ClearRCwatchdog ; clear harware watchdog
1201 LDUB @R0, R2 ; LOAD PLLCTR to R2
1202 AND R1, R2 ; GRUP, counter reach 0
1206 STB R1, @R0 ; Clear Gear-Up Flag
1211 ;=========================================================================================
1212 ; 7.6.8 Enable Frequncy Modulation - Clock Modulator Part II
1213 ;=========================================================================================
1214 #if CLOMO == ON ; Only applicable if Modulator is on
1215 LDI #0x04B8, R0 ; Clock Modulation Parameter Reg
1216 LDI #CMPR, R1 ; Load CMP value
1217 STH R1, @R0 ; Store CMP value in CMPR
1219 LDI #0x04BB, R0 ; Clock Modulator Control Reg
1220 LDI #0x13, R1 ; Load value to FM on CM
1227 ;=========================================================================================
1228 ; 7.7 Set BusInterface
1229 ;=========================================================================================
1230 ; Start restriction; No ext. bus interface
1231 #if (DEVICE != MB91464A) && (DEVICE != MB91467C) && (DEVICE != MB91465K) && \
1232 (DEVICE != MB91463N) && (DEVICE != MB91465X)
1236 emu_sram_cs_mb91461r:
1239 #endif ; #endif (excl. devices)
1242 ;=========================================================================================
1243 ; 7.8 Copy code from Flash to I-RAM
1244 ;=========================================================================================
1248 LDI #sizeof(IRAM), R13
1253 LDUB @(R13, R1), R12
1260 ;=========================================================================================
1261 ; Standard C startup
1262 ;=========================================================================================
1263 ;=========================================================================================
1265 ;=========================================================================================
1266 ; clear DATA section
1267 ; According to ANSI, the DATA section must be cleared during start-up
1269 LDI #sizeof DATA &~0x3, R1
1278 LDI:8 #sizeof DATA & 0x3, R1
1279 LDI #DATA + (sizeof DATA & ~0x3), R13
1290 ;=========================================================================================
1291 ; 7.11 Copy Init section from ROM to RAM
1292 ;=========================================================================================
1294 ; All initialised data's (e.g. int i=1) must be stored in ROM/FLASH area.
1296 ; The Application must copy the Section (Init) into the RAM area.
1299 LDI #sizeof(INIT), R2
1310 LDUB @(R13, R1), R12
1325 ;=========================================================================================
1326 ; 7.14 call main routine
1327 ;=========================================================================================
1328 ClearRCwatchdog ; clear harware watchdog
1329 LDI:8 #0, r4 ; Set the 1st parameter for main to 0.
1331 LDI:8 #0, r5 ; Set the 2nd parameter for main to 0.
1332 ;=========================================================================================
1333 ; 7.15 Return from main function
1334 ;=========================================================================================