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