00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00049
00050
00051
00052
00053
00054 #include <string.h>
00055
00056 #include "pm.h"
00057 #include "flashc.h"
00058 #include "gpio.h"
00059 #include "spi.h"
00060 #include "delay.h"
00061
00062
00063 #include "ctrl_access.h"
00064 #include "fsaccess.h"
00065
00067 #include "FreeRTOS.h"
00068 #include "task.h"
00069
00071 #include "serial.h"
00072 #include "navigation.h"
00073 #include "supervisor.h"
00074 #include "shell.h"
00075 #include "cptime.h"
00076
00077 #include "conf_ctrlpanel.h"
00078 #include "conf_at45dbx.h"
00079
00080 #if SD_MMC_SPI_MEM == ENABLE
00081 #include "conf_sd_mmc_spi.h"
00082 #endif
00083
00084
00085
00086
00088 #define mainSUPERVISOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
00089
00090
00091
00092
00093 static void prv_at45dbx_resources_init( void );
00094 #if SD_MMC_SPI_MEM == ENABLE
00095 static void prv_sd_mmc_resources_init(void);
00096 #endif
00097 static void prv_clk_gen_start(void);
00098
00099 #if defined(__GNUC__)
00100 const char *const pcCtrlPanelVersion = "GCC "__VERSION__" "__DATE__" "__TIME__" ATMEL_CONTROLPANEL_AVR32_UC3_10400"CRLF;
00101 #elif defined(__ICCAVR32__)
00102 const char *const pcCtrlPanelVersion = "IAR "ASTRINGZ(__VER__)"G "__DATE__" "__TIME__" ATMEL_CONTROLPANEL_AVR32_UC3_10400"CRLF;
00103 #endif
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00123 int main( void )
00124 {
00125
00126
00127
00128
00129
00130
00131
00132
00133 pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
00134
00135
00136 delay_init(CP_CPU_SPEED);
00137
00138
00139 prv_clk_gen_start();
00140
00141
00142 prv_at45dbx_resources_init();
00143
00144 #if SD_MMC_SPI_MEM == ENABLE
00145 prv_sd_mmc_resources_init();
00146 #endif
00147
00148
00149 LED_Off( LED0 ); LED_Off( LED1 ); LED_Off( LED2 ); LED_Off( LED3 );
00150 LED_Off( LED4 ); LED_Off( LED5 ); LED_Off( LED6 ); LED_Off( LED7 );
00151
00152
00153
00154 if( FALSE == ctrl_access_init() )
00155 {
00156
00157
00158 while( 1 );
00159 }
00160
00161
00162 while( CTRL_GOOD != mem_test_unit_ready( LUN_ID_AT45DBX_MEM ) )
00163 {
00164
00165
00166 }
00167
00168
00169 if( FALSE == b_fsaccess_init() )
00170 {
00171
00172
00173 while( 1 );
00174 }
00175
00176
00177 v_cptime_Init();
00178
00179
00180
00181
00182
00183 vSupervisor_Start( mainSUPERVISOR_TASK_PRIORITY );
00184
00185
00186
00187
00188
00189 vTaskStartScheduler();
00190
00191
00192 return 42;
00193 }
00194
00195
00196
00200 static void prv_at45dbx_resources_init(void)
00201 {
00202 static const gpio_map_t AT45DBX_SPI_GPIO_MAP =
00203 {
00204 {AT45DBX_SPI_SCK_PIN, AT45DBX_SPI_SCK_FUNCTION },
00205 {AT45DBX_SPI_MISO_PIN, AT45DBX_SPI_MISO_FUNCTION },
00206 {AT45DBX_SPI_MOSI_PIN, AT45DBX_SPI_MOSI_FUNCTION },
00207 #define AT45DBX_ENABLE_NPCS_PIN(NPCS, unused) \
00208 {AT45DBX_SPI_NPCS##NPCS##_PIN, AT45DBX_SPI_NPCS##NPCS##_FUNCTION}, // Chip Select NPCS.
00209 MREPEAT(AT45DBX_MEM_CNT, AT45DBX_ENABLE_NPCS_PIN, ~)
00210 #undef AT45DBX_ENABLE_NPCS_PIN
00211 };
00212
00213
00214 spi_options_t spiOptions =
00215 {
00216 .reg = AT45DBX_SPI_FIRST_NPCS,
00217 .baudrate = AT45DBX_SPI_MASTER_SPEED,
00218 .bits = AT45DBX_SPI_BITS,
00219 .spck_delay = 0,
00220 .trans_delay = 0,
00221 .stay_act = 1,
00222 .spi_mode = 0,
00223 .modfdis = 1
00224 };
00225
00226
00227 gpio_enable_module(AT45DBX_SPI_GPIO_MAP,
00228 sizeof(AT45DBX_SPI_GPIO_MAP) / sizeof(AT45DBX_SPI_GPIO_MAP[0]));
00229
00230
00231 if (!spi_is_enabled(AT45DBX_SPI))
00232 {
00233
00234 spi_initMaster(AT45DBX_SPI, &spiOptions);
00235
00236
00237 spi_selectionMode(AT45DBX_SPI, 0, 0, 0);
00238
00239
00240 spi_enable(AT45DBX_SPI);
00241 }
00242
00243
00244 at45dbx_init(spiOptions, CP_PBA_SPEED);
00245 }
00246
00247
00248 #if SD_MMC_SPI_MEM == ENABLE
00249
00252 static void prv_sd_mmc_resources_init(void)
00253 {
00254 static const gpio_map_t SD_MMC_SPI_GPIO_MAP =
00255 {
00256 {SD_MMC_SPI_SCK_PIN, SD_MMC_SPI_SCK_FUNCTION },
00257 {SD_MMC_SPI_MISO_PIN, SD_MMC_SPI_MISO_FUNCTION},
00258 {SD_MMC_SPI_MOSI_PIN, SD_MMC_SPI_MOSI_FUNCTION},
00259 {SD_MMC_SPI_NPCS_PIN, SD_MMC_SPI_NPCS_FUNCTION}
00260 };
00261
00262
00263 spi_options_t spiOptions =
00264 {
00265 .reg = SD_MMC_SPI_NPCS,
00266 .baudrate = SD_MMC_SPI_MASTER_SPEED,
00267 .bits = SD_MMC_SPI_BITS,
00268 .spck_delay = 0,
00269 .trans_delay = 0,
00270 .stay_act = 1,
00271 .spi_mode = 0,
00272 .modfdis = 1
00273 };
00274
00275
00276 gpio_enable_module(SD_MMC_SPI_GPIO_MAP,
00277 sizeof(SD_MMC_SPI_GPIO_MAP) / sizeof(SD_MMC_SPI_GPIO_MAP[0]));
00278
00279
00280 if (!spi_is_enabled(SD_MMC_SPI))
00281 {
00282
00283 spi_initMaster(SD_MMC_SPI, &spiOptions);
00284
00285
00286 spi_selectionMode(SD_MMC_SPI, 0, 0, 0);
00287
00288
00289 spi_enable(SD_MMC_SPI);
00290 }
00291
00292
00293 sd_mmc_spi_init(spiOptions, CP_PBA_SPEED);
00294 }
00295
00296 #endif // SD_MMC_SPI_MEM == ENABLE
00297
00298
00302 static void prv_clk_gen_start(void)
00303 {
00304 volatile avr32_pm_t *pm = &AVR32_PM;
00305
00307 #ifdef USB_ENABLE
00308
00309
00310 pm_pll_setup(pm, 1,
00311 7,
00312 1,
00313 0,
00314 16);
00315
00316 pm_pll_set_option( pm, 1,
00317 1,
00318 1,
00319 0 );
00320
00321
00322 pm_pll_enable(pm, 1);
00323
00324
00325 pm_wait_for_pll1_locked(pm);
00326
00327
00328 pm_gc_setup(pm, AVR32_PM_GCLK_USBB,
00329 1,
00330 1,
00331 0,
00332 0);
00333
00334
00335 pm_gc_enable(pm, AVR32_PM_GCLK_USBB);
00336 #endif
00337
00338
00340 #if CP_CPU_SPEED == 60000000
00341
00342
00343
00344 pm_pll_setup(pm,
00345 0,
00346 9,
00347 1,
00348 0,
00349 16);
00350
00351 pm_pll_set_option( pm, 0,
00352 1,
00353 1,
00354 0 );
00355
00356
00357 pm_pll_enable(pm,0);
00358
00359
00360 pm_wait_for_pll0_locked(pm) ;
00361 #endif
00362
00363 #if (CP_PBA_SPEED == 27000000) && (CP_CPU_SPEED == 54000000)
00364
00365
00366
00367
00368 pm_cksel(pm,1,1,1,0,1,0);
00369 #elif (CP_PBA_SPEED == 15000000) && (CP_CPU_SPEED == 60000000)
00370
00371
00372
00373 pm_cksel(pm,1,1,0,0,0,0);
00374 #endif
00375
00376 #if CP_CPU_SPEED > 33000000
00377
00378 flashc_set_wait_state(1);
00379
00380
00381 pm_switch_to_clock(pm, AVR32_PM_MCCTRL_MCSEL_PLL0);
00382 #endif
00383 }
00384
00385
00386 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
00387 {
00388 volatile int i = 10000;
00389 LED_On(LED0 | LED1 | LED2 | LED3 | LED4 | LED5 | LED6 | LED7);
00390 while(1)
00391 {
00392 while(i--);
00393 LED_Toggle(LED0 | LED1 | LED2 | LED3 | LED4 | LED5 | LED6 | LED7);
00394 i = 10000;
00395 }
00396 }