- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# main.c

    00001 /*
    00002   FreeRTOS V3.2.4 - copyright (C) 2003-2005 Richard Barry.
    00003
    00004   This file is part of the FreeRTOS distribution.
    00005
    00006   FreeRTOS is free software; you can redistribute it and/or modify
    00007   it under the terms of the GNU General Public License as published by
    00008   the Free Software Foundation; either version 2 of the License, or
    00009   (at your option) any later version.
    00010
    00011   FreeRTOS is distributed in the hope that it will be useful,
    00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014   GNU General Public License for more details.
    00015
    00016   You should have received a copy of the GNU General Public License
    00017   along with FreeRTOS; if not, write to the Free Software
    00018   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00019
    00020   A special exception to the GPL can be applied should you wish to distribute
    00021   a combined work that includes FreeRTOS, without being obliged to provide
    00022   the source code for any proprietary components.  See the licensing section
    00023   of http://www.FreeRTOS.org for full details of how and when the exception
    00024   can be applied.
    00025
    00026   ***************************************************************************
    00027   See http://www.FreeRTOS.org for documentation, latest information, license
    00028   and contact details.  Please ensure to read the configuration and relevant
    00029   port sections of the online documentation.
    00030   ***************************************************************************
    00031 */
    00032
    00033 /*
    00034   NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
    00035   The processor MUST be in supervisor mode when vTaskStartScheduler is
    00036   called.  The demo applications included in the FreeRTOS.org download switch
    00037   to supervisor mode prior to main being called.  If you are not using one of
    00038   these demo application projects then ensure Supervisor mode is used.
    00039 */
    00040
    00041
    00042 /*
    00043  * Creates all the application tasks, then starts the scheduler.
    00044  * Main.c includes an idle hook function that simply periodically sends data
    00045  * to the USB task for transmission.
    00046  */
    00047
    00048 /*
    00049   Changes from V3.2.2
    00050
    00051   + Modified the stack sizes used by some tasks to permit use of the
    00052     command line GCC tools.
    00053 */
    00054
    00055 /* Library includes. */
    00056 #include <string.h>
    00057 #include <stdio.h>
    00058
    00059 /* Scheduler includes. */
    00060 #include "FreeRTOS.h"
    00061 #include "task.h"
    00062 #include "portable.h"
    00063
    00064 /* MAKE CODE */
    00065 #include "config.h"
    00066
    00067 /* Hardware specific headers. */
    00068 #include "AT91SAM7X256.h"
    00069
    00070
    00071 // NORMAL PROGRAMMING RESUMES
    00072
    00073 /*-----------------------------------------------------------*/
    00074
    00075 /*
    00076  * Configure the processor for use with the Atmel demo board.  This is very
    00077  * minimal as most of the setup is performed in the startup code.
    00078  */
    00079 static void prvSetupHardware( void );
    00080
    00081 /*
    00082  * The idle hook.
    00083  */
    00084 void vApplicationIdleHook( void );
    00085 /*-----------------------------------------------------------*/
    00086
    00087 /*
    00088  * Setup hardware then start all the demo application tasks.
    00089  */
    00090 void MakeStarterTask( void* parameters );
    00091
    00092 void MakeStarterTask( void* parameters )
    00093 {
    00094  (void)parameters;
    00095   Run( );
    00096   TaskDelete( NULL );
    00097 }
    00098
    00099 int main( void )
    00100 {
    00101   /* Setup the ports. */
    00102   prvSetupHardware();
    00103
    00104   /* Create the make task. */
    00105   TaskCreate( MakeStarterTask, "Make", 1200, NULL, 4 );
    00106
    00107   /*NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
    00108   The processor MUST be in supervisor mode when vTaskStartScheduler is
    00109   called.  The demo applications included in the FreeRTOS.org download switch
    00110   to supervisor mode prior to main being called.  If you are not using one of
    00111   these demo application projects then ensure Supervisor mode is used here. */
    00112   vTaskStartScheduler();
    00113
    00114   /* Should never get here! */
    00115   return 0;
    00116 }
    00117 /*-----------------------------------------------------------*/
    00118
    00119
    00120 static void prvSetupHardware( void )
    00121 {
    00122   /* When using the JTAG debugger the hardware is not always initialised to
    00123   the correct default state.  This line just ensures that this does not
    00124   cause all interrupts to be masked at the start. */
    00125   AT91C_BASE_AIC->AIC_EOICR = 0;
    00126
    00127   /* Most setup is performed by the low level init function called from the
    00128   startup asm file.*/
    00129
    00130   // ENABLE HARDWARE RESET
    00131   while((AT91C_BASE_RSTC->RSTC_RSR & (AT91C_RSTC_SRCMP | AT91C_RSTC_NRSTL)) != (AT91C_RSTC_NRSTL));
    00132   AT91C_BASE_RSTC->RSTC_RMR = (0xa5 << 24)
    00133     | AT91C_RSTC_URSTEN
    00134     | ((12 - 1) << 8) // 125ms == (1 << 12) / 32768
    00135   ;
    00136
    00137   // EEPROM DISABLE
    00138   #if ( CONTROLLER_VERSION == 90 )
    00139     AT91C_BASE_PIOB->PIO_PER = 1 << 17; // Set PB17 - the EEPROM ~enable - in PIO mode
    00140     AT91C_BASE_PIOB->PIO_OER = 1 << 17; // Configure in Output
    00141     AT91C_BASE_PIOB->PIO_SODR = 1 << 17; // Set Output
    00142   #elif ( CONTROLLER_VERSION == 95 || CONTROLLER_VERSION == 100 || CONTROLLER_VERSION == 200 )
    00143     AT91C_BASE_PIOA->PIO_PER = 1 << 9; // Set PA9 - the EEPROM ~enable - in PIO mode
    00144     AT91C_BASE_PIOA->PIO_OER = 1 << 9; // Configure in Output
    00145     AT91C_BASE_PIOA->PIO_SODR = 1 << 9; // Set Output
    00146   #endif
    00147
    00148   // CAN DISABLE
    00149   #if ( CONTROLLER_VERSION == 90 )
    00150     AT91C_BASE_PIOB->PIO_PER = 1 << 16; // Set PB16 - the CAN ~enable - in PIO mode
    00151     AT91C_BASE_PIOB->PIO_OER = 1 << 16; // Configure in Output
    00152     AT91C_BASE_PIOB->PIO_SODR = 1 << 16; // Set Output
    00153   #elif ( CONTROLLER_VERSION == 95  || CONTROLLER_VERSION == 100 || CONTROLLER_VERSION == 200 )
    00154     AT91C_BASE_PIOA->PIO_PER = 1 << 7; // Set PA7 - the CAN ~enable - in PIO mode
    00155     AT91C_BASE_PIOA->PIO_OER = 1 << 7; // Configure in Output
    00156     AT91C_BASE_PIOA->PIO_SODR = 1 << 7; // Set Output
    00157   #endif
    00158
    00159   /* Enable the peripheral clock. */
    00160   AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
    00161   AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;
    00162
    00163   // Enable the EMAC
    00164   AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;
    00165
    00166   #if ( APPBOARD_VERSION == 100 )
    00167     // Kill the outputs
    00168     // Outputs 0 - 7 are PA24, PA5, PA6, PA2, PB25, PA25, PA26, PB23
    00169     int outputAMask = ( 1 << 24 ) | ( 1 << 5 ) | ( 1 << 6 ) | ( 1 << 2  ) | ( 1 << 25  ) | ( 1 << 26 );
    00170     int outputBMask = ( 1 << 25 ) | ( 1 << 23 );
    00171     // Set in peripheral mode
    00172     AT91C_BASE_PIOA->PIO_PER = outputAMask;
    00173     AT91C_BASE_PIOB->PIO_PER = outputBMask;
    00174     // Set to Outputs
    00175     AT91C_BASE_PIOA->PIO_OER = outputAMask;
    00176     AT91C_BASE_PIOB->PIO_OER = outputBMask;
    00177     // Turn Off
    00178     AT91C_BASE_PIOA->PIO_CODR = outputAMask;
    00179     AT91C_BASE_PIOB->PIO_CODR = outputBMask;
    00180   #endif
    00181
    00182   /* Turn the USB line into an input, kill the pull up */
    00183   #if ( CONTROLLER_VERSION == 90 )
    00184     AT91C_BASE_PIOB->PIO_PER = AT91C_PIO_PB10;
    00185     AT91C_BASE_PIOB->PIO_ODR = AT91C_PIO_PB10;
    00186     AT91C_BASE_PIOB->PIO_PPUDR = AT91C_PIO_PB10;
    00187   #elif ( CONTROLLER_VERSION == 95 || CONTROLLER_VERSION == 100 )
    00188     AT91C_BASE_PIOA->PIO_PER = AT91C_PIO_PA10;
    00189     AT91C_BASE_PIOA->PIO_ODR = AT91C_PIO_PA10;
    00190     AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA10;
    00191   #elif ( CONTROLLER_VERSION == 200 )
    00192     AT91C_BASE_PIOA->PIO_PER = AT91C_PIO_PA29;
    00193     AT91C_BASE_PIOA->PIO_ODR = AT91C_PIO_PA29;
    00194     AT91C_BASE_PIOA->PIO_PPUDR = AT91C_PIO_PA29;
    00195   #endif
    00196
    00197   /* Setup the PIO for the USB pull up resistor. */
    00198   /* Start low: no USB */
    00199   #if ( CONTROLLER_VERSION == 90 )
    00200     AT91C_BASE_PIOB->PIO_PER = AT91C_PIO_PB11;
    00201     AT91C_BASE_PIOB->PIO_OER = AT91C_PIO_PB11;
    00202     AT91C_BASE_PIOB->PIO_SODR = AT91C_PIO_PB11;
    00203   #elif ( CONTROLLER_VERSION == 95 || CONTROLLER_VERSION == 100 )
    00204     AT91C_BASE_PIOA->PIO_PER = AT91C_PIO_PA11;
    00205     AT91C_BASE_PIOA->PIO_OER = AT91C_PIO_PA11;
    00206     AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA11; // had this round the wrong way...
    00207   #elif ( CONTROLLER_VERSION == 200 )
    00208     AT91C_BASE_PIOA->PIO_PER = AT91C_PIO_PA30;
    00209     AT91C_BASE_PIOA->PIO_OER = AT91C_PIO_PA30;
    00210     AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA30;
    00211   #endif
    00212 }
    00213 /*-----------------------------------------------------------*/
    00214
    00215 /*-----------------------------------------------------------*/
    00216
    00217 int toggle;
    00218 void vApplicationIdleHook( void )
    00219 {
    00220   // prevent the function from being optimized away?
    00221   toggle = !toggle;
    00222 }
    00223
    00224 /*----------------------------------------------------------------------*/
    00225
    00226

The Make Controller Kit is an open source project maintained by MakingThings.
MakingThings code is released under the Apache 2.0 license.
Bug tracker, development wiki and status can be found at http://dev.makingthings.com.
This document was last updated on 18 May 2009.