Example #1
0
File: i2c.cpp Project: 980f/cortexm
void I2C::init400k(void){ //todo:3 parameters for fast and a kiloHertz
  init();
  clearHW();
#if I2C_TRACE
  stageTrace.rewind();
#endif
  //cr1 as apb.init sets it up is fine
  int apbRate = getClockRate();
  dcb->cr2 = apbRate / 1000000; //keeps all interrupt enable stuff disabled
  //compute the two fast options, choose the highest
  int r1 = rate(apbRate, (25 * 400000)); //@36 = 4, 4*25 = 100 clocks = 360kHz
  int r0 = rate(apbRate, (3 * 400000)); //@36 = 30, 30*3 = 90 clocks = 400kHz
  if(25 * r1 > 3 * r0) {
    dcb->ccr = (3 << 14) /* fast 9:16*/ | r1;
  } else {
    dcb->ccr = (2 << 14) /* 400kHz 1:2*/ | r0;
  }
  //maximum clock risetime: 3/1000000 = 3e-9 in integers without overflowing
  dcb->riseTime = 1 + quanta(apbRate * 3, 10000000); //300ns: ~11 clocks at 36MHz apb clock.
  //alh: suspect the +1 given in the documents is due to them truncating rather than rounding up.

  //enable interrupts at NVIC:
  eventIrq.prepare(); //NB: simple enable() often generates an interrupt even when all interrupts are masked, dammit! (Busy was true)
  errorIrq.enable();
} /* init */
Example #2
0
	void update() {
		char buf[80];
#ifdef PGMCOMOUT
		// read from system;
		acq200_getRoot(DROOT, SR_START, 1, "%d", &_sysstart);
		acq200_getRoot(DROOT, SR_STRIDE, 1, "%d", &_sysstride);
#endif
		pipin("acqcmd getNumSamples", buf, 80);
		
		if (sscanf(buf, "ACQ32:getNumSamples=%d pre=%d post=%d", 
			   &samples, &s0, &s2) != 3){
			err("failed to read numsamples");
			exit(1);
		}
		s0 = -s0;

		getClockRate();
	}
Example #3
0
double Device::tsToTime(ULong64_t timeStamp) const
{
  return (double)((timeStamp - getTimeStart()) / (double)getClockRate());
}