/*
*
* * $Rev: 51 $
* Filename:      ssensor_demo_main.c
* $Author: Morten & Suyash $
* $Date: 2010-06-11 10:17:22 -0700  $
* Description: This file contains the main C-code entry point of the ZNP Sample Application.
*
* YOU ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY 
* OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, 
* TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL TEXAS INSTRUMENTS 
* OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, 
* BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
* INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, 
* LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY 
* CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
*/

#include "../HAL/hal.h"
#include "Sensor_demo_app.h"
#include "../MT/mt.h"

/* Main This is the starting point for the sensor monitor demo application.
Program execution begins with halinit
halinit - Initializes the MSP430 for communication with the ZNP and peripherals by setting or configuring the
MSP430 modules and input and output pins. 
After halinit, program executes the mtInit if compile flag HOST_MT is enabled
mtInit - Initialize the UART module for communication with PC GUI
After mtInit znp is intialized via the znpInit() by a hardreset on the znp 
Then application is then started via appInit appInit - intializes the LED blink and then enables the interrupts
for program to accept and process hardware interrupts (button press, timer, adc, etc)
The programs then, forever, processes hardware and ZNP events (or interrupts). 
If no event is pending or generated it enters the low power mode and wakes up for 
procesing on a hardware or ZNP event.
*/


void main(void)
{
 /* Initialize the hardware */
  halInit();   
  
 #if HOST_MT
  /*Initialize the UART module*/
  mtInit();    
 #endif

  /* Initialize the hardware interface to the ZNP (SPI) and reset the ZNP */
  znpInit(); 

 #ifndef NV_RESTORE
  /*If NV_RESTORE is not defined then intialize the ZNP application*/
  /*Initialize the application - reset ZNP and enable the interrupts */
   appInit();
 #else
  /*Initialize the application parameters from last configured state*/
  appSync();
 #endif  

 for (;;)
 {
    /* Prioritize HAL events to maintain quasi-realtime performance on H/W related events.
     * After all HAL events are processed, service the ZNP events.
     */

   if (!appExecHal())
   {
      /* If all HAL and Host events have been processed, it is ok to go to low power.*/
     if (!appExecHost() && (appFlags & appLowPwrF))
    {
       /*Enter low power mode*/
       HAL_SLEEP();
    }
   }
  }
}

