/*初期化*/

#include "m9402.h"
/*#include "io.h"*/
int errno ; 
void rtc_clr();
void init_gro();

void init()
{ 
  /* rtc_clr(); */
  init_gro();
     /*  MMI PIT0 */
	outportb(PGCR0 ,0x00);	/*	clear PGCR0	*/
	outportb(PADDR0,0xff);	/*	all output	*/
	outportb(PBDDR0,0x10);  /*      RRRWRRRR        */
	outportb(PACR0 ,0x80);
	outportb(PBCR0 ,0x80);
        outportb(PGCR0 ,0x02);	/*	mode 0		*/

        outportb(TCR0,0x00);	/*	clear TCR0	*/
	outportl(CPR0,0x00003f);/*	TOUT 2kHz	*/
	outportb(TCR0,0x41);	/*	square wave	*/
      /*  PWM PIT1 */
	outportb(PGCR1 ,0x00);  /*	clear PGCR1	*/
	outportb(PADDR1,0xff);	/*	all output	*/
	outportb(PBDDR1,0xff);	/*	all output	*/
	outportb(PACR1 ,0x80);	/*	submode 1x	*/
	outportb(PBCR1 ,0x80);	/*	submode 1x	*/
        outportb(PGCR1 ,0x00);  /*  mode0 & H1,H2,H3,H4  disable*/

	outportb(TCR1  ,0x00);	
	outportl(CPR1  ,0x000001);	/* Toutの出力は125[kHz] */	
	outportb(TCR1  ,0x41);	/*	square wave	*/


      /* SSS & PHOTO PIT2 */
	outportb(PGCR2 ,0x00);	/*	clear PGCR2	*/
        outportb(PSRR2, 0x1c); 
	outportb(PACR2 ,0x20);
        outportb(PADDR2,0x03);
        outportb(PBCR2, 0xA0);   
        outportb(PBDDR2,0x00);
	outportb(PGCR2 ,0x18);  /*mode0 &  H3,H4  disable*/

	outportb(TCR2  ,0x00);
	outportl(CPR2 ,SSS_LIMIT);	/*under flow 3m*/
	outportb(TCR2  ,0xb2);

       outportb(TIVR2,72+0);    /*      sss interrupt causes by tout*/




/*	RE/TS	*/
	outportb(TSIE,0x00);	/*	Touch Sensor Interrupt Enable	*/
	outportb(CRST,0x03);	/*	counter reset	*/	


}


void rtc_clr()
{
int	rtc_base;
	int	i;

	rtc_base=0xfdfe00;

	outportb(MSR,0x44);
	for ( i=3 ; rtc_base+ i<0xfdfe40 ; i+=2 ) outportb(rtc_base+i,0x00);

	outportb(MSR,0x04);
	for ( i=3 ; rtc_base+ i<0xfdfe0a ; i+=2 ) outportb(rtc_base+i,0x00);

}

extern unsigned char pwm_mode;
extern unsigned int mmi_iivseg;
extern struct pos{
   int x;
   int y;
   int v;
   int theta;
   int thetav;
   int way;
}rot_position_i;

void init_gro()
{
   int i,j;
 /*  initialize grobal variables  */
   pwm_mode = 0x00;
   mmi_iivseg = 0000;
   rot_position_i.x = 0;
   rot_position_i.y = 0;
   rot_position_i.v = 0;
   rot_position_i.theta = 0;
   rot_position_i.thetav = 0;
   rot_position_i.way = 0;
}


開発規約に戻る