Ejemplo n.º 1
0
/**
 * @brief   USB device configured handler.
 *
 * @param[in] usbp      pointer to the @p USBDriver object
 *
 * @iclass
 */
void sduConfigureHookI(USBDriver *usbp) {
  SerialUSBDriver *sdup = usbp->param;

  sdup->flags = CHN_NO_ERROR;
  chIQResetI(&sdup->iqueue);
  chOQResetI(&sdup->oqueue);
  chnAddFlagsI(sdup, CHN_CONNECTED);
}
Ejemplo n.º 2
0
static void queues1_execute(void) {
  unsigned i;
  size_t n;

  /* Initial empty state */
  test_assert_lock(1, chIQIsEmptyI(&iq), "not empty");

  /* Queue filling */
  chSysLock();
  for (i = 0; i < TEST_QUEUES_SIZE; i++)
    chIQPutI(&iq, 'A' + i);
  chSysUnlock();
  test_assert_lock(2, chIQIsFullI(&iq), "still has space");
  test_assert_lock(3, chIQPutI(&iq, 0) == Q_FULL, "failed to report Q_FULL");

  /* Queue emptying */
  for (i = 0; i < TEST_QUEUES_SIZE; i++)
    test_emit_token(chIQGet(&iq));
  test_assert_lock(4, chIQIsEmptyI(&iq), "still full");
  test_assert_sequence(5, "ABCD");

  /* Queue filling again */
  chSysLock();
  for (i = 0; i < TEST_QUEUES_SIZE; i++)
    chIQPutI(&iq, 'A' + i);
  chSysUnlock();

  /* Reading the whole thing */
  n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE * 2, TIME_IMMEDIATE);
  test_assert(6, n == TEST_QUEUES_SIZE, "wrong returned size");
  test_assert_lock(7, chIQIsEmptyI(&iq), "still full");

  /* Queue filling again */
  chSysLock();
  for (i = 0; i < TEST_QUEUES_SIZE; i++)
    chIQPutI(&iq, 'A' + i);
  chSysUnlock();

  /* Partial reads */
  n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE);
  test_assert(8, n == TEST_QUEUES_SIZE / 2, "wrong returned size");
  n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE);
  test_assert(9, n == TEST_QUEUES_SIZE / 2, "wrong returned size");
  test_assert_lock(10, chIQIsEmptyI(&iq), "still full");

  /* Testing reset */
  chSysLock();
  chIQPutI(&iq, 0);
  chIQResetI(&iq);
  chSysUnlock();
  test_assert_lock(11, chIQGetFullI(&iq) == 0, "still full");
  threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+1, thread1, NULL);
  test_assert_lock(12, chIQGetFullI(&iq) == 0, "not empty");
  test_wait_threads();

  /* Timeout */
  test_assert(13, chIQGetTimeout(&iq, 10) == Q_TIMEOUT, "wrong timeout return");
}
Ejemplo n.º 3
0
/**
 * @brief   USB device configured handler.
 *
 * @param[in] bdup      pointer to a @p BulkUSBDriver object
 *
 * @iclass
 */
void bduConfigureHookI(BulkUSBDriver *bdup) {
  USBDriver *usbp = bdup->config->usbp;

  chIQResetI(&bdup->iqueue);
  chOQResetI(&bdup->oqueue);
  chnAddFlagsI(bdup, CHN_CONNECTED);

  /* Starts the first OUT transaction immediately.*/
  usbPrepareQueuedReceive(usbp, bdup->config->bulk_out, &bdup->iqueue,
                          usbp->epc[bdup->config->bulk_out]->out_maxsize);
  usbStartReceiveI(usbp, bdup->config->bulk_out);
}
Ejemplo n.º 4
0
/**
 * @brief SD2 status change handler.
 *
 * @param[in] id event id.
 */
static void sd2_handler(eventid_t id) {
	eventflags_t flags;

	(void) id;
	flags = chEvtGetAndClearFlags(&sd2fel);
	if ((flags & CHN_CONNECTED)) {
		cputs("Init: connection on SD2");
	}
	if (flags & CHN_DISCONNECTED) {
		cputs("Init: disconnection on SD2");
		chSysLock();
		chIQResetI(&SD2.iqueue);
		chSysUnlock();
	}
}
/**
 * @brief   Stops the driver.
 * @details Any thread waiting on the driver's queues will be awakened with
 *          the message @p Q_RESET.
 *
 * @param[in] sdp       pointer to a @p SerialDriver object
 *
 * @api
 */
void sdStop(SerialDriver *sdp) {

  chDbgCheck(sdp != NULL, "sdStop");

  chSysLock();
  chDbgAssert((sdp->state == SD_STOP) || (sdp->state == SD_READY),
              "sdStop(), #1",
              "invalid state");
  sd_lld_stop(sdp);
  sdp->state = SD_STOP;
  chOQResetI(&sdp->oqueue);
  chIQResetI(&sdp->iqueue);
  chSchRescheduleS();
  chSysUnlock();
}
Ejemplo n.º 6
0
/**
 * @brief SD2 status change handler.
 *
 * @param[in] id event id.
 */
