Guest User

Untitled

a guest
Mar 20th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. /*
  2.     ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
  3.  
  4.     Licensed under the Apache License, Version 2.0 (the "License");
  5.     you may not use this file except in compliance with the License.
  6.     You may obtain a copy of the License at
  7.  
  8.         http://www.apache.org/licenses/LICENSE-2.0
  9.  
  10.     Unless required by applicable law or agreed to in writing, software
  11.     distributed under the License is distributed on an "AS IS" BASIS,
  12.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.     See the License for the specific language governing permissions and
  14.     limitations under the License.
  15. */
  16.  
  17.  
  18. extern "C"{
  19.   #include "main.h"
  20.  
  21.   #include "usb_istr.h"
  22.   #include "usb_pwr.h"
  23. }
  24. #include "ch.hpp"
  25. #include "hal.h"
  26.  
  27.  
  28. using namespace chibios_rt;
  29.  
  30.  
  31. // USB
  32. uint8_t Send_Buffer[64];
  33. uint32_t packet_sent=1;
  34. uint32_t packet_receive=1;
  35. __IO uint32_t USBConnectTimeOut;
  36.  
  37. //usb
  38. extern __IO uint8_t Receive_Buffer[64];
  39. extern __IO  uint32_t Receive_length ;
  40. extern __IO  uint32_t length ;
  41.  
  42.  
  43.  
  44.  
  45. /**
  46.   * @brief  Configure the USB.
  47.   * @param  None
  48.   * @retval None
  49.   */
  50. void Demo_USB (void)
  51. {
  52.   Set_System();
  53.  Set_USBClock();
  54.   USB_Interrupts_Config();
  55.  
  56.   USB_Init();
  57.  
  58.   while ((bDeviceState != CONFIGURED)&&(USBConnectTimeOut != 0))
  59.   {}/* */
  60. }
  61.  
  62.  
  63.  
  64. class cUsbUartTask : public BaseStaticThread<512> {
  65. private:
  66.  
  67. protected:
  68.   virtual msg_t main(void) {
  69.     setName("cUsbUartTask");
  70.  
  71.     Demo_USB();
  72.  
  73.     while (true) {
  74.       /*if (bDeviceState == CONFIGURED)
  75.       {
  76.         CDC_Receive_DATA();
  77.         //Check to see if we have data yet
  78.         if (Receive_length  != 0)
  79.         {
  80.         }
  81.       }*/
  82.     }
  83.     sleep(100);
  84.   }
  85. };
  86.  
  87.  
  88. static cUsbUartTask myUsbTask;
  89.  
  90.  
  91.  
  92. extern "C"{
  93.   CH_IRQ_HANDLER(Vector8C) {
  94.   }
  95.  
  96.   CH_IRQ_HANDLER(Vector90) {
  97.     CH_IRQ_PROLOGUE();
  98.     chSysLockFromIsr();
  99.  
  100.     chSysUnlockFromIsr();
  101.  
  102.     USB_Istr();
  103.     CH_IRQ_EPILOGUE();
  104.   }
  105.  
  106.   CH_IRQ_HANDLER(VectorE8)
  107.   {
  108.     CH_IRQ_PROLOGUE();
  109.  
  110.     chSysLockFromIsr();
  111.     chSysUnlockFromIsr();
  112.     CH_IRQ_EPILOGUE();
  113.  
  114.     Resume(RESUME_EXTERNAL);
  115.     EXTI_ClearITPendingBit(EXTI_Line18);
  116.   }
  117.  
  118.   CH_IRQ_HANDLER(HardFaultVector) {
  119.     while(1) {;}
  120.   }  
  121. }
  122.  
  123. /*
  124.  * Application entry point.
  125.  */
  126. int main(void) {
  127.  
  128.  
  129.   halInit();
  130.   System::init();
  131.  
  132.   myUsbTask.start(NORMALPRIO);
  133.  
  134.   while (true) {
  135.    BaseThread::sleep(MS2ST(500));
  136.   }
  137.  
  138.  
  139.   return 0;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment