Exemplo n.º 1
0
	Vector3& clampScalar(T min, T max){

		Vector3 low(min, min, min), high(max, max, max);

		return clamp(low, high);

	}
Exemplo n.º 2
0
static uint16_t SPIReadADC(uint8_t channel)
{
    uint8_t ii;
    uint32_t result;
    uint32_t setup;

    //Setting up pins

    // In case pin was already been low, we put it high
    // so we can initiate communication after setting up pins
    set_output(SPI_CS, HIGH);
    set_output(SPI_DATA, LOW);
    set_output(SPI_CLK, LOW);
    low(SPI_CS);   // Active chip select by setting pin low

    // Sending configuration to device
    setup = channel | 0b11000;
    for(ii = 0; ii < 5; ++ii) 
    {
        pulse_out(SPI_CLK, 1);
        if ((setup & 0b10000) == 0b10000)
        {
            high(SPI_DATA);
        }            
        else
        {
            low(SPI_DATA); // is MSB != 0
        }            
        setup <<= 1;  // shift left
    }

    pulse_out(SPI_CLK, HIGH); //Empty clock, for sampling
    pulse_out(SPI_CLK, HIGH); //Device returns low, NULL bit, we ignore it...
    input(SPI_DATA);

    // read ADC result 12 bit
    result = 0;
    for(ii = 0; ii < 12; ++ii) 
    {
        // We are sending pulse, clock signal, to ADC, because on falling edge it will return data...
        pulse_out(SPI_CLK, HIGH);
        // Shifting bit to left, to make room for current one...
        result <<= 1;
        result = result | (get_state(SPI_DATA) & 0x01);
    }
    high(SPI_CS);
}
Exemplo n.º 3
0
void ExprRep::reduceToBigRat(const BigRat& rat) {
  Real value(rat);

  //appValue() = value;
  appComputed() = false; // since appValue is not assigned until approx() is called
  flagsComputed() = true;
  knownPrecision() = CORE_negInfty;

#ifdef CORE_DEBUG
  relPrecision() = EXTLONG_ZERO;
  absPrecision() = CORE_negInfty;
  //numNodes() = numNodes();
#endif

  d_e() = EXTLONG_ONE;
  //visited() = e->visited();
  sign() = value.sign();
  uMSB() = value.MSB();
  lMSB() = value.MSB();
  // length() = value.length(); 	// fixed? original = 1
  measure() = value.height();		// measure <= height for rational value

  // BFMSS[2,5] bound.
  value.ULV_E(u25(), l25(), v2p(), v2m(), v5p(), v5m());

  extLong u_e = u25() + v2p();
  extLong l_e = l25() + v2m();

  u_e = u_e + ceilLg5(v5p());
  l_e = l_e + ceilLg5(v5m());

  if (l_e == EXTLONG_ZERO) {           // no divisions introduced
    high() = u_e;
    low() = EXTLONG_ONE - u_e; // - (u_e - 1)
  } else {
    high() = u_e - l_e + EXTLONG_ONE;
    low() = 2 - high();
  }

  lc() = l_e;
  tc() = u_e;

  if (ratValue() == NULL)
    ratValue() = new BigRat(rat);
  else
    *(ratValue()) = rat;
}
const Real GreensFunction2DAbs::drawTime(const Real rnd) const
{
    THROW_UNLESS(std::invalid_argument, 0.0<=rnd && rnd <= 1.0);
    if(D == 0e0 || a == std::numeric_limits<Real>::infinity() || rnd == 1e0)
        return std::numeric_limits<Real>::infinity();
    if(a == r0 || rnd == 0e0)
        return 0e0;

    p_survival_params params = {this, rnd};

    gsl_function F = 
    {
        reinterpret_cast<double (*)(double, void*)>(&p_survival_F), &params
    };

    // this is not so accurate because
    // initial position is not the center of this system.
    const Real t_guess(a * a * 0.25 / D);
    Real value(GSL_FN_EVAL(&F, t_guess));
    Real low(t_guess);
    Real high(t_guess);

    // to determine high and low border
    if(value < 0.0)
    {
        do
        {
            high *= 1e1;
            value = GSL_FN_EVAL(&F, high);
            if(fabs(high) > t_guess * 1e6)
                throw std::invalid_argument("could not adjust higher border");
        }
        while(value <= 0e0);
    }
    else
    {
        Real value_prev = value;
        do
        {
            low *= 1e-1;
            value = GSL_FN_EVAL(&F, low);
            if(fabs(low) <= t_guess * 1e-6 || fabs(value - value_prev) < CUTOFF)
                throw std::invalid_argument("could not adjust lower border");
            value_prev = value;
        }
        while(value >= 0e0);
    }

    //find the root
    const gsl_root_fsolver_type* solverType(gsl_root_fsolver_brent);
    gsl_root_fsolver* solver(gsl_root_fsolver_alloc(solverType));

    const Real t(findRoot(F, solver, low, high, 1e-18, 1e-12,
                          "GreensFunction2DAbs::drawTime"));

    gsl_root_fsolver_free(solver);

    return t;
}
Exemplo n.º 5
0
int main(){
	// initialize hardware
	// Ports
	DDRB = (1<<PB0) | (1<<PB4); // MISO and PB0
	// spi
	SPCR = (1<<SPIE) | (1<<SPE);	// interrupt, f/4
	SPDR = 0;
	// timer counter 1
	OCR1A = TIMEOUT;
	uint16_t risingEdge = 0;
	uint16_t fallingEdge = 0;
	
	while(1){
		// trigger the sonar with a 5 micro second pulse
		DDRB |= (1<<PB0);
		cli();
		// atmega88pa pins can be flipped by writing to them
		// hence the two writes and not one write and one
		// clear
		PINB |= (_BV(PB0));
		_delay_us(5);
		PINB |= (_BV(PB0));
		sei();
		// PB0 now input to receive pulse from Ping)))
		DDRB &=~(1<<PB0);
		// Start Timer
		// set timer up to capture incoming pulse
		// rising edge, ctc, OCR1A as top, f/8
		TCCR1B = (1<<ICES1) | (1<<WGM12) | (1<<CS11);
		// clear pending interrupts
		TIFR1 |= (1<<ICF1) | (1<<OCF1B) | (1<<OCF1A);
		// input capture compA interrupt enabled
		TIMSK1 = (1<<ICIE1) | (1<<OCIE1A);
		
		// look for rising edge, timestamp it then look for falling edge, timestamp it.
		// Do math to find distance. Distance is just a number of counts not normal units
		// ie inches or cm.
		while(conversionComplete == 0){
			if(edgeDetect == 1)
				risingEdge = time_stamp(0);
			if(edgeDetect == 3){
				cli();
				fallingEdge = time_stamp(1);
				distance = fallingEdge - risingEdge;
				SPDR = low(distance);
				conversionComplete = 1;
				sei();
			}
		}
		// delay 200 microseconds before next reading 
		// as instructed by Ping))) datasheet
		// stop and reset timer
		conversionComplete = 0;
		TCCR1B = 0x00;
		TCNT1 = 0x0000;
		TIMSK1 = 0x00;
		_delay_us(200);
	}
}
static void prix(PnlMat *res, PnlMat *res_no_call, int M, int N, PnlMat *asset, PnlVectInt *res_theta, double spot, double T, param *P, PnlBasis *basis)
{
  int i,j;
  double Sij,mu_ij,v0;
  PnlVect *Si,*V_iplus1,*alpha, *c_iplus1;//(ligne i de la matrice)
  PnlMat MSi;
  double h=T/N;
  Si=pnl_vect_new();
  c_iplus1=pnl_vect_create(M);
  alpha=pnl_vect_new();
  V_iplus1=pnl_vect_new();
  pnl_mat_resize(res,N+1,M);
  prix_no_call(res_no_call,M,N,asset,spot,T,P,basis);
  for(j=0;j<M;j++) pnl_mat_set(res,N,j,(pnl_mat_get(res_no_call,N,j)));
  for(i=N-1;i>=1;i--)
    {
      for(j=0;j<M;j++) pnl_vect_set(c_iplus1,j,c(pnl_mat_get(asset,i+1,j),spot,P)*h);
      pnl_mat_get_row(Si,asset,i);
      pnl_vect_mult_double(Si,1.0/spot);
      pnl_mat_get_row(V_iplus1,res,i+1);
      pnl_vect_plus_vect(V_iplus1,c_iplus1);
      MSi = pnl_mat_wrap_vect(Si);
      pnl_basis_fit_ls(basis,alpha,&MSi,V_iplus1);
      for(j=0;j<M;j++)
        {
          Sij=pnl_mat_get(asset,i,j)/spot;
          mu_ij=mu(spot,spot*Sij,P);
          if(i>=pnl_vect_int_get(res_theta,j)) { pnl_mat_set(res,i,j,pnl_mat_get(res_no_call,i,j));}
          else pnl_mat_set(res,i,j,MAX(low(spot*Sij,P),exp(-mu_ij*h)*pnl_basis_eval(basis,alpha,&Sij)));
        }
    }
  pnl_mat_get_row(V_iplus1,res,1);
  for(j=0;j<M;j++) pnl_vect_set(c_iplus1,j,c(pnl_mat_get(asset,1,j),spot,P)*h);
  pnl_vect_plus_vect(V_iplus1,c_iplus1);
  v0=pnl_vect_sum(V_iplus1)/M;
  v0=MAX(low(spot,P),exp(-mu(spot,spot,P)*h)*v0);
  for(j=0;j<M;j++)
    {
      if(pnl_vect_int_get(res_theta,j)==0) pnl_mat_set(res,0,j,pnl_mat_get(res_no_call,i,j));
      else pnl_mat_set(res,0,j,v0);
    }
  pnl_vect_free(&Si);
  pnl_vect_free(&c_iplus1);
  pnl_vect_free(&V_iplus1);
  pnl_vect_free(&alpha);
}
Exemplo n.º 7
0
int test (void)
{
  low (5, 6);			// { dg-error "no matching function" }
  // { dg-message "(candidate|3 arguments, 2 provided)" "" { target *-*-* } 11 }
  high (5, 6, 7, 8);		// { dg-error "no matching function" }
  // { dg-message "(candidate|3 arguments, 4 provided)" "" { target *-*-* } 13 }
  return 0;
}
Exemplo n.º 8
0
int query(int k) { // 求a[1..k]的和
    ret = 0;
    while (k > 0) {
        ret += a[k];
        k -= low(k);
    }
    return ret;
}
Exemplo n.º 9
0
void inv(elem_t *l[]){
    int i;
    for(i=0;i<PER_LIST && l[i]!=NULL;i++){
        l[i]->x = -l[i]->x;
        l[i]->low = low(l[i]->x);
        l[i]->inverted = 1;
    }
}
Exemplo n.º 10
0
vEB* vEB_tree_insert(vEB *V, int x, int qtd, int u){

    if(!V){
        V = (vEB*)malloc(sizeof(vEB));
        V->min = V->max = x;
        V->u = u;
        V->contMin = V->contMax = qtd;
        if(u > 2){
            V->summary = NULL;
            V->cluster = (vEB**)calloc(sqrt(u),sizeof(vEB*));
        }
        else{
            V->summary = NULL;
            V->cluster = NULL;
        }
    }
    else if(V->min == x){
        V->contMin+=qtd;
        if(V->max == x)
            V->contMax = V->contMin;
    }
    else if(V->max == x){
        V->contMax+=qtd;
    }
    else{
        if(x < V->min){
            if(V->min == V->max){
                V->min = x;
                V->contMin = qtd;
                return V;
            }
            int aux = V->min;
            V->min = x;
            x = aux;
            int qtdAux = V->contMin;
            V->contMin = qtd;
            qtd = qtdAux;
        }
        else if(x > V->max){
            int aux = V->max;
            V->max = x;
            x = aux;
            int qtdAux = V->contMax;
            V->contMax = qtd;
            qtd = qtdAux;
            if(V->min == x)
                return V;
        }
        if(V->u > 2){
            if(V->cluster[high(x, V->u)] == NULL){
                V->summary = vEB_tree_insert(V->summary, high(x, V->u), 1, sqrt(V->u));
            }
            V->cluster[high(x, V->u)] =
            vEB_tree_insert(V->cluster[high(x, V->u)], low(x, V->u), qtd, sqrt(V->u));
        }
    }
    return V;
}
Exemplo n.º 11
0
void pulse_out(int pin, int time)              // pulseOut function definition
{
  /*
  if(st_iodt == 0)
  {
    set_io_dt(CLKFREQ/1000000);
    set_io_timeout(CLKFREQ/4);
  }
  */
  signed long phsVal = -time * st_iodt;
  //int ctr = 0;
  int frq = 1;
  int phs = 0;
  int state = get_output(pin);
  if(state == 1)
  {
    phsVal = -phsVal;
    phs = -1;
    frq = -1;
  }
  if (CTRA == 0)
  {
    PHSA = phs;
    FRQA = frq;
    CTRA = pin;
    CTRA += (4 << 26);
    low(pin);
    PHSA = phsVal;
    while(get_state(pin) != state);
    set_output(pin, state);
    CTRA = 0;
  }
  else if (CTRB == 0)
  {
    PHSA = phs;
    FRQA = frq;
    CTRA = pin;
    CTRA += (4 << 26);
    low(pin);
    PHSA = phsVal;
    while(get_state(pin) != state);
    set_output(pin, state);
    CTRA = 0;
  }
}
Exemplo n.º 12
0
int main()                                    // Main function
{
  // Add startup code here.

 
  while(1)
  {
    freqout(1, 1, 33000);                       // Repeat for right detector
    irRight = input(2);
   if(ping_cm(8)>50){ //Salida del laberinto 
       drive_speed(64,64);
       pause (3000);
     }
    if(irRight == 1){ // Si no hay pared a la derecha
      drive_speed(42,42); //Avanza
      pause(600);
      high(26);
      high(27);
      //drive_goto(25,-26); //Gira derecha
      drive_speed(32,-32);
      pause(750);
      //drive_speed(0,0);
      low(26);
      low(27);
      drive_speed(42,42); //Avanza
      pause(1200);
      //drive_speed(0,0);
    }      
    if(irRight == 0 && ping_cm(8)<10){    //Si hay pared a la derecha y enfrente 
      
      drive_speed(0,0);
     //Gira izquierda
      drive_speed(-32,32);
      pause(800);
      drive_speed(0,0);
     }       
     else{ //Si no hay pared enfrente
        drive_speed(42,42);
        pause(50);
    }

     
    
  }  
}
Exemplo n.º 13
0
void pixel()
{
	step();
	high( P1H );
	high( P2A4BH );
	high( P4A2BH );
	low( P3H );
	low( P2C4DH );
	low( P4C2DH );
	low( SG);
	step();
	step();
	step();
	step();
	low( P1H );
	low( P2A4BH );
	low( P4A2BH );
	high( P3H );
	high( P2C4DH );
	high( P4C2DH );
	high( SG);
	step();
	step();
	step();
	step();
}
void Adafruit_PS2::write(uint8_t x)  {
  uint16_t tosend = x;
  uint8_t parity = 1;
  
  for (uint8_t i=0; i<8; i++) {
    parity ^= (tosend >> i);
  }
  if (parity & 0x1)
    tosend |= 0x100;

  idle();
  delayMicroseconds(300);
  low(_clk);
  delayMicroseconds(100);
  low(_data);
  delayMicroseconds(10);

  // we pull the clock line up to indicate we're ready
  high(_clk);
  // wait for the device to acknowledge by pulling it down
  while (digitalRead(_clk));
  
  for (uint8_t i=0; i < 9; i++) {
    if (tosend & 0x1)
      high(_data);
    else
      low(_data);
    
    // the clock lines are driven by the -DEVICE- so we wait
    while (!digitalRead(_clk));
    while (digitalRead(_clk));

    tosend >>= 1;
  }  

  // send stop bit (high)
  high(_data);
  delayMicroseconds(50);
  while (digitalRead(_clk));
  // wait for mouse to switch modes
  while (!digitalRead(_clk) || !digitalRead(_data));

  // inhibit any more data (we will poll!)
  inhibit();
}
Exemplo n.º 15
0
//------------------------------------------------------------------------
inline bool pe64_to_pe(peheader_t &pe, const peheader64_t &pe64, bool silent)
{
    bool ok = true;
    switch ( pe64.magic )
    {
    default:
        if ( !silent )
        {
            ask_for_feedback("The input file has non-standard magic number (%x)",
                             pe64.magic);
        }
        ok = false;
    /* no break */
    case MAGIC_P32:
    case MAGIC_ROM:
        memcpy(&pe, &pe64, sizeof(pe));
        break;
    case MAGIC_P32_PLUS:
        memcpy(&pe, &pe64, offsetof(peheader_t, stackres));
        memcpy(&pe.loaderflags, &pe64.loaderflags,
               sizeof(pe) - qoffsetof(peheader_t, loaderflags));
        pe.stackres  = low(pe64.stackres);
        pe.stackcom  = low(pe64.stackcom);
        pe.heapres   = low(pe64.heapres);
        pe.heapcom   = low(pe64.heapcom);
        break;
    }
    // do various checks
    if ( !pe.is_efi()
            && (pe.objalign < pe.filealign
                || pe.filealign !=0 && (pe.filealign & (pe.filealign-1) ) != 0   // check for power of 2
                || pe.objalign  !=0 && (pe.objalign  & (pe.objalign -1) ) != 0) ) // check for power of 2
    {
        if ( !silent )
            pe_failure("Invalid file: bad alignment value specified (section alignment: %08X, file alignment: %08X)", pe.objalign, pe.filealign);
    }
    if ( pe.imagesize > 0x77000000 || pe.imagesize < pe.allhdrsize )
    {
        if ( !silent )
            pe_failure("Invalid file: bad ImageSize value %x", pe.imagesize);
    }
    if ( pe.nrvas && pe.nrvas < total_rvatab_count )
        memset(&pe.expdir+pe.nrvas, 0, total_rvatab_size-pe.nrvas*sizeof(petab_t));
    return ok;
}
Exemplo n.º 16
0
void MMA7455_writeByte(unsigned char address, unsigned char value)
{
  low(MMA7455_pinEn);                                           
  int cmd = address | MMA7455_writeMask;               
  shift_out(MMA7455_pinDat, MMA7455_pinClk, MSBFIRST, 7, cmd);
  shift_out(MMA7455_pinDat, MMA7455_pinClk, MSBFIRST, 1, 0b0);
  shift_out(MMA7455_pinDat, MMA7455_pinClk, MSBFIRST, 8, value);
  high(MMA7455_pinEn);
}
Exemplo n.º 17
0
int main()                                      // main function
{
  low(26);                                      // D/A0 & D/A1 to 0 V
  low(27);

  while(1)                                      // Main loop
  {
    freqout(11, 1, 38000);                      // Left IR LED light
    irLeft = input(10);                         // Check left IR detector

    freqout(1, 1, 38000);                       // Repeat for right detector
    irRight = input(2);

    print("%c irLeft = %d, irRight = %d",       // Display detector states
           HOME,       irLeft,       irRight);
    pause(100);                                 // Pause before repeating
  }
}
Exemplo n.º 18
0
int main(){
	int a,b;
	int low(int,int),high(int,int);
	printf("Please input two numbers:");
	scanf("%d,%d",&a,&b);
	printf("The lowest common multiple of %d and %d is %d.\n",a,b,low(a,b));
	printf("The greatest common divisor of %d and %d is %d.\n",a,b,high(a,b));
	return 0;
}
Exemplo n.º 19
0
void MACWriteTXEndPt( unsigned int _size)
{
    // calc end offset
    unsigned int offsetEnd    = TXSTART_INIT + _size; 
    
    // Set the TXND pointer to correspond to the packet size given
    enc28j60Write(ETXNDL, low(offsetEnd));
    enc28j60Write(ETXNDH, high(offsetEnd));
}
Exemplo n.º 20
0
bool MetronomeConf::isValidConfDir(QString path) {
    QDir dir(path);
	QFile high( path + "/high.mp3");
	QFile low( path + "/low.mp3");
	if( dir.exists() && high.exists() && low.exists() )
		return true;

    return false;
}
Exemplo n.º 21
0
	surface& surface::build(SDL_Surface* ptr,bool shouldDestroy) {
		if(ptr==NULL)
			throw exception_sdl();
		auto_ptr<surface_low> low(new surface_low());
		low->ptr=ptr;
		low->should_destroy=shouldDestroy;
		this->low = boost::shared_ptr<surface_low>(low);
		return *this;
	}
