Move CRC value out of VCS
[rapper.git] / src / main.c
1 /******************************************************************************
2  * @file:    main.c
3  * @purpose: CMSIS Cortex-M3 Core Peripheral Access Layer Source File
4  *           Blink a LED using CM3 SysTick
5  * @version: V1.0
6  * @date:    22. May 2009
7  *----------------------------------------------------------------------------
8  *
9  * Copyright (C) 2008 ARM Limited. All rights reserved.
10  *
11  * ARM Limited (ARM) is supplying this software for use with Cortex-M3
12  * processor based microcontrollers.  This file can be freely distributed
13  * within development tools that are supporting such ARM based processors.
14  *
15  * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
16  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
17  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
18  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
19  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
20  *
21  ******************************************************************************/
22
23 #include <board.h>
24 #include "usb.h"
25
26 uint32_t msTicks;                               /* counts 1ms timeTicks */
27 /*----------------------------------------------------------------------------
28   SysTick_Handler
29  *----------------------------------------------------------------------------*/
30 void SysTick_Handler(void) {
31   msTicks++;                                    /* increment counter necessary in Delay() */
32 }
33
34 /*------------------------------------------------------------------------------
35   delays number of tick Systicks (happens every 1 ms)
36  *------------------------------------------------------------------------------*/
37 __inline static void Delay (uint32_t dlyTicks) {
38   uint32_t curTicks;
39
40   curTicks = msTicks;
41   while ((msTicks - curTicks) < dlyTicks);
42 }
43
44 /*------------------------------------------------------------------------------
45   configer LED pins
46  *------------------------------------------------------------------------------*/
47 __inline static void LED_Config(void) {
48
49   GPIO1->FIODIR = (1<<29)|(1<<18);     /* LEDs on PORT1 18 & 29 are Output */
50 }
51
52 /*------------------------------------------------------------------------------
53   Switch on LEDs
54  *------------------------------------------------------------------------------*/
55 __inline static void LED_On (uint32_t led) {
56
57   GPIO1->FIOPIN |=  (led);                      /* Turn On  LED */
58 }
59
60
61 /*------------------------------------------------------------------------------
62   Switch off LEDs
63  *------------------------------------------------------------------------------*/
64 __inline static void LED_Off (uint32_t led) {
65
66   GPIO1->FIOPIN &= ~(led);                      /* Turn Off LED */
67 }
68
69 void lightshow() {
70         while (1) {
71                 LED_On ((1<<29));                           /* Turn on the LED. */
72                 LED_On ((1<<18));                           /* Turn on the LED. */
73                 Delay (100);                                /* delay  100 Msec */
74                 LED_Off ((1<<29));                           /* Turn on the LED. */
75                 Delay (100);                                /* delay  100 Msec */
76                 LED_Off ((1<<18));                           /* Turn on the LED. */
77                 LED_On ((1<<29));                           /* Turn on the LED. */
78                 Delay (100);                                /* delay  100 Msec */
79         }
80 }
81
82 /*----------------------------------------------------------------------------
83   MAIN function
84  *----------------------------------------------------------------------------*/
85 int main (void) {
86
87         SystemInit();   /* setup clocks */
88
89         if (SysTick_Config(SystemFrequency / 1000)) { /* Setup SysTick Timer for 1 msec interrupts  */
90                 while (1);                                  /* Capture error */
91         }
92
93         LED_Config();
94
95         VCOM_Init();                              // VCOM Initialization
96
97         USB_Init();                               // USB Initialization
98
99         USB_Connect(TRUE);                        // USB Connect
100         //lightshow();
101
102         while (!USB_Configuration) ;              // wait until USB is configured
103
104         while (1) {                               // Loop forever
105                 VCOM_Serial2Usb();                      // read serial port and initiate USB event
106                 VCOM_CheckSerialState();
107                 VCOM_Usb2Serial();
108         } // end while
109 }
110