Beispiel #1
0
void MainTask(void) {
  OS_CREATETASK(&_TCB, "HPTask", HPTask, 150, _Stack);
  while (1) {
    BSP_ToggleLED(1);
    OS_Delay (200);
  }
}
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);
    }
  }
}
Beispiel #3
0
void MainTask(void) {

    USBH_Init();
    OS_SetPriority(OS_GetTaskID(), TASK_PRIO_APP);                                       // This task has highest prio for real-time application
    OS_CREATETASK(&_TCBMain, "USBH_Task", USBH_Task, TASK_PRIO_USBH_MAIN, _StackMain);   // Start USBH main task
    OS_CREATETASK(&_TCBIsr, "USBH_isr", USBH_ISRTask, TASK_PRIO_USBH_ISR, _StackIsr);    // Start USBH main task
    USBH_HID_Init();
    while (1) {
        BSP_ToggleLED(1);
        if (USBH_HID_GetNumDevices(NULL, 0)) {
            USBH_HID_HANDLE hDevice;
            USBH_HID_DEVICE_INFO aDevInfo[20];
            unsigned NumItems = COUNTOF(_aReportInfo);

            USBH_HID_GetNumDevices(aDevInfo, COUNTOF(aDevInfo));
            hDevice = USBH_HID_Open("hid000");
            if (hDevice) {
                USBH_HID_GetReportDescriptorParsed(hDevice, &_aReportInfo[0], &NumItems);
                USBH_HID_GetReport(hDevice, _aReport, sizeof(_aReport), NULL, NULL);
                USBH_HID_Close(hDevice);
            }
        }
        OS_Delay(100);
    }
}
Beispiel #4
0
static void wolfTask(void) {
    printf("Begin Benchmark Tests\n");
    benchmark_test(NULL);
    printf("Benchmark Tests Complete\n");
    while (1) {
        BSP_ToggleLED(1);
        OS_Delay(200);
    }
}
Beispiel #5
0
void LEDIndicateWorking(void)
{
    if (BSP_ReadCoreTimer() >= APP_LED_BLINK_DELAY_1s)
    {
        /* Toggle LED */
        BSP_ToggleLED(LED_1);

        /* Clear the core timer to restart count. */
        BSP_WriteCoreTimer(0);
    }
}
Beispiel #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);
  }
}
Beispiel #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();
  }
}
Beispiel #8
0
void MainTask(void) {
  IP_Init();
  OS_SetPriority(OS_GetTaskID(), 255);                                 // This task has highest prio for real-time application
  OS_CREATETASK(&_TCB,       "IP_Task", IP_Task, 150, _Stack);         // Start the IP task
  OS_CREATETASK(&_TCBMailer, "Mailer",  _Mailer, 100, _StackMailer);   // Start the mailer
  while (1) {
    BSP_ToggleLED(1);
    if (IP_GetCurrentLinkSpeed() == 0) {
      OS_Delay(50);
    } else {
      OS_Delay (200);
    }
  }
}
Beispiel #9
0
void MainTask(void) {
  BSP_ClrLED(0);
  BSP_ClrLED(1);
  BSP_ClrLED(2);
  IP_Init();
  OS_SetPriority(OS_GetTaskID(), 255);
  OS_CREATETASK(&_TCBIP       , "IP_Task"  , IP_Task  , 150, _StackIP);
#if USE_RX_TASK
  OS_CREATETASK(&_TCBIPRx     , "IP_RxTask", IP_RxTask, 250, _StackIPRx);
#endif
  OS_CREATETASK_EX(&_TCBClient, "Client"   ,  _Client , 100, _StackClient, NULL);
  while (1) {
    BSP_ToggleLED(2);
    OS_Delay (200);
  }
}
/*********************************************************************
*
*       _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("");
    }
}
Beispiel #11
0
void MainTask(void) {
  IP_Init();
  OS_SetPriority(OS_GetTaskID(), 255);                                      // This task has highest prio for real-time application
  OS_CREATETASK(&_TCB     , "IP_Task"  , IP_Task       , 150, _Stack);      // Start the IP task
#if USE_RX_TASK
  OS_CREATETASK(&_IPRxTCB , "IP_RxTask", IP_RxTask     , 140, _IPRxStack);  // Start the IP_RxTask, optional.
#endif
  OS_CREATETASK(&_TCBShell, "Shell"    , IP_ShellServer, 100, _StackShell); // Start the shell server

  while (IP_IFaceIsReady() == 0) {
    OS_Delay(50);
  }
  while (1) {
    BSP_ToggleLED(1);
    OS_Delay (200);
  }
}
/*********************************************************************
*
*       _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);
  }
}
Beispiel #13
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);
    }
  }
}
Beispiel #14
0
void APP_Tasks ( void )
{
    /* Take appropriate action, depending on the current state. */
    switch (appObject.state)
    {

         /* Application is stuck in an idle loop. */
        case APP_STATE_IDLE:
        {
            break;
        }

        /* Continuously blinking the LED. */
        case APP_STATE_BLINKING:
        {
            /* Blink LED every 1/4 second */
            if (BSP_ReadCoreTimer() >= (APP_LED_BLINK_DELAY_1s/4))
            {
               /* Toggle LED */
               BSP_ToggleLED(LED_1);

               /* Clear the core timer to restart count. */
               BSP_WriteCoreTimer(0);
            }

            break;
        }

        /* Should not come here during normal operation */
        default:
        {
            PLIB_ASSERT(false , "unknown application state");

            break;
        }

    }
}
Beispiel #15
0
/*********************************************************************
*
*       _Receive
*
*  Function description
*    Sends a command to server and receives data from server.
*/
static int _Receive(long TCPSockID) {
  U8  acBuffer[20];
  U8 Flag;
  int NumberOfBytesAtOnce;
  U32 ReceiveCnt;
  int r;

  //
  // Send command and receive data
  //
  acBuffer[0] = 'S';                                       // [0:0]: Command
  IP_StoreU32LE((void*)&acBuffer[1], NUMBER_OF_BYTES);     // [1:4]: Number of bytes
  r = send(TCPSockID, (void *) &acBuffer[0], 5, MSG_DONTWAIT); // Send command
  if (r == SOCKET_ERROR) {
    return SOCKET_ERROR;
  }
  ReceiveCnt = 0;
  do {
    if (USE_ZERO_COPY == 0) {                              // Using the socket interface
      NumberOfBytesAtOnce = recv(TCPSockID, _aRxTxBuffer, 1024, 0);
      if (NumberOfBytesAtOnce == SOCKET_ERROR) {
        return SOCKET_ERROR;
      } else {
        ReceiveCnt += NumberOfBytesAtOnce;
      }
    } else {                                              // Register callback for zero-copy interface
      setsockopt(TCPSockID, SOL_SOCKET, SO_CALLBACK, (void *)_rx_callback, 0);
      OS_Delay(1);
    }
  } while (ReceiveCnt < NUMBER_OF_BYTES);
  Flag = 'X';            // Confirmation
  r = send(TCPSockID, (void *) &Flag, 1, 0);
  if (r == SOCKET_ERROR) {
    return SOCKET_ERROR;
  }
  BSP_ToggleLED(1);
  return 0;
}
Beispiel #16
0
/*********************************************************************
*
*       HPTask
*/
static void HPTask(void) {
  while (1) {
    BSP_ToggleLED(0);
    OS_Delay (50);
  }
}
Beispiel #17
0
/*********************************************************************
*
*       _Send
*
*  Function description
*    Sends a command to server and sends data to server.
*/
static int _Send(long TCPSockID) {
  U8  acBuffer[20];
  int NumBytesAtOnce;
  U32 SendCnt;
  U8  Flag;
  IP_PACKET * pPacket;
  int e;
  int r;

  //
  // Send command and data
  //
  acBuffer[0] = 'R';                                       // [0:0]: Command
  IP_StoreU32LE((void*)&acBuffer[1], NUMBER_OF_BYTES);     // [1:4]: Number of bytes
  r = send(TCPSockID, (void *) &acBuffer[0], 5, MSG_DONTWAIT); // Send command
  if (r == SOCKET_ERROR) {
    return SOCKET_ERROR;
  }
  SendCnt = 0;
  do {
    if (USE_ZERO_COPY == 0) {    // Send using sockets
      NumBytesAtOnce = send(TCPSockID, (void *)&_aRxTxBuffer[0], sizeof(_aRxTxBuffer), 0);
      if (NumBytesAtOnce == SOCKET_ERROR) {
        return NumBytesAtOnce;
      } else {
        SendCnt += NumBytesAtOnce;
      }
    } else {  // Send using Zero-copy
      U8 * pData;
      NumBytesAtOnce = sizeof(_aRxTxBuffer);
      do {
        pPacket = IP_TCP_Alloc(NumBytesAtOnce);
      } while (!pPacket);
      //
      // Fill buffer with data to send
      //
      pData = (U8*)pPacket->pData;
      memcpy(pData, "MyData", 6);
      //
      // Send data. We have to do this in the loop since we may try to send faster than we can transmit.
      //
      for (;;) {
        e = IP_TCP_Send(TCPSockID, pPacket);
        if (e >= 0) {
          break;     // Packet sent succesfully
        }
        OS_Delay(1);
      }
      SendCnt += NumBytesAtOnce;
    }
  } while (SendCnt < NUMBER_OF_BYTES);
  Flag = 0;
  //
  // Wait for response to make sure data has been sent completly
  //
  r = recv(TCPSockID, (void *) &Flag, 1, 0);
  if (r == SOCKET_ERROR) {
    return SOCKET_ERROR;
  }
  BSP_ToggleLED(1);
  return 0;
}