Exemple #1
0
void generate_tone(long frequency, long duration)
{
   int32 total_delay_time;                      // in microseconds
   long total_ms_delay_time, total_us_delay_time;
   int num_us_delays, num_ms_delays, ms_delay_time, us_delay_time;
   long num_periods;

   total_delay_time = (1000000/frequency)/2-10; // calculate total delay time (10 for error)

   total_ms_delay_time = total_delay_time/1000; // total delay time of ms
   num_ms_delays = total_ms_delay_time/250;     // number of 250ms delays needed
   ms_delay_time = total_ms_delay_time%250;     // left over ms delay time needed

   total_us_delay_time = total_delay_time%1000; // total delay time of us (ms already acounted for)
   num_us_delays = total_us_delay_time/250;     // number of 250us delays needed
   us_delay_time = total_us_delay_time%250;     // left over us delay time needed

   num_periods = ((int32)duration*1000)/(1000000/frequency);

   while((num_periods--) != 0)
   {
      do_delay(ms_delay_time, num_ms_delays, us_delay_time, num_us_delays);
      output_high(TONE_PIN);
      do_delay(ms_delay_time, num_ms_delays, us_delay_time, num_us_delays);
      output_low(TONE_PIN);
   }

   return;
}
Exemple #2
0
/*
 * reset AC link
 */
