示例#1
0
/***********************************************************************************
* @fn          appRfReceiverTask
*
* @brief       Check if a new packet has been received. If a new packet
*              is received the payload is sent to the UART.
*
* @param       none
*
* @return      none
*/
static void appRfReceiverTask(void)
{

    if (mrfiLinkDataRdy()) {
        uint8 nToSend;
        uint8 fSuccess;

        // Tell the PC not to send data
        halUartEnableRxFlow(FALSE);

        // Wait for the PC to respond
        halMcuWaitUs(1000);

        // Receive RF data
        nToSend = mrfiLinkRecv(pRxData);

        // If reception successful, send packet to UART
        fSuccess= FALSE;
        if(nToSend>0) {
            if (halUartWrite(pRxData,nToSend)==nToSend)
                fSuccess= TRUE;
        }

        if (!fSuccess) {
            nRxErr++;
            appUpdateDisplay();
        }

        // Signal RX flow on, the PC may send data again
        halUartEnableRxFlow(TRUE);
    }
}
示例#2
0
/***********************************************************************************
* @fn          appLoopbackTask
*
* @brief       Checks if new bytes have arrived from the UART and echo them back.
*
* @param       none
*
* @return      none
*/
static void appLoopbackTask(void)
{
    uint8 nBytes, n;

    nBytes = halUartGetNumRxBytes();

    if( nBytes>0 ) {
        n= MIN(sizeof(pTxData),nBytes);
        halUartRead(pTxData,n);
        halUartWrite(pTxData,n);
    }
}
示例#3
0
__interrupt void PORT1_ISR(void)
{
  int i,j;
  int modeChange;
  char txString[2];
  
  // Clear Port 1 Interrupt Flag
  P1IFG = 0;
  IRCON2 &= 0xF7;
   
  modeChange = 1;
  for (j=0; j<0x20; j++) {
    for (i=0; i<0xFFFF; i++) asm("nop");
    if (P1_2 == 1) {
      modeChange = 0;
      j=0x20;
    }
  }
  
  if (modeChange == 1) {
    if (txFilterEnabled == 1) {
      txFilterEnabled = 0;
      P1_1 = 1;
      txString[0] = 0x13;
    } else {
      txFilterEnabled = 1;
      P1_1 = 0;
      txString[0] = 0x03;
    }
    halUartWrite((uint8 const *)txString,1);
  }

  // Clear Port 1 Interrupt Flag
  P1IFG = 0;  
  IRCON2 &= ~0x04;
}
示例#4
0
void usbReceiveData (void) {
  uint8_t tempData[128] = { 0 };
  size_t uartRxIndex = 0;
  bool txCalcCRC8 = false;
  bool txCalcCRC16 = false;
  uint8_t txLength = 0;
  static uint8_t uartRxBuffer[SIZE_OF_UART_RX_BUFFER] = { 0 };
  uint8_t txTimes = 0;
  uint16_t nBytes = halUartGetNumRxBytes();
  size_t i = 0;

  for( i=0; i<nBytes; i=i+48) {
    uint16_t readBytes;
    if (nBytes-i > 48) {
      readBytes = 48;
    } else {
      readBytes = nBytes-i;
    }
    halUartRead( &tempData[i], readBytes);
    usbUartProcess();
  }



  for( i=0; i<nBytes; i++) {

    // Read Rx buffer
    uartRxBuffer[uartRxIndex] = tempData[i];

    switch( uartRxIndex ) {
    case 0: {
      switch( uartRxBuffer[0] ) {
      case 0x01:
        uartRxIndex++;
        txCalcCRC8   = false;
        txCalcCRC16 = false;
        enableTimerInt();
        break;
      case 0x81:
        uartRxIndex++;
        txCalcCRC8   = true;
        txCalcCRC16 = false;
        enableTimerInt();
        break;
      case 0xC1:
        uartRxIndex++;
        txCalcCRC8   = false;
        txCalcCRC16 = true;
        enableTimerInt();
        break;
      case 0x03:
      case 0x13:
        txFilterEnabled = true;
        P1_1 = 0;
        uartRxBuffer[0] = 0x03;
        halUartWrite(uartRxBuffer,1);
        break;
      case 0x00:
        uartRxBuffer[0] = _MMCOMMANDER_VERSION_ ;
        halUartWrite(uartRxBuffer,1);
        break;
      }
      break;
    }
    case 1: {
      txLength = uartRxBuffer[1];
      uartRxIndex++;
      resetTimerCounter();
      break;
    }
    case 2: {
      txTimes = uartRxBuffer[2];
      uartRxIndex++;
      resetTimerCounter();
      break;
    }
    default: {
      resetTimerCounter();
      if (uartRxIndex == (txLength + 2)) {
        stopTimerInt();
        if (txCalcCRC8 ) {
          uartRxBuffer[++uartRxIndex] = crc8(&uartRxBuffer[3], (size_t)(txLength));
          txLength++;
        }
        if (txCalcCRC16 ) {
          uint16_t const tmpCRC16 = crc16 (&uartRxBuffer[3],(size_t)(txLength));
          uartRxBuffer[++uartRxIndex] = (uint8_t)((tmpCRC16 >> 8) & 0x00FF);
          uartRxBuffer[++uartRxIndex] = (uint8_t)(tmpCRC16 & 0x00FF);
          txLength += 2;
        }

        if (txFilter(&uartRxBuffer[3],txLength) == 0) {
          sendMedtronicMessage(&uartRxBuffer[3],txLength,txTimes);
          halUartWrite( uartRxBuffer, 3 );
          uartRxIndex=0;
        } else {
          uartRxBuffer[1]=0x00;
          uartRxBuffer[2]=0x00;
          halUartWrite( uartRxBuffer, 3 );
          uartRxIndex=0;
        }
      } else {
        uartRxIndex++;
      }
      break;
    }
    }