X-Git-Url: http://git.asbjorn.biz/?p=rapper.git;a=blobdiff_plain;f=new_cmsis%2Fmain.c;fp=new_cmsis%2Fmain.c;h=d89416beff5b328f9ff938036c2b505124a4fe33;hp=3daf11b277da6ef392c25bd02aa61e77dea8cf92;hb=2253dc3498d4ace7f07884ec6d40d654ca677571;hpb=678d5839c35477bcb24f2a29ebb5bce4ce5f8152 diff --git a/new_cmsis/main.c b/new_cmsis/main.c index 3daf11b..d89416b 100644 --- a/new_cmsis/main.c +++ b/new_cmsis/main.c @@ -1,93 +1,110 @@ -/****************************************************************************** - * @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 "LPC17xx.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 */ -} - -/*---------------------------------------------------------------------------- - 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(); - - 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 */ - } - -} - +/****************************************************************************** + * @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 +#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 +} +