static int snd_atiixp_aclink_reset(atiixp_t *chip)
{
    int timeout;

    /* reset powerdoewn */
    if (atiixp_update(chip, CMD, ATI_REG_CMD_POWERDOWN, 0))
        udelay(10);

    /* perform a software reset */
    atiixp_update(chip, CMD, ATI_REG_CMD_AC_SOFT_RESET, ATI_REG_CMD_AC_SOFT_RESET);
    atiixp_read(chip, CMD);
    udelay(10);
    atiixp_update(chip, CMD, ATI_REG_CMD_AC_SOFT_RESET, 0);

    timeout = 10;
    while (! (atiixp_read(chip, CMD) & ATI_REG_CMD_ACLINK_ACTIVE)) {
        /* do a hard reset */
        atiixp_update(chip, CMD, ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET,
                      ATI_REG_CMD_AC_SYNC);
        atiixp_read(chip, CMD);
        do_delay();
        atiixp_update(chip, CMD, ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_RESET);
        if (--timeout) {
            snd_printk(KERN_ERR "atiixp: codec reset timeout\n");
            break;
        }
    }

    /* deassert RESET and assert SYNC to make sure */
    atiixp_update(chip, CMD, ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET,
                  ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET);

    return 0;
}
Exemple #3
0
void
Receiver::handle_read_stream (const TRB_Asynch_Read_Stream::Result &result)
{
    this->trace_read_completion (result);

    // emulate long callback
    do_delay (cfg.delay());  // delay milliseconds

    {
        ACE_GUARD (ACE_SYNCH_MUTEX, monitor, this->mutex () );

        this->ref_cnt_r_--;

        ACE_Message_Block & mb = result.message_block ();

        if (result.error () == 0 && result.bytes_transferred () > 0)
        {
            this->initiate_write_stream (&mb);

            this->initiate_read_stream (0);
        }
        else
        {
            mb.release ();
        }

        if (result.error () != 0)
            this->stream_.cancel_and_close ();

        if (!is_safe_to_delete())
            return;
    }
    this->manager()->destroy_session(this);
}
Exemple #4
0
void
RcvProtocol::on_read_finished (ACE_Message_Block & mb,
                               size_t bytes_transferred,
                               int  error)
{
  if (bytes_transferred == 0)
  {
    this->get_connection()->free_msg (&mb);
    return;
  }
    
  // emulate long callback
  do_delay (cfg.delay());  // delay milliseconds

  this->write(mb);

  //u_int blksize = this->get_connection()->config().r_blksize();
  u_int winsize = this->get_connection()->config().w_size();

  // flow control
  if ((u_long)(this->get_connection()->get_total_rcv () - 
               this->get_connection()->get_total_snd () > winsize))
    return; 
          
  this->read();
}
//
// Transition the card/slot to a new state
// note: currently only supports transitions to Ready, Empty
//
bool
cf_hwr_change_state(struct cf_slot *slot, int new_state)
{    
    int i, ptr, len;
    unsigned char buf[256];

    if (new_state == CF_SLOT_STATE_Ready) {
        if (slot->state == CF_SLOT_STATE_Inserted) {
            assabet_BCR(SA1110_BCR_CF_POWER |
                        SA1110_BCR_CF_RESET |
                        SA1110_BCR_CF_BUS,
                        SA1110_BCR_CF_POWER_ON |
                        SA1110_BCR_CF_RESET_DISABLE |
                        SA1110_BCR_CF_BUS_OFF);
            do_delay(30);  // At least 300 ms
            slot->state = CF_SLOT_STATE_Powered;
            assabet_BCR(SA1110_BCR_CF_POWER |
                        SA1110_BCR_CF_RESET |
                        SA1110_BCR_CF_BUS,
                        SA1110_BCR_CF_POWER_ON |
                        SA1110_BCR_CF_RESET_ENABLE |
                        SA1110_BCR_CF_BUS_ON);
            do_delay(1);  // At least 10 us
            slot->state = CF_SLOT_STATE_Reset;
            assabet_BCR(SA1110_BCR_CF_POWER |
                        SA1110_BCR_CF_RESET |
                        SA1110_BCR_CF_BUS,
                        SA1110_BCR_CF_POWER_ON |
                        SA1110_BCR_CF_RESET_DISABLE |
                        SA1110_BCR_CF_BUS_ON);
            do_delay(5); // At least 20 ms
            // Wait until the card is ready to talk
            for (i = 0;  i < 10;  i++) {
                ptr = 0;
                if (cf_get_CIS(slot, CF_CISTPL_VERS_1, buf, &len, &ptr)) {
                    slot->state = CF_SLOT_STATE_Ready;
                    break;
                }
                do_delay(10); 
            }
        }
    }
}
Exemple #6
0
//
// Transition the card/slot to a new state
// note: currently only supports transitions to Ready, Empty
//
void
cf_hwr_change_state(struct cf_slot *slot, int new_state)
{    
    int i, ptr, len;
    unsigned char buf[256];

    if (new_state == CF_SLOT_STATE_Ready) {
        if (slot->state == CF_SLOT_STATE_Inserted) {
            ipaq_EGPIO( SA1110_EIO_OPT_PWR | SA1110_EIO_OPT | SA1110_EIO_CF_RESET,
                        SA1110_EIO_OPT_PWR_ON | SA1110_EIO_OPT_ON | SA1110_EIO_CF_RESET_DISABLE);
            do_delay(30);  // At least 300 ms
            slot->state = CF_SLOT_STATE_Powered;
            ipaq_EGPIO( SA1110_EIO_CF_RESET, SA1110_EIO_CF_RESET_ENABLE);
            *(volatile unsigned short *)IPAQ_CF_CTRL = IPAQ_CF_CTRL_V5_DISABLE | 
                                                       IPAQ_CF_CTRL_V3_ENABLE | 
                                                       IPAQ_CF_CTRL_RESET_ENABLE | 
                                                       IPAQ_CF_CTRL_APOE_ENABLE | 
                                                       IPAQ_CF_CTRL_SOE_ENABLE;
            do_delay(1);  // At least 10 us
            slot->state = CF_SLOT_STATE_Reset;
            ipaq_EGPIO( SA1110_EIO_CF_RESET, SA1110_EIO_CF_RESET_DISABLE);
            do_delay(5); // At least 20 ms
            // This is necessary for the two slot sleeve and doesn't seem to
            // hurt on the single slot versions.  Note: only 3.3V is ever used!
            *(volatile unsigned short *)IPAQ_CF_CTRL = IPAQ_CF_CTRL_V5_DISABLE | 
                                                       IPAQ_CF_CTRL_V3_ENABLE | 
                                                       IPAQ_CF_CTRL_RESET_DISABLE | 
                                                       IPAQ_CF_CTRL_APOE_ENABLE | 
                                                       IPAQ_CF_CTRL_SOE_ENABLE;
            do_delay(5); // At least 20 ms
            // Wait until the card is ready to talk
            for (i = 0;  i < 10;  i++) {
                ptr = 0;
                if (cf_get_CIS(slot, CF_CISTPL_VERS_1, buf, &len, &ptr)) {
                    slot->state = CF_SLOT_STATE_Ready;
                    break;
                }
                do_delay(10); 
            }
        }
    }
}
Exemple #7
0
int spi_adc_read(struct busyboard *bb) {
  int i, val;
  spi_set_cs(bb, 0);

  for (i = 0; i < 3; ++i) {
    do_delay();
    spi_set_clk(bb);
    do_delay();
    spi_clear_clk(bb);
  }

  for (i = val = 0; i < 10; ++i) {
    do_delay();
    spi_set_clk(bb);
    do_delay();
    busyboard_in(bb);
    val = (val << 1) | (bb->in_state[1] & 1);
    spi_clear_clk(bb);
  }

  spi_clear_cs(bb);

  return val;
}
Exemple #8
0
static int snd_atiixp_codec_detect(atiixp_t *chip)
{
    int timeout;

    chip->codec_not_ready_bits = 0;
    atiixp_write(chip, IER, CODEC_CHECK_BITS);
    /* wait for the interrupts */
    timeout = HZ / 10;
    while (timeout-- > 0) {
        do_delay();
        if (chip->codec_not_ready_bits)
            break;
    }
    atiixp_write(chip, IER, 0); /* disable irqs */

    if ((chip->codec_not_ready_bits & ALL_CODEC_NOT_READY) == ALL_CODEC_NOT_READY) {
        snd_printk(KERN_ERR "atiixp: no codec detected!\n");
        return -ENXIO;
    }
    return 0;
}
Exemple #9
0
void do_blink(void) {
	uint8_t i = 0;
	for (i = 0; i < 3; i++) {
		do_delay();
		GPIO_BSRR(GPIOB) = GPIO10;

		do_delay();
		GPIO_BRR(GPIOB) = GPIO10;
	}

	do_delay();
	do_delay();
	do_delay();
	do_delay();

	for (i = 0; i < 10; i++) {
		do_delay();
		GPIO_BSRR(GPIOB) = GPIO10;

		do_delay();
		GPIO_BRR(GPIOB) = GPIO10;
	}
}
Exemple #10
0
static double eval_rpn(int *equat) {
  int i;
  double temx, temy, temz;
  union /*  WARNING  -- ASSUMES 32 bit int  and 64 bit double  */
  {
    struct {
      int int1;
      int int2;
    } pieces;
    struct {
      double z;
    } num;
  } encoder;

  while ((i = *equat++) != ENDEXP) {
    switch (i) {
    case NUMSYM:
      encoder.pieces.int2 = *equat++;
      encoder.pieces.int1 = *equat++;
      PUSH(encoder.num.z);
      break;
    case ENDFUN:
      i = *equat++;
      uptr -= i;
      break;
    case MYIF: {
      int ijmp;

      temx = POP;
      ijmp = *equat++;
      if (temx == 0.0)
        equat += ijmp;
      break;
    }
    case MYTHEN: {
      int ijmp = *equat++;

      equat += ijmp;
      break;
    }
    case MYELSE:
      break;
    case ENDDELSHFT:
      temx = POP;
      temy = POP;
      temz = POP;
      PUSH(do_delay_shift(temx, temy, temz));
      break;
    case ENDDELAY:
      temx = POP;
      temy = POP;
      PUSH(do_delay(temx, temy));
      break;
    case ENDSHIFT:
      temx = POP;
      temy = POP;
      PUSH(do_shift(temx, temy));
      break;
    case ENDISHIFT:
      temx = POP;
      temy = POP;
      PUSH(do_ishift(temx, temy));
      break;
    case SUMSYM: {
      int high;
      int low;
      int ijmp;
      double sum;

      temx = POP;
      high = (int)temx;
      temx = POP;
      low = (int)temx;
      ijmp = *equat++;
      sum = 0.0;
      if (low <= high) {
        for (int is = low; is <= high; is++) {
          constants.elems[SumIndex] = (double)is;
          sum += eval_rpn(equat);
        }
      }
      equat += ijmp;
      PUSH(sum);
      break;
    }
    case ENDSUM:
      return (POP);
    case INDXCOM:
      PUSH(0.0);
      break;
    default: {
      int it = i / MAXTYPE;
      int in = i % MAXTYPE;
      switch (it) {
      case FUN1TYPE:
        PUSH(expr_fun1[in](POP));
        break;
      case FUN2TYPE:
        switch (in) {
        case 0:
          temx = POP;
          temy = POP;
          PUSH(temx + temy);
          break;
        case 1:
          temx = POP;
          temy = POP;
          PUSH(temy - temx);
          break;
        case 2:
          temx = POP;
          temy = POP;
          PUSH(temx * temy);
          break;
        case 3:
          temx = POP;
          if (temx == 0.0)
            temx = DOUB_EPS;
          temy = POP;
          PUSH(temy / temx);
          break;
        default:
          temx = POP;
          temy = POP;
          PUSH(expr_fun2[in](temy, temx));
          break;
        }
        break;
      case CONTYPE:
        PUSH(constants.elems[in]);
        break;
      case NETTYPE:
        PUSH(network_value(POP, in));
        break;
      case TABTYPE:
        PUSH(lookup(POP, in));
        break;
      case USTACKTYPE:
        /* ram: so this means ustacks really do need to be of USTACKTYPE */
        PUSH(ustack[uptr - 1 - in]);
        break;
      case KERTYPE:
        PUSH(ker_val(in));
        break;
      case VARTYPE:
        PUSH(variables.elems[in]);
        break;
      /* indexes for shift and delay operators... */
      case SCONTYPE:
        PUSH((double)(COM(CONTYPE, in)));
        break;
      case SVARTYPE:
        PUSH((double)(COM(VARTYPE, in)));
        break;
      case UFUNTYPE:
        i = *equat++;
        for (int j = 0; j < i; j++) {
          ustack[uptr] = POP;
          uptr++;
        }
        PUSH(eval_rpn(ufuns.elems[in].rpn));
        break;
      }
      break;
    }
    }
  }
  return (POP);
}
Exemple #11
0
void main()
{
restart:

#ifdef JOYSTICK
	hit_border();
#ifndef LOMEM
#if defined(MSX) || defined(SVI) || defined(SC3000) || defined(EINSTEIN)
	msx_text();
#endif

#ifdef SPECTRUM
#ifdef ZX81
	hrg_off();
	zx_colour(112);
#endif
#endif

	printf("%c",12);
	  printf("\n  CHOOSE YOUR JOYSTICK INTERFACE\n\n");
	for (k=0 ; k!=GAME_DEVICES; k++)
	  printf("    %u - %s\n\n",k+1,joystick_type[k]);

	stick=0;
	while ((stick<1) || (stick>GAME_DEVICES)) {
	  stick=getk()-48;
	  }
#else
	stick=1;
#endif
#endif

#ifdef SPECTRUM
#ifdef ZX81
	hrg_on();
	zx_colour(112);
#endif
#endif


#ifdef CLOCK
    srand(clock());
#endif
	tt=-1;

#ifdef ZX81
#if (spritesize == 2)
	speed=500;
#else
	speed=300;
#endif
#else
#ifdef C128
#else
	speed=300;
#endif
#endif

start_level:
#ifdef ZX81
	speed-=100;
#else
	speed-=200;
#endif

	tt++; t=0; p=1;
	clg();
	hit_border();

#ifdef LAMBDA
	zx_border (INK_CYAN);
	zx_colour(112);
#endif


  for (m=1; m<=4; m+=2)
	for (n=0; n<=30; n+=2) {
		putsprite(spr_or,(n*spritesize),((m+3)*spritesizeh),brick_l);
		putsprite(spr_or,((n+1)*spritesize),((m+3)*spritesizeh),brick_r);
		putsprite(spr_or,(n*spritesize),((m+4)*spritesizeh),brick_r);
		putsprite(spr_or,((n+1)*spritesize),((m+4)*spritesizeh),brick_l);
	#if (spritesize == 8)
	#ifdef SPECTRUM
	#ifdef ZX81
		*zx_cyx2aaddr(m+3,n) = m<<4;
		*zx_cyx2aaddr(m+3,n+1) = m<<4;
		*zx_cyx2aaddr(m+4,n) = (m+1)<<4;
		*zx_cyx2aaddr(m+4,n+1) = (m+1)<<4;
	#else
		*zx_cyx2aaddr(m+3,n) = m<<3;
		*zx_cyx2aaddr(m+3,n+1) = m<<3;
		*zx_cyx2aaddr(m+4,n) = (m+1)<<3;
		*zx_cyx2aaddr(m+4,n+1) = (m+1)<<3;
	#endif
	#endif
	#endif
	
	#ifdef LAMBDA
		*zx_cyx2aaddr(m+3,n) = m<<4;
		*zx_cyx2aaddr(m+3,n+1) = m<<4;
		*zx_cyx2aaddr(m+4,n) = (m+1)<<4;
		*zx_cyx2aaddr(m+4,n+1) = (m+1)<<4;
	#endif
	
	#if defined(MSX) || defined(SVI) || defined(SC3000) || defined(MTX) || defined(EINSTEIN)
	#if (spritesize == 8)
		set_attr(m+3,n,((m+1)<<1)|0x10);
		set_attr(m+3,n+1,((m+1)<<1)|0x10);
		set_attr(m+4,n,(m<<1)|0x10);
		set_attr(m+4,n+1,(m<<1)|0x10);
	#endif
	#endif
	}
  for (n=0; n<=30; n+=2) {
		putsprite(spr_or,(n*spritesize),((m+3)*spritesizeh),brick_l);
		putsprite(spr_or,((n+1)*spritesize),((m+3)*spritesizeh),brick_r);
	#if (spritesize == 8)
	#ifdef SPECTRUM
	#ifdef ZX81
		*zx_cyx2aaddr(m+3,n) = 6<<4;
		*zx_cyx2aaddr(m+3,n+1) = 6<<4;
	#else
		*zx_cyx2aaddr(m+3,n) = 6<<3;
		*zx_cyx2aaddr(m+3,n+1) = 6<<3;
	#endif
	#endif
	#endif
	
	#ifdef LAMBDA
		*zx_cyx2aaddr(m+3,n) = 6<<4;
		*zx_cyx2aaddr(m+3,n+1) = 6<<4;
	#endif
	
	#if defined(MSX) || defined(SVI) || defined(SC3000) || defined(MTX) || defined(EINSTEIN)
	#if (spritesize == 8)
		set_attr(m+3,n,LIGHT_YELLOW|0x10);
		set_attr(m+3,n+1,LIGHT_YELLOW|0x10);
	#endif
	#endif
	}
	
	u=0; v=0; a=14; t=0; w=0;

  for (r=0; r<=6; r++) {
			m=10;  n=8+rand()%15;
			p=0; a=13;

#if (spritesize == 2)
	putsprite(spr_or,(a*spritesize),(21*spritesizeh)-1,paddle);
#else
	putsprite(spr_or,(a*spritesize),(21*spritesizeh),paddle);
#endif

#ifndef LOMEM
	for (i=0; i<=6; i++) {
	  putsprite (spr_and, (24+i)*spritesize, 23*spritesizeh, ball);
	  if (i>r)
		putsprite (spr_or, (24+i)*spritesize, 23*spritesizeh, ball);
	}
#endif

		g=200;

		/* Let's show where the ball stars before the dance begins */
		putsprite(spr_or,(n*spritesize),(m*spritesizeh),ball);

		hit_border();
#ifdef SOUND
		for (i=1; i<14; i++) {
			bit_synth(4, 199+i, 200+i, 239+i, 240+i);
			putsprite(spr_xor,(n*spritesize),(m*spritesizeh),ball);
		}
		bit_synth(9, 255, 254, 253, 252);
#endif

		putsprite(spr_and,(n*spritesize),(m*spritesizeh),ball);

		while (m <= 20) {

			/* delay */
			do_delay();

			move_ball();

			/* total score count is 574 */
			if (t>=573) goto start_level;

			if (u==20)
				putsprite(spr_and,(v*spritesize),(u*spritesizeh),bounce);
			else
				putsprite(spr_and,(v*spritesize),(u*spritesizeh),ball);

			/* Intermediate step to move the ball smoothly */
			putsprite(spr_xor,(((n+v)*spritesize)>>1),(((m+u)*spritesizeh)>>1),ball);
			do_delay();
			putsprite(spr_xor,(((n+v)*spritesize)>>1),(((m+u)*spritesizeh)>>1),ball);

			u=m; v=n;
			if (m==20)
				putsprite(spr_or,(n*spritesize),(m*spritesizeh),bounce);
			else
				putsprite(spr_or,(n*spritesize),(m*spritesizeh),ball);

/*
	#ifdef SOUND
		bit_click();
	#endif
*/

#ifdef JOYSTICK
			if (joystick(stick) & MOVE_LEFT) {
				move_left();
				if (joystick(stick) & MOVE_FIRE)
					move_left();
			}
			if (joystick(stick) & MOVE_RIGHT) {
				move_right();
				if (joystick(stick) & MOVE_FIRE)
					move_right();
			}
#else
			k=getk();
			switch (k) {
				case '2':
					move_left();
					break
				case '1':
					move_left();
					move_left();
					break;
				case '9':
					move_right();
					break;
				case '0':
					move_right();
					move_right();
					break;
			}
#endif
		}
		/* ball is lost */

#if (spritesize == 2)
	  putsprite(spr_and,(a*spritesize),(21*spritesizeh)-1,paddle);
#else
	  putsprite(spr_and,(a*spritesize),(21*spritesizeh),paddle);
#endif
  }


#ifdef ZX81
#if (spritesize == 2)
  #asm
			ld	a,$1e
			ld	i,a
  #endasm
#endif
#endif

#ifndef LOMEM
#ifdef BANNERS
  putsprite(spr_or,40,(12*spritesizeh),scorebanner);
  sprintf (scoretxt,"%05u",tt*1000+t);

  k=0;
  for (i=0; i<5; i++) {
    putsprite (spr_or, 140+i+k, 12*spritesizeh+7, &bigdigit[(scoretxt[i]-48)*38]);
	if (scoretxt[i]=='1')
		k+=5;
	else
		k+=14;
  }

#else
  printf("%c\n\n Score: %u ",12,tt*1000+t);
#endif
#endif

/*  return (tt*1000+t); */
#ifdef SOUND
bit_fx2(5);
#endif
while (getk()) {}
while (!getk()) {}

goto restart;

}
Exemple #12
0
static void
#else
static int
#endif
sc_lpe_card_handler(cyg_addrword_t param)
{
    struct eth_drv_sc *sc = (struct eth_drv_sc *)param;
    dp83902a_priv_data_t *dp = (dp83902a_priv_data_t*)sc->driver_private;
    struct cf_slot *slot;
    struct cf_cftable cftable;
    struct cf_config config;
    int i, len, ptr, cor = 0;
    unsigned char buf[256], *cp;
    cyg_uint8* base;
    unsigned char *vers_product, *vers_manuf, *vers_revision, *vers_date;
#ifndef CYGPKG_KERNEL
    int tries = 0;
#endif
    bool first = true;

    slot = (struct cf_slot*)dp->plf_priv;
    cyg_drv_dsr_lock();
    while (true) {
        cyg_drv_dsr_unlock();   // Give DSRs a chance to run (card insertion)
        cyg_drv_dsr_lock();
        if ((slot->state == CF_SLOT_STATE_Inserted) ||
            ((slot->state == CF_SLOT_STATE_Ready) && first)) {
            first = false;
            if (slot->state != CF_SLOT_STATE_Ready) {
                cf_change_state(slot, CF_SLOT_STATE_Ready);
            }
            if (slot->state != CF_SLOT_STATE_Ready) {
                diag_printf("CF card won't go ready!\n");
#ifndef CYGPKG_KERNEL
                return false;
#else
                continue;
#endif
            }
            len = sizeof(buf);
            ptr = 0;
            if (cf_get_CIS(slot, CF_CISTPL_MANFID, buf, &len, &ptr)) {
                if (*(short *)&buf[2] != SC_LPE_MANUF) {
                    diag_printf("Not a SC LPE, sorry\n");
                    continue;
                }
            } 
            ptr = 0;
            if (cf_get_CIS(slot, CF_CISTPL_VERS_1, buf, &len, &ptr)) {
                // Find individual strings
                cp = &buf[4];
                vers_product = cp;
                while (*cp++) ;  // Skip to nul
                vers_manuf = cp;
                while (*cp++) ;  // Skip to nul
                vers_revision = cp;
                while (*cp++) ;  // Skip to nul
                vers_date = cp;
#ifndef CYGPKG_KERNEL
                if (tries != 0) diag_printf("\n");
                diag_printf("%s: %s %s %s\n", vers_manuf, vers_product, vers_revision, vers_date);
#endif
            }
            ptr = 0;
            if (cf_get_CIS(slot, CF_CISTPL_CONFIG, buf, &len, &ptr)) {
                if (cf_parse_config(buf, len, &config)) {
                    cor = config.base;
                }
            }
            if (!cor) {
//                diag_printf("Couldn't find COR pointer!\n");
                continue;
            }

            ptr = 0;
            if (cf_get_CIS(slot, CF_CISTPL_CFTABLE_ENTRY, buf, &len, &ptr)) {
                if (cf_parse_cftable(buf, len, &cftable)) {
                    cyg_uint8 tmp;
                    // Initialize dp83902a IO details
                    dp->base = base = (cyg_uint8*)&slot->io[cftable.io_space.base[0]];
                    dp->data = base + DP_DATA;
                    dp->interrupt = slot->int_num;
                    cf_set_COR(slot, cor, cftable.cor);
                    // Reset card  (read issues RESET, write clears it)
                    HAL_READ_UINT8(base+DP_CARD_RESET, tmp);
                    HAL_WRITE_UINT8(base+DP_CARD_RESET, tmp);
                    // Wait for card
                    do {
                        DP_IN(base, DP_ISR, tmp);
                    } while (0 == (tmp & DP_ISR_RESET));

                    // Fetch hardware address from card - terrible, but not well defined
                    // Patterned after what Linux drivers do
                    if (!dp->hardwired_esa) {
                        static unsigned char sc_lpe_addr[] = { 0x00, 0xC0, 0x1B, 0x00, 0x99, 0x9E};
                        if ((slot->attr[0x1C0] == sc_lpe_addr[0]) &&
                            (slot->attr[0x1C2] == sc_lpe_addr[1]) &&
                            (slot->attr[0x1C4] == sc_lpe_addr[2])) {
                            sc_lpe_addr[3] = slot->attr[0x1C6];
                            sc_lpe_addr[4] = slot->attr[0x1C8];
                            sc_lpe_addr[5] = slot->attr[0x1CA];
                        } else {
                            // Coudn't find it in the CIS (attribute) data
                            unsigned char prom[32];

                            // Tell device to give up ESA
                            DP_OUT(base, DP_DCR, 0x48);  // Bytewide access
                            DP_OUT(base, DP_RBCH, 0);    // Remote byte count
                            DP_OUT(base, DP_RBCL, 0);
                            DP_OUT(base, DP_ISR, 0xFF);  // Clear any pending interrupts
                            DP_OUT(base, DP_IMR, 0x00);  // Mask all interrupts 
                            DP_OUT(base, DP_RCR, 0x20);  // Monitor
                            DP_OUT(base, DP_TCR, 0x02);  // loopback
                            DP_OUT(base, DP_RBCH, 32);   // Remote byte count
                            DP_OUT(base, DP_RBCL, 0);
                            DP_OUT(base, DP_RSAL, 0);    // Remote address
                            DP_OUT(base, DP_RSAH, 0);
                            DP_OUT(base, DP_CR, DP_CR_START|DP_CR_RDMA);  // Read data
                            for (i = 0;  i < 32;  i++) {
                                HAL_READ_UINT8(base+DP_DATAPORT, prom[i]);
                            }
                            if ((prom[0] == sc_lpe_addr[0]) &&
                                (prom[2] == sc_lpe_addr[1]) &&
                                (prom[4] == sc_lpe_addr[2])) {
                                diag_printf("Getting address from port\n");
                                sc_lpe_addr[3] = prom[6];
                                sc_lpe_addr[4] = prom[8];
                                sc_lpe_addr[5] = prom[10];
                            } else {
                                diag_printf("No valid ESA found in CIS! Hardwiring to 00:C0:1B:00:99:9E\n");
                            }
                        }
                        for (i = 0;  i < 6;  i++) {
                            dp->esa[i] = sc_lpe_addr[i];
                        }
                    }

                    // Initialize upper level driver
                    (sc->funs->eth_drv->init)(sc, dp->esa);
                    // Tell system card is ready to talk
                    dp->tab->status = CYG_NETDEVTAB_STATUS_AVAIL;
#ifndef CYGPKG_KERNEL
                    cyg_drv_dsr_unlock();
                    return true;
#endif
                } else {
                    diag_printf("Can't parse CIS\n");
                    continue;
                }
            } else {
                diag_printf("Can't fetch config info\n");
                continue;
            }
        } else if (slot->state == CF_SLOT_STATE_Removed) {
            diag_printf("Compact Flash card removed!\n");
        } else {
            cyg_drv_dsr_unlock();
            do_delay(50);  // FIXME!
#ifndef CYGPKG_KERNEL
            if (tries == 0) diag_printf("... Waiting for network card: ");
            diag_printf(".");
            if (++tries == 10) {
                // 5 seconds have elapsed - give up
                return false;
            }
            cf_hwr_poll(slot);  // Check to see if card has been inserted
#endif
            cyg_drv_dsr_lock();
        }
    }
}
Exemple #13
0
void
DSession::handle_read_dgram (const TRB_Asynch_Read_Dgram::Result &result)
{
  {
    ACE_GUARD (ACE_SYNCH_MUTEX, monitor, this->lock_ );

    this->io_count_r_--;

    int loglevel = cfg.loglevel();

    ACE_Message_Block *mb = result.message_block ();

    size_t xfer_bytes = result.bytes_transferred();
    char * last  = mb->wr_ptr();
    char * first = last - xfer_bytes; 

    u_long error = result.error ();


    if (loglevel == 0)
      {
        LogLocker log_lock;

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%t) **** %s=%d handle_read_dgram() ****\n"),
                    this->get_name(),
                    this->index()));
        
        this->print_address (result.remote_address());

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("%s = %d\n"),
                    ACE_TEXT ("bytes_to_read"),
                    result.bytes_to_read ()));

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("%s = %d\n"),
                    ACE_TEXT ("handle"),
                    result.handle ()));

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("%s = %d\n"),
                    ACE_TEXT ("bytes_transfered"),
                    result.bytes_transferred ()));

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("%s = %d\n"),
                    ACE_TEXT ("error"),
                    error));

        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT ("message_block:\n")));

        ACE_HEX_DUMP ((LM_DEBUG, first, xfer_bytes));


        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT ("**** end of message ****************\n")));
      }
    else if (error != 0)
      {
        LogLocker log_lock;

        this->print_address (result.remote_address());

        ACE_OS::last_error (error);
        ACE_Log_Msg::instance ()->errnum (error);
        ACE_Log_Msg::instance ()->log (LM_ERROR,
                                       ACE_TEXT ("(%t) %s=%d READ ERROR=%d %p\n"),
                                       this->get_name (),
                                       this->index (),
                                       error,
                                       ACE_TEXT (":"));
      }
    else if (loglevel == 1)
      {
         LogLocker log_lock;
         this->print_address (result.remote_address());

         ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%t) %s=%d READ=%d bytes ok\n"),
                    this->get_name (),
                    this->index (),
                    result.bytes_transferred ()));
      }


    do_delay (cfg.delay());  // delay milliseconds

    if (error == 0 && result.bytes_transferred () > 0)
      {
        this->total_rcv_ += result.bytes_transferred ();

      }
    else
      {
        mb->msg_type (ACE_Message_Block::MB_HANGUP);
        mb->wr_ptr (mb->rd_ptr());
      }

      this->on_data_received (*mb, 
                              static_cast<const ACE_INET_Addr&>
                                      (result.remote_address()));

    if (this->io_count_r_ != 0 || 
        this->io_count_w_ != 0 ||
        this->post_count_ != 0 )
      return;
  }
  delete this;
}