File indexing completed on 2025-05-11 08:23:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <bsp.h>
0018
0019
0020 #define MCF_CIM_CCON (*(vuint16*)(void*)(&__IPSBAR[0x00110004]))
0021
0022
0023 #define MCF_CIM_CCON_SZEN (0x00000040)
0024 #define MCF_CIM_CCON_PSTEN (0x00000020)
0025 #define MCF_CIM_CCON_BME (0x00000008)
0026 #define MCF_CIM_CCON_BMT(x) (((x)&0x00000007)<<0)
0027
0028
0029 void init_main(void);
0030 static void disable_interrupts(void);
0031 static void disable_watchdog_timer(void);
0032 static void init_ipsbar(void);
0033 static void init_clock_config(void);
0034 static void init_sram(void);
0035 static void init_flash_controller(void);
0036 static void init_eport(void);
0037 static void init_flexcan(void);
0038 static void init_bus_config(void);
0039 static void init_power_management(void);
0040 static void init_dma_timers(void);
0041 static void init_gp_timer(void);
0042 static void init_interrupt_timers(void);
0043 static void init_real_time_clock(void);
0044 static void init_watchdog_timer(void);
0045 static void init_pin_assignments(void);
0046 static void init_interrupt_controller(void);
0047
0048
0049
0050
0051 void init_main(void)
0052 {
0053
0054 __asm__ ("move.w #0x2700,%sr");
0055
0056
0057 init_ipsbar();
0058 init_clock_config();
0059
0060
0061 disable_interrupts();
0062 disable_watchdog_timer();
0063
0064
0065 init_sram();
0066 init_flash_controller();
0067 init_eport();
0068 init_flexcan();
0069 init_bus_config();
0070 init_power_management();
0071 init_dma_timers();
0072 init_gp_timer();
0073 init_interrupt_timers();
0074 init_real_time_clock();
0075 init_watchdog_timer();
0076 init_pin_assignments();
0077
0078
0079 init_interrupt_controller();
0080 }
0081
0082
0083
0084
0085 static void disable_interrupts(void)
0086 {
0087 vuint8 *p;
0088 int i;
0089
0090
0091 p = (vuint8 *) & MCF_INTC0_ICR8;
0092 for (i = 8; i <= 63; i++)
0093 *p++ = 0x0;
0094
0095
0096 p = (vuint8 *) & MCF_INTC1_ICR8;
0097 for (i = 108; i <= 139; i++)
0098 *p++ = 0x0;
0099 }
0100
0101
0102
0103
0104 static void disable_watchdog_timer(void)
0105 {
0106
0107 MCF_SCM_CWCR = 0;
0108 }
0109
0110
0111
0112
0113 static void init_clock_config(void)
0114 {
0115
0116
0117
0118
0119
0120
0121
0122
0123 MCF_CLOCK_CCHR = MCF_CLOCK_CCHR_PFD(0x4);
0124
0125
0126 MCF_CLOCK_SYNCR = 0x4103;
0127 while ((MCF_CLOCK_SYNSR & 0x08) == 0) ;
0128
0129
0130 MCF_CLOCK_SYNCR = 0x4003;
0131 while ((MCF_CLOCK_SYNSR & 0x08) == 0) ;
0132 MCF_CLOCK_SYNCR = 0x4007;
0133 }
0134
0135
0136
0137
0138 static void init_ipsbar(void)
0139 {
0140
0141
0142
0143
0144
0145 *(vuint32 *) 0x40000000 = (vuint32) __IPSBAR + 1;
0146 }
0147
0148
0149
0150
0151 static void init_flash_controller(void)
0152 {
0153
0154
0155
0156
0157
0158
0159 MCF_CFM_CFMCLKD = MCF_CFM_CFMCLKD_PRDIV8 | MCF_CFM_CFMCLKD_DIV(0x12);
0160 MCF_CFM_CFMMCR = 0;
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175 __asm__ ("move.l #0x00000161,%d0");
0176 __asm__ ("movec %d0,%FLASHBAR");
0177 }
0178
0179
0180
0181
0182 static void init_eport(void)
0183 {
0184
0185 MCF_EPORT_EPDDR0 = 0;
0186 MCF_EPORT_EPDDR1 = 0;
0187 MCF_EPORT_EPPAR0 = 0;
0188 MCF_EPORT_EPPAR1 = 0;
0189 MCF_EPORT_EPIER0 = 0;
0190 MCF_EPORT_EPIER1 = 0;
0191 }
0192
0193
0194
0195
0196 static void init_flexcan(void)
0197 {
0198
0199 MCF_CAN_IMASK = 0;
0200 MCF_CAN_RXGMASK = MCF_CAN_RXGMASK_MI(0x1fffffff);
0201 MCF_CAN_RX14MASK = MCF_CAN_RX14MASK_MI(0x1fffffff);
0202 MCF_CAN_RX15MASK = MCF_CAN_RX15MASK_MI(0x1fffffff);
0203 MCF_CAN_CANCTRL = 0;
0204 MCF_CAN_CANMCR = MCF_CAN_CANMCR_MDIS |
0205 MCF_CAN_CANMCR_FRZ |
0206 MCF_CAN_CANMCR_HALT | MCF_CAN_CANMCR_SUPV | MCF_CAN_CANMCR_MAXMB(0xf);
0207 }
0208
0209
0210
0211
0212 static void init_bus_config(void)
0213 {
0214
0215
0216
0217
0218
0219
0220
0221
0222 MCF_SCM_MPARK = MCF_SCM_MPARK_M3PRTY(0x3) |
0223 MCF_SCM_MPARK_M2PRTY(0x2) | (0x1 << 16);
0224 }
0225
0226
0227
0228
0229 static void init_sram(void)
0230 {
0231
0232
0233
0234
0235 __asm__ ("move.l #0x20000001,%d0");
0236 __asm__ ("movec %d0,%RAMBAR");
0237 }
0238
0239
0240
0241
0242 static void init_power_management(void)
0243 {
0244
0245
0246
0247 MCF_PMM_LPICR = MCF_PMM_LPICR_ENBSTOP;
0248 MCF_PMM_LPCR = MCF_PMM_LPCR_LPMD_RUN;
0249 }
0250
0251
0252
0253
0254 static void init_dma_timers(void)
0255 {
0256
0257 MCF_DTIM0_DTMR = MCF_DTIM_DTMR_CLK(0x1);
0258 MCF_DTIM0_DTXMR = 0;
0259 MCF_DTIM0_DTRR = MCF_DTIM_DTRR_REF(0xffffffff);
0260
0261
0262 MCF_DTIM1_DTMR = 0;
0263 MCF_DTIM1_DTXMR = 0;
0264 MCF_DTIM1_DTRR = MCF_DTIM_DTRR_REF(0xffffffff);
0265
0266
0267 MCF_DTIM2_DTMR = 0;
0268 MCF_DTIM2_DTXMR = 0;
0269 MCF_DTIM2_DTRR = MCF_DTIM_DTRR_REF(0xffffffff);
0270
0271
0272 MCF_DTIM3_DTMR = MCF_DTIM_DTMR_CLK(0x1);
0273 MCF_DTIM3_DTXMR = 0;
0274 MCF_DTIM3_DTRR = MCF_DTIM_DTRR_REF(0xffffffff);
0275 }
0276
0277
0278
0279
0280 static void init_gp_timer(void)
0281 {
0282
0283
0284
0285
0286
0287
0288
0289 MCF_GPT_GPTSCR1 = 0;
0290 MCF_GPT_GPTDDR = 0;
0291 }
0292
0293
0294
0295
0296 static void init_interrupt_timers(void)
0297 {
0298
0299 MCF_PIT0_PCSR = 0;
0300
0301
0302 MCF_PIT1_PCSR = 0;
0303 }
0304
0305
0306
0307
0308 static void init_real_time_clock(void)
0309 {
0310
0311 MCF_RTC_CR = 0;
0312 }
0313
0314
0315
0316
0317 static void init_watchdog_timer(void)
0318 {
0319
0320 MCF_SCM_CWCR = 0;
0321 }
0322
0323
0324
0325
0326 static void init_interrupt_controller(void)
0327 {
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337 MCF_INTC0_ICR1 = 0;
0338 MCF_INTC0_ICR2 = 0;
0339 MCF_INTC0_ICR3 = 0;
0340 MCF_INTC0_ICR4 = 0;
0341 MCF_INTC0_ICR5 = 0;
0342 MCF_INTC0_ICR6 = 0;
0343 MCF_INTC0_ICR7 = 0;
0344 MCF_INTC0_ICR8 = 0;
0345 MCF_INTC0_ICR9 = 0;
0346 MCF_INTC0_ICR10 = 0;
0347 MCF_INTC0_ICR11 = 0;
0348 MCF_INTC0_ICR12 = 0;
0349 MCF_INTC0_ICR13 = 0;
0350 MCF_INTC0_ICR14 = 0;
0351 MCF_INTC0_ICR15 = 0;
0352 MCF_INTC0_ICR17 = 0;
0353 MCF_INTC0_ICR18 = 0;
0354 MCF_INTC0_ICR19 = 0;
0355 MCF_INTC0_ICR20 = 0;
0356 MCF_INTC0_ICR21 = 0;
0357 MCF_INTC0_ICR22 = 0;
0358 MCF_INTC0_ICR23 = 0;
0359 MCF_INTC0_ICR24 = 0;
0360 MCF_INTC0_ICR25 = 0;
0361 MCF_INTC0_ICR26 = 0;
0362 MCF_INTC0_ICR27 = 0;
0363 MCF_INTC0_ICR28 = 0;
0364 MCF_INTC0_ICR29 = 0;
0365 MCF_INTC0_ICR30 = 0;
0366 MCF_INTC0_ICR31 = 0;
0367 MCF_INTC0_ICR32 = 0;
0368 MCF_INTC0_ICR33 = 0;
0369 MCF_INTC0_ICR34 = 0;
0370 MCF_INTC0_ICR35 = 0;
0371 MCF_INTC0_ICR36 = 0;
0372 MCF_INTC0_ICR41 = 0;
0373 MCF_INTC0_ICR42 = 0;
0374 MCF_INTC0_ICR43 = 0;
0375 MCF_INTC0_ICR44 = 0;
0376 MCF_INTC0_ICR45 = 0;
0377 MCF_INTC0_ICR46 = 0;
0378 MCF_INTC0_ICR47 = 0;
0379 MCF_INTC0_ICR48 = 0;
0380 MCF_INTC0_ICR49 = 0;
0381 MCF_INTC0_ICR50 = 0;
0382 MCF_INTC0_ICR51 = 0;
0383 MCF_INTC0_ICR52 = 0;
0384 MCF_INTC0_ICR53 = 0;
0385 MCF_INTC0_ICR55 = 0;
0386 MCF_INTC0_ICR56 = 0;
0387 MCF_INTC0_ICR59 = 0;
0388 MCF_INTC0_ICR60 = 0;
0389 MCF_INTC0_ICR61 = 0;
0390 MCF_INTC0_ICR62 = 0;
0391 MCF_INTC0_ICR63 = 0;
0392 MCF_INTC1_ICR8 = 0;
0393 MCF_INTC1_ICR9 = 0;
0394 MCF_INTC1_ICR10 = 0;
0395 MCF_INTC1_ICR11 = 0;
0396 MCF_INTC1_ICR12 = 0;
0397 MCF_INTC1_ICR13 = 0;
0398 MCF_INTC1_ICR14 = 0;
0399 MCF_INTC1_ICR15 = 0;
0400 MCF_INTC1_ICR16 = 0;
0401 MCF_INTC1_ICR17 = 0;
0402 MCF_INTC1_ICR18 = 0;
0403 MCF_INTC1_ICR19 = 0;
0404 MCF_INTC1_ICR20 = 0;
0405 MCF_INTC1_ICR21 = 0;
0406 MCF_INTC1_ICR22 = 0;
0407 MCF_INTC1_ICR23 = 0;
0408 MCF_INTC1_ICR24 = 0;
0409 MCF_INTC1_ICR25 = 0;
0410 MCF_INTC1_ICR32 = 0;
0411 MCF_INTC1_ICR33 = 0;
0412 MCF_INTC1_ICR34 = 0;
0413 MCF_INTC1_ICR35 = 0;
0414 MCF_INTC1_ICR36 = 0;
0415 MCF_INTC1_ICR37 = 0;
0416 MCF_INTC1_ICR38 = 0;
0417 MCF_INTC1_ICR39 = 0;
0418 MCF_INTC0_IMRH = 0xffffffff;
0419 MCF_INTC0_IMRL = 0xfffffffe;
0420 MCF_INTC1_IMRH = 0xffffffff;
0421 MCF_INTC1_IMRL = 0xfffffffe;
0422 }
0423
0424
0425
0426
0427 static void init_pin_assignments(void)
0428 {
0429
0430
0431
0432 MCF_GPIO_DDRNQ = 0;
0433 MCF_GPIO_PNQPAR = MCF_GPIO_PNQPAR_PNQPAR7(0x1) |
0434 MCF_GPIO_PNQPAR_PNQPAR6(0x1) |
0435 MCF_GPIO_PNQPAR_PNQPAR5(0x1) |
0436 MCF_GPIO_PNQPAR_PNQPAR4(0x1) |
0437 MCF_GPIO_PNQPAR_PNQPAR3(0x1) |
0438 MCF_GPIO_PNQPAR_PNQPAR2(0x1) | MCF_GPIO_PNQPAR_PNQPAR1(0x1);
0439
0440
0441
0442
0443 MCF_GPIO_DDRGP = 0;
0444 MCF_GPIO_PGPPAR = MCF_GPIO_PGPPAR_PGPPAR7 |
0445 MCF_GPIO_PGPPAR_PGPPAR6 |
0446 MCF_GPIO_PGPPAR_PGPPAR5 |
0447 MCF_GPIO_PGPPAR_PGPPAR4 |
0448 MCF_GPIO_PGPPAR_PGPPAR3 |
0449 MCF_GPIO_PGPPAR_PGPPAR2 |
0450 MCF_GPIO_PGPPAR_PGPPAR1 | MCF_GPIO_PGPPAR_PGPPAR0;
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463 MCF_GPIO_DDRDD = 0;
0464 MCF_GPIO_PDDPAR = MCF_GPIO_PDDPAR_PDDPAR7 |
0465 MCF_GPIO_PDDPAR_PDDPAR6 |
0466 MCF_GPIO_PDDPAR_PDDPAR5 |
0467 MCF_GPIO_PDDPAR_PDDPAR4 |
0468 MCF_GPIO_PDDPAR_PDDPAR3 |
0469 MCF_GPIO_PDDPAR_PDDPAR2 |
0470 MCF_GPIO_PDDPAR_PDDPAR1 | MCF_GPIO_PDDPAR_PDDPAR0;
0471 MCF_CIM_CCON = 0x0021;
0472
0473
0474
0475
0476 MCF_GPIO_DDRAN = 0;
0477 MCF_GPIO_PANPAR = 0;
0478
0479
0480
0481
0482 MCF_GPIO_DDRAS = 0;
0483 MCF_GPIO_PASPAR = 0;
0484
0485
0486
0487
0488 MCF_GPIO_DDRLD = 0;
0489 MCF_GPIO_PLDPAR = 0;
0490
0491
0492
0493
0494 MCF_GPIO_DDRQS = 0;
0495 MCF_GPIO_PQSPAR = 0;
0496
0497
0498
0499
0500 MCF_GPIO_DDRTA = 0;
0501 MCF_GPIO_PTAPAR = 0;
0502
0503
0504
0505
0506 MCF_GPIO_DDRTC = 0;
0507 MCF_GPIO_PTCPAR = 0;
0508
0509
0510
0511
0512 MCF_GPIO_DDRTD = 0;
0513 MCF_GPIO_PTDPAR = 0;
0514
0515
0516
0517
0518
0519
0520
0521 MCF_GPIO_DDRUA = 0;
0522 MCF_GPIO_PUAPAR = MCF_GPIO_PUAPAR_PUAPAR3(0x1) |
0523 MCF_GPIO_PUAPAR_PUAPAR2(0x1) |
0524 MCF_GPIO_PUAPAR_PUAPAR1(0x1) | MCF_GPIO_PUAPAR_PUAPAR0(0x1);
0525
0526
0527
0528
0529
0530
0531
0532 MCF_GPIO_DDRUB = 0;
0533 MCF_GPIO_PUBPAR = MCF_GPIO_PUBPAR_PUBPAR3(0x1) |
0534 MCF_GPIO_PUBPAR_PUBPAR2(0x1) |
0535 MCF_GPIO_PUBPAR_PUBPAR1(0x1) | MCF_GPIO_PUBPAR_PUBPAR0(0x1);
0536
0537
0538
0539
0540
0541
0542
0543 MCF_GPIO_DDRUC = 0;
0544 MCF_GPIO_PUCPAR = MCF_GPIO_PUCPAR_PUCPAR3 |
0545 MCF_GPIO_PUCPAR_PUCPAR2 |
0546 MCF_GPIO_PUCPAR_PUCPAR1 | MCF_GPIO_PUCPAR_PUCPAR0;
0547
0548
0549 MCF_GPIO_PDSRH = 0;
0550 MCF_GPIO_PDSRL = 0;
0551
0552
0553 MCF_GPIO_PWOR = 0;
0554 }