Example #1
0
/*""FUNC COMMENT""*******************************************************
 * Outline     : main
 *-----------------------------------------------------------------------
 * Include     : 
 *-----------------------------------------------------------------------
 * Declaration : void main(void);
 *-----------------------------------------------------------------------
 * Description : 
 *-----------------------------------------------------------------------
 * Argument    : void
 *-----------------------------------------------------------------------
 * Return Value: void
 *-----------------------------------------------------------------------
 * Notice      : 
 *""FUNC COMMENT END""***************************************************/
int main(void)
{
	USB_setup();
	while(1) {
		USB_loop();
	}
	return 0;
}
Example #2
0
File: main.c Project: ctag/cpe495
/*
 * ======== main ========
 */
void main(void)
{
    WDT_A_hold(WDT_A_BASE); //Stop watchdog timer

    // Minimum Vcore setting required for the USB API is PMM_CORE_LEVEL_2
    PMM_setVCore(PMM_CORE_LEVEL_2);
    USBHAL_initPorts();           // Config GPIOS for low-power (output low)
    USBHAL_initClocks(8000000);   // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz
    USB_setup(TRUE,TRUE);  // Init USB & events; if a host is present, connect
    initRTC();             // Start the real-time clock

    __enable_interrupt();  // Enable interrupts globally

    int prevLeft = getLeft();
    int prevRight = getRight();
    int left;
    int right;

    while (1)
    {
        // Enter LPM0, which keeps the DCO/FLL active but shuts off the
        // CPU.  For USB, you can't go below LPM0!
        __bis_SR_register(LPM0_bits + GIE);

        // If USB is present, sent the time to the host.  Flag is set every sec

        left = getLeft();
        right = getRight();
        timeStr[0] = '[';
        itoa(left, &timeStr[1], 10);
        itoa(right, &timeStr[2], 10);
        timeStr[3] = ']';
        timeStr[4] = '\n';
        timeStr[5] = '\0';
//
//        if (bSendTimeToHost)
//        {
//            bSendTimeToHost = FALSE;
//            convertTimeBinToASCII(timeStr);

            // This function begins the USB send operation, and immediately
            // returns, while the sending happens in the background.
            // Send timeStr, 9 bytes, to intf #0 (which is enumerated as a
            // COM port).  1000 retries.  (Retries will be attempted if the
            // previous send hasn't completed yet).  If the bus isn't present,
            // it simply returns and does nothing.
            if (USBCDC_sendDataInBackground(timeStr, 6, CDC0_INTFNUM, 1000))
            {
              _NOP();  // If it fails, it'll end up here.  Could happen if
                       // the cable was detached after the connectionState()
            }           // check, or if somehow the retries failed
//        }
    }  //while(1)
}  //main()
Example #3
0
//TI Leaf Board Specific init
void TILEAF_BoardInit(uint32_t clockFreq)
{
    //set clock frequency variable '
    CLOCKFREQ = clockFreq;

    WDT_A_hold(WDT_A_BASE); // Stop watchdog timer
    // Minimum Vcore setting required for the USB API is PMM_CORE_LEVEL_2 .
    PMM_setVCore(PMM_CORE_LEVEL_2);
    USBHAL_initPorts();           // Config GPIOS for low-power (output low)
    USBHAL_initClocks(clockFreq);   // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz
    USB_setup(TRUE, TRUE); // Init USB & events; if a host is present, connect

    __enable_interrupt();  // Enable interrupts globally
}
Example #4
0
/*  
 * ======== main ========
 */
