]> git.sur5r.net Git - freertos/blob - Demo/lwIP_AVR32_UC3/main.c
Start to re-arrange files to include FreeRTOS+ in main download.
[freertos] / Demo / lwIP_AVR32_UC3 / main.c
1 /*This file has been prepared for Doxygen automatic documentation generation.*/\r
2 /*! \file *********************************************************************\r
3  *\r
4  * \brief FreeRTOS and lwIP example for AVR32 UC3.\r
5  *\r
6  * - Compiler:           GNU GCC for AVR32\r
7  * - Supported devices:  All AVR32 devices can be used.\r
8  * - AppNote:\r
9  *\r
10  * \author               Atmel Corporation: http://www.atmel.com \n\r
11  *                       Support and FAQ: http://support.atmel.no/\r
12  *\r
13  *****************************************************************************/\r
14 \r
15 /* Copyright (c) 2007, Atmel Corporation All rights reserved.\r
16  *\r
17  * Redistribution and use in source and binary forms, with or without\r
18  * modification, are permitted provided that the following conditions are met:\r
19  *\r
20  * 1. Redistributions of source code must retain the above copyright notice,\r
21  * this list of conditions and the following disclaimer.\r
22  *\r
23  * 2. Redistributions in binary form must reproduce the above copyright notice,\r
24  * this list of conditions and the following disclaimer in the documentation\r
25  * and/or other materials provided with the distribution.\r
26  *\r
27  * 3. The name of ATMEL may not be used to endorse or promote products derived\r
28  * from this software without specific prior written permission.\r
29  *\r
30  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED\r
31  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
32  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND\r
33  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,\r
34  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
35  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
36  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
37  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
39  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
40  */\r
41 \r
42 \r
43 /* Environment include files. */\r
44 #include <stdlib.h>\r
45 #include <string.h>\r
46 #include "pm.h"\r
47 #include "flashc.h"\r
48 \r
49 /* Scheduler include files. */\r
50 #include "FreeRTOS.h"\r
51 #include "task.h"\r
52 \r
53 /* Demo file headers. */\r
54 #include "partest.h"\r
55 #include "serial.h"\r
56 #include "ethernet.h"\r
57 #include "netif/etharp.h"\r
58 #include "flash.h"\r
59 \r
60 /* Priority definitions for most of the tasks in the demo application. */\r
61 #define mainLED_TASK_PRIORITY     ( tskIDLE_PRIORITY + 1 )\r
62 #define mainETH_TASK_PRIORITY     ( tskIDLE_PRIORITY + 1 )\r
63 \r
64 /* Baud rate used by the serial port tasks. */\r
65 #define mainCOM_BAUD_RATE      ( ( unsigned portLONG ) 57600 )\r
66 #define mainCOM_BUFFER_LEN     ( ( unsigned portLONG ) 70 )\r
67 \r
68 /* An address in the internal Flash used to count resets.  This is used to check that\r
69 the demo application is not unexpectedly resetting. */\r
70 #define mainRESET_COUNT_ADDRESS     ( ( void * ) 0xC0000000 )\r
71 \r
72 \r
73 //!\r
74 //! \fn     main\r
75 //! \brief  start the software here\r
76 //!         1) Initialize the microcontroller and the shared hardware resources\r
77 //!         of the board.\r
78 //!         2) Launch the IP modules.\r
79 //!         3) Start FreeRTOS.\r
80 //! \return 42, which should never occur.\r
81 //! \note\r
82 //!\r
83 int main( void )\r
84 {\r
85 volatile avr32_pm_t* pm = &AVR32_PM;\r
86 \r
87         /* 1) Initialize the microcontroller and the shared hardware resources of the board. */\r
88 \r
89         /* Switch to external oscillator 0 */\r
90         pm_switch_to_osc0( pm, FOSC0, OSC0_STARTUP );\r
91 \r
92         /* Setup PLL0 on OSC0, mul+1=16 ,divisor by 1, lockcount=16, ie. 12Mhzx16/1 = 192MHz output.\r
93            Extra div by 2 => 96MHz */\r
94         pm_pll_setup(pm,        /* volatile avr32_pm_t* pm */\r
95                                 0,              /* unsigned int pll */\r
96                                 15,             /* unsigned int mul */\r
97                                 1,              /* unsigned int div, Sel Osc0/PLL0 or Osc1/Pll1 */\r
98                                 0,              /* unsigned int osc */\r
99                                 16);            /* unsigned int lockcount */\r
100 \r
101         pm_pll_set_option( pm, 0,   // pll0\r
102                                0,   // Choose the range 160-240MHz.\r
103                                1,   // div2\r
104                                0 ); // wbwdisable\r
105 \r
106         /* Enable PLL0 */\r
107         pm_pll_enable(pm,0);\r
108 \r
109         /* Wait for PLL0 locked */\r
110         pm_wait_for_pll0_locked(pm) ;\r
111 \r
112         /* Setup generic clock number 2 on PLL, with OSC0/PLL0, no divisor */\r
113         pm_gc_setup(pm,\r
114                                 0,\r
115                                 1, /* Use Osc (=0) or PLL (=1) */\r
116                                 0, /* Sel Osc0/PLL0 or Osc1/Pll1 */\r
117                                 0,\r
118                                 1);\r
119 \r
120         /* Enable Generic clock 0*/\r
121         pm_gc_enable(pm, 0);\r
122 \r
123         /* switch to clock */\r
124         pm_cksel( pm, 1, 1, 1, 0, 1, 0 );\r
125         flashc_set_wait_state( 1 );\r
126         pm_switch_to_clock( pm, AVR32_PM_MCCTRL_MCSEL_PLL0 );\r
127 \r
128         /* Setup the LED's for output. */\r
129         vParTestInitialise();\r
130 \r
131         /* Start the flash tasks just to provide visual feedback that the demo is\r
132         executing. */\r
133         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
134 \r
135         /* 2) Start ethernet task. */\r
136         vStartEthernetTask( mainETH_TASK_PRIORITY );\r
137 \r
138         /* 3) Start FreeRTOS. */\r
139         vTaskStartScheduler();\r
140 \r
141         /* Will only reach here if there was insufficient memory to create the idle task. */\r
142 \r
143         return 0;\r
144 }\r
145 /*-----------------------------------------------------------*/\r