2 FreeRTOS MCF5235 port - Copyright (C) 2006 Christian Walter.
4 This file is part of the FreeRTOS distribution.
6 FreeRTOS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 FreeRTOS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with FreeRTOS; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 A special exception to the GPL can be applied should you wish to distribute
21 a combined work that includes FreeRTOS, without being obliged to provide
22 the source code for any proprietary components. See the licensing section
23 of http://www.FreeRTOS.org for full details of how and when the exception
26 ***************************************************************************
27 See http://www.FreeRTOS.org for documentation, latest information, license
28 and contact details. Please ensure to read the configuration and relevant
29 port sections of the online documentation.
30 ***************************************************************************
36 /* Function prototypes */
37 void init_main( void );
38 static void disable_interrupts( void );
39 static void disable_watchdog_timer( void );
40 static void disable_cache( void );
41 static void init_ipsbar( void );
42 static void init_basics( void );
43 static void init_clock_config( void );
44 static void init_chip_selects( void );
45 static void init_bus_config( void );
46 static void init_cache( void );
47 static void init_eport( void );
48 static void init_flexcan( void );
49 static void init_power_management( void );
50 static void init_dma_timers( void );
51 static void init_interrupt_timers( void );
52 static void init_watchdog_timers( void );
53 static void init_pin_assignments( void );
54 static void init_sdram_controller( void );
55 static void init_interrupt_controller( void );
58 /*********************************************************************
59 * init_main - Main entry point for initialisation code *
60 **********************************************************************/
65 /* Initialise base address of peripherals, VBR, etc */
70 /* Disable interrupts, watchdog timer, cache */
71 disable_interrupts( );
72 disable_watchdog_timer( );
75 /* Initialise individual modules */
81 init_power_management( );
83 init_interrupt_timers( );
84 init_watchdog_timers( );
85 init_pin_assignments( );
86 init_sdram_controller( );
88 /* Initialise interrupt controller */
89 init_interrupt_controller( );
92 /*********************************************************************
93 * disable_interrupts - Disable all interrupt sources *
94 **********************************************************************/
96 disable_interrupts( void )
102 /* Set ICR008-ICR063 to 0x0 */
103 p = ( vuint8 * ) & MCF_INTC0_ICR8;
104 for( i = 8; i <= 63; i++ )
107 /* Set ICR108-ICR163 to 0x0 */
108 p = ( vuint8 * ) & MCF_INTC1_ICR8;
109 for( i = 108; i <= 163; i++ )
114 /*********************************************************************
115 * disable_watchdog_timer - Disable system watchdog timer *
116 **********************************************************************/
118 disable_watchdog_timer( void )
121 /* Disable Core Watchdog Timer */
125 /*********************************************************************
126 * disable_cache - Disable and invalidate cache *
127 **********************************************************************/
129 disable_cache( void )
131 asm ( "move.l #0x01000000, %d0" );
132 asm ( "movec %d0, %CACR" );
135 /*********************************************************************
136 * init_basics - Configuration Information & VBR *
137 **********************************************************************/
142 extern uint32 __RAMVEC[];
143 extern uint32 __ROMVEC[];
145 /* Transfer size not driven on SIZ[1:0] pins during external cycles
146 Processor Status (PST) and Debug Data (DDATA) functions disabled
148 Output pads configured for full strength
150 MCF_CCM_CCR = ( 0x1 << 15 ) | MCF_CCM_CCR_BME;
152 /* Set up RAM vectors */
153 for( i = 0; i < 256; i++ )
156 __RAMVEC[i] = __ROMVEC[i];
158 asm( "move.l %0,%%d0": :"i"( __RAMVEC ) );
159 asm( "movec %d0,%vbr" );
163 /*********************************************************************
164 * init_clock_config - Clock Module *
165 **********************************************************************/
167 init_clock_config( void )
169 /* Clock module uses normal PLL mode with 25.0000 MHz external reference (Fref)
171 Bus clock frequency = 25.00 MHz
172 Processor clock frequency = 2 x bus clock = 50.00 MHz
173 Frequency Modulation disabled
174 Loss of clock detection disabled
175 Reset/Interrupt on loss of lock disabled
177 MCF_FMPLL_SYNCR = 0x00100000; /* Set RFD=RFD+1 to avoid frequency overshoot */
178 while( ( MCF_FMPLL_SYNSR & 0x08 ) == 0 ) /* Wait for PLL to lock */
180 MCF_FMPLL_SYNCR = 0x00080000; /* Set desired RFD */
181 while( ( MCF_FMPLL_SYNSR & 0x08 ) == 0 ) /* Wait for PLL to lock */
186 /*********************************************************************
187 * init_ipsbar - Internal Peripheral System Base Address (IPSBAR) *
188 **********************************************************************/
194 /* Base address of internal peripherals (IPSBAR) = 0x40000000
196 Note: Processor powers up with IPS base address = 0x40000000
197 Write to IPS base + 0x00000000 to set new value
199 *( vuint32 * ) 0x40000000 = ( vuint32 ) __IPSBAR + 1;
201 /* Configure RAMBAR in SCM module and allow dual-ported access. */
202 MCF_SCM_RAMBAR = ( uint32 ) &__SRAM | MCF_SCM_RAMBAR_BDE;
205 /*********************************************************************
206 * init_chip_selects - Chip Select Module *
207 **********************************************************************/
209 init_chip_selects( void )
212 uint32 FLASH_ADDR = (uint32)&__FLASH;
214 /* Chip Select 0 - External Flash */
215 MCF_CS_CSAR0 = MCF_CS_CSAR_BA( FLASH_ADDR );
217 | MCF_CS_CSCR_IWS( 6 )
218 | MCF_CS_CSCR_AA | MCF_CS_CSCR_PS_16 );
219 MCF_CS_CSMR0 = MCF_CS_CSMR_BAM_2M | MCF_CS_CSMR_V;
221 /* Chip Select 1 disabled (CSMR1[V] = 0) */
226 /* Chip Select 2 disabled (CSMR2[V] = 0) */
231 /* Chip Select 3 disabled (CSMR3[V] = 0) */
236 /* Chip Select 4 disabled (CSMR4[V] = 0) */
241 /* Chip Select 5 disabled (CSMR5[V] = 0) */
246 /* Chip Select 6 disabled (CSMR6[V] = 0) */
251 /* Chip Select 7 disabled (CSMR7[V] = 0) */
257 /*********************************************************************
258 * init_bus_config - Internal Bus Arbitration *
259 **********************************************************************/
261 init_bus_config( void )
264 /* Use round robin arbitration scheme
265 Assigned priorities (highest first):
269 DMA bandwidth control disabled
270 Park on last active bus master
273 MCF_SCM_MPARK_M3_PRTY( 0x3 ) | MCF_SCM_MPARK_M2_PRTY( 0x2 ) |
274 MCF_SCM_MPARK_M1_PRTY( 0x1 );
277 /*********************************************************************
278 * init_cache - Instruction/Data Cache *
279 **********************************************************************/
283 /* Configured as split cache: 4 KByte instruction cache and 4 Kbyte data cache
284 ACR0: Don't cache accesses to 16 MB memory region at address $20000000
285 ACR1: Don't cache accesses to 1 GB memory region at address $40000000
286 CACR: Cache accesses to the rest of memory
288 asm("move.l #0x80000000,%d0");
289 asm("movec %d0,%CACR");
290 asm("move.l #0x2000c040,%d0");
291 asm("movec %d0,%ACR0");
292 asm("move.l #0x403fc040,%d0");
293 asm("movec %d0,%ACR1");
295 /* Instruction/Data cache disabled. */
296 //asm( "move.l #0x00000000, %d0" );
297 //asm( "movec %d0,%cacr" );
300 /*********************************************************************
301 * init_eport - Edge Port Module (EPORT) *
302 **********************************************************************/
307 /* Pins 1-7 configured as GPIO inputs */
313 /*********************************************************************
314 * init_flexcan - FlexCAN Module *
315 **********************************************************************/
320 /* FlexCAN controller 0 disabled (CANMCR0[MDIS]=1) */
322 MCF_CAN_RXGMASK0 = MCF_CAN_RXGMASK_MI( 0x1fffffff );
323 MCF_CAN_RX14MASK0 = MCF_CAN_RX14MASK_MI( 0x1fffffff );
324 MCF_CAN_RX15MASK0 = MCF_CAN_RX15MASK_MI( 0x1fffffff );
325 MCF_CAN_CANCTRL0 = 0;
327 MCF_CAN_CANMCR_MDIS | MCF_CAN_CANMCR_FRZ | MCF_CAN_CANMCR_HALT |
328 MCF_CAN_CANMCR_SUPV | MCF_CAN_CANMCR_MAXMB( 0xf );
330 /* FlexCAN controller 1 disabled (CANMCR1[MDIS]=1) */
332 MCF_CAN_RXGMASK1 = MCF_CAN_RXGMASK_MI( 0x1fffffff );
333 MCF_CAN_RX14MASK1 = MCF_CAN_RX14MASK_MI( 0x1fffffff );
334 MCF_CAN_RX15MASK1 = MCF_CAN_RX15MASK_MI( 0x1fffffff );
335 MCF_CAN_CANCTRL1 = 0;
337 MCF_CAN_CANMCR_MDIS | MCF_CAN_CANMCR_FRZ | MCF_CAN_CANMCR_HALT |
338 MCF_CAN_CANMCR_SUPV | MCF_CAN_CANMCR_MAXMB( 0xf );
341 /*********************************************************************
342 * init_power_management - Power Management *
343 **********************************************************************/
345 init_power_management( void )
348 /* On executing STOP instruction, processor enters RUN mode
349 Mode is exited when an interrupt of level 1 or higher is received
351 MCF_SCM_LPICR = MCF_SCM_LPICR_ENBSTOP;
355 /*********************************************************************
356 * init_sdram_controller - SDRAM Controller *
357 **********************************************************************/
359 init_sdram_controller( void )
362 uint32 SDRAM_ADDR = (uint32)&__SDRAM;
367 * Check to see if the SDRAM has already been initialized
368 * by a run control tool
370 if( !( MCF_SDRAMC_DACR0 & MCF_SDRAMC_DACR0_RE ) )
372 /* Initialize DRAM Control Register: DCR */
373 MCF_SDRAMC_DCR = ( MCF_SDRAMC_DCR_RTIM( 1 ) |
374 MCF_SDRAMC_DCR_RC( ( 15 * FSYS_2 ) >> 4 ) );
376 /* Initialize DACR0 */
377 MCF_SDRAMC_DACR0 = ( MCF_SDRAMC_DACR0_BA( SDRAM_ADDR >> 18UL ) |
378 MCF_SDRAMC_DACR0_CASL( 1 ) |
379 MCF_SDRAMC_DACR0_CBM( 3 ) |
380 MCF_SDRAMC_DACR0_PS( 0 ) );
382 /* Initialize DMR0 */
383 MCF_SDRAMC_DMR0 = ( MCF_SDRAMC_DMR_BAM_16M | MCF_SDRAMC_DMR0_V );
385 /* Set IP (bit 3) in DACR */
386 MCF_SDRAMC_DACR0 |= MCF_SDRAMC_DACR0_IP;
388 /* Wait 30ns to allow banks to precharge */
389 for( i = 0; i < 5; i++ )
391 asm volatile ( " nop" );
393 /* Write to this block to initiate precharge */
394 *( uint32 * ) ( SDRAM_ADDR ) = 0xA5A59696;
396 /* Set RE (bit 15) in DACR */
397 MCF_SDRAMC_DACR0 |= MCF_SDRAMC_DACR0_RE;
399 /* Wait for at least 8 auto refresh cycles to occur */
400 for( i = 0; i < 2000; i++ )
402 asm volatile ( "nop" );
404 /* Finish the configuration by issuing the IMRS. */
405 MCF_SDRAMC_DACR0 |= MCF_SDRAMC_DACR0_MRS;
407 /* Write to the SDRAM Mode Register */
408 *( uint32 * ) ( SDRAM_ADDR + 0x400 ) = 0xA5A59696;
412 /*********************************************************************
413 * init_dma_timers - DMA Timer Modules *
414 **********************************************************************/
416 init_dma_timers( void )
419 /* DMA Timer 0 disabled (DTMR0[RST] = 0) */
421 MCF_TIMER_DTXMR0 = 0;
422 MCF_TIMER_DTRR0 = 0xffffffff;
424 /* DMA Timer 1 disabled (DTMR1[RST] = 0) */
426 MCF_TIMER_DTXMR1 = 0;
427 MCF_TIMER_DTRR1 = 0xffffffff;
429 /* DMA Timer 2 disabled (DTMR2[RST] = 0) */
431 MCF_TIMER_DTXMR2 = 0;
432 MCF_TIMER_DTRR2 = 0xffffffff;
434 /* DMA Timer 3 disabled (DTMR3[RST] = 0) */
436 MCF_TIMER_DTXMR3 = 0;
437 MCF_TIMER_DTRR3 = 0xffffffff;
440 /**********************************************************************
441 * init_interrupt_timers - Programmable Interrupt Timer (PIT) Modules *
442 ***********************************************************************/
444 init_interrupt_timers( void )
447 /* PIT0 disabled (PCSR0[EN]=0) */
450 /* PIT1 disabled (PCSR1[EN]=0) */
453 /* PIT2 disabled (PCSR2[EN]=0) */
456 /* PIT3 disabled (PCSR3[EN]=0) */
460 /*********************************************************************
461 * init_watchdog_timers - Watchdog Timer Modules *
462 **********************************************************************/
464 init_watchdog_timers( void )
467 /* Watchdog Timer disabled (WCR[EN]=0)
468 NOTE: WCR and WMR cannot be written again until after the
471 MCF_WTM_WCR = MCF_WTM_WCR_WAIT | MCF_WTM_WCR_DOZE | MCF_WTM_WCR_HALTED;
472 MCF_WTM_WMR = 0xffff;
474 /* Core Watchdog Timer disabled (CWCR[CWE]=0) */
478 /*********************************************************************
479 * init_interrupt_controller - Interrupt Controller *
480 **********************************************************************/
482 init_interrupt_controller( void )
485 /* Configured interrupt sources in order of priority...
486 Level 7: External interrupt /IRQ7, (initially masked)
487 Level 6: External interrupt /IRQ6, (initially masked)
488 Level 5: External interrupt /IRQ5, (initially masked)
489 Level 4: External interrupt /IRQ4, (initially masked)
490 Level 3: External interrupt /IRQ3, (initially masked)
491 Level 2: External interrupt /IRQ2, (initially masked)
492 Level 1: External interrupt /IRQ1, (initially masked)
588 MCF_INTC0_IMRH = 0xffffffff;
590 MCF_INTC0_IMRL_INT_MASK31 | MCF_INTC0_IMRL_INT_MASK30 |
591 MCF_INTC0_IMRL_INT_MASK29 | MCF_INTC0_IMRL_INT_MASK28 |
592 MCF_INTC0_IMRL_INT_MASK27 | MCF_INTC0_IMRL_INT_MASK26 |
593 MCF_INTC0_IMRL_INT_MASK25 | MCF_INTC0_IMRL_INT_MASK24 |
594 MCF_INTC0_IMRL_INT_MASK23 | MCF_INTC0_IMRL_INT_MASK22 |
595 MCF_INTC0_IMRL_INT_MASK21 | MCF_INTC0_IMRL_INT_MASK20 |
596 MCF_INTC0_IMRL_INT_MASK19 | MCF_INTC0_IMRL_INT_MASK18 |
597 MCF_INTC0_IMRL_INT_MASK17 | MCF_INTC0_IMRL_INT_MASK16 |
598 MCF_INTC0_IMRL_INT_MASK15 | MCF_INTC0_IMRL_INT_MASK14 |
599 MCF_INTC0_IMRL_INT_MASK13 | MCF_INTC0_IMRL_INT_MASK12 |
600 MCF_INTC0_IMRL_INT_MASK11 | MCF_INTC0_IMRL_INT_MASK10 |
601 MCF_INTC0_IMRL_INT_MASK9 | MCF_INTC0_IMRL_INT_MASK8 |
602 MCF_INTC0_IMRL_INT_MASK7 | MCF_INTC0_IMRL_INT_MASK6 |
603 MCF_INTC0_IMRL_INT_MASK5 | MCF_INTC0_IMRL_INT_MASK4 |
604 MCF_INTC0_IMRL_INT_MASK3 | MCF_INTC0_IMRL_INT_MASK2 |
605 MCF_INTC0_IMRL_INT_MASK1;
606 MCF_INTC1_IMRH = 0xffffffff;
608 MCF_INTC1_IMRL_INT_MASK31 | MCF_INTC1_IMRL_INT_MASK30 |
609 MCF_INTC1_IMRL_INT_MASK29 | MCF_INTC1_IMRL_INT_MASK28 |
610 MCF_INTC1_IMRL_INT_MASK27 | MCF_INTC1_IMRL_INT_MASK26 |
611 MCF_INTC1_IMRL_INT_MASK25 | MCF_INTC1_IMRL_INT_MASK24 |
612 MCF_INTC1_IMRL_INT_MASK23 | MCF_INTC1_IMRL_INT_MASK22 |
613 MCF_INTC1_IMRL_INT_MASK21 | MCF_INTC1_IMRL_INT_MASK20 |
614 MCF_INTC1_IMRL_INT_MASK19 | MCF_INTC1_IMRL_INT_MASK18 |
615 MCF_INTC1_IMRL_INT_MASK17 | MCF_INTC1_IMRL_INT_MASK16 |
616 MCF_INTC1_IMRL_INT_MASK15 | MCF_INTC1_IMRL_INT_MASK14 |
617 MCF_INTC1_IMRL_INT_MASK13 | MCF_INTC1_IMRL_INT_MASK12 |
618 MCF_INTC1_IMRL_INT_MASK11 | MCF_INTC1_IMRL_INT_MASK10 |
619 MCF_INTC1_IMRL_INT_MASK9 | MCF_INTC1_IMRL_INT_MASK8 |
620 MCF_INTC1_IMRL_INT_MASK7 | MCF_INTC1_IMRL_INT_MASK6 |
621 MCF_INTC1_IMRL_INT_MASK5 | MCF_INTC1_IMRL_INT_MASK4 |
622 MCF_INTC1_IMRL_INT_MASK3 | MCF_INTC1_IMRL_INT_MASK2 |
623 MCF_INTC1_IMRL_INT_MASK1;
626 /*********************************************************************
627 * init_pin_assignments - Pin Assignment and General Purpose I/O *
628 **********************************************************************/
630 init_pin_assignments( void )
633 /* Pin assignments for port ADDR
634 Pins are all GPIO inputs
636 MCF_GPIO_PDDR_APDDR = 0;
637 MCF_GPIO_PAR_AD = MCF_GPIO_PAR_AD_PAR_ADDR23
638 | MCF_GPIO_PAR_AD_PAR_ADDR22
639 | MCF_GPIO_PAR_AD_PAR_ADDR21 | MCF_GPIO_PAR_AD_PAR_DATAL;
641 /* Pin assignments for ports DATAH and DATAL
642 Pins are all GPIO inputs
644 MCF_GPIO_PDDR_DATAH = 0;
645 MCF_GPIO_PDDR_DATAL = 0;
647 /* Pin assignments for port BUSCTL
648 Pin /OE : External bus output enable, /OE
649 Pin /TA : External bus transfer acknowledge, /TA
650 Pin /TEA : External bus transfer error acknowledge, /TEA
651 Pin R/W : External bus read/write indication, R/W
652 Pin TSIZ1 : External bus transfer size TSIZ1 or DMA acknowledge /DACK1
653 Pin TSIZ0 : External bus transfer size TSIZ0 or DMA acknowledge /DACK0
654 Pin /TS : External bus transfer start, /TS
655 Pin /TIP : External bus transfer in progess, /TIP
657 MCF_GPIO_PDDR_BUSCTL = 0;
658 MCF_GPIO_PAR_BUSCTL =
659 MCF_GPIO_PAR_BUSCTL_PAR_OE | MCF_GPIO_PAR_BUSCTL_PAR_TA |
660 MCF_GPIO_PAR_BUSCTL_PAR_TEA( 0x3 ) | MCF_GPIO_PAR_BUSCTL_PAR_RWB |
661 MCF_GPIO_PAR_BUSCTL_PAR_TSIZ1 | MCF_GPIO_PAR_BUSCTL_PAR_TSIZ0 |
662 MCF_GPIO_PAR_BUSCTL_PAR_TS( 0x3 ) |
663 MCF_GPIO_PAR_BUSCTL_PAR_TIP( 0x3 );
665 /* Pin assignments for port BS
666 Pin /BS3 : External byte strobe /BS3
667 Pin /BS2 : External byte strobe /BS2
668 Pin /BS1 : External byte strobe /BS1
669 Pin /BS0 : External byte strobe /BS0
671 MCF_GPIO_PDDR_BS = 0;
673 MCF_GPIO_PAR_BS_PAR_BS3 | MCF_GPIO_PAR_BS_PAR_BS2 |
674 MCF_GPIO_PAR_BS_PAR_BS1 | MCF_GPIO_PAR_BS_PAR_BS0;
676 /* Pin assignments for port CS
677 Pin /CS7 : Chip select /CS7
678 Pin /CS6 : Chip select /CS6
679 Pin /CS5 : Chip select /CS5
680 Pin /CS4 : Chip select /CS4
681 Pin /CS3 : Chip select /CS3
682 Pin /CS2 : Chip select /CS2
683 Pin /CS1 : Chip select /CS1
685 MCF_GPIO_PDDR_CS = 0;
687 MCF_GPIO_PAR_CS_PAR_CS7 | MCF_GPIO_PAR_CS_PAR_CS6 |
688 MCF_GPIO_PAR_CS_PAR_CS5 | MCF_GPIO_PAR_CS_PAR_CS4 |
689 MCF_GPIO_PAR_CS_PAR_CS3 | MCF_GPIO_PAR_CS_PAR_CS2 |
690 MCF_GPIO_PAR_CS_PAR_CS1;
692 /* Pin assignments for port SDRAM
693 Pin /SD_WE : SDRAM controller /SD_WE
694 Pin /SD_SCAS : SDRAM controller /SD_SCAS
695 Pin /SD_SRAS : SDRAM controller /SD_SRAS
696 Pin /SD_SCKE : SDRAM controller /SD_SCKE
697 Pin /SD_CS1 : SDRAM controller /SD_CS1
698 Pin /SD_CS0 : SDRAM controller /SD_CS0
700 MCF_GPIO_PDDR_SDRAM = 0;
702 MCF_GPIO_PAR_SDRAM_PAR_SDWE | MCF_GPIO_PAR_SDRAM_PAR_SCAS |
703 MCF_GPIO_PAR_SDRAM_PAR_SRAS | MCF_GPIO_PAR_SDRAM_PAR_SCKE |
704 MCF_GPIO_PAR_SDRAM_PAR_SDCS1 | MCF_GPIO_PAR_SDRAM_PAR_SDCS0;
706 /* Pin assignments for port FECI2C
707 Pins are all GPIO inputs
709 MCF_GPIO_PDDR_FECI2C = 0;
710 MCF_GPIO_PAR_FECI2C =
711 MCF_GPIO_PAR_FECI2C_PAR_EMDC_FEC | MCF_GPIO_PAR_FECI2C_PAR_EMDIO_FEC;
713 /* Pin assignments for port UARTL
714 Pins are all GPIO inputs
716 MCF_GPIO_PDDR_UARTL = 0;
717 MCF_GPIO_PAR_UART = 0;
719 /* Pin assignments for port UARTH
720 Pin U2TXD : GPIO input
721 Pin U2RXD : GPIO input
722 Pin /IRQ2 : Interrupt request /IRQ2 or GPIO
724 MCF_GPIO_PDDR_UARTH = 0;
726 /* Pin assignments for port QSPI
727 Pins are all GPIO inputs
729 MCF_GPIO_PDDR_QSPI = 0;
730 MCF_GPIO_PAR_QSPI = 0;
732 /* Pin assignments for port TIMER
733 Pins are all GPIO inputs
735 MCF_GPIO_PDDR_TIMER = 0;
736 MCF_GPIO_PAR_TIMER = 0;
738 /* Pin assignments for port ETPU
739 Pins are all GPIO inputs
741 MCF_GPIO_PDDR_ETPU = 0;
742 MCF_GPIO_PAR_ETPU = 0;