コード例 #1
0
ファイル: main.c プロジェクト: siddhugit/Operating-System
/*
* Turns on one light and turns off remaing LEDs depending upon counter value
*/
void changestate(int counter)
{
	switch(counter)
	{
		case 0 ://orange on
			ledOrangeOn();
			ledYellowOff();
			ledGreenOff();
			ledBlueOff();
			break;
		case 1 ://yellow on
			ledOrangeOff();
			ledYellowOn();
			ledGreenOff();
			ledBlueOff();
			break;
		case 2 ://green on
			ledOrangeOff();
			ledYellowOff();
			ledGreenOn();
			ledBlueOff();
			break;
		case 3 ://blue on
			ledOrangeOff();
			ledYellowOff();
			ledGreenOff();
			ledBlueOn();
			break;
		default:
			break;
						
	}
}
コード例 #2
0
ファイル: main_button_flash.c プロジェクト: skarger/sos
int main(void) {
    int number_presses = 0;

    /* Initialize all of the LEDs */
    ledInitAll();
    /* Initialize both of the pushbuttons */
    pushbuttonInitAll();

    /* initially orange LED should be on and all others should be off */
    ledOrangeOn();

    while(1) {
        if (sw1In()) {
            /* avoid contact bounce */
            delay(DELAY_LIMIT);

            number_presses++;
            if (number_presses == 4) {
                number_presses = 0;
            }

            if (number_presses == 0) {
                ledOrangeOn();
            } else {
                ledOrangeOff();
            }

            if (number_presses == 1) {
                ledYellowOn();
            } else {
                ledYellowOff();
            }

            if (number_presses == 2) {
                ledGreenOn();
            } else {
                ledGreenOff();
            }

            if (number_presses == 3) {
                ledBlueOn();
            } else {
                ledBlueOff();
            }

            /* wait until button released before checking if pushed again */
            while(sw1In()) { ; }
        }
    }

    return 0;
}
コード例 #3
0
ファイル: ledfs.c プロジェクト: siddhugit/Operating-System
/*
*   Implements write interface.
*   Parameters:
*       o void *fp - stream to read.
*       o char c - Expects 1 to turn on led and 0 to turn off.
*       Return : Number of bytes written
*/
int led_write(void *fp,char c)
{
	struct led_stream* stream = (struct led_stream*)fp;
	int val = c - '0';
	if(val)
	{
		switch(stream->minor)
		{
			case ORANGE:
				ledOrangeOn();				
				break;
			case YELLOW:
				ledYellowOn();				
				break;
			case GREEN:
				ledGreenOn();				
				break;
			case BLUE:
				ledBlueOn();				
				break;
			default:
				return 0;
		}
	}
	else
	{
		switch(stream->minor)
		{
			case ORANGE:
				ledOrangeOff();				
				break;
			case YELLOW:
				ledYellowOff();				
				break;
			case GREEN:
				ledGreenOff();				
				break;
			case BLUE:
				ledBlueOff();				
				break;
			default:
				return 0;
		}
	}
	return 1;
}
コード例 #4
0
/**
 * Routine to initialize all of the LEDs
 * 
 * Note: This procedure *does* enable the appropriate port clock
 */
void ledInitAll(void) {
	/* Enable the clock for PORTA using the SIM_SCGC5 register (System Clock Gating
	 * Control Register 5) (See 12.2.13 on page 342 of the K70 Sub-Family Reference
	 * Manual, Rev. 2, Dec 2011) */
	SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;
	
	/* Turn off the LEDs */
	ledOrangeOff();
	ledYellowOff();
	ledGreenOff();
	ledBlueOff();

	/* Configure the LED ports */
	ledOrangeConfig();
	ledYellowConfig();
	ledGreenConfig();
	ledBlueConfig();
}
コード例 #5
0
// intialization functions
void bootARM(void) {
    // had to steal some code from the original SparkFun code because I don't
    // understand it yet.
    rprintf_devopen(putc_serial0);  // Init rprintf
    delay_ms(30);                   // wait for power to stabilize
    
    // bring up SD / FAT *
    if (! (sd_raw_init()) ) { rprintf("SD init error!\n"); }
    if ( openroot() ) { rprintf("openroot error!\n"); }
    
    // set up I/O pins *
    
	//Setup the MP3 I/O Lines
	IODIR0 |= MP3_XCS;
	IODIR0 &= ~MP3_DREQ;
	PINSEL1 |= 0x00000C00;	        // Set the MP3_DREQ Pin to be a capture pin
	IODIR1 |= MP3_XDCS | MP3_GPIO0 | MP3_XRES;	
	
	//Setupt the FM Trans. Lines
	IODIR1 |= FM_LA; 				// FM trans outputs (Leave SPI pins 
	IODIR1 |= FM_CS;                //    unconfigured for now)
	
	//Setup the SD Card I/O Lines
	IODIR0 |= SD_CS;				// SD card outputs
	
	//Setup the Accelerometer I/O Lines
	IODIR0 |= (GS1 | GS2);			// accelerometer outputs
	
	// ensure ADC pins have ADC Functions selected
	PINSEL0 |= (MMA_X_PINSEL | MMA_Y_PINSEL | MMA_Z_PINSEL);		
	IOCLR0 = (GS1 | GS2);		    // initialize acceleration to 1.5 G mode
	
	//Setup the LCD I/O Lines
	IODIR0 |= (LCD_RES | LCD_CS);   // LCD Outputs
	
	//Setup the LED Lines										
	IODIR0 |= (LED_BLU | LED_RED | LED_GRN);
	ledBlueOff();
	ledRedOff();
	ledGrnOff();
	
	//Setup the Buttons
	IODIR1 &= (~SW_UP & ~SW_DWN & ~SW_MID);		//Button Inputs

	IODIR0 &= ~(1<<23);							//Set the Vbus line as an input

    //Setupt the Interrupts
	VPBDIV = 1;									// Set PCLK equal to the system clock	
	VICIntSelect = ~0x30; 						// Timer 0 AND TIMER 1 interrupt is an IRQ interrupt
    VICIntEnable = 0x10; 						// Enable Timer 0 interrupts 
                                                // (don't start sending song data with Timer 1)
    VICVectCntl0= 0x25; 						// Use slot 0 for timer 1 interrupt
    VICVectAddr0 = (unsigned int)timer1ISR; 	// Set the address of ISR for slot 1		
    VICVectCntl1 = 0x24; 						// Use slot 1 for timer 0 interrupt
    VICVectAddr1 = (unsigned int)timer0ISR; 	// Set the address of ISR for slot 1
	
	//Configure Timer0
	T0PR = 1500;								// divide clock(60MHz) by 1500 for 40kHz PS
	T0TCR |=0X01;							    // enable the clock
	T0CTCR=0;									// timer node
	T0MCR=0x0003;								// interrupt and reset timer on match
	T0MR0=1000;									// interrupt on 40Hz
	
	//Configure Timer1
	T1PR = 200;									// divide clock by 300 for 40kHz PS
	T1TCR |=0X01;								// enable the clock
	T1CTCR=0;									// timer mode
	T1CCR=0x0A00;								// capture and interrupt on the 
	                                            //    rising edge of DREQ
	
	//Setup the SPI Port
    S0SPCCR = 64;              					// SCK = 1 MHz, counter > 8 and even
    S0SPCR  = 0x20;                				// Master, no interrupt enable, 8 bits	
    
    
    
    // set up MP3 decoder
    vs1002Config();	// set up ARM <-> VS1002 communication
    vs1002Reset();	// hardware reset
    vs1002Init();	// initialization
    
    return;
    
}