Exemplo n.º 22
0
void lifTSDIOPin::turn_on() {
  if (!is_output())
    output();
  if (enabledLow) {
    low();
  } else {
    high();
  }
}
Exemplo n.º 23
0
void VirtualSpace::print() {
  tty->print   ("Virtual space:");
  if (special()) tty->print(" (pinned in memory)");
  tty->cr();
  tty->print_cr(" - committed: " SIZE_FORMAT, committed_size());
  tty->print_cr(" - reserved:  " SIZE_FORMAT, reserved_size());
  tty->print_cr(" - [low, high]:     [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",  low(), high());
  tty->print_cr(" - [low_b, high_b]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",  low_boundary(), high_boundary());
}
Exemplo n.º 24
0
u8 SPI_write(u8 module, u8 data_out)
{
    u8 i;
    u8 bitMask;

    switch(module)
    {
        case SPISW:
            for (i = 0; i < 8; i++)
            {
                // MSB first
                if (SPI[module].bitorder == SPI_MSBFIRST)
                    bitMask = 0x80 >> i;

                // LSB first
                else
                    bitMask = 1 << i;

                // Send bit
                digitalwrite(SPI[module].sda, (data_out & bitMask) ? 1 : 0);

                // pulse
                high(SPI[module].sck);
                low(SPI[module].sck);
            }
            return data_out;

        #if !defined(__32MX440F256H__)

        case SPI1:
            SPI1BUF = data_out;             // write to buffer for TX
            while (!SPI1STATbits.SPIRBF);   // wait for the receive flag (transfer complete)
            return SPI1BUF;

        #endif

        case SPI2:
            SPI2BUF = data_out;             // write to buffer for TX
            while (!SPI2STATbits.SPIRBF);   // wait for the receive flag (transfer complete)
            return SPI2BUF;

        #if defined(__32MX795F512L__) || \
            defined(__32MX795F512H__)

        case SPI3:
            SPI3BUF = data_out;             // write to buffer for TX
            while (!SPI3STATbits.SPIRBF);   // wait for the receive flag (transfer complete)
            return SPI3BUF;

        case SPI4:
            SPI4BUF = data_out;             // write to buffer for TX
            while (!SPI4STATbits.SPIRBF);   // wait for the receive flag (transfer complete)
            return SPI4BUF;

        #endif
    }
Exemplo n.º 25
0
bool checkBook::lookup(int vipID, QDate date)
{
	QString sVipID;
	sVipID.setNum(vipID);
	QDateTime low(date);
	QDateTime up = low.addDays(1);
	QString filter = "vip_id = " + sVipID + " AND book_date >= '" + low.toString("yyyy-MM-dd h:m:s") + "' AND book_date <= '" + up.toString("yyyy-MM-dd h:m:s") + "';";
	model->setFilter(filter);
	return model->select();
}
Exemplo n.º 26
0
void Lakrits::setHeader(int type, int dataLen) {
	oBuffer[0] = STX;
	oBuffer[RECIPIENT_ID_LOW_OFFSET] = 0;
	oBuffer[RECIPIENT_ID_HIGH_OFFSET] = 0;
	oBuffer[SENDER_ID_LOW_OFFSET] = id_low;
	oBuffer[SENDER_ID_HIGH_OFFSET] = id_high;
	oBuffer[MESSAGE_TYPE_LOW_OFFSET] = low(type);
	oBuffer[MESSAGE_TYPE_HIGH_OFFSET] = high(type);
	oBuffer[PAYLOAD_LENGTH_OFFSET] = dataLen;
}
Exemplo n.º 27
0
int main()                                    // main function
{
  while(1)                                    // Endless loop
  {
    high(26);                                 // Set P26 I/O pin high
    pause(100);                               // Wait 1/10 second
    low(26);                                  // Set P26 I/O pin low
    pause(100);                               // Wait another 1/10 second
  }
}
Exemplo n.º 28
0
static void pulse_outCtr(int pin, int time)           // pulseOut function definition
{
  /*
  if(st_iodt == 0)
  {
    set_io_dt(CLKFREQ/1000000);
    set_io_timeout(CLKFREQ/4);
  }
  */
  signed long phsVal = -time * st_iodt;
  int ctr = 0;
  int frq = 1;
  int phs = 0;
  int state = get_output(pin);
  if(state == 1)
  {
    phsVal = -phsVal;
    phs = -1;
    frq = -1;
  }
  if(ta == 0 || (dta && (CNT - ta > dta)))
  {
    PHSA = phs;
    FRQA = frq;
    CTRA = pin;
    CTRA += (4 << 26);
    low(pin);
    PHSA = phsVal;
    dta = abs(phsVal);
    ta = CNT;
  }
  else if(tb == 0 || (dtb && (CNT - tb > dtb)))
  {
    PHSB = phs;
    FRQB = frq;
    CTRB = pin;
    CTRB += (4 << 26);
    low(pin);
    PHSB = phsVal;
    dtb = abs(phsVal);
    tb = CNT;
  }
}
Exemplo n.º 29
0
/******************************************************************************
 * Function:        void SOCKETWriteBuffer(unsigned char* _buf, unsigned int _size, unsigned int _start)
 *
 * PreCondition:    none
 *
 * Input:           *_buf:  buffer to write data 
 *                  _size:  amount data to write
 *                  _start: socket's buffer start address
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Writes bytes to Socket RX/TX Buffer space
 *
 * Note:            None
 *****************************************************************************/
void SOCKETWriteBuffer(unsigned char* _buf, unsigned int _size, unsigned int _start)
{
    // Set the write pointer to start of socket buffer area
    enc28j60Write(EWRPTL, low(_start));
    enc28j60Write(EWRPTH, high(_start));
    
    // copy the packet into the socket buffer
    enc28j60WriteBuffer(_size, _buf);
    
}
Exemplo n.º 30
0
/** @brief Check for incoming messages and respond.

An incoming message is assembled over multiple calls to this function. A status
is returned indicating completion or error status of the message.

The message is built up as serial data is received, and therefore must not be
changed outside the function until the function returns COMPLETE.

@param[out] rxFrameType *rxMessage: Message received.
@param[out] uint8_t *messageState: Message build state, must be set to zero on
                                   the first call.
@returns uint8_t message completion/error state. XBEE_STATE_MACHINE,
            XBEE_CHECKSUM, XBEE_INCOMPLETE, XBEE_COMPLETE, XBEE_NO_CHARACTER
*/
uint8_t receiveMessage(rxFrameType *rxMessage, uint8_t *messageState)
{
/* Wait for data to appear */
    uint16_t inputChar = getch();
    uint16_t messageError = XBEE_INCOMPLETE;
    if (high(inputChar) != NO_DATA)
    {
        uint8_t state = *messageState;
/* Pull in the received character and look for message start */
/* Read in the length (16 bits) and frametype then the rest to a buffer */
        uint8_t inputValue = low(inputChar);
        switch(state)
        {
/* Sync character */
            case 0:
                if (inputValue == 0x7E) state++;
                break;
/* Two byte length */
            case 1:
                rxMessage->length = (inputChar << 8);
                state++;
                break;
            case 2:
                rxMessage->length += inputValue;
                state++;
                break;
/* Frame type */
            case 3:
                rxMessage->frameType = inputValue;
                rxMessage->checksum = inputValue;
                state++;
                break;
/* Rest of message, maybe include addresses or just data */
            default:
                if (state > rxMessage->length + 3)
                    messageError = XBEE_STATE_MACHINE;
                else if (rxMessage->length + 3 > state)
                {
                    rxMessage->message.array[state-4] = inputValue;
                    state++;
                    rxMessage->checksum += inputValue;
                }
                else
                {
                    state = 0;
                    if (((rxMessage->checksum + inputValue + 1) & 0xFF) > 0)
                        messageError = XBEE_CHECKSUM;
                    else messageError = XBEE_COMPLETE;
                }
        }
        *messageState = state;
    }
    else messageError = XBEE_NO_CHARACTER;
    return messageError;
}