示例#1
0
extern int _write( int file, char *ptr, int len )
{
    // declared in variant.cpp
    // UART0_TX will not TX or lockup flushing TX if UART0 has not been started
    extern void UART0_TX( uint8_t uc_data );

    int i;
    for (i = 0; i < len; i++, ptr++)
        UART0_TX(*ptr);
    return i;
}
示例#2
0
static void * run(void *arg)
{
  int res=0;
  int len;
  char buf[10];
  
  struct termios term, term_orig;

  if (!(tcgetattr(0, &term_orig)))
  {
    term = term_orig;

    term.c_lflag &= ~ICANON;
    //term.c_lflag |= ECHO;
    term.c_cc[VMIN] = 0;
    term.c_cc[VTIME] = 0;

    if (tcsetattr(0, TCSANOW, &term))
    {
      printf("tcsetattr failed.\n");
    }
  }
  
  
  while (1)
  {  
    res = poll(&fds,2, 100);

    if (fds[0].revents)
    {
      len = read(0,&buf[0],1);
      if (len>0)
      {
        UART0_RX(buf[0]); 
      }
    }
    if (fds[1].revents)
    {
      if (UART0_TXQNE())
      { // if there is data then send it
         buf[0] = UART0_TX();
         write(1,buf,1);
      } 
      else
      {
        fds[1].events=0; // no more data to send, turn off data ready interrupt
        UART0_EOFTX();
      }
    }
    
  }
  
  return NULL;
}
示例#3
0
int RFduinoBLEClass::begin()
{
  // declared in variant.h
  extern bool override_uart_limit;

  if (! override_uart_limit)
  {
    if (UART0_State != UART0_State_NotStarted && UART0_BaudRate() > 9600)
    {
      const char *error = "BLE + UART > 9600 baud not permitted due to critical BLE timing requirements.\r\n"
        "To override, add: override_uart_limit = true; to the top of setup() in your sketch.";

      // attempt to notify user of error condition
      const char *p = error;
      while (*p)
        UART0_TX(*p++);

      // don't continue
      while (1)
        ;
    }
  }

  RFduinoBLE_custom_uuid = customUUID;
  RFduinoBLE_device_name = deviceName;
  RFduinoBLE_advertisement_data = advertisementData;
  RFduinoBLE_ibeacon = iBeacon;
  memcpy(RFduinoBLE_ibeacon_uuid, iBeaconUUID, sizeof(RFduinoBLE_ibeacon_uuid));
  RFduinoBLE_ibeacon_major = iBeaconMajor;
  RFduinoBLE_ibeacon_minor = iBeaconMinor;
  RFduinoBLE_ibeacon_measured_power = iBeaconMeasuredPower;
  RFduinoBLE_advertisement_interval = advertisementInterval;
  RFduinoBLE_tx_power_level = txPowerLevel;
  RFduinoBLE_connectable = connectable;

  return RFduinoBLE_begin();
}
示例#4
0
void UART0_Start( int dwBaudRate, uint8_t rx_pin, uint8_t tx_pin )
{
  // must STOP before restarting
  if (UART0_State != UART0_State_NotStarted)
    return;

  NRF_GPIO->PIN_CNF[tx_pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
              | (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos)
              | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
              | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
              | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);

  NRF_GPIO->PIN_CNF[rx_pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
              | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
              | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
              | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
              | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);

  NRF_UART0->PSELTXD = tx_pin;
  NRF_UART0->PSELRXD = rx_pin;

  uint32_t dw;
  switch (dwBaudRate)
  {
    case 1200: dw = UART_BAUDRATE_BAUDRATE_Baud1200; break;
    case 2400: dw = UART_BAUDRATE_BAUDRATE_Baud2400; break;
    case 4800: dw = UART_BAUDRATE_BAUDRATE_Baud4800; break;
    case 9600: dw = UART_BAUDRATE_BAUDRATE_Baud9600; break;
    case 14400: dw = UART_BAUDRATE_BAUDRATE_Baud14400; break;
    case 19200: dw = UART_BAUDRATE_BAUDRATE_Baud19200; break;
    case 28800: dw = UART_BAUDRATE_BAUDRATE_Baud28800; break;
    case 31250: dw = UART_BAUDRATE_BAUDRATE_Baud31250; break;
    case 38400: dw = UART_BAUDRATE_BAUDRATE_Baud38400; break;
    case 57600: dw = UART_BAUDRATE_BAUDRATE_Baud57600; break;
    case 76800: dw = UART_BAUDRATE_BAUDRATE_Baud76800; break;
    case 115200: dw = UART_BAUDRATE_BAUDRATE_Baud115200; break;
    case 230400: dw = UART_BAUDRATE_BAUDRATE_Baud230400; break;
    case 250000: dw = UART_BAUDRATE_BAUDRATE_Baud250000; break;
    case 460800: dw = UART_BAUDRATE_BAUDRATE_Baud460800; break;
    case 921600: dw = UART_BAUDRATE_BAUDRATE_Baud921600; break;
    case 1000000: dw = UART_BAUDRATE_BAUDRATE_Baud1M; break;
  }

  NRF_UART0->BAUDRATE         = (dw << UART_BAUDRATE_BAUDRATE_Pos);
  NRF_UART0->ENABLE           = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
  NRF_UART0->EVENTS_RXDRDY    = 0;
  NRF_UART0->EVENTS_TXDRDY    = 0;

  NRF_UART0->INTENSET        |= (UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos )
                              | (UART_INTENSET_TXDRDY_Enabled << UART_INTENSET_TXDRDY_Pos );

  UART0_State = UART0_State_BeforeFirstTX;

  attachInterrupt(UART0_IRQn, UART0_Interrupt);

  NRF_UART0->TASKS_STARTTX    = 1;
  NRF_UART0->TASKS_STARTRX    = 1;

  if (! override_uart_limit)
  {
    if (RFduinoBLE_enabled && dwBaudRate > 9600)
    {
      const char *error = "BLE + UART > 9600 baud not recommended due to critical BLE timing requirements.\r\n"
        "To override, add: override_uart_limit = true; to the top of setup() in your sketch.";

      // attempt to notify user of error condition
      const char *p = error;
      while (*p)
        UART0_TX(*p++);

      // don't continue
      while (1)
        ;
    }
  }
}
示例#5
0
/**********************************************************************
name :
function : 
**********************************************************************/
size_t UARTClass::write( const uint8_t c)
{
	UART0_TX( c );
	return 1;
}