Example #1
0
int main( void )
{
    WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
    BCSCTL1=0x00; //&= ~XT2OFF; // XT2= HF XTAL
    do{
      IFG1 &= ~OFIFG; // Clear OSCFault flag
      for (int i = 0xFF; i > 0; i--); // Time for flag to set
    }while ((IFG1 & OFIFG)); // OSCFault flag still set?
    BCSCTL2 |= SELM_2+SELS; // MCLK=SMCLK=XT2 (safe)

//Init System Service    
    InitialPort();
    InitFileSystem();
    Init_Pipe();
    InitTB();
//Init Device    
    InitialRTC();        
    Init_UART();
    InitADC();
    Creat_Command_Task();                   //After the bluetooth has beed connected
    SCH_Init();
   SCH_Start();

//    SCH_Add_Task(Task_UART_Send,0,5);       //creat a task for sending data via uart,after bluetooth connect
//   SCH_Add_Task(Acquire_ECG,0,4);      //32768/4*32 = 256hz
//    CommandSwitchList(1);

    while(1){
        SCH_Dispatch_Task();
    }
}
Example #2
0
/*--------------------------------------------------------------------*-

  SYSTEM_Configure_Required_Mode()

  Configure the system in the required mode.  

-*--------------------------------------------------------------------*/
void SYSTEM_Configure_Required_Mode(void)
{
	switch (System_mode_G)
	{
		default:          // Default to "FAIL_SILENT"

		case FAIL_SILENT:
			// Reset caused by WDT
			// Trigger "fail silent" behaviour
			SYSTEM_Perform_Safe_Shutdown();

			break;

		case NORMAL:
            mcu_init();
        
			// Set up WDT 
			// Set to overflow after ~12ms
			WATCHDOG_Init();

			// Set up scheduler for 1 ms ticks
			SCH_Init();

			// Prepare for heartbeat task
			HEARTBEAT_Init();

			// Add tasks to schedule.
			// Parameters are:
			// 1. Task name
			// 2. Initial delay / offset (in Ticks)
			// 3. Task period (in Ticks): Must be > 0
			// 4. Task WCET (in microseconds)
			// 5. Task BCET (in microseconds)

			// Add watchdog task first
			SCH_Add_Task(WATCHDOG_Update, 0, 1500, 10, 0);

			// Add heartbeat task
			SCH_Add_Task(HEARTBEAT_Update, 0, 1000, 20, 0);

			// Feed the watchdog
			WATCHDOG_Update();

			break;
	}
}
Example #3
0
int main(void){
    //cli(); /* Ensure usb interrupts enabled by bootloader alter disconnect of usb */
    wdt_enable(WDTO_1S);
    SCH_Init();
    ADM_Init();
    UIB_Init();
    UIF_Init();
    LED_Init();
    CRD_Init();
    UCP_Init();
    OSCCAL_Init();

    /* USB Init */
    usbInit();
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    _delay_ms(500);
    usbDeviceConnect();

    sei();


    /* 1 - Keyboard report id
       2 - HID feature report id
       reportBuffer is only used to send keyboard data so, initialize to 1
     */
    reportBuffer.reportid = 1;

    for(;; ) {                /* main event loop */
        wdt_reset();
        usbPoll();
        ADM_Task();
        SCH_Task();

        if(usbInterruptIsReady()) {
            UCP_WriteTask();
            LED_Task();
            printUpdate();
            usbSetInterrupt((void*)&reportBuffer, sizeof(reportBuffer));
        }
    }
}