示例#1
0
void MainTask(void) {

  USB_Init();
  USB_EnableIAD();
  _AddCDC();
  _AddHID();
  USB_Start();
  BSP_SetLED(0);
  OS_CREATETASK(&_HIDTCB,  "HIDTask",  _HIDTask, 200, _aHIDStack);

  while (1) {
    char ac[64];
    int  NumBytesReceived;

    //
    // Wait for configuration
    //
    while ((USB_GetState() & (USB_STAT_CONFIGURED | USB_STAT_SUSPENDED)) != USB_STAT_CONFIGURED) {
      BSP_ToggleLED(0);
      USB_OS_Delay(50);
    }
    BSP_SetLED(0);
    NumBytesReceived = USB_CDC_Receive(&ac[0], sizeof(ac));
    if (NumBytesReceived > 0) {
      USB_CDC_Write(&ac[0], NumBytesReceived);
    }
  }
}
示例#2
0
/*********************************************************************
*
*       LPTask
*/
static void LPTask(void) {
  while (1) {
    OS_Delay(100);     // Syncronize to tick to avoid jitter
    //
    // Display measurement overhead
    //
    BSP_SetLED(0);
    BSP_ClrLED(0);
    //
    // Perform measurement
    //
    BSP_SetLED(0);     // Start measurement
    OS_Resume(&TCBHP); // Resume high priority task to force task switch
  }
}
void BSP_ToggleLED(int Index) {
    if (_LEDPORT_STATE & (1 << (19 + Index))) {  /* LED is switched off */
        BSP_SetLED(Index);
    } else {
        BSP_ClrLED(Index);
    }
}
示例#4
0
void MainTask(void) {
  OS_CREATETASK(&TCBHP, "HP Task", HPTask, 150, StackHP);
  OS_Delay(1);
  while (1) {
    OS_Delay(100);     // Syncronize to tick to avoid jitter
    //
    // Display measurement overhead
    //
    BSP_SetLED(0);
    BSP_ClrLED(0);
    //
    // Perform measurement
    //
    BSP_SetLED(0);     // Start measurement
    OS_Resume(&TCBHP); // Resume high priority task to force task switch
  }
}
示例#5
0
void BSP_ToggleLED(int Index) {
  if (Index >= NUM_LEDS) {
    return;
  }
  if (LPC_GPIO2->PIN & (1 << (LED0_BIT + Index))) {  // Active low
    BSP_SetLED(Index);
  } else {
    BSP_ClrLED(Index);
  }
}
示例#6
0
/*********************************************************************
*
*       _Client
*/
static void _Client(void * p) {
  long               TCPSockID;
  struct sockaddr_in ServerAddr;
  int                ConnectStatus;
  int                r;

  //
  // Wait until link is up and network interface is configured.
  //
  while (IP_IFaceIsReady() == 0) {
    OS_Delay(50);
  }
  while(1) {
    TCPSockID = socket(AF_INET, SOCK_STREAM, 0);  // Open socket
    if (TCPSockID == 0) {                          // Error, Could not get socket
      while (1) {
        BSP_ToggleLED(0);
        OS_Delay(20);
      }
    } else {
      //
      // Connect to server
      //
      BSP_SetLED(0);
      ServerAddr.sin_family      = AF_INET;
      ServerAddr.sin_port        = htons(SERVER_PORT);
      ServerAddr.sin_addr.s_addr = htonl(SERVER_IP_ADDR);
      ConnectStatus              = connect(TCPSockID, (struct sockaddr *)&ServerAddr, sizeof(struct sockaddr_in));
      if (ConnectStatus != SOCKET_ERROR) {
        while(1) {
          if (DIRECTION & 1) {
            r = _Receive(TCPSockID);
            if (r == -1) {
              break;
            }
            _Statistics.RxCnt++;
          }
          if (DIRECTION & 2) {
            r = _Send(TCPSockID);
            if (r == -1) {
              break;
            }
            _Statistics.TxCnt++;
          }
          OS_Delay(50);
        }
      }
    }
    _Statistics.ErrCnt++;
    closesocket(TCPSockID);
    OS_Delay(1000);
  }
}
示例#7
0
void MainTask(void) {
  USB_Init();
  _AddMSD();
  USB_Start();
  while (1) {
    while ((USB_GetState() & (USB_STAT_CONFIGURED | USB_STAT_SUSPENDED)) != USB_STAT_CONFIGURED) {
      BSP_ToggleLED(0);
      USB_OS_Delay(50);
    }
    BSP_SetLED(0);
    USB_MSD_Task();
  }
}
示例#8
0
/*********************************************************************
*
*       _USBTask
*/
static void _USBTask(void) {
    _AddMSD();
    USB_Start();
    while(1) {
        //
        // Wait for configuration
        //
        while ((USB_GetState() & (USB_STAT_CONFIGURED | USB_STAT_SUSPENDED)) != USB_STAT_CONFIGURED) {
            BSP_ToggleLED(0);
            USB_OS_Delay(50);
        }
        BSP_SetLED(0);
        FS_Unmount("");
        USB_MSD_Task();    // Task, does only return when device is non-configured mode
        FS_Mount("");
    }
}
示例#9
0
/*********************************************************************
*
*       _HIDTask
*
*  Function description
*    Task to make the mouse jump from left to right.
*/
static void _HIDTask(void) {
  //
  // Loop: Receive data byte by byte, send back (data + 1)
  //
  while (1) {
    //
    // Wait for configuration
    //
    while ((USB_GetState() & (USB_STAT_CONFIGURED | USB_STAT_SUSPENDED)) != USB_STAT_CONFIGURED) {
      BSP_ToggleLED(1);
      USB_OS_Delay(50);
    }
    BSP_SetLED(1);
    USB_HID_Read(&_aHIDData[0], OUTPUT_REPORT_SIZE);
    _aHIDData[0]++;
    USB_HID_Write(&_aHIDData[0], INPUT_REPORT_SIZE);
    USB_OS_Delay(50);
  }
}
示例#10
0
/*********************************************************************
*
*       _USBTask
*/
static void _USBTask(void) {
  while(1) {
    //
    // Loop: Receive data byte by byte, send back (data + 1)
    //
    while (1) {
      char c;

      while ((USB_GetState() & (USB_STAT_CONFIGURED | USB_STAT_SUSPENDED)) != USB_STAT_CONFIGURED) {
        BSP_ToggleLED(0);
        USB_OS_Delay(50);
      }
      BSP_SetLED(0);         // LED on to indicate we are waiting for data
      USB_BULK_Read(&c, 1);
      BSP_ClrLED(0);
      c++;
      USB_BULK_Write(&c, 1);
    }
  }
}