Ejemplo n.º 1
0
void initCan(void) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
	addConsoleAction("caninfo", canInfo);
	if (!engineConfiguration->isCanEnabled)
		return;
#endif /* EFI_PROD_CODE */

#if STM32_CAN_USE_CAN2 || defined(__DOXYGEN__)
	// CAN1 is required for CAN2
	canStart(&CAND1, &canConfig);
	canStart(&CAND2, &canConfig);
#else
	canStart(&CAND1, &canConfig);
#endif

	canStart(&EFI_CAN_DEVICE, &canConfig);
#if EFI_PROD_CODE || defined(__DOXYGEN__)

	chThdCreateStatic(canTreadStack, sizeof(canTreadStack), NORMALPRIO, (tfunc_t) canThread, NULL);

	mySetPadMode2("CAN TX", boardConfiguration->canTxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
	mySetPadMode2("CAN RX", boardConfiguration->canRxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));

#endif /* EFI_PROD_CODE */
}
Ejemplo n.º 2
0
/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  /*
   * Activates the CAN driver 1.
   */
  canStart(&CAND1, &cancfg);

  /*
   * Starting the transmitter and receiver threads.
   */
  chThdCreateStatic(can_rx_wa, sizeof(can_rx_wa), NORMALPRIO + 7, can_rx, NULL);
  chThdCreateStatic(can_tx_wa, sizeof(can_tx_wa), NORMALPRIO + 7, can_tx, NULL);

  /*
   * Normal main() thread activity, in this demo it does nothing.
   */
  while (true) {
    chThdSleepMilliseconds(500);
  }
  return 0;
}
Ejemplo n.º 3
0
bool TransferItem::queue() {
    if (!canStart()) {
        return false;
    }
    
    foreach (TransferItem *child, m_childItems) {
        child->queue();
    }

    return true;
}
Ejemplo n.º 4
0
QVariantMap TransferItem::itemDataWithRoleNames() const {
    QVariantMap map;
    map[roles.value(CanCancelRole)] = canCancel();
    map[roles.value(CanPauseRole)] = canPause();
    map[roles.value(CanStartRole)] = canStart();
    map[roles.value(ExpandedRole)] = expanded();
    map[roles.value(ItemTypeRole)] = itemType();
    map[roles.value(ItemTypeStringRole)] = itemTypeString();
    map[roles.value(RowRole)] = row();
    map[roles.value(RowCountRole)] = rowCount();
    return map;
}
Ejemplo n.º 5
0
QMap<int, QVariant> TransferItem::itemData() const {
    QMap<int, QVariant> map;
    map[CanCancelRole] = canCancel();
    map[CanPauseRole] = canPause();
    map[CanStartRole] = canStart();
    map[ExpandedRole] = expanded();
    map[ItemTypeRole] = itemType();
    map[ItemTypeStringRole] = itemTypeString();
    map[RowRole] = row();
    map[RowCountRole] = rowCount();
    return map;
}
Ejemplo n.º 6
0
void BoardDriverStart(void)
{
	canStart(&CAND1, &cancfg);

	/*CAN1 RX and TX*/
	palSetPadMode(GPIOB, 8, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
	palSetPadMode(GPIOB, 9, PAL_MODE_STM32_ALTERNATE_PUSHPULL);

	sdStart(&SD2, &serialConfig);
	palSetPadMode(GPIOA, 0, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
    palSetPadMode(GPIOA, 1, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
	palSetPadMode(GPIOA, 2, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
    palSetPadMode(GPIOA, 3, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
}
Ejemplo n.º 7
0
void cancom_init(void) {
	palSetPadMode(GPIOD, 0,
			PAL_MODE_ALTERNATE(GPIO_AF_CAN1) |
			PAL_STM32_OTYPE_PUSHPULL |
			PAL_STM32_OSPEED_MID1);
	palSetPadMode(GPIOD, 1,
			PAL_MODE_ALTERNATE(GPIO_AF_CAN1) |
			PAL_STM32_OTYPE_PUSHPULL |
			PAL_STM32_OSPEED_MID1);

	canStart(&CANDx, &cancfg);

	chThdCreateStatic(cancom_thread_wa, sizeof(cancom_thread_wa), NORMALPRIO + 1,
			cancom_thread, NULL);
}
Ejemplo n.º 8
0
Thread* CanInitLocal(void){
  canInit();
  canStart(&CAND1, &cancfg);

  can_tp = chThdCreateFromHeap(
      &ThdHeap,
      sizeof(CanTxThreadWA),
      LINK_THREADS_PRIO - 2,
      CanTxThread,
      NULL);

  if (can_tp == NULL)
    chDbgPanic("Can not allocate memory");

  return can_tp;
}
Ejemplo n.º 9
0
void MigratorBase::start()
{
    if (mMigrationState == InProgress) {
        qWarning() << "already running";
        return;
    }
    if (!canStart()) {
        Q_EMIT message(Error, i18n("Failed to start migration because migrator is not ready"));
        Q_EMIT stoppedProcessing();
        return;
    }
    //TODO acquire dbus lock
    logMessage(Info, displayName());
    Q_EMIT message(Info, i18n("Starting migration..."));
    setMigrationState(InProgress);
    setProgress(0);
    startWork();
}
Ejemplo n.º 10
0
// 开启server
bool CServerRoot::startServices()
{
	showToConsole("<Prepare Game Service...>");

	//把自己加入定时器
	// 注意:需要先addtimer,再startTimer,因为没有pending事件或active事件,event_base_dispatch会退出循环,导致timer线程提前结束
	CTimer::GetSingleton().addTimer(std::bind(&CServerRoot::timerProcess, this), 10);

	//启动定时器,创建了一个timer线程,这个线程就是处理消息包的线程
	if(!CTimer::GetSingleton().startTimer())
		return false;

	while(!m_clExitEvent.wait_event(1000))
	{
		if (canStart())
			break;
	}

	return true;
}
Ejemplo n.º 11
0
QVariant TransferItem::data(int role) const {
    switch (role) {
    case CanCancelRole:
        return canCancel();
    case CanPauseRole:
        return canPause();
    case CanStartRole:
        return canStart();
    case ExpandedRole:
        return expanded();
    case ItemTypeRole:
        return itemType();
    case ItemTypeStringRole:
        return itemTypeString();
    case RowRole:
        return row();
    case RowCountRole:
        return rowCount();
    default:
        return QVariant();
    }
}
Ejemplo n.º 12
0
void move(Train* train_train_quotidien){
  pthread_mutex_lock(&mutex);
  Voie* nextVoie = getNextVoieTRAIN(train_train_quotidien);
  if (nextVoie != NULL) {
    if (canStart(train_train_quotidien)) {
      printf("Le Train n°%d départ de la voie %d pour aller vers %d\n", train_train_quotidien->id, train_train_quotidien->position->id, nextVoie->id);
      // On enlève le train de la voie actuelle
      train_train_quotidien->position->nbTrainAct--;
      // On enlève la réservation sur la voie qu'on va quitter
      train_train_quotidien->position->reserve = false;
      train_train_quotidien->position->reserveId = -1;
      // On réinitialise le sens courant de la voie
      train_train_quotidien->position->currentSens = train_train_quotidien->position->sens;

      pthread_cond_broadcast(&train_train_quotidien->position->voieLibre); // le broadcast est une précaution si jamais il y a des trains qui pourraient ne jamais être réveillés.
      // ça y est le train a officiellement changé de voie :)
      train_train_quotidien->position = nextVoie;
      // On adapte le sens de la voie
      train_train_quotidien->position->currentSens = train_train_quotidien->sens;
      // On ajoute le train dans le décompte de la voie
      train_train_quotidien->position->nbTrainAct++;

      printf("Le Train n°%d est sur la Voie %d\n", train_train_quotidien->id, train_train_quotidien->position->id);
      if (train_train_quotidien->position->id == 4) {
        //printf("Nombre train sur 4 :  %d\n", train_train_quotidien->position->nbTrainAct);
        //printf("########################### Sens train : %d\t\t\tSens Voie : %d\t\t\tSens courant : %d\n", train_train_quotidien->sens,train_train_quotidien->position->sens, train_train_quotidien->position->currentSens);
        printf(" !!! Petite PAUSE au Garage !!!\n");
        usleep(5000);

      }else if (train_train_quotidien->position->id == 2) {
        printf(" !!! Petite PAUSE à la Gare !!!\n");
        usleep(5000);
      }
      usleep(50);
    }
  }
  pthread_mutex_unlock(&mutex);

}
Ejemplo n.º 13
0
/*
 * Application entry point.
 */
int main(void) {

	/*
	 * System initializations.
	 * - HAL initialization, this also initializes the configured device drivers
	 *   and performs the board-specific initializations.
	 * - Kernel initialization, the main() function becomes a thread and the
	 *   RTOS is active.
	 */
	halInit();
	chSysInit();

	oca_led_init();

	oca_usb_init();

	canStart(&CAND1, &cancfg);

	//set_led(led_act, led_blink_250);
	oca_led_set(oca_led_stat, oca_led_blink_500);
	//set_led(led_err, led_blink_1000);

	/*
	 * Creates the blinker thread.
	 */
	chThdCreateStatic(can_rx_wa, sizeof(can_rx_wa), NORMALPRIO + 5, can_rx, NULL);
	chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
	chThdCreateStatic(can_tx_wa, sizeof(can_tx_wa), NORMALPRIO, can_tx, NULL);

	/*
	 * Normal main() thread activity, in this demo it does nothing except
	 * sleeping in a loop and check the button state.
	 */
	while (true) {
		chThdSleepSeconds(1);
	}
}
Ejemplo n.º 14
0
int main(void)
{
  /*
   * Start OS and HAL
   */

  halInit();
  chSysInit();
  setupIPC();

  DEBUGEN(printf("App Mode\n"));

  usbDisconnectBus(&USBD1);

  /*
   * Initialize extra driver objects.
   */
  sduObjectInit(&SDU1);
  sduObjectInit(&SDU2);

  /*
   * Start peripherals
   */
  sdStart(&SD1, &uart1Cfg);
  sdStart(&SD2, &uart2Cfg);
  sdStart(&SD3, &uart3Cfg);
  usbStart(&USBD1, &usbcfg);
  sduStart(&SDU1, &serusbcfg1);
  sduStart(&SDU2, &serusbcfg2);
  canStart(&CAND1, &cancfg);
  dacStart(&DACD1, &dac1cfg1);
  adcStart(&ADCD1, NULL);
  adcStart(&ADCD3, NULL);
  timcapStart(&TIMCAPD3, &tc_conf);
  pwmStart(&PWMD_LED2, &pwmcfg);

  eeInit();
  // Compare and update versions in EEprom if needed.
  version_t v;
  if (readVersionFromEE(VERSION_IDX_APP, &v) == 0 && memcmp(&versions, &v, sizeof(version_t)) != 0) {

    writeVersionToEE(VERSION_IDX_APP, &versions[VERSION_IDX_APP]);
  }
  if (readVersionFromEE(VERSION_IDX_BL, &v) == 0 ) {
    memcpy(&versions[VERSION_IDX_BL], &v, sizeof(version_t));
  }

  /*
   * Creates the threads.
   */
  chThdCreateStatic(waThreadBDU, sizeof(waThreadBDU), NORMALPRIO+5, ThreadBDU, NULL);
  chThdCreateStatic(waThreadSDU, sizeof(waThreadSDU), NORMALPRIO+2, ThreadSDU, NULL);
  chThdCreateStatic(waThreadADC, sizeof(waThreadADC), NORMALPRIO, ThreadADC, NULL);
  chThdCreateStatic(waThreadKnock, sizeof(waThreadKnock), NORMALPRIO, ThreadKnock, NULL);
  chThdCreateStatic(waThreadCAN, sizeof(waThreadCAN), NORMALPRIO, ThreadCAN, NULL);
  chThdCreateStatic(waThreadSER1, sizeof(waThreadSER1), NORMALPRIO, ThreadSER1, NULL);
  chThdCreateStatic(waThreadRecord, sizeof(waThreadRecord), NORMALPRIO+1, ThreadRecord, NULL);
  chThdCreateStatic(waThreadWdg, sizeof(waThreadWdg), HIGHPRIO, ThreadWdg, NULL);

  /* Create last as it uses pointers from above */
  chThdCreateStatic(waThreadMonitor, sizeof(waThreadMonitor), NORMALPRIO+10, ThreadMonitor, NULL);

  while (TRUE)
  {
    while(USBD1.state != USB_READY) chThdSleepMilliseconds(10);

    chThdSleepMilliseconds(100);

    if (usbConnected())
    {
      usbConnectBus(&USBD1);
    }
    else
    {
      usbDisconnectBus(&USBD1);
    }
  }
}