int main (void)
{
    WDT_A_hold(WDT_A_BASE); // Stop watchdog timer

    // Minumum Vcore setting required for the USB API is PMM_CORE_LEVEL_2 .
    PMM_setVCore(PMM_CORE_LEVEL_2);
    USBHAL_initPorts();                // Config GPIOS for low-power (output low)
    USBHAL_initClocks(MCLK_FREQUENCY); // Config clocks. MCLK=SMCLK=FLL=MCLK_FREQUENCY; ACLK=REFO=32kHz
    hal_sd_pwr_on();
    initTimer();
    USB_setup(FALSE, TRUE);      // Init USB & events; if a host is present, connect

    __enable_interrupt();       // Enable interrupts globally

   // GPS_init();

    // state machine
    while (1)
    {
    	switch( state )
    	{
    	case sIDLE:

    		hal_led_a(0);
    		hal_led_b(0);
    		hal_gps_pwr_off();
    		hal_sd_pwr_off();
    		UCS_turnOffXT2();



    			/* USB connected */
    			if(USB_getConnectionInformation() & USB_VBUS_PRESENT)
    			{
    				hal_led_a(CYAN);



    				//PMM_setVCore(PMM_CORE_LEVEL_2);
    				hal_sd_pwr_on();
    				shortDelay();
    				USBMSC_initMSC();                  // Initialize MSC API, and report media to the host
    				if (USB_enable() == USB_SUCCEED){
    					state = sUSB;
    					hal_led_a(GREEN);
    					//hal_sd_pwr_on();
    					//detectCard();

    					USB_reset();
    				    USB_connect();  //generate rising edge on DP -> the host enumerates our device as full speed device
    				}
    				break; // don't enter sleep
    			}

    			/* start GPS */
    			if(hal_button_event())
    			{

    				/* delay for starting */
    				hal_led_a(RED);
    				uint8_t timeout = 16;
    				while( hal_button_status() == 1 && --timeout )
    				{
    					shortDelay();
    				}
    				hal_led_a(0);
    				if( hal_button_status() == 0 )
    					break;

    				state = sGPS;
    				hal_led_a(CYAN);

    				hal_sd_pwr_on();

    				timeout = 8;
    				while( --timeout )
					{
						shortDelay();
					}

    				detectCard();
    			    Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_UP_MODE);

    			    gps_start();
    				hal_button_event();
    				break; // don't enter sleep
    			}


    			USB_disable(); //Disable
    			hal_gps_rtc_on(); // saves around 7uA
    			Timer_A_stop(TIMER_A0_BASE);
    			//UCS_turnOffSMCLK();
    			//PMM_setVCore(PMM_CORE_LEVEL_0);
    			__bis_SR_register(LPM4_bits + GIE);
    			_NOP();
    			//UCS_turnOnSMCLK();
    			//PMM_setVCore(PMM_CORE_LEVEL_2);

    		break;

    	case sGPS:


				/* stop GPS */
				if((USB_getConnectionInformation() & USB_VBUS_PRESENT))
				{
					state = sIDLE;
					gps_stop();
					break;
				}

				if(hal_button_event())
				{
					/* delay for stopping */
					uint8_t timeout = 16;

					while( hal_button_status() == 1 && --timeout )
					{
						hal_led_a(RED);
						shortDelay();
						hal_led_a(RED);
					}
					hal_led_a(0);
					if( hal_button_status() == 0 )
						break;

					state = sIDLE;
					gps_stop();
					break;


				}



    			if (bDetectCard){
					USBMSC_checkMSCInsertionRemoval();

					// Clear the flag, until the next timer ISR
					bDetectCard = 0x00;
				}
    			while( gps_check() )
    			{
    				gps_do();
    			}
    			__bis_SR_register(LPM0_bits + GIE);
    			_NOP();


    		break;

    	case sUSB:

    			if(!(USB_getConnectionInformation() & USB_VBUS_PRESENT))
				{
    				state = sIDLE;
    				break;
				}
    					/* check state of chareger? */
    			if( hal_charge_status())
    				hal_led_b(RED);
    			else
    				hal_led_b(GREEN);

    			hal_button_event(); // clear button event
    					switch (USB_getConnectionState())
    					{
    						case ST_ENUM_ACTIVE:



    							USBMSC_processMSCBuffer(); // Handle READ/WRITE cmds from the host

    							// Every second, the Timer_A ISR sets this flag.  The
    							// checking can't be done from within the timer ISR, because it
    							// enables interrupts, and this is not a recommended
    							// practice due to the risk of nested interrupts.
    							if (bDetectCard){
    								USBMSC_checkMSCInsertionRemoval();

    								// Clear the flag, until the next timer ISR
    								bDetectCard = 0x00;
    							}

    							break;

    						// These cases are executed while your device is disconnected from
    						// the host (meaning, not enumerated); enumerated but suspended
    						// by the host, or connected to a powered hub without a USB host
    						// present.
    						case ST_PHYS_DISCONNECTED:
    						case ST_ENUM_SUSPENDED:
    						case ST_PHYS_CONNECTED_NOENUM_SUSP:
    							hal_led_a(BLUE);
    							//state = sIDLE;
    							break;

    						// The default is executed for the momentary state
    						// ST_ENUM_IN_PROGRESS.  Usually, this state only last a few
    						// seconds.  Be sure not to enter LPM3 in this state; USB
    						// communication is taking place here, and therefore the mode must
    						// be LPM0 or active-CPU.
    						case ST_ENUM_IN_PROGRESS:
    						default:;
    					}
    		break;
    	}
    }

}
Example #5
0
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// 关闭看门狗

    __enable_interrupt();       //使能全局中断

    init_key();                 //初始化按键的管脚设置

    init_LCD_hardware();        //初始化LCD液晶显示屏的管脚设置

    SetVCore(3);                //设VCore为最大,提高Vcore电压到最高级,以满足倍频需求该函数位于HAL_PMM.H中

    initClocks(20000000);       //初始化时钟20MHz

    init_SPI();                 //初始化SPI

    ILI9325_CMO24_Initial();
    SPILCD_SetWindow(0,480-1,0,320-1);
    SPILCD_Clear(WHITE);

	P6DIR |= BIT3+BIT4;
    Show_splash();

    int ai;
	for(ai=0;ai<200;ai++)
	{
		myDelay();
	}

    SPILCD_Clear(WHITE);
    Show_MenuTheme();
    Show_MenuMode(1);
    Show_Select();



    Init_UART2();
    UCA0IE |= UCRXIE;

    int as1=1;

    buttonsPressed=0;

    USB_setup(TRUE,TRUE);

    while (!buttonsPressed)
    {
    	buttonsPressed = 0;

    	for(ai=0;ai<30;ai++)
    	{
    		myDelay();
    	}

    	if (buttonsPressed & BUTTON_S3)
        {
        	Show_ButtonS3();
        	if(as1==4){
        		as1=1;
        		Show_MenuMode(as1);
        	}else{
        		if(as1==1){
        			as1=2;
        		    Show_MenuMode(as1);
        		}else{
        			if(as1==2){
        				as1=3;
        		        Show_MenuMode(as1);
        			}else{
        				if(as1==3){
        					as1=4;
        		            Show_MenuMode(as1);
        				}
        			}
        		}
        	}
        	buttonsPressed=0;
        	Show_Select();
        }

        if (buttonsPressed & BUTTON_S2)
        {
        	Show_ButtonS2();
        	if(as1==2){
        		as1=1;
        		Show_MenuMode(as1);
        	}else{
        		if(as1==3){
        			as1=2;
        		    Show_MenuMode(as1);
        		}else{
        			if(as1==4){
        				as1=3;
        		        Show_MenuMode(as1);
        			}else{
        				if(as1==1){
        					as1=4;
        					Show_MenuMode(as1);
        				}
        			}
        		}
        	}
        	buttonsPressed=0;
        	Show_Select();
        }

        if (buttonsPressed & BUTTON_S1)
        {
        	Init_UART2();
        	Show_ButtonS1();
        	if(as1==1){
        	    menu_select=1;
        	}
        	if(as1==2){
        	    menu_select=2;
        	}
        	if(as1==3){
        	    menu_select=3;
        	}
        	if(as1==4){
        	    menu_select=4;
        	}

        	chanle_menu();

        	as1=1;
        	buttonsPressed=0;
        	SPILCD_Clear(WHITE);

            Show_MenuTheme();
            Show_MenuMode(1);
            Show_Select();
        }

        if (buttonsPressed & BUTTON_S4){
        	Show_ButtonS4();
        	Show_MenuMode(as1);
        	buttonsPressed=0;
        	Show_Select();
        }
    }
}
Example #6
0
/*
 *  ======== USBCDCMOUSE_init ========
 */
