main.c

Go to the documentation of this file.
00001 
00002 
00003 
00016 
00017 
00018 
00019 
00020     #define     MAIN_C
00021 
00022     #include    "main.h"
00023     #include    "mdns.h"
00024     #include    "sralloc.h"
00025 
00026 // ////////////////////////////////////////////////////////////////////////////
00027 
00028 
00029 // ////////////////////////////////////////////////////////////////////////////
00030 // ////////////////////////////////////////////////////////////////////////////
00031 
00032 void main()
00033 {
00034     u16GlobalFlags = 0; // Reset the indicator field.
00035 
00036     // Operate at 41.66667MHz (T=24 ns)
00037     OSCTUNE = 0x40;
00038 
00039     INTCON = 0;         // Disable all interrupts.
00040 
00041     TickInit();         // Initializes our tick module.
00042 
00043     RCONbits.IPEN = 1;  // Enable priority levels on interrupts.
00044     INTCONbits.GIEL = 1;    // Enable interrupts with low priority.
00045     INTCONbits.GIEH = 1;    // Enable interrupts with high priority.
00046 
00047     // Initializes the display and switch LEDs.
00048     OutInit();
00049 
00050     
00051     // For debugging reasons: Reset the EEPROMs content to 0xFF.
00052 #ifdef  EEPROM_ERASE
00053     XEEEraseEEPROM( );
00054 #endif
00055 
00056     // Initialize the heap
00057     SRAMInitHeap();
00058 
00059     // Initialize Microchip File System module
00060     MPFSInit();
00061 
00062     // Initialize input hardware (buttons and rotary encoder)
00063     InputInit();
00064 
00065     // Initialize eWicht application
00066     ApplInit();
00067 
00068     // Initialize MAC layer
00069     MACInit();
00070 
00071     while(ApplIsRunning() == TRUE)
00072     {
00073         if (u16GlobalFlags & LINKISUP_MASK)
00074         {
00075             // This task performs normal stack task including checking
00076             // for incoming packet, type of packet and calling
00077             // appropriate stack entity to process it.
00078             StackTask();
00079 
00080             StackApplications();
00081 
00082             // Call the MDNS responder
00083             MDNSResponder();
00084         }
00085 
00086         ApplMain();
00087         
00088         OutMain();
00089     }
00090 
00091 
00092     // Actions after switch off:
00093     OutSwitchOffLCD();
00094     OutSwitchOffAllLEDs();
00095     MACPowerDown();
00096 
00097     // Factory reset starts the eWicht immediately...
00098     if (u16GlobalFlags & FACRES_MASK)
00099     {
00100         ApplResetToFactory(FALSE);
00101     }
00102     else if (!(u16GlobalFlags & RESTART_MASK))
00103     {   
00104         // Shut down!
00105         ApplStop();
00106     }
00107     else if (u16GlobalFlags & BOOTLOADER_MASK)
00108     {
00109         // Prepare the MAC and IP address for bootloader.
00110         BootupEnterBootloader();
00111         RCONbits.NOT_POR = 0;
00112         Reset();
00113     }
00114 
00115     RCONbits.POR = 1;
00116     Reset();
00117 }
00118 
00119 // ////////////////////////////////////////////////////////////////////////////
00120 // ////////////////////////////////////////////////////////////////////////////
00121 
00123 // Lowprior Interrupt Service Routine
00125 
00126 #pragma interruptlow _peripheralTimerISR
00127 
00128 void _peripheralTimerISR(void)
00129 {
00130     InputInterruptHandler();    
00131 
00132     OutInterruptHandler();
00133 }
00134 
00135 // ////////////////////////////////////////////////////////////////////////////
00136 // ////////////////////////////////////////////////////////////////////////////
00137 
00138 #pragma code low_vector=0x18
00139 void low_interrupt(void)
00140 {
00141     _asm GOTO _peripheralTimerISR _endasm
00142 }
00143 
00144 #pragma code
00145 
00146 // ////////////////////////////////////////////////////////////////////////////
00147 // ////////////////////////////////////////////////////////////////////////////

Generated on Sun Nov 27 20:02:38 2011 for eWicht by  doxygen 1.5.5