Exemple #1
0
static void envia(void){
  //Coprovar 3 cops si pot enviar.
  if (intens < MAX_TRY){
    if(lan_can_put()){
      // Si el canal no esat ocupat enviem
      ether_block_put(tx);
      for(uint8_t i=0; i<64;i++) tx[i]='\0';
    }
    else{
      // Si el canal esta ocupat sumem 1 als intents
      intens++;
      // Esperem un temps aleatori i tornem a provar.
      timer_after(TIMER_MS(rand()%((10+1)*1000)),envia);
    }
  }
  // En el cas de que no s'hagi pogut enviar encenem el LED
  else pin_w(pin,true);
}
Exemple #2
0
void send(_TIMER *self) {
	pin_write(pingPin,0);
	timer_stop(&timer4);
	timer_after(&timer2, 1e-3, 1, receive);
}
Exemple #3
0
void VendorRequests(void) {
	WORD temp;

	switch (USB_setup.bRequest) {
		case GET_VOLTAGE:
			temp.w = VatTime0;
			BD[EP0IN].address[0] = VatTime0/256;
			BD[EP0IN].address[1] = VatTime1/256;
			BD[EP0IN].address[2] = VatTime2/256;
			BD[EP0IN].address[3] = VatTime3/256;
			BD[EP0IN].address[4] = VatTime4/256;
			BD[EP0IN].bytecount = 5;	// set EP0 IN byte count to 0
			BD[EP0IN].status = 0xC8;	// send packet as DATA1, set UOWN bit
			break; 
		case GET_STATE:
			BD[EP0IN].address[0] = touching0;
			BD[EP0IN].address[1] = touching1;
			BD[EP0IN].address[2] = touching2;
			BD[EP0IN].address[3] = touching3;
			BD[EP0IN].address[4] = touching4;
			BD[EP0IN].bytecount = 5;	// set EP0 IN byte count to 0
			BD[EP0IN].status = 0xC8;	// send packet as DATA1, set UOWN bit
			break;
		case DEBUG:
			temp.w = greenDuty;
			BD[EP0IN].address[0] = temp.b[0];
			BD[EP0IN].address[1] = temp.b[1];
			temp.w = redDuty;
			BD[EP0IN].address[2] = temp.b[0];
			BD[EP0IN].address[3] = temp.b[1];
			temp.w = blueDuty;
			BD[EP0IN].address[4] = temp.b[0];
			BD[EP0IN].address[5] = temp.b[1];
			temp.w = currentPetal;
			BD[EP0IN].address[6] = temp.b[0];
			BD[EP0IN].address[7] = temp.b[1];
			/*
			temp.w = irVoltage;
			BD[EP0IN].address[0] = temp.b[0];
			BD[EP0IN].address[1] = temp.b[1];
			temp.w = dist;
			BD[EP0IN].address[2] = temp.b[0];
			BD[EP0IN].address[3] = temp.b[1];
			temp.w = stepCount;
			BD[EP0IN].address[4] = temp.b[0];
			BD[EP0IN].address[5] = temp.b[1];
			temp.w = changeFlag;
			BD[EP0IN].address[6] = temp.b[0];
			BD[EP0IN].address[7] = temp.b[1];
			*/
			BD[EP0IN].bytecount = 8;	// set EP0 IN byte count to 0
			BD[EP0IN].status = 0xC8;	// send packet as DATA1, set UOWN bit
			break;
		case SET_THRESHOLD:	
			threshold = USB_setup.wValue.w;
			BD[EP0IN].bytecount = 0;	// set EP0 IN byte count to 0
			BD[EP0IN].status = 0xC8;	// send packet as DATA1, set UOWN bit
			break;
		case SET_DUTY:	
			dist = USB_setup.wValue.w;
			//motorControl(destination);
			BD[EP0IN].bytecount = 0;	// set EP0 IN byte count to 0
			BD[EP0IN].status = 0xC8;	// send packet as DATA1, set UOWN bit
			break;
		case GET_STEP_COUNT:
			temp.w = stepCount;
		   	BD[EP0IN].address[0] = temp.b[0];
			BD[EP0IN].address[1] = temp.b[1];
			temp.w = destination;
		   	BD[EP0IN].address[2] = temp.b[0];
			BD[EP0IN].address[3] = temp.b[1];
			BD[EP0IN].bytecount = 4;	// set EP0 IN byte count to 0
			BD[EP0IN].status = 0xC8;	// send packet as DATA1, set UOWN bit
			break;
		case SCAN:
			pin_write(pingPin, HALF_INT);
			timer_after(&timer4, 500e-6, 1, send);
			/*timer_setPeriod(&timer5, 50e-3);
			timer_start(&timer5);
			led_toggle(&led1);
			while(pin_read(&D[12]) == 0){
				if (timer_flag(&timer5) != 0){
					led_toggle(&led3);
					break;
				}
			}
			readTime = timer_read(&timer5);
			led_toggle(&led2);
			timer_stop(&timer5);
			temp.w = readTime;
			BD[EP0IN].address[0] = temp.b[0];
			BD[EP0IN].address[1] = temp.b[1];
			*/
			BD[EP0IN].bytecount = 2;	// set EP0 IN byte count to 4
			BD[EP0IN].status = 0xC8;	// send packet as DATA1, set UOWN bit
			break;	
		case SET_SPEED:	
			period = USB_setup.wValue.w;
			BD[EP0IN].bytecount = 0;	// set EP0 IN byte count to 0
			BD[EP0IN].status = 0xC8;	// send packet as DATA1, set UOWN bit
			break;
		case SET_RED:
			redTarget = USB_setup.wValue.w;
			BD[EP0IN].bytecount = 0;	// set EP0 IN byte count to 0
			BD[EP0IN].status = 0xC8;	// send packet as DATA1, set UOWN bit
			break;
		case SET_GREEN:
			greenTarget = USB_setup.wValue.w;
			BD[EP0IN].bytecount = 0;	// set EP0 IN byte count to 0
			BD[EP0IN].status = 0xC8;	// send packet as DATA1, set UOWN bit
			break;
		case SET_BLUE:
			blueTarget = USB_setup.wValue.w;
			BD[EP0IN].bytecount = 0;	// set EP0 IN byte count to 0
			BD[EP0IN].status = 0xC8;	// send packet as DATA1, set UOWN bit
			break;
		default:
			USB_error_flags |= 0x01;	// set Request Error Flag
	}
}