sh_io.h macros don't work...

Radzislaw Galler morib at morib.com.pl
Wed Jun 13 16:07:28 UTC 2001


Hi,

Today I found out what's wrong with my initialization. There is file 
hw_init.c in gensh2/startup directory. I uses macros defined in file sh_io.h 
to initialize some special registers. The problem is that the processor 
doesn't start if I use this file. When I write the initialization like this:

-----------------------------------------------
int hw_init()
{
    *SH2_704X_BSC_BCR1 = 0x200F;
    *SH2_704X_BSC_BCR2 = 0xFFFF;
    *SH2_704X_BSC_WCR1 = 0xff33;
    *SH2_704X_BSC_WCR2 = 0x000f;
    *SH2_704X_BSC_DCR = 0;
    *SH2_704X_BSC_RTCSR = 0;
    *SH2_704X_BSC_RTCNT = 0;
    *SH2_704X_BSC_RTCOR = 0;

    *SH2_704X_PFC_PACRL1 = 0x1555;

    *SH2_704X_PFC_PACRL2 = 0xAD75;
  
    *SH2_704X_PFC_PBCR1  = 0x0000;
    *SH2_704X_PFC_PBCR2  = 0x2005;
    *SH2_704X_PFC_PCCR   = 0xFFFF;
    *SH2_704X_PFC_PDCRL  = 0xffff;
    *SH2_704X_PFC_IFCR   = 0;
    *SH2_704X_PFC_PEIOR  = 0x0020;
    *SH2_704X_IO_PEDR    = 0x0020;

    /* turn on the 7045EDK's green led */
    *SH2_704X_PFC_PEIOR = 0xFF;
    *SH2_704X_IO_PEDR = 0x01;
}
----------------------------------------------------

where macros SH2_704X_... are defined this way:

----------------------------------------------------
/* BSC */

#define SH2_704X_BSC_WCR1   ((volatile short *)0xffff8624L)
#define SH2_704X_BSC_WCR2   ((volatile short *)0xffff8626L)
#define SH2_704X_BSC_BCR1   ((volatile short *)0xffff8620L)
#define SH2_704X_BSC_BCR2   ((volatile short *)0xffff8622L)
#define SH2_704X_BSC_DCR    ((volatile short *)0xffff862aL)
#define SH2_704X_BSC_RTCSR  ((volatile short *)0xffff862cL)
#define SH2_704X_BSC_RTCNT  ((volatile short *)0xffff862eL)
#define SH2_704X_BSC_RTCOR  ((volatile short *)0xffff8630L)


/* PFC */

#define SH2_704X_PFC_PAIORH ((volatile short *) 0xffff8384L)
#define SH2_704X_PFC_PAIORL ((volatile short *) 0xffff8386L)
#define SH2_704X_PFC_PACRH  ((volatile short *) 0xffff8388L)
#define SH2_704X_PFC_PACRL1 ((volatile short *) 0xffff838cL)
#define SH2_704X_PFC_PACRL2 ((volatile short *) 0xffff838eL)
#define SH2_704X_PFC_PBIOR  ((volatile short *) 0xffff8394L)
#define SH2_704X_PFC_PBCR1  ((volatile short *) 0xffff8398L)
#define SH2_704X_PFC_PBCR2  ((volatile short *) 0xffff839aL)
#define SH2_704X_PFC_PCIOR  ((volatile short *) 0xffff8396L)
#define SH2_704X_PFC_PCCR   ((volatile short *) 0xffff839cL)
#define SH2_704X_PFC_PDIORH ((volatile short *) 0xffff83a4L)
#define SH2_704X_PFC_PDIORL ((volatile short *) 0xffff83a6L)
#define SH2_704X_PFC_PDCRH1 ((volatile short *) 0xffff83a8L)
#define SH2_704X_PFC_PDCRH2 ((volatile short *) 0xffff83aaL)
#define SH2_704X_PFC_PDCRL  ((volatile short *) 0xffff83acL)
#define SH2_704X_PFC_PEIOR  ((volatile short *) 0xffff83b4L)
#define SH2_704X_PFC_PECR1  ((volatile short *) 0xffff83b8L)
#define SH2_704X_PFC_PECR2  ((volatile short *) 0xffff83baL)
#define SH2_704X_PFC_IFCR   ((volatile short *) 0xffff83c8L)
---------------------------------------------------
everything works OK.


For comparison here is the version from gensh2/startup

---------------------------------------------------
#include <bsp.h>

#include <stdlib.h>

#include <rtems/libio.h>
#include <iosupp.h>
#include <rtems/score/sh_io.h>
#include <rtems/score/iosh7045.h>

/* exported entries */
extern void bsp_hw_init (void);
extern void early_hw_init (void);

/*  called from 'start.S' on "#ifdef START_HW_INIT" */
void early_hw_init (void)
{
  /*  add early-init functions here */

  /* STANDALONE_EVB minimally sets up bus and DRAM here */
  /* no STANDALONE_EVB accepts defaults from debug monitor */

  /* FIXME: replace 'magic numbers' with logical names */

  write16(0x200F, BSC_BCR1);  /* Bus width access - 16-bit on CS0-3 */
  write16(0xFFFF, BSC_BCR2);  /* Idle cycles CS3-CS0 - 3 idle cycles*/
  write16(0xFF33, BSC_WCR1);  /* Waits for CS3-CS0 - 3 waits on CS1 and CS0 */
  write16(0x000F, BSC_WCR2);  /* Waits for DRAM/DMA access - default */
  write16(0x0000, BSC_DCR);   /* DRAM control - default */
  write16(0x0000, BSC_RTCSR); /* DRAM refresh - default */
  write16(0x0000, BSC_RTCNT); /* DRAM refresh counter - default*/
  write16(0x0000, BSC_RTCOR); /* DRAM refresh compare match - default */
  write16(0x1555, PFC_PACRL1); /* Pin fun. controller - 
WRH,WRL,RD,CS1,CS0,IRQ3,IRQ2 */
  write16(0xAD75, PFC_PACRL2); /* CS3, CS2,IRQ1,TXD0-1,RXD0-1,IRQ0*/
	                       /*  [re-connected by DEVICE_open()] */
  write16(0x0000, PFC_PBCR1);  /* Pin function controller - default */
  write16(0x2005, PFC_PBCR2);  /* Pin fcn. controller - A18,A17,A16 */
  write16(0xFFFF, PFC_PCCR);   /* Pin function controller - A15-A0  */
  write16(0xFFFF, PFC_PDCRL);  /* Pin function controller - D15-D0  */
  write16(0x0000, PFC_IFCR);   /* Pin function controller - default */



  /* PFC: General I/O except pin 13 (reset): */
  write16(read16(PFC_PECR1) | 0x0800, PFC_PECR1);

  /* All I/O lines bits 7-0: */
  write16(0x00, PFC_PECR2);

  /* P5 (LED) out, all other pins in: */
  write16(read16(PFC_PEIOR) | 0x00FF, PFC_PEIOR);
}
--------------------------------------------------

Do you see any significant difference?

Radek



More information about the users mailing list