void USBCDCMOUSE_init(void)
{
    Error_Block eb;
    Semaphore_Params semParams;
    GateMutex_Params gateParams;

    Error_init(&eb);

    /* RTOS primitives */
    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_BINARY;
    semParams.__iprms.name = "semTxSerial";
    semTxSerial = Semaphore_create(0, &semParams, &eb);
    if (semTxSerial == NULL) {
        System_abort("Can't create TX semaphore");
    }

    semParams.__iprms.name = "semRxSerial";
    semRxSerial = Semaphore_create(0, &semParams, &eb);
    if (semRxSerial == NULL) {
        System_abort("Can't create RX semaphore");
    }

    semParams.__iprms.name = "semMouse";
    semMouse = Semaphore_create(0, &semParams, &eb);
    if (semMouse == NULL) {
        System_abort("Can't create USB semaphore");
    }

    semParams.__iprms.name = "semUSBConnected";
    semUSBConnected = Semaphore_create(0, &semParams, &eb);
    if (semUSBConnected == NULL) {
        System_abort("Can't create USB semaphore");
    }

    GateMutex_Params_init(&gateParams);
    gateParams.__iprms.name = "gateTxSerial";
    gateTxSerial = GateMutex_create(NULL, &eb);
    if (gateTxSerial == NULL) {
        System_abort("Can't create gate");
    }

    gateParams.__iprms.name = "gateRxSerial";
    gateRxSerial = GateMutex_create(NULL, &eb);
    if (gateRxSerial == NULL) {
        System_abort("Can't create gate");
    }

    gateParams.__iprms.name = "gateMouse";
    gateMouse = GateMutex_create(NULL, &eb);
    if (gateMouse == NULL) {
        System_abort("Can't create mouse gate");
    }

    gateParams.__iprms.name = "gateUSBWait";
    gateUSBWait = GateMutex_create(NULL, &eb);
    if (gateUSBWait == NULL) {
        System_abort("Could not create USB Wait gate");
    }

    /* Initialize the USB module, enable events and connect if UBUS is present */
    USB_setup(true, true);
}