static void sd2_handler(eventid_t id) {
  ioflags_t flags;

  (void)id;
  flags = chIOGetAndClearFlags(&SD2);
  if ((flags & IO_CONNECTED) && (shelltp2 == NULL)) {
    cputs("Init: connection on SD2");
    shelltp2 = shellCreate(&shell_cfg2, SHELL_WA_SIZE, NORMALPRIO + 10);
  }
  if (flags & IO_DISCONNECTED) {
    cputs("Init: disconnection on SD2");
    chSysLock();
    chIQResetI(&SD2.iqueue);
    chSysUnlock();
  }
}
Ejemplo n.º 7
0
/**
 * @brief SD1 status change handler.
 *
 * @param[in] id event id.
 */
static void sd1_handler(eventid_t id) {
  eventflags_t flags;

  (void)id;
  flags = chEvtGetAndClearFlags(&sd1fel);
  if ((flags & CHN_CONNECTED) && (shelltp1 == NULL)) {
    cputs("Init: connection on SD1");
    shelltp1 = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO + 1);
  }
  if (flags & CHN_DISCONNECTED) {
    cputs("Init: disconnection on SD1");
    chSysLock();
    chIQResetI(&SD1.iqueue);
    chSysUnlock();
  }
}
Ejemplo n.º 8
0
/**
 * @brief SD1 status change handler.
 *
 * @param[in] id event id.
 */
static void sd1_handler(eventid_t id) {
	eventflags_t flags;

	(void) id;
	flags = chEvtGetAndClearFlags(&sd1fel);
	if ((flags & CHN_CONNECTED)) {
		cputs("Init: connection on SD1");
		isSerialOverTcpReady = TRUE;

	}
	if (flags & CHN_DISCONNECTED) {
		cputs("Init: disconnection on SD1");
		isSerialOverTcpReady = FALSE;
		chSysLock();
		chIQResetI(&SD1.iqueue);
		chSysUnlock();
	}
}
Ejemplo n.º 9
0
/*
 * Handles the USB driver global events.
 */
static void usb_event(USBDriver *usbp, usbevent_t event)
{
	extern SerialUSBDriver SDU2;

	switch (event) {
	case USB_EVENT_RESET:
		return;
	case USB_EVENT_ADDRESS:
		return;
	case USB_EVENT_CONFIGURED:
		chSysLockFromISR();

		/* Enables the endpoints specified into the configuration.
		   Note, this callback is invoked from an ISR so I-Class functions
		   must be used.*/
		usbInitEndpointI(usbp, USBD2_DATA_REQUEST_EP, &ep1config);
		usbInitEndpointI(usbp, USBD2_INTERRUPT_REQUEST_EP, &ep2config);

		/* Resetting the state of the CDC subsystem.*/
		sduConfigureHookI(&SDU2);

		chSysUnlockFromISR();
		return;
	case USB_EVENT_SUSPEND:
		if (usbp->state == USB_ACTIVE) {
			// USB cable unplugged
			chSysLockFromISR();
			_usb_reset(usbp);
			// Reset queues and unlock waiting threads
			chIQResetI(&SDU2.iqueue);
			chOQResetI(&SDU2.oqueue);
			chSysUnlockFromISR();
		}
		return;
	case USB_EVENT_WAKEUP:
		return;
	case USB_EVENT_STALLED:
		return;
	}
	return;
}
Ejemplo n.º 10
0
void
vexLcdCheckReceiveMessage( LcdData *lcd )
{
    int16_t i;

    // any characters
    if( sdGetWouldBlock(lcd->sdp) )
        return;

    // read up to 16 bytes from serial port
    for(i=0;i<16;i++)
        {
        int16_t c;

        c = sdGetTimeout( lcd->sdp, TIME_IMMEDIATE);
        if( c != Q_TIMEOUT )
            lcd->rxbuf[i] = c;
        else
            break;
        }

    // 6 chars ?
    if( i == 6 )
        {
        // lcd message ?
        if( (lcd->rxbuf[0] == 0xAA) && (lcd->rxbuf[1] == 0x55) && (lcd->rxbuf[2] == 0x16))
            // verify checksum
            if( !((lcd->rxbuf[4] + lcd->rxbuf[5]) & 0xFF) )
                lcd->buttons = lcd->rxbuf[4];
        }

    // flush anything left
    if( !sdGetWouldBlock(lcd->sdp) )
        {
        chSysLock();
        chIQResetI( &(lcd->sdp)->iqueue );
        chSysUnlock();
        }

}
Ejemplo n.º 11
0
/**
 * @brief   Stops the driver.
 * @details Any thread waiting on the driver's queues will be awakened with
 *          the message @p Q_RESET.
 *
 * @param[in] bdup      pointer to a @p BulkUSBDriver object
 *
 * @api
 */
void bduStop(BulkUSBDriver *bdup) {
  USBDriver *usbp = bdup->config->usbp;

  chDbgCheck(bdup != NULL, "sdStop");

  chSysLock();

  chDbgAssert((bdup->state == BDU_STOP) || (bdup->state == BDU_READY),
              "bduStop(), #1",
              "invalid state");

  /* Driver in stopped state.*/
  usbp->in_params[bdup->config->bulk_in - 1]   = NULL;
  usbp->out_params[bdup->config->bulk_out - 1] = NULL;
  bdup->state = BDU_STOP;

  /* Queues reset in order to signal the driver stop to the application.*/
  chnAddFlagsI(bdup, CHN_DISCONNECTED);
  chIQResetI(&bdup->iqueue);
  chOQResetI(&bdup->oqueue);
  chSchRescheduleS();

  chSysUnlock();
}
Ejemplo n.º 12
0
void InQueue::resetI(void) {

    chIQResetI(&iq);
}