Added triangles + reset
[hackover2013-badge-firmware.git] / main.c
1 /**************************************************************************/
2 /*!
3 @file main.c
4 @author K. Townsend (microBuilder.eu)
5
6 @section LICENSE
7
8 Software License Agreement (BSD License)
9
10 Copyright (c) 2011, microBuilder SARL
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 1. Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 2. Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 3. Neither the name of the copyright holders nor the
21 names of its contributors may be used to endorse or promote products
22 derived from this software without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 /**************************************************************************/
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39
40 #include "projectconfig.h"
41 #include "sysinit.h"
42
43 #include "core/gpio/gpio.h"
44 #include "core/systick/systick.h"
45
46 #ifdef CFG_INTERFACE
47 #include "core/cmd/cmd.h"
48 #endif
49
50 /**************************************************************************/
51 /*!
52 Approximates a 1 millisecond delay using "nop". This is less
53 accurate than a dedicated timer, but is useful in certain situations.
54
55 The number of ticks to delay depends on the optimisation level set
56 when compiling (-O). Depending on the compiler settings, one of the
57 two defined values for 'delay' should be used.
58 */
59 /**************************************************************************/
60 void delayms(uint32_t ms)
61 {
62 uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 45); // Release Mode (-Os)
63 // uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 120); // Debug Mode (No optimisations)
64
65 while (delay > 0)
66 {
67 __asm volatile ("nop");
68 delay--;
69 }
70 }
71
72 /**************************************************************************/
73 /*!
74 Main program entry point. After reset, normal code execution will
75 begin here.
76 */
77 /**************************************************************************/
78 int main(void)
79 {
80 // Configure cpu and mandatory peripherals
81 systemInit();
82
83 uint32_t currentSecond, lastSecond;
84 currentSecond = lastSecond = 0;
85
86 while (1)
87 {
88 // Toggle LED once per second ... rollover = 136 years :)
89 currentSecond = systickGetSecondsActive();
90 if (currentSecond != lastSecond)
91 {
92 lastSecond = currentSecond;
93 if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN) == CFG_LED_OFF)
94 {
95 gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON);
96 }
97 else
98 {
99 gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF);
100 }
101 }
102
103 // Poll for CLI input if CFG_INTERFACE is enabled in projectconfig.h
104 #ifdef CFG_INTERFACE
105 cmdPoll();
106 #endif
107 }
108
109 return 0;
110 }
This page took 0.04638 seconds and 5 git commands to generate.