Esempio n. 1
0
int main()
{
  while(true){
    Reset();
    systickInit();
    gpioInit();
    adcInit();
    lcdInit();
    tsInit();
    welcomeScreen();
    #ifdef DEBUG
      ledInit();
    #endif
    spiInit();
    while(!IsRebootRequired()){
      if(IsSynchronizationRequired()){
        AssertGoBusIRQ();
      }
      #ifdef DEBUG
        GPIO_ToggleBits(GPIOC, GPIO_Pin_13);
        delay(5);
      #endif
    }
  }
}
Esempio n. 2
0
void tsReadZ(uint32_t* z1, uint32_t* z2)
{
  if (!_tsInitialised) tsInit();

  // Make sure that X+/Y- are set to GPIO
  TS_XP_FUNC_GPIO;
  TS_YM_FUNC_GPIO;

  // Set X- and Y+ to inputs (necessary?)
  gpioSetDir (TS_XM_PORT, TS_XM_PIN, 0);
  gpioSetDir (TS_YP_PORT, TS_YP_PIN, 0);

  // Set X+ and Y- to output
  gpioSetDir (TS_XP_PORT, TS_XP_PIN, 1);
  gpioSetDir (TS_YM_PORT, TS_YM_PIN, 1);

  // X+ goes low, Y- goes high
  gpioSetValue(TS_XP_PORT, TS_XP_PIN, 0);   // GND
  gpioSetValue(TS_YM_PORT, TS_YM_PIN, 1);   // 3.3V

  // Set X- and Y+ to ADC
  TS_XM_FUNC_ADC;  
  TS_YP_FUNC_ADC;  

  // Get ADC results
  *z1 = adcRead(TS_YP_ADC_CHANNEL);     // Z1 (Read Y+)
  *z2 = adcRead(TS_XM_ADC_CHANNEL);     // Z2 (Read X-)
}
void LockSystemController::timeSlice()
{
	// TBD - nothing for now
#ifdef LOCK_SYSTEM_CONTROLLER_DEBUG
	static int counter = 0;
	if (++counter % 100 == 1) {
		stateInfo();
	}
#endif
	switch (mainState) {
		case Initial:
			tsInit();
			return;
			break;
		case Automatic:
			tsAuto();
			return;
			break;
		case Fault:
			tsFault();
			return;
			break;
		case Manual:
			tsManual();
			return;
			break;
	}
}
Esempio n. 4
0
void tsReadZ(uint32_t* z1, uint32_t* z2)
{
  if (!_tsInitialised) tsInit();

  // XP = ADC
  // XM = GPIO Output Low
  // YP = GPIO Output High
  // YM = GPIO Input

  TS_XM_FUNC_GPIO;
  TS_YP_FUNC_GPIO;
  TS_YM_FUNC_GPIO;

  gpioSetDir (TS_XM_PORT, TS_XM_PIN, 1);
  gpioSetDir (TS_YP_PORT, TS_YP_PIN, 1);
  gpioSetDir (TS_YM_PORT, TS_YM_PIN, 0);

  gpioSetValue(TS_XM_PORT, TS_XM_PIN, 0);   // GND
  gpioSetValue(TS_YP_PORT, TS_YP_PIN, 1);   // 3.3V

  TS_XP_FUNC_ADC;
  *z1 = adcRead(TS_XP_ADC_CHANNEL);

  // XP = GPIO Input
  // XM = GPIO Output Low
  // YP = GPIO Output High
  // YM = ADC

  TS_XP_FUNC_GPIO;
  gpioSetDir (TS_YM_PORT, TS_YM_PIN, 0);

  TS_YM_FUNC_ADC;
  *z2 = adcRead(TS_YM_ADC_CHANNEL);
}
Esempio n. 5
0
uint32_t tsReadY(void)
{
  if (!_tsInitialised) tsInit();

  // YP = GPIO Output High
  // YM = GPIO Output Low
  // XP = GPIO Input
  // XM = ADC

  TS_YP_FUNC_GPIO;
  TS_YM_FUNC_GPIO;
  TS_XP_FUNC_GPIO;

  gpioSetDir (TS_YP_PORT, TS_YP_PIN, 1);
  gpioSetDir (TS_YM_PORT, TS_YM_PIN, 1);
  gpioSetDir (TS_XP_PORT, TS_XP_PIN, 0);

  gpioSetValue(TS_YP_PORT, TS_YP_PIN, 1);   // 3.3V
  gpioSetValue(TS_YM_PORT, TS_YM_PIN, 0);   // GND

  TS_XM_FUNC_ADC;

  // Return the ADC results
  return adcRead(TS_XM_ADC_CHANNEL);
}
void RunTasks(size_t tasks, TaskGenerator_t gen)
{

  long firstRunTime = 0;

  for (size_t i = 1; i <= 16; ++i)
  {
    auto t = make_timer([&firstRunTime, i](long t)
                        {
                          if (i == 1)
                          {
                            firstRunTime = t;
                          }
                          std::cout << i << ' ' << (double)firstRunTime / t
                                    << std::endl;
                        });

    tbb::task_scheduler_init tsInit(i);
    tbb::task_group tg;
    for (size_t task = 0; task < tasks; ++task)
    {
      tg.run(gen());
    }
    tg.wait();
  }
  std::cout << std::endl;
}
Esempio n. 7
0
uint32_t tsReadY(void)
{
  if (!_tsInitialised) tsInit();

  lcdOrientation_t orientation;
  orientation = lcdGetOrientation();

  if (orientation == LCD_ORIENTATION_LANDSCAPE)
  {
    // Make sure Y+/Y- are set to GPIO
    TS_YP_FUNC_GPIO;
    TS_YM_FUNC_GPIO;
  
    // Set X- and X+ to inputs
    gpioSetDir (TS_XM_PORT, TS_XM_PIN, 0);
    gpioSetDir (TS_XP_PORT, TS_XP_PIN, 0);
    
    // Set Y- and Y+ to output
    gpioSetDir (TS_YM_PORT, TS_YM_PIN, 1);
    gpioSetDir (TS_YP_PORT, TS_YP_PIN, 1);
  
    // Y+ goes high, Y- goes low
    gpioSetValue(TS_YP_PORT, TS_YP_PIN, 1);   // 3.3V
    gpioSetValue(TS_YM_PORT, TS_YM_PIN, 0);   // GND
  
    // Set pin 1.0 (X+) to ADC1
    TS_XP_FUNC_ADC;  
  
    // Return the ADC results
    return adcRead(TS_XP_ADC_CHANNEL);
  }
  else
  {
    // Make sure X+/X- are set to GPIO
    TS_XP_FUNC_GPIO;
    TS_XM_FUNC_GPIO;
  
    // Set Y- and Y+ to inputs
    gpioSetDir (TS_YM_PORT, TS_YM_PIN, 0);
    gpioSetDir (TS_YP_PORT, TS_YP_PIN, 0);
    
    // Set X- and X+ to output
    gpioSetDir (TS_XM_PORT, TS_XM_PIN, 1);
    gpioSetDir (TS_XP_PORT, TS_XP_PIN, 1);
  
    // X+ goes high, X- goes low
    gpioSetValue(TS_XP_PORT, TS_XP_PIN, 1);   // 3.3V
    gpioSetValue(TS_XM_PORT, TS_XM_PIN, 0);   // GND
  
    // Set pin 0.11 (Y+) to ADC0
    TS_YP_FUNC_ADC;
  
    // Return the ADC results
    return adcRead(TS_YP_ADC_CHANNEL);
  }
}
Esempio n. 8
0
tsTouchError_t tsWaitForEvent(tsTouchData_t* data, uint32_t timeoutMS)
{
  if (!_tsInitialised) tsInit();

  tsRead(data, false);

  // Return the results right away if reading is valid
  if (data->valid)
  {
    return TS_ERROR_NONE;
  }

  // Handle timeout if delay > 0 milliseconds
  if (timeoutMS)
  {
    uint32_t startTick = systickGetTicks();
    // Systick rollover may occur while waiting for timeout
    if (startTick > 0xFFFFFFFF - timeoutMS)
    {
      while (data->valid == false)
      {
        // Throw alert if timeout delay has been passed
        if ((systickGetTicks() < startTick) && (systickGetTicks() >= (timeoutMS - (0xFFFFFFFF - startTick))))
        {
          return TS_ERROR_TIMEOUT;
        }      
        tsRead(data, false);
      }
    }
    // No systick rollover will occur ... calculate timeout the simple way
    else
    {
      // Wait in infinite loop
      while (data->valid == false)
      {
        // Throw timeout if delay has been passed
        if ((systickGetTicks() - startTick) > timeoutMS)
        {
          return TS_ERROR_TIMEOUT;
        }
        tsRead(data, false);
      }
    }
  }
  // No timeout requested ... wait forever
  else
  {
    while (data->valid == false)
    {
      tsRead(data, false);
    }
  }

  // Indicate correct reading
  return TS_ERROR_NONE;
}
Esempio n. 9
0
int main(int argc, char* argv[])
{
  size_t THREADS = 4;
  if (argc > 1)
  {
    THREADS = boost::lexical_cast<size_t>(argv[1]);
  }

  size_t dim = 1024;
  if (argc > 2)
  {
    dim = boost::lexical_cast<size_t>(argv[2]);
  }

  std::uniform_real_distribution<double> distribution(-1, 1);
  std::mt19937 engine;
  auto generator = [&]
  {
    return distribution(engine);
  };

  SquareMatrix m(dim);
  std::generate(m.begin(), m.end(), generator);


  std::vector<size_t> perThreadCount(THREADS, 0);
  tbb::task_scheduler_init tsInit(THREADS);
  tbb::task_group tg;
  {
    Timer t("Time count");

    for (size_t iTask = 0; iTask < THREADS; ++iTask)
    {
      tg.run([=, &perThreadCount, &m]
             {
               size_t taskSize = dim / THREADS;
               size_t taskStart = iTask * taskSize;
               size_t taskEnd = std::min(taskStart + taskSize, dim);
               size_t count = 0;
               for (size_t i = taskStart; i < taskEnd; ++i)
               {
                 for (size_t j = 0; j < dim; ++j)
                 {
                   if (m[i][j] >= 0.0)
                   {
                     ++perThreadCount[iTask]; // Causes false sharing
                     //++count; //This prevents false sharing
                   }
                 }
               }
               // perThreadCount[iTask] = count; // This prevents false sharing
             });
    }
    tg.wait();
  }
  auto positiveCount =
      std::accumulate(perThreadCount.begin(), perThreadCount.end(), 0);
  std::cout << dim << " by " << dim << " matrix has " << positiveCount
            << " positive entries = " << 100.0 * positiveCount / (dim * dim)
            << "%" << std::endl;
}
Esempio n. 10
0
int
main(int argc, char *argv[])
#endif
{
  int res=0;
  char firmware_filename[50];
  int current_fw_version=0;
#ifdef WRITESERIALNUMBER
  unsigned int serial_number=0;
  unsigned int hall_board_version=0;
  unsigned int firmware_version=0;
#endif
  int inputchar=10;

  printf("\nJLAB Signal Distribution (SD) Firmware Update\n");
  printf("------------------------------------------------\n");

#ifdef VXWORKS
  strncpy(bin_name,__FUNCTION__,50);
#else
  strncpy(bin_name,argv[0],50);

#ifdef WRITESERIALNUMBER
  if(argc<5)
    {
      printf(" ERROR: Must specify four (4) arguments\n");
      Usage();
      exit(-1);
    }
  else
    {
      strncpy(firmware_filename,argv[1],50);
      serial_number = (unsigned int) strtoll(argv[2],NULL,10)&0xffffffff;
      hall_board_version = (unsigned int) strtoll(argv[3],NULL,16)&0xffffffff;
      firmware_version = (unsigned int) strtoll(argv[4],NULL,16)&0xffffffff;
    }
#else
  if(argc<2)
    {
      printf(" ERROR: Must specify two (2) arguments\n");
      Usage();
      exit(-1);
    }
  else
    {
      strncpy(firmware_filename,argv[1],50);
    }
#endif
#endif /* VXWORKS */

#ifdef WRITESERIALNUMBER
  /* Check on provided items */
  if(serial_number<1 || serial_number>255)
    {
      printf(" ERROR: Invalid Serial Number (%d).  Must be 1-255\n",serial_number);
      exit(-1);
    }

  if(hall_board_version<0x1 || hall_board_version>0xFF)
    {
      printf(" ERROR: Invalid Assigned Hall and Board Version (0x%x).\n  Must be 0x01-0xFF\n"
	     ,hall_board_version);
      exit(-1);
    }

  if(firmware_version<0x1 || firmware_version>0xFF)
    {
      printf(" ERROR: Firmware Version (0x%x).  Must be 0x01-0xFF\n",firmware_version);
      exit(-1);
    }

  printf("Firmware File                   = %s\n",firmware_filename);
  printf("Serial Number (dec)             = %4d\n",serial_number);
  printf("Assigned Hall and Board Version = 0x%02X\n",hall_board_version);
  printf("Firmware Version                = 0x%02X\n",firmware_version);
  printf("\n");

  printf(" Please verify these items before continuing... \n");
#else
  printf("Firmware File                   = %s\n",firmware_filename);
#endif
  printf("\n");

#ifndef VXWORKS
  vmeSetQuietFlag(1);
  res = vmeOpenDefaultWindows();
  if(res!=OK)
    goto CLOSE;
#endif

  res = sdFirmwareLoadFile(firmware_filename);
  if(res!=OK)
    goto CLOSE;

  res = tiInit(21<<19,0,1);
  if(res!=OK)
    {
      /* try tsInit, instead */
      res = tsInit(21<<19,0,1);
      if(res!=OK)
	goto CLOSE;
    }
  
  res = sdInit(SD_INIT_IGNORE_VERSION);
  if(res!=OK)
    goto CLOSE;

  current_fw_version = sdGetFirmwareVersion(0);
  printf("\n  Current SD Firmware Version = 0x%x\n\n",current_fw_version);

  printf(" <ENTER> to continue... or q and <ENTER> to quit without update\n");
  inputchar = getchar();

  if((inputchar == 113) ||
     (inputchar == 81))
    {
      printf(" Exiting without update\n");
      res=1;
      goto CLOSE;
    }


  res = sdFirmwareFlushFifo();
  if(res!=OK)
    goto CLOSE;

  res = sdFirmwareWriteToMemory();
  if(res!=OK)
    goto CLOSE;

  goto CLOSE;

/*   res = sdFirmwareVerifyMemory(); */
/*   if(res!=OK) */
/*     goto CLOSE; */

  sdFirmwareFlushFifo();
#ifdef WRITESERIALNUMBER
  sdFirmwareWriteSpecs(0x7F0000,serial_number,hall_board_version,firmware_version);
  sleep(3);
  sdFirmwarePrintSpecs();
#endif

 CLOSE:

  sdFirmwareFreeMemory();
#ifndef VXWORKS
  vmeCloseDefaultWindows();
#endif

  printf("\n");
  if(res==ERROR)
    printf(" ******** SD Update ended in ERROR! ******** \n");
  else if (res==OK)
    {
      printf(" ++++++++ SD Update Successful! ++++++++\n");
      printf("   Power Cycle to load new firmware\n");
    }
  

  printf("\n");
  return OK;
}
Esempio n. 11
0
tsTouchError_t tsWaitForEvent(tsTouchData_t* data, uint32_t timeoutMS)
{
  if (!_tsInitialised) tsInit();

  uint32_t z1, z2;
  uint32_t xRaw1, xRaw2, yRaw1, yRaw2;
  z1 = z2 = 0;

  // Handle timeout if delay > 0 milliseconds
  if (timeoutMS)
  {
    uint32_t startTick = systickGetTicks();
    // Systick rollover may occur while waiting for timeout
    if (startTick > 0xFFFFFFFF - timeoutMS)
    {
      // Wait for timeout or touch event
      while (z2 < CFG_TFTLCD_TS_THRESHOLD)
      {
        // Throw alert if timeout delay has been passed
        if ((systickGetTicks() < startTick) && (systickGetTicks() >= (timeoutMS - (0xFFFFFFFF - startTick))))
        {
          return TS_ERROR_TIMEOUT;
        }      
        tsReadZ(&z1, &z2);
      }
    }
    // No systick rollover will occur ... calculate timeout the simple way
    else
    {
      // Wait in infinite loop
      while (z2 < CFG_TFTLCD_TS_THRESHOLD)
      {
        // Throw timeout if delay has been passed
        if ((systickGetTicks() - startTick) > timeoutMS)
        {
          return TS_ERROR_TIMEOUT;
        }
        tsReadZ(&z1, &z2);
      }
    }
  }
  // No timeout requested ... wait forever
  else
  {
    while (z2 < CFG_TFTLCD_TS_THRESHOLD)
    {
      tsReadZ(&z1, &z2);
    }
  }

  // Get raw conversion results
  // Each value is read twice and compared to avoid erroneous readings
  xRaw1 = tsReadY();    // X and Y are reversed
  xRaw2 = tsReadY();    // X and Y are reversed
  yRaw1 = tsReadX();    // X and Y are reverse
  yRaw2 = tsReadX();    // X and Y are reverse

  // If both read attempts aren't identical, return mismatch error
  if ((xRaw1 != xRaw2) || (yRaw1 != yRaw2))
  {
    return TS_ERROR_XYMISMATCH;
  }

  // Normalise X
  data->x = ((xRaw1 - _calibration.offsetLeft > TS_ADC_LIMIT ? 0 : xRaw1 - _calibration.offsetLeft) * 100) / _calibration.divisorX;
  if (data->x > lcdGetWidth() - 1) data->x = lcdGetWidth() - 1;

  // Normalise Y
  data->y = ((yRaw1 - _calibration.offsetTop > TS_ADC_LIMIT ? 0 : yRaw1 - _calibration.offsetTop) * 100) / _calibration.divisorY;
  if (data->y > lcdGetHeight() - 1) data->y = lcdGetHeight() - 1;

  // Indicate correct reading
  return TS_ERROR_NONE;
}
Esempio n. 12
0
int 
main(int argc, char *argv[]) {

    int stat;

    printf("\nJLAB TS Tests\n");
    printf("----------------------------\n");

    vmeOpenDefaultWindows();

  /* Setup Address and data modes for DMA transfers
   *   
   *  vmeDmaConfig(addrType, dataType, sstMode);
   *
   *  addrType = 0 (A16)    1 (A24)    2 (A32)
   *  dataType = 0 (D16)    1 (D32)    2 (BLK32) 3 (MBLK) 4 (2eVME) 5 (2eSST)
   *  sstMode  = 0 (SST160) 1 (SST267) 2 (SST320)
   */
    vmeDmaConfig(2,5,1);

    /* INIT dmaPList */

    dmaPFreeAll();
    vmeIN  = dmaPCreate("vmeIN",1024,500,0);
    vmeOUT = dmaPCreate("vmeOUT",0,0,0);
    
    dmaPStatsAll();

    dmaPReInitAll();

/*     gefVmeSetDebugFlags(vmeHdl,0x0); */
    /* Set the TS structure pointer */
    tsInit((21<<19),TS_READOUT_EXT_POLL,0);
    if(tsCheckAddresses()==ERROR)
      goto CLOSE;

    tsStatus(1);

    tsSetSyncEventInterval(20);

    tsSetBlockLevel(BLOCKLEVEL);

    
    tsLoadTriggerTable();

    stat = tsIntConnect(TS_INT_VEC, mytsISR, 0);
    if (stat != OK) 
      {
	printf("ERROR: tsIntConnect failed \n");
	goto CLOSE;
      } 
    else 
      {
	printf("INFO: Attached TS Interrupt\n");
      }

    tsSetTriggerSource(5);

    tsSetFPInput(0x0);
    tsSetGenInput(0xffff);
    tsSetGTPInput(0x0);

    tsSetBusySource(TS_BUSY_LOOPBACK,1);

    tsSetBlockLimit(20);

    tsSetBlockBufferLevel(1);

    tsTrigLinkReset();
    taskDelay(1);

    tsStatus(1);
    int again=0;

 AGAIN:
    tsSyncReset(1);

    taskDelay(1);

    tsGetCurrentBlockLevel();
    
    tsStatus(1);

    printf("Hit enter to start triggers\n");
    getchar();

    tsIntEnable(0);
    tsStatus(1);
#define SOFTTRIG
#ifdef SOFTTRIG
    tsSetRandomTrigger(1,0x7);
    taskDelay(10);
/*     tsSoftTrig(1,BLOCKLEVEL-3,0x700,0); */
#endif

    printf("Hit any key to Disable triggers.\n");
    getchar();
    tsStatus(1);
    tsSetBlockLimit(1014);
    printf("Hit any key to Disable triggers.\n");
    getchar();
    tsDisableTriggerSource(1);
    tsStatus(1);
    tsPrintScalers(1);
    tsPrintScalers(2);
    tsPrintScalers(3);

#ifdef SOFTTRIG
    /* No more soft triggers */
/*     tidSoftTrig(0x0,0x8888,0); */
    tsSoftTrig(1,0,0x700,0);
    tsDisableRandomTrigger();
#endif

    printf("Hit any key to Disconnect and exit.\n");
    getchar();

    tsIntDisable();

    tsIntDisconnect();

    tsStatus(1);

    again=0;
    if(again==1)
      {
	again=0;
	goto AGAIN;
      }

 CLOSE:

    vmeCloseDefaultWindows();

    exit(0);
}