Fix USB, DOS line endings, integrate and reorganize project
[rapper.git] / new_cmsis / main.c
index 3daf11b..d89416b 100644 (file)
-/******************************************************************************\r
- * @file:    main.c\r
- * @purpose: CMSIS Cortex-M3 Core Peripheral Access Layer Source File\r
- *           Blink a LED using CM3 SysTick\r
- * @version: V1.0\r
- * @date:    22. May 2009\r
- *----------------------------------------------------------------------------\r
- *\r
- * Copyright (C) 2008 ARM Limited. All rights reserved.\r
- *\r
- * ARM Limited (ARM) is supplying this software for use with Cortex-M3\r
- * processor based microcontrollers.  This file can be freely distributed\r
- * within development tools that are supporting such ARM based processors.\r
- *\r
- * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
- * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
- * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
- * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
- *\r
- ******************************************************************************/\r
-\r
-#include "LPC17xx.h"\r
-\r
-\r
-uint32_t msTicks;                               /* counts 1ms timeTicks */\r
-/*----------------------------------------------------------------------------\r
-  SysTick_Handler\r
- *----------------------------------------------------------------------------*/\r
-void SysTick_Handler(void) {\r
-  msTicks++;                                    /* increment counter necessary in Delay() */\r
-}\r
-\r
-/*------------------------------------------------------------------------------\r
-  delays number of tick Systicks (happens every 1 ms)\r
- *------------------------------------------------------------------------------*/\r
-__inline static void Delay (uint32_t dlyTicks) {\r
-  uint32_t curTicks;\r
-\r
-  curTicks = msTicks;\r
-  while ((msTicks - curTicks) < dlyTicks);\r
-}\r
-\r
-/*------------------------------------------------------------------------------\r
-  configer LED pins\r
- *------------------------------------------------------------------------------*/\r
-__inline static void LED_Config(void) {\r
-\r
-  GPIO1->FIODIR = (1<<29)|(1<<18);     /* LEDs on PORT1 18 & 29 are Output */\r
-}\r
-\r
-/*------------------------------------------------------------------------------\r
-  Switch on LEDs\r
- *------------------------------------------------------------------------------*/\r
-__inline static void LED_On (uint32_t led) {\r
-\r
-  GPIO1->FIOPIN |=  (led);                      /* Turn On  LED */\r
-}\r
-\r
-\r
-/*------------------------------------------------------------------------------\r
-  Switch off LEDs\r
- *------------------------------------------------------------------------------*/\r
-__inline static void LED_Off (uint32_t led) {\r
-\r
-  GPIO1->FIOPIN &= ~(led);                      /* Turn Off LED */\r
-}\r
-\r
-/*----------------------------------------------------------------------------\r
-  MAIN function\r
- *----------------------------------------------------------------------------*/\r
-int main (void) {\r
-\r
-  SystemInit();                                                                        /* setup clocks */\r
-  if (SysTick_Config(SystemFrequency / 1000)) { /* Setup SysTick Timer for 1 msec interrupts  */\r
-    while (1);                                  /* Capture error */\r
-  }\r
-\r
-  LED_Config();\r
-\r
-  while(1) {\r
-    LED_On ((1<<29));                           /* Turn on the LED. */\r
-    LED_On ((1<<18));                           /* Turn on the LED. */\r
-    Delay (100);                                /* delay  100 Msec */\r
-    LED_Off ((1<<29));                           /* Turn on the LED. */\r
-    Delay (100);                                /* delay  100 Msec */\r
-    LED_Off ((1<<18));                           /* Turn on the LED. */\r
-    LED_On ((1<<29));                           /* Turn on the LED. */\r
-    Delay (100);                                /* delay  100 Msec */\r
-  }\r
-\r
-}\r
-\r
+/******************************************************************************
+ * @file:    main.c
+ * @purpose: CMSIS Cortex-M3 Core Peripheral Access Layer Source File
+ *           Blink a LED using CM3 SysTick
+ * @version: V1.0
+ * @date:    22. May 2009
+ *----------------------------------------------------------------------------
+ *
+ * Copyright (C) 2008 ARM Limited. All rights reserved.
+ *
+ * ARM Limited (ARM) is supplying this software for use with Cortex-M3
+ * processor based microcontrollers.  This file can be freely distributed
+ * within development tools that are supporting such ARM based processors.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
+ * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
+ * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
+ *
+ ******************************************************************************/
+
+#include <board.h>
+#include "usb.h"
+
+uint32_t msTicks;                               /* counts 1ms timeTicks */
+/*----------------------------------------------------------------------------
+  SysTick_Handler
+ *----------------------------------------------------------------------------*/
+void SysTick_Handler(void) {
+  msTicks++;                                    /* increment counter necessary in Delay() */
+}
+
+/*------------------------------------------------------------------------------
+  delays number of tick Systicks (happens every 1 ms)
+ *------------------------------------------------------------------------------*/
+__inline static void Delay (uint32_t dlyTicks) {
+  uint32_t curTicks;
+
+  curTicks = msTicks;
+  while ((msTicks - curTicks) < dlyTicks);
+}
+
+/*------------------------------------------------------------------------------
+  configer LED pins
+ *------------------------------------------------------------------------------*/
+__inline static void LED_Config(void) {
+
+  GPIO1->FIODIR = (1<<29)|(1<<18);     /* LEDs on PORT1 18 & 29 are Output */
+}
+
+/*------------------------------------------------------------------------------
+  Switch on LEDs
+ *------------------------------------------------------------------------------*/
+__inline static void LED_On (uint32_t led) {
+
+  GPIO1->FIOPIN |=  (led);                      /* Turn On  LED */
+}
+
+
+/*------------------------------------------------------------------------------
+  Switch off LEDs
+ *------------------------------------------------------------------------------*/
+__inline static void LED_Off (uint32_t led) {
+
+  GPIO1->FIOPIN &= ~(led);                      /* Turn Off LED */
+}
+
+void lightshow() {
+       while (1) {
+               LED_On ((1<<29));                           /* Turn on the LED. */
+               LED_On ((1<<18));                           /* Turn on the LED. */
+               Delay (100);                                /* delay  100 Msec */
+               LED_Off ((1<<29));                           /* Turn on the LED. */
+               Delay (100);                                /* delay  100 Msec */
+               LED_Off ((1<<18));                           /* Turn on the LED. */
+               LED_On ((1<<29));                           /* Turn on the LED. */
+               Delay (100);                                /* delay  100 Msec */
+       }
+}
+
+/*----------------------------------------------------------------------------
+  MAIN function
+ *----------------------------------------------------------------------------*/
+int main (void) {
+
+       SystemInit();   /* setup clocks */
+
+       if (SysTick_Config(SystemFrequency / 1000)) { /* Setup SysTick Timer for 1 msec interrupts  */
+               while (1);                                  /* Capture error */
+       }
+
+       LED_Config();
+
+       VCOM_Init();                              // VCOM Initialization
+
+       USB_Init();                               // USB Initialization
+
+       USB_Connect(TRUE);                        // USB Connect
+       //lightshow();
+
+       while (!USB_Configuration) ;              // wait until USB is configured
+
+       while (1) {                               // Loop forever
+               VCOM_Serial2Usb();                      // read serial port and initiate USB event
+               VCOM_CheckSerialState();
+               VCOM_Usb2Serial();
+       } // end while
+}
+