Ejemplo n.º 1
0
static void USART_IRQHandler(USART_TypeDef *USART, IOEventFlags device) {
    if (USART_GetFlagStatus(USART, USART_FLAG_FE) != RESET) {
        // If we have a framing error, push status info onto the event queue
        jshPushIOEvent(
            IOEVENTFLAGS_SERIAL_TO_SERIAL_STATUS(device) | EV_SERIAL_STATUS_FRAMING_ERR, 0);
    }
    if (USART_GetFlagStatus(USART, USART_FLAG_PE) != RESET) {
        // If we have a parity error, push status info onto the event queue
        jshPushIOEvent(
            IOEVENTFLAGS_SERIAL_TO_SERIAL_STATUS(device) | EV_SERIAL_STATUS_PARITY_ERR, 0);
    }
    if(USART_GetITStatus(USART, USART_IT_RXNE) != RESET) {
        /* Clear the USART Receive interrupt */
        USART_ClearITPendingBit(USART, USART_IT_RXNE);
        /* Read one byte from the receive data register */
        jshPushIOCharEvent(device, (char)USART_ReceiveData(USART));
    }
    /* If overrun condition occurs, clear the ORE flag and recover communication */
    if (USART_GetFlagStatus(USART, USART_FLAG_ORE) != RESET)
    {
        (void)USART_ReceiveData(USART);
    }
    if(USART_GetITStatus(USART, USART_IT_TXE) != RESET) {
        /* If we have other data to send, send it */
        int c = jshGetCharToTransmit(device);
        if (c >= 0) {
            USART_SendData(USART, (uint16_t)c);
        } else
            USART_ITConfig(USART, USART_IT_TXE, DISABLE);
    }
}
Ejemplo n.º 2
0
void jshInputThread() {
  while (isInitialised) {
    bool shortSleep = false;
    /* Handle the delayed Ctrl-C -> interrupt behaviour (see description by EXEC_CTRL_C's definition)  */
    if (execInfo.execute & EXEC_CTRL_C_WAIT)
      execInfo.execute = (execInfo.execute & ~EXEC_CTRL_C_WAIT) | EXEC_INTERRUPTED;
    if (execInfo.execute & EXEC_CTRL_C)
      execInfo.execute = (execInfo.execute & ~EXEC_CTRL_C) | EXEC_CTRL_C_WAIT;
    // Read from the console
    while (kbhit()) {
      int ch = getch();
      if (ch<0) break;
      jshPushIOCharEvent(EV_USBSERIAL, (char)ch);
    }
    // Read from any open devices - if we have space
    if (jshGetEventsUsed() < IOBUFFERMASK/2) {
      int i;
      for (i=0;i<=EV_DEVICE_MAX;i++) {
        if (ioDevices[i]) {
          char buf[32];
          // read can return -1 (EAGAIN) because O_NONBLOCK is set
          int bytes = (int)read(ioDevices[i], buf, sizeof(buf));
          if (bytes>0) {
            //int j; for (j=0;j<bytes;j++) printf("]] '%c'\r\n", buf[j]);
            jshPushIOCharEvents(i, buf, (unsigned int)bytes);
            shortSleep = true;
          }
        }
      }
    }
    // Write any data we have
    IOEventFlags device = jshGetDeviceToTransmit();
    while (device != EV_NONE) {
      char ch = (char)jshGetCharToTransmit(device);
      //printf("[[ '%c'\r\n", ch);
      if (ioDevices[device]) {
        write(ioDevices[device], &ch, 1);
        shortSleep = true;
      }
      device = jshGetDeviceToTransmit();
    }


#ifdef SYSFS_GPIO_DIR
    Pin pin;
    for (pin=0;pin<JSH_PIN_COUNT;pin++)
      if (gpioShouldWatch[pin]) {
        shortSleep = true;
        bool state = jshPinGetValue(pin);
        if (state != gpioLastState[pin]) {
          jshPushIOEvent(pinToEVEXTI(pin) | (state?EV_EXTI_IS_HIGH:0), jshGetSystemTime());
          gpioLastState[pin] = state;
        }
      }
#endif

    usleep(shortSleep ? 1000 : 50000);
  }
}
Ejemplo n.º 3
0
void uart0_event_handle(app_uart_evt_t * p_event) {
  if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR) {
    jshPushIOEvent(IOEVENTFLAGS_SERIAL_TO_SERIAL_STATUS(EV_SERIAL1) | EV_SERIAL_STATUS_FRAMING_ERR, 0);
  } else if (p_event->evt_type == APP_UART_TX_EMPTY) {
    int ch = jshGetCharToTransmit(EV_SERIAL1);
    if (ch >= 0) {
      uartIsSending = true;
      while (app_uart_put((uint8_t)ch) != NRF_SUCCESS);
    } else
      uartIsSending = false;
  } else if (p_event->evt_type == APP_UART_DATA) {
    uint8_t character;
    while (app_uart_get(&character) != NRF_SUCCESS);
    jshPushIOCharEvent(EV_SERIAL1, (char) character);
  }
}
Ejemplo n.º 4
0
void jshIdle() {
  while (kbhit()) {
    jshPushIOCharEvent(EV_USBSERIAL, (char)getch());
  }

#ifdef SYSFS_GPIO_DIR
  Pin pin;
  for (pin=0;pin<JSH_PIN_COUNT;pin++)
    if (gpioShouldWatch[pin]) {
      bool state = jshPinGetValue(pin);
      if (state != gpioLastState[pin]) {
        jshPushIOEvent(pinToEVEXTI(pin) | (state?EV_EXTI_IS_HIGH:0), jshGetSystemTime());
        gpioLastState[pin] = state;
      }
    }
#endif
}