//Main Function
int main(void)
{
	unsigned int value;
	init_devices();
	
	lcd_set_4bit();
	lcd_init();
	int i=0;
	
	
	DDRH=0b01110000;  //led pin config
	char got;
	char send;
	char block_i;
	
	while(1)
	{
		sharp=ADC_Conversion(11);
		value=Sharp_GP2D12_estimation(sharp);
		
		got=data;
		if(got=='U' || got=='B'){
			block_i=got;
		}
		
		lcd_print(1,1,got,2);
		lcd_print(2,1,send,2);
		if(value>100 && value<150){
			send='B';
			UDR0=send;
		}				
		else{
			send='U';
			UDR0=send;
		}
		
		if(block_i=='U' && send=='B')
		{
			PORTH=0;
		}
		
		else if(block_i=='B' && send=='B')
		{
			PORTH=0b00100000;
		}
		
		else if(got=='R'){
			PORTH=0b00010000;
			got="";
		}		
		
		else if(got=='G'){
			PORTH=0b01000000;
			got="";
		}
		else if(got=='T'){
			PORTH=0;
			got="";
		}
	}
}
Exemplo n.º 2
0
void main(uint32_t arg, uint32_t addr)
{
    unsigned char* loadbuffer;
    int buffer_size;
    void(*kernel_entry)(void);
    int ret;

    system_init();
    kernel_init();

    power_init();
    enable_irq();

    lcd_init();
    lcd_clear_display();
    lcd_update();

    backlight_init();

    button_init();

    //button_debug_screen();
    printf("Boot version: %s", RBVERSION);
    printf("arg=%x addr=%x", arg, addr);

#ifdef SANSA_FUZEPLUS
    extern void imx233_mmc_disable_window(void);
    if(arg == 0xfee1dead)
    {
        printf("Disable MMC window.");
        imx233_mmc_disable_window();
    }
#endif

    ret = storage_init();
    if(ret < 0)
        error(EATA, ret, true);

    /* NOTE: allow disk_init and disk_mount_all to fail since we can do USB after.
     * We need this order to determine the correct logical sector size */
    while(!disk_init(IF_MV(0)))
        printf("disk_init failed!");

    if((ret = disk_mount_all()) <= 0)
        error(EDISK, ret, false);

    if(usb_detect() == USB_INSERTED)
        usb_mode(HZ);

    printf("Loading firmware");

    loadbuffer = (unsigned char*)loadaddress;
    buffer_size = (int)(loadaddressend - loadaddress);

    while((ret = load_firmware(loadbuffer, BOOTFILE, buffer_size)) < 0)
    {
        error(EBOOTFILE, ret, true);
    }

    kernel_entry = (void*) loadbuffer;
    printf("Executing");
    disable_interrupt(IRQ_FIQ_STATUS);
    commit_discard_idcache();
    kernel_entry();
    printf("ERR: Failed to boot");

    /* never returns */
    while(1) ;
}
/*
? *
? * Function Name: <Initialisation>
? * Example Call: <intialisation()>
? *
? */
void intialisation()
{
	cli();   //Clears the global interrupts 
	//buzzer initialization
	DDRC = DDRC | 0x08;		//Setting PORTC 3 as output
	PORTC = PORTC & 0xF7;		//Setting PORTC 3 logic low to turnoff buzzer
	
	//usart init
	UBRR0L = 0x5F; //set baud rate lo
	UBRR0H = 0x00; //set baud rate hi
	UCSR0B = ((1 << RXEN0) | (1<<TXEN0));
	UCSR0C =((1 << UCSZ01) | (1 << UCSZ00)); // character size 8bit
	
	//motion 
	DDRA = DDRA | 0x0F;					//PA3..PA0 for DC motor direction control
	PORTA = PORTA & 0xF0;
	DDRL = DDRL | 0x18;   				//Setting PL3 and PL4 pins as output for PWM generation
	PORTL = PORTL | 0x18; 				//PL3 and PL4 pins are for velocity control using PWM.
	
	//barled
	DDRJ = 0xFF;						//LED Bargraph
	PORTJ = 0x00; 						//LED Bargraph OFF
	
	//position encoder
	DDRE  = DDRE & 0xCF;  				//INT4 & INT5 for left & right position encoder
	PORTE = PORTE | 0x30; 				//Enable internal pull-up for PE4 & PE5
		//left position encoder
		 EICRB = EICRB | 0x05; 				// INT4 & INT5 - both edge (+ & -) triggered
		 EIMSK = EIMSK | 0x10; 				// INT4 Interrupts Enabled
		 /*
		 EICRA = EICRA | 0x01;               // INT0 is set to trigger with both edges(+ & -)
		 EIMSK = EIMSK | 0x01;               // Enable Interrupt INT0 for color sensor*/
	
	//lcd
	DDRC = DDRC | 0xFF; 				//all the LCD pin's direction set as output
	PORTC = PORTC & 0x80; 				//all the LCD pins are set to logic 0 except PORTC 7
	
	//adc
	DDRF = 0x00;						//set PORTF direction as input
	PORTF = 0x00;						//set PORTF pins floating
	DDRK = 0x00;						//set PORTK direction as input
	PORTK = 0x00;						//set PORTK pins floating
	ADCSRA = 0x00;
	ADCSRB = 0x00;		//MUX5 = 0
	ADMUX = 0x00;		//Vref=5V external --- ADLAR=1 --- MUX4:0 = 0000
	ACSR = 0x80;
	ADCSRA = 0x87;		//ADEN=1 --- ADIE=1 --- ADPS2:0 = 1 1 0
	
	
	// Timer 5 initialized in PWM mode for velocity control
	// Prescale:256
	// PWM 8bit fast, TOP=0x00FF
	// Timer Frequency:225.000Hz
	TCCR5B = 0x00;						//Stop
	TCNT5H = 0xFF;						//Counter higher 8-bit value to which OCR5xH value is compared with
	TCNT5L = 0x01;						//Counter lower 8-bit value to which OCR5xH value is compared with
	OCR5AH = 0x00;						//Output compare register high value for Left Motor
	OCR5AL = 0xFF;						//Output compare register low value for Left Motor
	OCR5BH = 0x00;						//Output compare register high value for Right Motor
	OCR5BL = 0xFF;						//Output compare register low value for Right Motor
	OCR5CH = 0x00;						//Output compare register high value for Motor C1
	OCR5CL = 0xFF;						//Output compare register low value for Motor C1
	TCCR5A = 0xA9;						/*{COM5A1=1, COM5A0=0; COM5B1=1, COM5B0=0; COM5C1=1 COM5C0=0}
 					  					   For Overriding normal port functionality to OCRnA outputs.
				  	  					   {WGM51=0, WGM50=1} Along With WGM52 in TCCR5B for Selecting FAST PWM 8-bit Mode*/
	TCCR5B = 0x0B;						//WGM12=1; CS12=0, CS11=1, CS10=1 (Prescaler=64)	
	
	sei();     //Enables the global interrupts
	lcd_set_4bit();
	lcd_init();	
}
Exemplo n.º 4
0
void main(void)
{
    unsigned char* loadbuffer;
    int buffer_size;
    int rc;
    int(*kernel_entry)(void);

    /* Make sure interrupts are disabled */
    set_irq_level(IRQ_DISABLED);
    set_fiq_status(FIQ_DISABLED);
    system_init();
    kernel_init();
    
    /* Now enable interrupts */
    set_irq_level(IRQ_ENABLED);
    set_fiq_status(FIQ_ENABLED);

    lcd_init();
    backlight_init();
    font_init();
    button_init();
    usb_init();
    
    
    power_init();
//    enable_irq();
//    enable_fiq();

    adc_init();

    lcd_setfont(FONT_SYSFIXED);

    /* Show debug messages if button is pressed */
//    if(button_read_device())
        verbose = true;

    printf("Rockbox boot loader");
    printf("Version " RBVERSION);

    /* Enter USB mode without USB thread */
    if(usb_detect() == USB_INSERTED)
    {
        const char msg[] = "Bootloader USB mode";
        reset_screen();
        lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                    (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
        lcd_update();

        ide_power_enable(true);
        storage_enable(false);
        sleep(HZ/20);
        usb_enable(true);

        while (usb_detect() == USB_INSERTED)
        {
            storage_spin(); /* Prevent the drive from spinning down */
            sleep(HZ);
        }

        usb_enable(false);

        reset_screen();
        lcd_update();
    }
    
    sleep(50);

    printf("ATA");
    rc = storage_init();
    if(rc)
    {
        reset_screen();
        error(EATA, rc, true);
    }

    printf("disk");
    disk_init();

    printf("mount");
    rc = disk_mount_all();
    if (rc<=0)
    {
        error(EDISK,rc, true);
    }

    printf("Loading firmware");

    loadbuffer = (unsigned char*) 0x00900000;
    buffer_size = (unsigned char*)0x01900000 - loadbuffer;

    rc = load_firmware(loadbuffer, BOOTFILE, buffer_size);
    if(rc < 0)
        error(EBOOTFILE, rc, true);

    if (rc == EOK)
    {
        kernel_entry = (void*) loadbuffer;
        rc = kernel_entry();
    }
}
Exemplo n.º 5
0
int main(void)
{  
	//Konfiguration der Ausgänge bzw. Eingänge
	//definition erfolgt in der config.h
	DDRA = OUTA;
	#if USE_SER_LCD
		DDRC = OUTC;
	#else
		DDRC = OUTC;
		#if PORTD_SCHALT
			DDRD = OUTD;
		#endif
	#endif
	// RoBue:
	// Pullups einschalten
	PORTA = (1 << PORTA0) | (1 << PORTA1) | (1 << PORTA2) | (1 << PORTA3) | (1 << PORTA4) | (1 << PORTA5) | (1 << PORTA6);
	
    unsigned long a;
	#if USE_SERVO
		servo_init ();
	#endif //USE_SERVO
	
    usart_init(BAUDRATE); // setup the UART
	
	#if USE_ADC
		ADC_Init();
	#endif
	
	usart_write("\n\rSystem Ready\n\r");
    usart_write("Compiliert am "__DATE__" um "__TIME__"\r\n");
    usart_write("Compiliert mit GCC Version "__VERSION__"\r\n");
	for(a=0;a<1000000;a++){asm("nop");};

	//Applikationen starten
	stack_init();
	httpd_init();
	telnetd_init();
	
	//Spielerrei mit einem LCD
	#if USE_SER_LCD
		udp_lcd_init();
		lcd_init();
		// RoBue:
		// LCD-Ausgaben:
		lcd_clear();
		lcd_print(0,0,"*AVR-NET-IO "Version"*");
		lcd_print(2,0,"Counter: ");
		lcd_print(3,0,"Zeit:");
	#endif

	//Ethernetcard Interrupt enable
	ETH_INT_ENABLE;
	
	#if USE_SER_LCD
		// RoBue:
		// IP auf LCD
		lcd_print(1,0,"%1i.%1i.%1i.%1i",myip[0],myip[1],myip[2],myip[3]);
	#endif
	
	//Globale Interrupts einschalten
	sei(); 
	
	#if USE_CAM
		#if USE_SER_LCD
			lcd_print(1,0,"CAMERA INIT");
		#endif //USE_SER_LCD
		for(a=0;a<2000000;a++){asm("nop");};
		cam_init();
		max_bytes = cam_picture_store(CAM_RESELUTION);
		#if USE_SER_LCD
			back_light = 0;
			lcd_print(1,0,"CAMERA READY");
		#endif //USE_SER_LCD
	#endif // -> USE_CAM
	
	#if USE_NTP
	        ntp_init();
	        ntp_request();
	#endif //USE_NTP
	
	#if USE_WOL
	        wol_init();
	#endif //USE_WOL
    
	#if USE_MAIL
	        mail_client_init();
	#endif //USE_MAIL  

	// Startwerte für ow_array setzen
	#if USE_OW
		uint8_t i = 0;
		for (i=0;i<MAXSENSORS;i++){
			ow_array[i]=OW_START;
		}
		for (i=MAXSENSORS;i<MAXSENSORS*3;i++){
			ow_array[i]=OW_MINMAX;
		}
		DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL );
		for(a=0;a<1000000;a++){asm("nop");};
		auslesen = 0;
		minmax = 1;
	#endif


//Hauptschlfeife
// *************
		
	while(1)
	{

	#if USE_ADC
		ANALOG_ON;
	#endif

	eth_get_data();
		
        //Terminalcommandos auswerten
	if (usart_status.usart_ready){
	usart_write("\r\n");
		if(extract_cmd(&usart_rx_buffer[0]))
		{
			usart_write("Ready\r\n\r\n");
		}
		else
		{
			usart_write("ERROR\r\n\r\n");
		}
		usart_status.usart_ready =0;
	
	}
	
	// RoBue:
	// Counter ausgeben
	#if USE_SER_LCD
		lcd_print(2,9,"%4i",var_array[MAX_VAR_ARRAY-1]);
	#endif

	// RoBue:
	// Uhrzeit bestimmen und auf LCD ausgeben
	hh = (time/3600)%24;
	mm = (time/60)%60;
	ss = time%60;

	#if USE_SER_LCD
		lcd_print(3,7,"%2i:%2i:%2i",hh,mm,ss);
	#endif

	#if USE_HIH4000
		var_array[VA_OUT_HIH4000] = ((var_array[VA_IN_HIH4000]-160)/6);
	#endif

	#if USE_OW
	// RoBue:
	// Zurücksetzen der Min/Max-Werte um 00:00 Uhr einschalten
	if (( hh == 00 )&&( mm == 00 )) {
		minmax = 1;
	}
	#endif

	// ******************************************************************
	// RoBue:
	// 1-Wire-Temperatursensoren (DS18B20) abfragen
	// ******************************************************************

		#if USE_OW

		uint8_t i = 0;
		uint8_t subzero, cel, cel_frac_bits;
		uint8_t tempID[OW_ROMCODE_SIZE];

		// Messen bei ss=5,15,25,35,45,55		
		if ( ss%10 == 5 ) {

		// Messen?
		if ( messen == 1 ) {

		// RoBue Anmerkung:
		// Hiermit werden ALLE Sensoren zum Messen aufgefordert.
		// Aufforderung nur bestimmter Sensoren:
		// "NULL" durch "tempID" ersetzen
		
		// RoBue Testausgabe UART:
		// usart_write("Starte Messvorgang ...\r\n");		 

		DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL );
		
		// Kein Messen mehr bis ss=5,15,25,35,45,55
		messen = 0;

		// Jetzt kann ausgelesen werden
		auslesen = 1;

		}	// -> if messen
		
		}	// -> if ss

		// Auslesen bei ss=8,18,28,38,48,58
		if ( ss%10 == 8 ) {

		// Auslesen?
		if ( auslesen == 1 ) {

		// (erste) ID ins RAM holen
		memcpy_P(tempID,DS18B20IDs[0],OW_ROMCODE_SIZE);	
				
		while ( tempID[0] != 0 ) {
		//while ( tempID[0] == 0x10 ) {
				
			// RoBue Anmerkung:
			// Hiermit wird jeweils ein einzelner Sensor ausgelesen
			// und die Temperatur in ow_array abgelegt.
			// Achtung:
			// Pro Sekunde können max. ca. 10 Sensoren ausgelesen werden!
			if ( DS18X20_read_meas( tempID, &subzero,&cel, &cel_frac_bits) == DS18X20_OK ) {

				ow_array[i] = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits);

				// Minuswerte:
					if ( subzero )
						ow_array[i] *= (-1);
				
				// min/max:
				if ( minmax == 1 ) {
					// Zurücksetzen der Min/Max_Werte 1x/Tag
					// auf die gerade aktuellen Temperaturen 
					ow_array[i+MAXSENSORS] = ow_array[i];
					ow_array[i+MAXSENSORS*2] = ow_array[i];
				}
				else {
					// Abgleich der Temp. mit den gespeicherten Min/Max-Werten
					if (ow_array[i]  < ow_array[i+MAXSENSORS])
        					ow_array[i+MAXSENSORS] = ow_array[i];
               				if (ow_array[i]  > ow_array[i+MAXSENSORS*2])
						ow_array[i+MAXSENSORS*2] = ow_array[i];
        			}

				//TWert = DS18X20_temp_to_decicel(subzero, cel, cel_frac_bits);
				//ow_array[i] = TWert;
				
				// RoBue:
				// Testausgabe UART:
				// usart_write("%2i:%2i:%2i: Temperatur: %3i Grad\r\n",hh,mm,ss,ow_array[i]/10);
				
			}	// -> if
			else {
				usart_write("\r\nCRC Error (lost connection?) ");
				DS18X20_show_id_uart( tempID, OW_ROMCODE_SIZE );


			}	// -> else
		
		// nächste ID ins RAM holen
		memcpy_P(tempID,DS18B20IDs[++i],OW_ROMCODE_SIZE);

		}	// -> while
		
		// RoBue:
		// Temperatur auf LCD ausgeben (IP von Startausgabe (s.o.) wird Überschrieben)
		#if USE_SER_LCD
			lcd_print(1,0,"Tmp:            ");
			lcd_print(1,5,"%i C",ow_array[0]/10);
			lcd_print(1,11,"%i C",ow_array[1]/10);
		#endif

		}	// -> if auslesen

		auslesen = 0;	// Auslesen vorläufig abschalten
		messen = 1;	// Messen wieder ermöglichen
		minmax = 0;	// Min/Max-Werte vergleichen

		}	// -> if ss
		
	#endif
	

	// **********************************************************
	// RoBue:
	// Schalten der Ports (PORTC) durch bestimmte Bedingungen
	// - Temperatur (1-Wire -> PORTA7) mit/ohne Lüftungsautomatik
	// - digital, analog (-> PORTA0-6)
	// - Zeit
	// **********************************************************
	
	// Automatik eingeschaltet?
	if ( var_array[9] == 1 ) {

	if ( ss%10 == 1 ) {
		schalten = 1;
	}

	// Abfrage bei ss =0,10,20,30,40,50
	if ( ss%10 == 0 ) {
	if ( schalten == 1 ) {
	
	// RoBue Testausgabe UART:
	// usart_write("%2i:%2i: Schaltfunktionen testen ...\r\n",hh,mm);	


	// PORTC0:
	// Über Temperatur: var_array[10] - Sensor0		
	if (( ow_array[0]/10 < var_array[10] ) || ( ow_array[0] < 0 )) {
		PORTC |= (1 << PC0); // ein
	//
	// Über Temperatur: var_array[10] - Sensor0 - PORTA0
	// if ((PINA&0b00000001) == 0 ) {		// PORTA0: Fenster geschlossen?
	//	if (( ow_array[0]/10 < var_array[10] ) || ( ow_array[0] < 0 )) {
	//		PORTC |= (1 << PC0); // ein
	//	}
	//  	else { 
	//     		PORTC &= ~(1 << PC0); // aus
	//	}
	}
	else {
	      	PORTC &= ~(1 << PC0); // aus
	}

	// PORTC1:
	// Über Temperatur: var_array[11] - Sensor1
	// if (( ow_array[1]/10 < var_array[11] ) || ( ow_array[1] < 0 )) {
	//	PORTC |= (1 << PC1); // ein
	//
	// Über Temperatur: var_array[11] - Sensor1 - PORTA1
	if ((PINA&0b00000010) == 0 ) {		// PORTA1: Fenster geschlossen?
		if (( ow_array[1]/10 < var_array[11] ) || ( ow_array[1] < 0 )) {
			PORTC |= (1 << PC1); // ein
		}
		else {
			PORTC &= ~(1 << PC1); // aus
		}
	}
	else {
		PORTC &= ~(1 << PC1); // aus
	}
		
	// PORTC2:
	// Über Temperatur: var_array[12] - Sensor2
	// if (( ow_array[2]/10 < var_array[12] ) || ( ow_array[2] < 0 )) {						
	//	PORTC |= (1 << PC2); // ein
	// Über Temperatur: var_array[12] - Sensor2 - PORTA2
	// if ((PINA&0b00000100) == 0 ) {		// PORTA2: Fenster geschlossen?
	//	if (( ow_array[2]/10 < var_array[12] ) || ( ow_array[2] < 0 )) {
	//		PORTC |= (1 << PC2); // ein
	//	}
	//	else {
	//		PORTC &= ~(1 << PC2); // aus
	//	}
	//}
	//else {
	//	PORTC &= ~(1 << PC2); // aus
	//}

	// PORTC4:
	// Über 2 Temperaturen (Differenz)
	// var_array[13] - Sensor3 Vorlauf, Sensor4 Ruecklauf
	//
	// z.B. Zirkulationspumpe für Warmwasser
	// Achtung: Temp. von Sensor3 MUSS höher/gleich sein als Temp. von Sensor4
	// Ansonsten laeuft die Pumpe immer
	//
		if ( (ow_array[3]/10 - ow_array[4]/10) >= var_array[14] ) {						
		PORTC |= (1 << PC4); // ein
	}
	else {
		PORTC &= ~(1 << PC4); // aus
	}

		// PORTC6:
	// Über Analogwert:
	if ( var_array[6] > var_array[18] ) {
		PORTC |= (1 << PC6); // ein
	}
	else {
		PORTC &= ~(1 << PC6); // aus
	}

	// PORTC7:
	// Über Zeit: ein/aus
	if ( hh == var_array[20] ) {
		if ( mm == var_array[21] ) {
			PORTC |= (1 << PC7); // ein
		}
	}
	if ( hh == var_array[22] ) {
		if ( mm == var_array[23] ) {
			PORTC &= ~(1 << PC7); // aus
		}
	}


	schalten = 0;	// Vorerst nicht mehr schalten

	} // -> schalten == 1
	} // -> if ss == ...
	} // -> if var_array == 1
	
	
        //Wetterdaten empfangen (Testphase)
        #if GET_WEATHER
        http_request ();
        #endif
        
        //Empfang von Zeitinformationen
	#if USE_NTP
		if(!ntp_timer){
		ntp_timer = NTP_REFRESH;
		ntp_request();
		}
	#endif //USE_NTP
		
        //Versand von E-Mails
        #if USE_MAIL
	        if (mail_enable == 1)
	        {
	            mail_enable = 0;
	            mail_send();
	        }
        #endif //USE_MAIL
        
        //Rechner im Netzwerk aufwecken
        #if USE_WOL
	        if (wol_enable == 1)
	        {
	            wol_enable = 0;
	            wol_request();
	        }
        #endif //USE_WOL
           
	//USART Daten für Telnetanwendung?
	telnetd_send_data();
    }

return(0);
}
Exemplo n.º 6
0
/* MAIN FUNCTION */
int main(void)
{
	lcd_init();
	START_init();
	ADC_init();
	Hello();
	PORTD	&= ~SOLAR_RELAY;
	PORTD	&= ~BATERRY_RELAY;
	PWM_init();
	ADC_ACS712_Calib();
	OCR0 = 85;
	srand(OCR0);
	
	
	
    while(1)
    {
        //TODO:: Please write your application code 
		lcd_clear();
		lcd_home();
		Mes_V();
		Mes_I();
		Mes_P();
		
		
		////////////////
		//MPPT
		///////////////
		if (Pf > Pfp)
		{
			if (Vf > Vfp)
			{
				OCR0 += 10;
			} 
			else
			{
				OCR0 -= 10;
			}
		}
		else
		{
			if (Vf > Vfp)
			{
				OCR0 -= 10;
			}
			else
			{
				OCR0 += 10;
			}	
		}
		
		Vfp = Vf;
		Pfp = Pf;
		
		//////////////////////////////////////////////////////////////////////////
		//ZABEZPIECZENIE PRZED ZWARCIEM
		/////////////////////////////////////////////////////////////////////////
		if ((OCR0 <= 15) || (OCR0 >= 245))
		{
			OCR0 = rand()%190 + 50;
		} 
		
		lcd_swrite(" OCR "); lcd_iwrite(OCR0);
		_delay_ms(100);			//TODO: remove or redesign this part later
    }
}
Exemplo n.º 7
0
int WB_lcd_init_and_display(void)
{
	lcd_init();
	lcd_draw_picture(0x20007fc0);
}
Exemplo n.º 8
0
int cmd_lcd(int argc, char **argv)
{
	int i;
	int ret;

	if (is_command(argc, argv, "init")) {
		printf("Initializing LCD... ");
		ret = lcd_init();
		if (ret)
			printf("failed: %d\n", ret);
		else
			printf("Ok\n");
	}
#ifdef LCD_DEBUG
	else if (is_command(argc, argv, "dump")) {
		lcd_dump();
	}
#endif
	else if (is_command(argc, argv, "run")) {
		printf("Running LCD... ");
		ret = lcd_run();
		if (ret)
			printf("failed: %d\n", ret);
		else
			printf("Ok\n");
	}
	else if (is_command(argc, argv, "stop")) {
		printf("Stopping LCD... ");
		ret = lcd_stop();
		if (ret)
			printf("failed: %d\n", ret);
		else
			printf("Ok\n");
	}
	else if (is_command(argc, argv, "tpp1")) {
		int w = lcd_width();
		int h = lcd_height();
		int total = w * h;

		for (i = 0; i < total; i++)
			lcd_addpixel(i);
	}
	else if (is_command(argc, argv, "tpp2")) {
		int x, y;

		i = 0;
		for (y = 0; y < lcd_height(); y++)
			for (x = 0; x < lcd_width(); x++)
				lcd_addpixel(rgb(i++, 0, 0));
	}
	else if (is_command(argc, argv, "tpd")) {
		static int step = 0;
		pixel_t *fb;
		int x, y;
		int w, h;

		fb = lcd_fb();

		h = lcd_height();
		w = lcd_width();

		/* Stupid clear-screen */
		memset(fb, 0, w * h * lcd_bpp());

		printf("Width: %d  Height: %d\n", w, h);

		i = step++;
		fb = lcd_fb();
		for (y = 0; y < h; y++) {
			for (x = 0; x < w; x++) {
				/* Swap axes, to verify X and Y work */
				if (step & 1)
					*fb++ = color_wheel(y + step);
				else
					*fb++ = color_wheel(x + step);
			}
		}
		lcd_run();
	}
	else {
		printf("lcd sub-commands (usage: lcd [subcmd]):\n");
		printf("\tinit    Initialize LCD registers\n");
		printf("\trun     Transfer one frame of the LCD\n");
		printf("\tstop    Stop and reset LCD auto-update\n");
#ifdef LCD_DEBUG
		printf("\tdump    Dump current register list\n");
#endif
		printf("\ttpp1    Display bitbanged, PIO 'test pattern 1'\n");
		printf("\ttpp2    Display bitbanged, PIO 'test pattern 2'\n");
		printf("\ttpd     DMA test pattern (flips on each iteration)\n");
	}

	return 0;
}
Exemplo n.º 9
0
void ui_task( void * data)
{
	portBASE_TYPE res;
	m_eMode = mdAUTHENTICATE;
	// init LCD;
	lcd_clear_all();
	lcd_init();
	lcd_led_power(1);
	//lcd_test(0);
	lcd_text(32,10,3,"NFC",0);
	lcd_text(12,40,1,"ipTronix   Arrow   NXP",0);
	lcd_update(0,63);

	lcd_clear_all();
	vTaskDelay(1500);

	for (;;)
	{
		char str[30];
		lcd_clear_all();
		lcd_text(32,0,1,"Authentication",0);
		lcd_text(32,20,2,"Scan card",0);
		switch (m_eMode)
		{
			case mdAUTHENTICATE:
				lcd_text(10,40,2,"AUTHENTICATE",1);
				break;
			case mdAUTHORIZE:
				lcd_text(22,40,2,"AUTHORIZE",1);
				break;
			case mdDENY:
				lcd_text(42,40,2,"DENY",1);
				break;
		}
		lcd_update(0,63);


		do
		{
			key=CAP_KEY_GetEvent();
			res = xQueueReceive(xUIQueue,&payload,100);

			if (GPIOGetPinValue( PIN_ISP ) == 0)
			{
				lcd_clear_all();
				lcd_text(52,26,2,"ISP",0);
				lcd_update(0,63);
				NVIC_SystemReset();
			}
		} while ((key==keNONE) && (res!= pdPASS));
		if (key==keK3_PRESS || key==keK3_REPEAT)
		{
			if (m_eMode<mdDENY)
				m_eMode++;
			else
				m_eMode=mdAUTHENTICATE;
		}
		else if (key==keK1_PRESS || key==keK1_REPEAT)
		{
			if (m_eMode>mdAUTHENTICATE)
				m_eMode--;
			else
				m_eMode = mdDENY;
		}
		key=keNONE;

		if (res==pdPASS)
		{
			lcd_clear_all();
			snprintf(str, sizeof(payload.name),"Name %s", payload.name);
			lcd_text(0,20,2,str,0);
			sprintf(str,"Access %08X",payload.access_rights);
			lcd_text(0,40,2,str,0);
			lcd_update(0,63);
			if (payload.access_rights==0xffffffff)
				GPIOSetBitValue(PIN_MOSFET,1);
			vTaskDelay(1500);
			GPIOSetBitValue(PIN_MOSFET,0);
		}
	}

}
Exemplo n.º 10
0
void main(void) {


	uint8_t genx = 0;
	uint8_t geny = 0;
	int8_t posx = 0;
	int8_t posy = 0;
	uint8_t bumpx[ANZ + 1];
	uint8_t bumpy[ANZ + 1];
	uint8_t i = 0;
	uint8_t mscount = 0;
	int8_t randx = 0;
	int8_t randy = 0;
	//char *schtring = "hello world";
	PDR00 = 0xff;
	DDR00 = 0xff; // Set Port00 as output (right 7Segment display)
	PDR09 = 0xff;
	DDR09 = 0xff; // Set Port09 as output (left 7Segment display)


	PDR09 = DEC7SEG[1];
	PDR00 = DEC7SEG[1];

	lcd_init();
	adc_init();
	lcd_clear(0);
	random_init();

	for(i = 0; i < ANZ + 1; i++)
	{
		do
		{
			genx = (random() % (128 / bumpsize)) * bumpsize;
			geny = (random() % (64 / bumpsize)) * bumpsize;
		} while((genx == 0 && geny == 0) || bumpcollision(bumpx, bumpy, i, genx, geny));
		bumpx[i] = genx;
		bumpy[i] = geny;
	}
	for(;;)
	{
		for(i = 0; i < ANZ; i++)
		{
			lcd_drawRect(bumpx[i], bumpy[i], bumpsize, bumpsize, 1, 1);
		}
		lcd_drawRect(bumpx[ANZ], bumpy[ANZ], size + 2, size + 2, 0, 1);
		lcd_drawRect(posx, posy, size, size, 0, 1);
		posx = minmax((int) (((float) -(adc_getValue(1) - 255) / (float) 255) * (128 - size)) + randx, 128);
		posy = minmax((int) (((float) -(adc_getValue(2) - 255) / (float) 255) * (64 - size)) + randy, 64);
		lcd_drawRect(posx, posy, size, size, 1, 1);
		if(checkCollision(posx, posy) == 1)
			looser();
		if(posx == bumpx[ANZ] + 1 && posy == bumpy[ANZ] + 1)
			winner();
		lcd_drawRect(bumpx[ANZ], bumpy[ANZ], size + 2, size + 2, 1, 1);
		lcd_drawRect(bumpx[ANZ] + 1, bumpy[ANZ] + 1, size, size, 0, 1);
		mscount++;
		if(mscount == 50)
		{
			mscount = 0;
			if(random() % 2)
			{
				randx = minmax(randx + posorneg(), 5 + size);
			}
			else
			{
				randy = minmax(randy + posorneg(), 5 + size);

			}
		}
		delay_ms(10);
	}
}
Exemplo n.º 11
0
int main(void)
{
	
	lcd_init(LCD_DISP_ON);
	lcd_clrscr();
	lcd_puts("Je suis");
	lcd_gotoxy(0,1);
	lcd_puts("Roberto");

	int i, pos_servo, flag_error = 0;
	
	DDRC = 0xFF;
	DDRD = 0xFF;
	DDRA = 0x80;
	PORTD = 0b01100011;
	PORTC = 0b00000000;
	set_servo(0, 20);
	set_servo(1, 80);
	set_servo(2, 50);
	set_servo(3, 50);
	set_servo(4, 50);
	while(1)
	{	
		/*
		
		if(_PINA0 == 1 )
		{
			if(_PINA1 == 0)
			{
				_PORTA7 = 1;				
			}
			else _PORTA7 = 0;
		}
		else _PORTA7 = 0;	
		*/

		/*
		_PORTA7 = 1;
		waitms(3000);
		_PORTA7 = 0;
		waitms(5000);

		*/
		/*
		if(_PINA5 == 1 )
		{
			set_servo(3, 20);
		}
		else set_servo(3, 50);
		*/


		if(_PINA0 == 1) 
		{

sortie: 	PORTD = 0b11000110;

			lcd_gotoxy(0,0);
			lcd_clrscr();
			lcd_puts("Payez le gentil");
			lcd_gotoxy(0,1);
			lcd_puts("serveur SVP");

			while(_PINA5 == 0); 

			PORTD = 0b00100001;
			
			lcd_gotoxy(0,0);
			lcd_clrscr();
			lcd_puts("Et un Ricard");
			for(i=0; i < 69; i++)
			{
				set_servo(0, 20 + i);

				waitms(20);
			}

			i = 0;

			while(_PINA2 == 0)
			{

				set_servo(1, 80 - i);

				waitms(20);

				i++;

			}
			pos_servo = i;	

			while(_PINA0 == 1 && _PINA2 == 1 && _PINA1 == 0) _PORTA7 = 1;

			if(_PINA2 == 1 && _PINA0 == 1)
			{
			
				set_servo(2, 30);
				waitms(400);
				set_servo(2, 70);
				waitms(400);
				set_servo(2, 30);
				waitms(400);
				set_servo(2, 70);
				waitms(400);
				set_servo(2, 30);
				waitms(400);
				set_servo(2, 70);
				waitms(400);
				set_servo(2, 30);
				waitms(400);
				set_servo(2, 70);
				waitms(400);
				set_servo(2, 30);
				waitms(400);
				set_servo(2, 70);
				waitms(400);
				set_servo(2, 50);

				flag_error = 0;
			}
			else 
			{
				PORTD = 0b10000100;

				lcd_gotoxy(0,0);
				lcd_clrscr();
				lcd_puts("Nous avons");
				lcd_gotoxy(0,1);
				lcd_puts("un probleme.");

				flag_error = 1;

			}
			

			_PORTA7 = 0;

			waitms(5000);

			
			for(i=0; i < 70; i++)
			{
				set_servo(1, 10 + i);

				waitms(30);
			}

			if(flag_error == 0)
			{
				lcd_gotoxy(0,0);
				lcd_clrscr();
				lcd_puts("Et voila.");

				PORTD = 0b01000010;
			}

			while(	_PINA0 == 1)
			{
				set_servo(4, 10);
				set_servo(3, 90);

				waitms(200);

				set_servo(4, 50);
				set_servo(3, 50);

				waitms(200);

				set_servo(4, 10);
				set_servo(3, 90);

				waitms(200);

				set_servo(4, 50);
				set_servo(3, 50);

				waitms(2000);


			}

			for(i=0; i < 70; i++)
			{
				set_servo(0, 85 - i);

				waitms(30);
			}

			

			if(flag_error == 0)
			{
				lcd_clrscr();
				lcd_gotoxy(0,0);
				lcd_puts("A votre sante.");
			}
			
			waitms(2000);		


			
		}
		else 	
		{
			PORTD = 0b01100011;

			//set_servo(0, 20);

			//set_servo(1, 80);

			lcd_gotoxy(0,0);
			lcd_clrscr();
			lcd_puts("Je suis");
			lcd_gotoxy(0,1);
			lcd_puts("Roberto");

			for(i=0; i< 100;i++)
			{
				waitms(20);
				if(_PINA0 == 1) goto sortie;
			}

			lcd_gotoxy(0,0);
			lcd_clrscr();
			lcd_puts("Le robot");
			lcd_gotoxy(0,1);
			lcd_puts("serveur");

			
			for(i=0; i< 100;i++)
			{
				waitms(20);
				if(_PINA0 == 1) goto sortie;
			}

			lcd_gotoxy(0,0);
			lcd_clrscr();
			lcd_puts("Je fais parti");
			lcd_gotoxy(0,1);
			lcd_puts("de Robopoly");

			set_servo(4, 10);
			set_servo(3, 90);

			waitms(200);

			set_servo(4, 50);
			set_servo(3, 50);

			
			for(i=0; i< 100;i++)
			{
				waitms(20);
				if(_PINA0 == 1) goto sortie;
			}

			lcd_gotoxy(0,0);
			lcd_clrscr();
			lcd_puts("Un Ricard");
			lcd_gotoxy(0,1);
			lcd_puts("Un vrai.");

			
			for(i=0; i< 100;i++)
			{
				waitms(20);
				if(_PINA0 == 1) goto sortie;
			}
		}


/*
		if(_PINA2 == 0) 
		{
			waitms(200);
			
			set_servo(1, 80);

			
		}
		else 	
		{
			waitms(200);
			
			set_servo(1, 20);
		}

*/


	
		
		/*
		set_servo(0, 30);
		set_servo(1, 30);
		set_servo(2, 30);
		set_servo(3, 40);
		set_servo(4, 40);

		waitms(500);

		set_servo(0, 70);
		set_servo(1, 70);
		set_servo(2, 70);
		set_servo(3, 60);
		set_servo(4, 60);

		waitms(500);
		*/

/*
		for(i=0; i<20;i++)
		{
			for(j=0;j<10;j++)
			{
				PORTD = 0b00000100;	
				waitms(20-i+1);
				PORTD = 0b00000001;	
				waitms((i+1));
				PORTD = 0b00000000;	
				waitms(5);
			}
			
		
		}
		for(i=0; i<20;i++)
		{

			for(j=0;j<10;j++)
			{
				PORTD = 0b00000001;	
				waitms(20-i+1);
				PORTD = 0b00000010;	
				waitms((i+1));
				PORTD = 0b00000000;	
				waitms(5);
			}
		}
		for(i=0; i<20;i++)
		{

			for(j=0;j<10;j++)
			{
				PORTD = 0b00000010;	
				waitms(20-i+1);
				PORTD = 0b00000100;	
				waitms((i+1));
				PORTD = 0b00000000;	
				waitms(5);
			}
		}
		*/
	
	}

	return 0; 
}
Exemplo n.º 12
0
void lcd_test(void)
{
	unsigned char c;
	static int lcdon = 0;
	static int blon = 0;
	static int dispon = 0;

	lcd_init();
	
	while (1)
	{
		printf("********LCD TEST MENU********\n\r");
		printf("[L] enable/disable LCD\n\r");
		printf("[B] enable/disable back light\n\r");
		printf("[C] enable/disable s3c6410 display controller\n\r");
		printf("[D] display color\n\r");
		printf("[I]  draw line\n\r");
		printf("[Q] quit\n\r");

		do {
			c = getc();
			if (c == '\n' || c == '\r')
			{
				printf("\n\r");
			}
			else
			{
				putc(c);
			}
		} while (c == '\n' || c == '\r');

		switch (c) {
			case 'l':
			case 'L':
			{
				if (lcdon)
				{
					lcd_off();
					printf("LCD off\n\r");
				}
				else
				{
					lcd_on();
					printf("LCD on\n\r");
				}
				lcdon = !lcdon;
				break;
			}


			case 'b':
			case 'B':
			{
				if (blon)
				{
					backlight_disable();
					printf("Backlight off\n\r");
				}
				else
				{
					backlight_enable();
					printf("Backlight on\n\r");
				}
				blon = !blon;
				break;
			}


			case 'c':
			case 'C':
			{
				if (dispon)
				{
					displaycon_off();
					printf("Display controller off\n\r");
				}
				else
				{
					displaycon_on();
					printf("Display controller on\n\r");
				}
				blon = !blon;
				break;
			}

			case 'd':
			case 'D':
			{
				display_red();
				break;
			}

			case 'i':
			case 'I':
			{
				draw_line();
				break;
			}

			case 'q':
			case 'Q':
			{
				return ;
				break;
			}

		}

	}
}
Exemplo n.º 13
0
int main (void)
{
    unsigned char           menu = MENU_SHOW_USER_TIME;

    static unsigned char    button_state = 0, counter_button = 0;

    unsigned                cpsr_temp;
    double                  voltage_temp,
                            current_temp,
                            wattage_hour_temp,
                            wattage_temp;

    unsigned short int      nr_adc_reads_temp;

    /* Initialize variables */
    voltage                             = 0;
    current                             = 0;
    wattage                             = 0;
    wattage_hour_user                   = 0;
    wattage_hour_system                 = 0;
    tick_update_lcd                     = 0;
    nr_adc_reads                        = 0;
    user_time_wattage                   = 0;

	/* Initialize the system */
    system_init ();

    /* Initialize the LCD */
    lcd_init ();

    /* Initialize the ADC */
    adc_init ();

    /* Initialize the buttons */
    buttons_init ();

    /* Initialize the Timer0 */
    timer1_init ();
    enableIRQ ();

    for (;;)
    {
        switch (menu)
        {
        case MENU_SHOW_USER_TIME:

        if (button_is_set(BUTTON_01) && !button_state)
        {
            menu = MENU_SHOW_USER_POWER;
            button_state = 1;
            counter_button = 0;
        }

        if (!button_is_set(BUTTON_01))
            button_state = 0;

        if (tick_update_lcd >= 50) /* Execute on every 50 * 5ms */
        {
            /* Disable the IRQ for avoid change on global variables used on
            * Timer1 IRQ handler code */
            cpsr_temp = disableIRQ ();
            wattage = 0;
            voltage = 0;
            current = 0;
            nr_adc_reads = 0;
            wattage_temp = user_time_wattage;
            tick_update_lcd = 0;
            /* Restore the IRQ */
            restoreIRQ (cpsr_temp);

            lcd_send_command (DD_RAM_ADDR); /* LCD set first row */
            lcd_send_char (' ');
            lcd_send_char ('A');
            lcd_send_char ('v');
            lcd_send_char ('a');
            lcd_send_char ('i');
            lcd_send_char ('l');
            lcd_send_char ('a');
            lcd_send_char ('b');
            lcd_send_char ('l');
            lcd_send_char ('e');
            lcd_send_char (' ');
            lcd_send_char ('t');
            lcd_send_char ('i');
            lcd_send_char ('m');
            lcd_send_char ('e');
            lcd_send_char (' ');

            lcd_send_command (DD_RAM_ADDR2); /* LCD set 2nd row */

            /* (watts per hour * 60) ==> watts per minute.
             * Load uses 30 watts so: ((watts per hour * 60) / 30) <=>
             *                         (watts per hour * 2).
             */
            double temp1, temp2;
            temp1 = ((long) (wattage_temp * 2));
            temp2 = ((double) (((double) (wattage_temp * 2)) - (double) temp1));
            lcd_send_char (' ');
            lcd_send_char (' ');
            lcd_send_char (' ');
            lcd_send_char (' ');
            lcd_send_int (temp1, 3);
            lcd_send_char ('m');
            lcd_send_char (' ');
            lcd_send_int (((long) (temp2 * 60)), 2);
            lcd_send_char ('s');
            lcd_send_char (' ');
            lcd_send_char (' ');
            lcd_send_char (' ');
            lcd_send_char (' ');

            /* Verify if we need to reset the "usage time available" */
            if (button_is_set(BUTTON_02))
            {
                if (++counter_button >= 4)
                {
                    while (button_is_set(BUTTON_02))
                    {
                        lcd_send_command (DD_RAM_ADDR);
                        lcd_send_char (' ');
                        lcd_send_char ('A');
                        lcd_send_char ('v');
                        lcd_send_char ('a');
                        lcd_send_char ('i');
                        lcd_send_char ('l');
                        lcd_send_char ('a');
                        lcd_send_char ('b');
                        lcd_send_char ('l');
                        lcd_send_char ('e');
                        lcd_send_char (' ');
                        lcd_send_char ('t');
                        lcd_send_char ('i');
                        lcd_send_char ('m');
                        lcd_send_char ('e');
                        lcd_send_char (' ');

                        lcd_send_command (DD_RAM_ADDR2);
                        lcd_send_char (' ');
                        lcd_send_char (' ');
                        lcd_send_char (' ');
                        lcd_send_char (' ');
                        lcd_send_char (' ');
                        lcd_send_char ('r');
                        lcd_send_char ('e');
                        lcd_send_char ('s');
                        lcd_send_char ('e');
                        lcd_send_char ('t');
                        lcd_send_char (' ');
                        lcd_send_char (' ');
                        lcd_send_char (' ');
                        lcd_send_char (' ');
                        lcd_send_char (' ');
                        lcd_send_char (' ');
                    }

             /* Disable the IRQ for avoid change on global variables used on
              * Timer1 IRQ handler code */
                    cpsr_temp = disableIRQ ();
                    user_time_wattage = 0;
                    tick_update_lcd = 0;
                    /* Restore the IRQ */
                    restoreIRQ (cpsr_temp);

                    counter_button = 0;
                }
            }
        }

        break;

            case MENU_SHOW_USER_POWER:

            if (button_is_set(BUTTON_01) && !button_state)
            {
                menu = MENU_SHOW_SYSTEM_POWER;
                button_state = 1;
                counter_button = 0;
            }

            if (!button_is_set(BUTTON_01))
                button_state = 0;

            if (tick_update_lcd >= 50) /* Execute on every 50 * 5ms */
            {
                /* Disable the IRQ for avoid change on global variables used on
                * Timer1 IRQ handler code */
                cpsr_temp = disableIRQ ();
                wattage_temp = wattage;
                wattage = 0;
                wattage_hour_temp = wattage_hour_user;
                voltage = 0;
                current = 0;
                nr_adc_reads_temp = nr_adc_reads;
                nr_adc_reads = 0;
                tick_update_lcd = 0;
                /* Restore the IRQ */
                restoreIRQ (cpsr_temp);

                lcd_send_command (DD_RAM_ADDR); /* LCD set first row */
                lcd_send_char (' ');
                lcd_send_float ((wattage_temp/nr_adc_reads_temp), 3, 1);
                lcd_send_char (' ');
                lcd_send_char ('W');
                lcd_send_char ('a');
                lcd_send_char ('t');
                lcd_send_char ('t');
                lcd_send_char ('s');
                lcd_send_char (' ');
                lcd_send_char (' ');
                lcd_send_char (' ');
                lcd_send_char (' ');

                lcd_send_command (DD_RAM_ADDR2); /* LCD set 2nd row */
                lcd_send_char (' ');
                lcd_send_float (wattage_hour_temp, 3, 3);
                lcd_send_char (' ');
                lcd_send_char ('W');
                lcd_send_char ('/');
                lcd_send_char ('h');
                lcd_send_char ('o');
                lcd_send_char ('u');
                lcd_send_char ('r');
                lcd_send_char (' ');

                /* Verify if we need to reset the wattage_hour_user */
                if (button_is_set(BUTTON_02))
                {
                    if (++counter_button >= 8)
                    {
                        while (button_is_set(BUTTON_02))
                        {
                            lcd_send_command (DD_RAM_ADDR);
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char ('W');
                            lcd_send_char ('a');
                            lcd_send_char ('t');
                            lcd_send_char ('t');
                            lcd_send_char ('s');
                            lcd_send_char (' ');
                            lcd_send_char ('h');
                            lcd_send_char ('o');
                            lcd_send_char ('u');
                            lcd_send_char ('r');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');

                            lcd_send_command (DD_RAM_ADDR2);
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char ('r');
                            lcd_send_char ('e');
                            lcd_send_char ('s');
                            lcd_send_char ('e');
                            lcd_send_char ('t');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                        }

                 /* Disable the IRQ for avoid change on global variables used on
                  * Timer1 IRQ handler code */
                        cpsr_temp = disableIRQ ();
                        wattage_hour_user = 0;
                        tick_update_lcd = 0;
                        /* Restore the IRQ */
                        restoreIRQ (cpsr_temp);

                        counter_button = 0;
                    }
                }
            }

            break;

            case MENU_SHOW_SYSTEM_POWER:

            if (button_is_set(BUTTON_01) && !button_state)
            {
                menu = MENU_SHOW_USER_TIME;
                button_state = 1;
                counter_button = 0;
            }

            if (!button_is_set(BUTTON_01))
                button_state = 0;

            if (tick_update_lcd >= 50) /* Execute on every 50 * 5ms */
            {
                /* Disable the IRQ for avoid change on global variables used on
                * Timer1 IRQ handler code */
                cpsr_temp = disableIRQ ();
                wattage_temp = wattage;
                wattage = 0;
                wattage_hour_temp = wattage_hour_system;
                voltage = 0;
                current = 0;
                nr_adc_reads_temp = nr_adc_reads;
                nr_adc_reads = 0;
                tick_update_lcd = 0;
                /* Restore the IRQ */
                restoreIRQ (cpsr_temp);

                lcd_send_command (DD_RAM_ADDR); /* LCD set first row */
                lcd_send_char (' ');
                lcd_send_char (' ');
                lcd_send_char ('T');
                lcd_send_char ('o');
                lcd_send_char ('t');
                lcd_send_char ('a');
                lcd_send_char ('l');
                lcd_send_char (' ');
                lcd_send_char ('p');
                lcd_send_char ('o');
                lcd_send_char ('w');
                lcd_send_char ('e');
                lcd_send_char ('r');
                lcd_send_char (' ');
                lcd_send_char (' ');
                lcd_send_char (' ');

                lcd_send_command (DD_RAM_ADDR2); /* LCD set 2nd row */
                lcd_send_char (' ');
                lcd_send_float (wattage_hour_temp, 4, 3);

                lcd_send_char (' ');
                lcd_send_char ('W');
                lcd_send_char ('/');
                lcd_send_char ('h');
                lcd_send_char ('o');
                lcd_send_char ('u');
                lcd_send_char ('r');

                /* Verify if we need to go on the advanced menus */
                if (button_is_set(BUTTON_02))
                {
                    if (++counter_button >= 20)
                    {
                        while (button_is_set(BUTTON_02))
                        {
                            lcd_send_command (DD_RAM_ADDR);
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char ('G');
                            lcd_send_char ('o');
                            lcd_send_char ('i');
                            lcd_send_char ('n');
                            lcd_send_char ('g');
                            lcd_send_char (' ');
                            lcd_send_char ('t');
                            lcd_send_char ('o');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');

                            lcd_send_command (DD_RAM_ADDR2); /* LCD set 2nd row */
                            lcd_send_char (' ');
                            lcd_send_char ('a');
                            lcd_send_char ('d');
                            lcd_send_char ('v');
                            lcd_send_char ('a');
                            lcd_send_char ('n');
                            lcd_send_char ('c');
                            lcd_send_char ('e');
                            lcd_send_char ('d');
                            lcd_send_char (' ');
                            lcd_send_char ('m');
                            lcd_send_char ('e');
                            lcd_send_char ('n');
                            lcd_send_char ('u');
                            lcd_send_char ('s');
                            lcd_send_char (' ');
                        }

                        menu = MENU_SHOW_VOLTAGE_CURRENT;

                        counter_button = 0;
                    }
                }
            }

            break;

            case MENU_SHOW_VOLTAGE_CURRENT:

            if (button_is_set(BUTTON_01) && !button_state)
            {
                menu = MENU_SHOW_ADC_READINGS;
                button_state = 1;
                counter_button = 0;
            }

            if (!button_is_set(BUTTON_01))
                button_state = 0;

            if (tick_update_lcd >= 50) /* Execute on every 50 * 5ms */
            {
                /* Disable the IRQ for avoid change on global variables used on
                 * Timer1 IRQ handler code */
                cpsr_temp = disableIRQ ();
                voltage_temp = voltage;
                voltage = 0;
                current_temp = current;
                current = 0;
                nr_adc_reads_temp = nr_adc_reads;
                nr_adc_reads = 0;
                tick_update_lcd = 0;
                /* Restore the IRQ */
                restoreIRQ (cpsr_temp);

                lcd_send_command (DD_RAM_ADDR); /* LCD set first row */
                lcd_send_char (' ');
                lcd_send_char (' ');
                lcd_send_char (' ');
                lcd_send_float ((((voltage_temp/nr_adc_reads_temp) * \
                                                K_VOLTAGE) + M_VOLTAGE), 2,1);

                lcd_send_char (' ');
                lcd_send_char ('V');
                lcd_send_char ('o');
                lcd_send_char ('l');
                lcd_send_char ('t');
                lcd_send_char ('s');
                lcd_send_char (' ');
                lcd_send_char (' ');
                lcd_send_char (' ');

                lcd_send_command (DD_RAM_ADDR2); /* LCD set 2nd row */
                lcd_send_char (' ');
                lcd_send_char (' ');
                lcd_send_char (' ');
          /* First 3 values from ADC_current should not be used since they are
           *  very non linear.
           */
                current_temp = (current_temp/nr_adc_reads_temp);
                if (current_temp < 3)
                {
                    lcd_send_float (0, 2, 1);
                }

                if (current_temp >= 3 && current_temp < 60)
                {
                    current_temp = \
                   ((-0.000004 * current_temp * current_temp * current_temp) + \
                   (0.0005 * current_temp * current_temp) - \
                   (0.0028 * current_temp) + 0.356);
                    lcd_send_float (current_temp, 2, 1);
                }

                if (current_temp >= 60)
                {
                    lcd_send_float (((current_temp * K_CURRENT) + \
                            M_CURRENT),2,1);
                }

                lcd_send_char (' ');
                lcd_send_char ('A');
                lcd_send_char ('m');
                lcd_send_char ('p');
                lcd_send_char ('s');
                lcd_send_char (' ');
                lcd_send_char (' ');
                lcd_send_char (' ');
                lcd_send_char (' ');

                /* Verify if we need to go on the normal menus */
                if (button_is_set(BUTTON_02))
                {
                    if (++counter_button >= 20)
                    {
                        while (button_is_set(BUTTON_02))
                        {
                            lcd_send_command (DD_RAM_ADDR);
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char ('L');
                            lcd_send_char ('e');
                            lcd_send_char ('a');
                            lcd_send_char ('v');
                            lcd_send_char ('i');
                            lcd_send_char ('n');
                            lcd_send_char ('g');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');
                            lcd_send_char (' ');

                            lcd_send_command (DD_RAM_ADDR2);
                            lcd_send_char (' ');
                            lcd_send_char ('a');
                            lcd_send_char ('d');
                            lcd_send_char ('v');
                            lcd_send_char ('a');
                            lcd_send_char ('n');
                            lcd_send_char ('c');
                            lcd_send_char ('e');
                            lcd_send_char ('d');
                            lcd_send_char (' ');
                            lcd_send_char ('m');
                            lcd_send_char ('e');
                            lcd_send_char ('n');
                            lcd_send_char ('u');
                            lcd_send_char ('s');
                            lcd_send_char (' ');
                        }

                        menu = MENU_SHOW_USER_TIME;

                        counter_button = 0;
                    }
                }
            }

            break;

            case MENU_SHOW_ADC_READINGS:

            disableIRQ ();
            lcd_send_command (CLR_DISP);

            while (1)
            {
                lcd_send_command (DD_RAM_ADDR); /* LCD set first row */
                lcd_send_char ('A');
                lcd_send_char ('D');
                lcd_send_char ('C');
                lcd_send_char (' ');
                lcd_send_char ('v');
                lcd_send_char ('o');
                lcd_send_char ('l');
                lcd_send_char ('t');
                lcd_send_char ('a');
                lcd_send_char ('g');
                lcd_send_char ('e');
                lcd_send_char (':');
                int i;
                for (i = 0; i < 5000; i++)
                    voltage += adc_read (6);
                lcd_send_int (voltage/5000, 4);
                voltage = 0;
                lcd_send_command (DD_RAM_ADDR2); /* LCD set 2nd row */
                lcd_send_char ('A');
                lcd_send_char ('D');
                lcd_send_char ('C');
                lcd_send_char (' ');
                lcd_send_char ('c');
                lcd_send_char ('u');
                lcd_send_char ('r');
                lcd_send_char ('r');
                lcd_send_char ('e');
                lcd_send_char ('n');
                lcd_send_char ('t');
                lcd_send_char (':');
                for (i = 0; i < 5000; i++)
                    current += adc_read (7);
                lcd_send_int (current/5000, 4);
                current = 0;

                if (button_is_set(BUTTON_01) && !button_state)
                {
                    menu = MENU_SHOW_VOLTAGE_CURRENT;
                    button_state = 1;
                    counter_button = 0;
                    voltage = 0;
                    current = 0;
                    restoreIRQ (cpsr_temp);
                    break;
                    break;
                }

                if (!button_is_set(BUTTON_01))
                    button_state = 0;
            }

            break;

            default:
            break;
        }

    /* Go to idle mode to save power. System leaves idle mode on interrupt, so,
     * at each 5ms interrupt from Timer 1.
     */
    /* UNCOMENT IN THE END - NOT POSSIBLE TO DEBUG WITH IDLE MODE */
    system_go_idle ();
    }
}
/*
  //Function Name -  Main
  //Input - Nothing
  //Output - control left and right Motor speeds
  //Logic - add pid correction error here.
*/
int main()
{
	init_devices();
	lcd_set_4bit();
	lcd_init();
	signed int max = 250;
	speed_L = 255;
	speed_R = 255;

	while(1)
	{

		data_received [0] = ADC_Conversion(3);	//Getting data of sensor-0 WL Sensor
		data_received [1] = ADC_Conversion(2);	//Getting data of sensor-1 WL Sensor
		data_received [2] = ADC_Conversion(1);	//Getting data of sensor-2 WL Sensor
        data_received [3] = spi_master_tx_and_rx(0); //Getting data of sensor-3 WL sensor connected to slave microcontroller.
        data_received [4] = spi_master_tx_and_rx(1); //Getting data of sensor-4 WL sensor connected to slave microcontroller.
        data_received [5] = spi_master_tx_and_rx(2); //Getting data of sensor-5 WL sensor connected to slave microcontroller.
		data_received [6] = spi_master_tx_and_rx(3); //Getting data of sensor-6 WL sensor connected to slave microcontroller.

		/*lcd_print(1, 1,data_received [0], 3);
		lcd_print(1, 5,data_received [1], 3);
		lcd_print(1, 9,data_received [2], 3);
		lcd_print(1, 14,data_received [3], 3);
		lcd_print(2, 1,data_received [4], 3);
		lcd_print(2, 5,data_received [5], 3);
		lcd_print(2, 9,data_received [6], 3);
		*/
		SetTunings();

		sensor_value[0] = sensor_on_line(data_received [0]);
		sensor_value[1] = sensor_on_line(data_received [1]);
		sensor_value[2] = sensor_on_line(data_received [2]);
		sensor_value[3] = sensor_on_line(data_received [3]);
		sensor_value[4] = sensor_on_line(data_received [4]);
		sensor_value[5] = sensor_on_line(data_received [5]);
		sensor_value[6] = sensor_on_line(data_received [6]);


		/*senser_value_sum = data_received [0] + data_received [1] + data_received [2] + data_received [3] + data_received [4] + data_received [5] + data_received [6] ;

		weight = ((-3)*data_received [0] + (-2)*data_received [1] + (-1)*data_received [2] + (0)*data_received [3] + (1)*data_received [4] + (2)*data_received [5] + (3)*data_received [6]);
		*/

		senser_value_sum = sensor_value[0] + sensor_value[1] + sensor_value[2] + sensor_value[3] + sensor_value[4] + sensor_value[5] + sensor_value[6] ;

		weight = 10*((-3)*sensor_value[0] + (-2)*sensor_value[1]+ (-1)*sensor_value[2] + (0)*sensor_value[3] + (1)*sensor_value[4] + (2)*sensor_value[5] + (3)*sensor_value[6]);

		//control variable

		value_on_line = weight/senser_value_sum ;

		//lcd_print(1, 3,100-value_on_line, 3);

		/*lcd_print(2, 10,sensor_value[0], 1);
		lcd_print(2, 11,sensor_value[1], 1);
		lcd_print(2, 12,sensor_value[2], 1);
		lcd_print(2, 13,sensor_value[3], 1);
		lcd_print(2, 14,sensor_value[4], 1);
		lcd_print(2, 15,sensor_value[5], 1);
		lcd_print(2, 16,sensor_value[6], 1);
		*/


		pid = PID(value_on_line);

		//pid = PID(weight);

		if (pid <= -max)
		{
			pid = -max ;
		}

		if (pid >= max)
		{
			pid = max;
		}

		if (senser_value_sum == 0)
		{
			stop();
		}
		else
		{
			if (pid == 0)
			{
				//integral = 0;
				forward();
				velocity(speed_L,speed_R);
				/*lcd_print(2,1,speed_L,3);
				lcd_print(2,5,speed_R,3);
				lcd_print(1,13,2000-pid, 4);*/
			}

			if(pid<0)
			{
				if(pid > -180)
				{
					forward();
					velocity(speed_L+pid,speed_R);
					/*lcd_print(2,1,speed_L+pid,3);
					lcd_print(2,5,speed_R,3);
					lcd_print(1,13,2000-pid, 4);*/
				}
				else
				{
						left();
						velocity(speed_L-50,speed_R-50);
						/*lcd_print(2,1,speed_L-50,3);
						lcd_print(2,5,speed_R-50,3);
						lcd_cursor(1,13);
					}*/

				}

			}

			if (pid>0)
			{
				if(pid<180)
				{
					forward();
					velocity(speed_L,speed_R-pid);
					/*lcd_print(2,1,speed_L,3);
					lcd_print(2,5,speed_R-pid,3);
					lcd_print(1,13,2000-pid, 4);*/
				}
				else
				{
						right();
						velocity(speed_L-50 , speed_R-50);
						/*lcd_print(2,1,speed_L-50,3);
						lcd_print(2,5,speed_R-50,3);
						lcd_cursor(1,13);
					}*/
				}
			}
		}
	}
}
Exemplo n.º 15
0
static portTASK_FUNCTION( vLcdTask, pvParameters )
{
	unsigned int pressure;
	unsigned int xPos;
	unsigned int yPos;
	//portTickType xLastWakeTime;
	
	int step_width = 320/sequence_steps;
	int step_height = 240/numNotes;
	int left, bottom = 0;
	int right = step_width;
	int top = step_height;
	
	int i, n, x;
	int waiting = 0;
	
	int newlySelectedSequence = 0;
	
	int prevMode = 0;
	int prevSeq = 0;

	/* Just to stop compiler warnings. */
	( void ) pvParameters;

	/* Initialise LCD display */
	/* NOTE: We needed to delay calling lcd_init() until here because it uses
	 * xTaskDelay to implement a delay and, as a result, can only be called from
	 * a task */
	lcd_init();
	
	lcd_fillScreen(LIGHT_GRAY);
	
	/* Initial LCD display */
	setupScreen(step_width,left, bottom,right,top);

	/* Infinite loop blocks waiting for a touch screen interrupt event from
	 * the queue. */
	 
	while(1)
	{
		/* Clear TS interrupts (EINT3) */
		/* Reset and (re-)enable TS interrupts on EINT3 */
		EXTINT = 8;						/* Reset EINT3 */

		/* Enable TS interrupt vector (VIC) (vector 17) */
		VICIntEnable = 1 << 17;			/* Enable interrupts on vector 17 */

		/* Block on a queue waiting for an event from the TS interrupt handler */
		xSemaphoreTake(xLcdSemphr, portMAX_DELAY);
				
		/* Disable TS interrupt vector (VIC) (vector 17) */
		VICIntEnClr = 1 << 17;

		/* Measure next sleep interval from this point */
		//xLastWakeTime = xTaskGetTickCount();
		
		// When switching sequences in edit mode.
		if(mode == 2){
			setupScreen(step_width,0, 0,step_width,step_height);
			mode = 0;
		}
		// Switching from playback mode to edit mode, screen must be setup.
		if((prevMode == 1) && (mode == 0)){
			setupScreen(step_width,0, 0,step_width,step_height);
		}
		// Switching from edit mode to playback mode.
		else if((prevMode == 0) && (mode == 1)) {
			setupPlaybackMode();
		}
		
		prevMode = mode;
		
		/*** EDIT MODE ***/
		/*****************/
		if(mode != 1) {
			/* Start polling the touchscreen pressure and position ( getTouch(...) ) */
			/* Keep polling until pressure == 0 */
			getTouch(&xPos, &yPos, &pressure);
			while (pressure > 0)
			{
				// Button debounce on screen touch.
				waiting = 0;
				while(waiting<100000) {
					waiting++;
				}
				// Iterating through each row.
				for(i=0; i<numNotes; i++) {
					if((xPos < top) && (xPos > bottom)) {
						// If touch within bounds of row i, check for the corresponding column.
						for(n=0; n<sequence_steps; n++) {
							if((yPos < right) && (yPos > left)){
								// Render column cells to clear previously selected cell and set up newly selected or change previously selected note time.
								for(x=0; x<numNotes;x++){
									lcd_fillRect((x*step_height), (n*step_width), (x*step_height)+step_height, ((n*step_width)+step_width), LIGHT_GRAY);
									lcd_drawRect((x*step_height), (n*step_width), (x*step_height)+step_height, ((n*step_width)+step_width), DARK_GRAY);
									if(x != i){
										// Majority of cells will have no note.
										timing[x][n] = 0;
									}
								}
								if(timing[i][n]==0 || timing[i][n]==1){
									timing[i][n]++;
								}
								else {
									timing[i][n] = timing[i][n] + 2;
								}
								if (timing[i][n] > 4){
									timing[i][n] = 0;
								}
								final_timing[n] = timing[i][n];
							  
								if(timing[i][n] == 1){
									// Full note.
									lcd_fillRect(bottom + 4, left + 4, top - 4, right - 4, MAROON);
								}
								else if(timing[i][n] == 2){
									// Half note.
									lcd_fillRect(bottom + 4, left + 4, top - 4, right - 4, OLIVE);
								}
								else if(timing[i][n] == 4){
									// Quarter note.
									lcd_fillRect(bottom + 4, left + 4, top - 4, right - 4, PURPLE);
								}
								sequence[n] = i;
							}
							left = left + step_width;
							right = right + step_width;
						}	
					}
					left = 0;
					right = step_width;
					top = top + step_height;
					bottom = bottom + step_height;
				}
				step_width = 320/sequence_steps;
				bottom = 0;
				left = 0;
				right = step_width;
				top = step_height;
				
				getTouch(&xPos, &yPos, &pressure);
			}
		}
		/*** PLAYBACK MODE ***/
		/*********************/
		else {
			/* Start polling the touchscreen pressure and position ( getTouch(...) ) */
			/* Keep polling until pressure == 0 */
			getTouch(&xPos, &yPos, &pressure);
			while (pressure > 0)
			{
				// Bound touch area for more efficiency.
				if((xPos < 235) && (xPos > 185)){
					// Select current sequence.
					for(i=0; i<9; i++) {
						if(((xPos < 235) && (xPos > 185)) && ((yPos < (35*i) + 35) && (yPos > (35*i) + 5))){
							// If a new sequence selected, must save the one that's currently in use to the listOfSequences[][] and listOfTimingSequences[][]
							// and then reinitialise the current sequence[] to the relative one in listOfSequences[][] and listOfTimingSequences[][].
							newlySelectedSequence = i;
							if(newlySelectedSequence != currentlySelectedSequence) {
								lcd_fillRect(185, (35*currentlySelectedSequence) + 5, 235, (35*currentlySelectedSequence) + 35, LIGHT_GRAY);
								lcd_fillRect(185, (35*newlySelectedSequence) + 5, 235, (35*newlySelectedSequence) + 35, MAGENTA);
								for(n=0;n<sequence_steps;n++){
									listOfSequences[currentlySelectedSequence][n] = sequence[n];
									listOfTimingSequences[currentlySelectedSequence][n] = final_timing[n];
								}
								currentlySelectedSequence = newlySelectedSequence;
								for(n=0;n<sequence_steps;n++){
									sequence[n] = listOfSequences[currentlySelectedSequence][n];
									final_timing[n] = listOfTimingSequences[currentlySelectedSequence][n];
								}
							}
						}
					}
				}
				getTouch(&xPos, &yPos, &pressure);
			}
			// Prevent flicker.
			if(prevSeq != currentlySelectedSequence){
				// Only fill part of screen to reduce flicker.
				lcd_fillRect(0, 0, 175, 320, LIGHT_GRAY);
				// Setup note bars for current sequence[] and final_timing[].
				for(i=0; i<sequence_steps; i++) {
					if(sequence[i] != numNotes) {
						if(final_timing[i]==1){
							lcd_fillRect(0, (i*31)+5, ((sequence[i]+1)*11), (i*31)+31, MAROON);
						}
						else if(final_timing[i]==2){
							lcd_fillRect(0, (i*31)+5, ((sequence[i]+1)*11), (i*31)+31, OLIVE);
						}
						else if(final_timing[i]==4){
							lcd_fillRect(0, (i*31)+5, ((sequence[i]+1)*11), (i*31)+31, PURPLE);
						}
					}
				}
				// Setup BPM visual display.
				updateBPMVisuals();
				// Setup octave visual display.
				updateOctaveVisuals();
			}
			prevSeq = currentlySelectedSequence;
		}
	}
}
Exemplo n.º 16
0
/**
 * Main.
 */ 
int main( void )
{
  prvSetupHardware();// set up peripherals etc

  USARTInit(USART_PARAMS1);

  xPrintQueue = xQueueCreate(150, sizeof(char *));
  if (xPrintQueue == NULL)
    {
      printf("Failed to make print queue\r\n");
      for (;;);
    }

  vParametersInit();
  lcd_init();
  menu_set_root(main_menu);

  vLEDInit();

  vI2C_Init();

  vMillInit();

  vMashPumpInit();

  vValvesInit();

  vDiagTempsInit();

  vHopsInit();

  vBoilInit();

  vStirInit();

  vCraneInit();

  hlt_init();

  vFlow1Init();

  vDiagPWMInit();

  vChillerPumpInit();

  vBoilValveInit();

  xTaskCreate( vSerialHandlerTask,
      ( signed portCHAR * ) "SerialTask",
      configMINIMAL_STACK_SIZE,
      NULL,
      tskIDLE_PRIORITY +4,
      &xSerialHandlerTaskHandle );


  xTaskCreate( vSerialControlCentreTask,
      ( signed portCHAR * ) "SerialctrlTask",
      configMINIMAL_STACK_SIZE + 100,
      NULL,
      tskIDLE_PRIORITY +2,
      &xSerialControlTaskHandle );

  xTaskCreate( vConsolePrintTask,
      ( signed portCHAR * ) "PrintTask",
      configMINIMAL_STACK_SIZE,
      NULL,
      tskIDLE_PRIORITY,
      &xPrintTaskHandle );

  xTaskCreate( vTouchTask,
      ( signed portCHAR * ) "touch    ",
      configMINIMAL_STACK_SIZE +400,
      NULL,
      tskIDLE_PRIORITY,
      &xTouchTaskHandle );

  // Create your application tasks if needed here
  xTaskCreate( vTaskDS1820Convert,
      ( signed portCHAR * ) "TempSensors",
      configMINIMAL_STACK_SIZE + 100,
      NULL,
      tskIDLE_PRIORITY,
      &xDS1820TaskHandle );

  xTaskCreate( vTaskLitresToBoil,
      ( signed portCHAR * ) "boil_litres",
      configMINIMAL_STACK_SIZE,
      NULL,
      tskIDLE_PRIORITY ,
      &xLitresToBoilHandle );

  xTaskCreate( vTaskLitresToMash,
      ( signed portCHAR * ) "mash_litres",
      configMINIMAL_STACK_SIZE,
      NULL,
      tskIDLE_PRIORITY ,
      &xLitresToMashHandle );

  xTaskCreate( vTaskHops,
      ( signed portCHAR * ) "hops    ",
      configMINIMAL_STACK_SIZE,
      NULL,
      tskIDLE_PRIORITY,
      &xHopsTaskHandle );

  xTaskCreate( vCheckTask,
      ( signed portCHAR * ) "check     ",
      configMINIMAL_STACK_SIZE +400,
      NULL,
      tskIDLE_PRIORITY,
      &xCheckTaskHandle );

  xTaskCreate( vTaskCrane,
      ( signed portCHAR * ) "Crane    ",
      configMINIMAL_STACK_SIZE + 200 ,
      NULL,
      tskIDLE_PRIORITY+1,
      &xCraneTaskHandle );

  xTaskCreate( vTaskBoilValve,
      ( signed portCHAR * ) "boilvalve",
      configMINIMAL_STACK_SIZE +200,
      NULL,
      tskIDLE_PRIORITY+1,
      &xBoilValveTaskHandle );


  //      xTaskCreate( vI2C_TestTask,
  //          ( signed portCHAR * ) "i2c_test",
  //          configMINIMAL_STACK_SIZE +400,
  //          NULL,
  //          tskIDLE_PRIORITY,
  //          &xI2C_TestHandle );

  xTaskCreate(  vTaskHLTLevelChecker,
      ( signed portCHAR * ) "hlt_level",
      configMINIMAL_STACK_SIZE +100,
      NULL,
      tskIDLE_PRIORITY,
      & xTaskHLTLevelCheckerTaskHandle );



  xTaskCreate(  vI2C_SendTask,
      ( signed portCHAR * ) "i2c_send",
      configMINIMAL_STACK_SIZE +500,
      NULL,
      tskIDLE_PRIORITY+2,
      & xI2C_SendHandle );


  /* Start the scheduler. */
  vTaskStartScheduler();



  printf("FAIL\r\n");

  /* Will only get here if there was insufficient memory to create the idle
       task. */
  return 0;
}
Exemplo n.º 17
0
int main(void) {
    // TODO disable JTAG

    /* STM32F4xx HAL library initialization:
         - Configure the Flash prefetch, instruction and Data caches
         - Configure the Systick to generate an interrupt each 1 msec
         - Set NVIC Group Priority to 4
         - Global MSP (MCU Support Package) initialization
       */
    HAL_Init();

    // set the system clock to be HSE
    SystemClock_Config();

    // enable GPIO clocks
    __GPIOA_CLK_ENABLE();
    __GPIOB_CLK_ENABLE();
    __GPIOC_CLK_ENABLE();
    __GPIOD_CLK_ENABLE();

    // enable the CCM RAM
    __CCMDATARAMEN_CLK_ENABLE();

#if 0
#if defined(NETDUINO_PLUS_2)
    {
        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

#if MICROPY_HW_HAS_SDCARD
        // Turn on the power enable for the sdcard (PB1)
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_WriteBit(GPIOB, GPIO_Pin_1, Bit_SET);
#endif

        // Turn on the power for the 5V on the expansion header (PB2)
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_WriteBit(GPIOB, GPIO_Pin_2, Bit_SET);
    }
#endif
#endif

    // basic sub-system init
    pendsv_init();
    led_init();
    switch_init0();

    int first_soft_reset = true;
    uint reset_mode;

soft_reset:

    // check if user switch held to select the reset mode
    reset_mode = 1;
    led_state(1, 0);
    led_state(2, 1);
    led_state(3, 0);
    led_state(4, 0);

#if MICROPY_HW_HAS_SWITCH
    if (switch_get()) {
        for (uint i = 0; i < 3000; i++) {
            if (!switch_get()) {
                break;
            }
            HAL_Delay(20);
            if (i % 30 == 29) {
                reset_mode = (reset_mode + 1) & 7;
                led_state(2, reset_mode & 1);
                led_state(3, reset_mode & 2);
                led_state(4, reset_mode & 4);
            }
        }
        // flash the selected reset mode
        for (uint i = 0; i < 6; i++) {
            led_state(2, 0);
            led_state(3, 0);
            led_state(4, 0);
            HAL_Delay(50);
            led_state(2, reset_mode & 1);
            led_state(3, reset_mode & 2);
            led_state(4, reset_mode & 4);
            HAL_Delay(50);
        }
        HAL_Delay(400);
    }
#endif

#if MICROPY_HW_ENABLE_RTC
    if (first_soft_reset) {
        rtc_init();
    }
#endif

    // more sub-system init
#if MICROPY_HW_HAS_SDCARD
    if (first_soft_reset) {
        sdcard_init();
    }
#endif
    if (first_soft_reset) {
        storage_init();
    }

    // GC init
    gc_init(&_heap_start, &_heap_end);

    // Change #if 0 to #if 1 if you want REPL on USART_6 (or another usart)
    // as well as on USB VCP
#if 0
    pyb_usart_global_debug = pyb_Usart(MP_OBJ_NEW_SMALL_INT(PYB_USART_YA),
                                       MP_OBJ_NEW_SMALL_INT(115200));
#else
    pyb_usart_global_debug = NULL;
#endif

    // Micro Python init
    qstr_init();
    mp_init();
    mp_obj_t def_path[3];
    def_path[0] = MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_);
    def_path[1] = MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_src);
    def_path[2] = MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_lib);
    mp_sys_path = mp_obj_new_list(3, def_path);

    readline_init();

    exti_init();

#if MICROPY_HW_HAS_SWITCH
    // must come after exti_init
    switch_init();
#endif

#if MICROPY_HW_HAS_LCD
    // LCD init (just creates class, init hardware by calling LCD())
    lcd_init();
#endif

    pin_map_init();

    // local filesystem init
    {
        // try to mount the flash
        FRESULT res = f_mount(&fatfs0, "0:", 1);
        if (reset_mode == 3 || res == FR_NO_FILESYSTEM) {
            // no filesystem, or asked to reset it, so create a fresh one

            // LED on to indicate creation of LFS
            led_state(PYB_LED_R2, 1);
            uint32_t start_tick = HAL_GetTick();

            res = f_mkfs("0:", 0, 0);
            if (res == FR_OK) {
                // success creating fresh LFS
            } else {
                __fatal_error("could not create LFS");
            }

            // create src directory
            res = f_mkdir("0:/src");
            // ignore result from mkdir

            // create empty main.py
            FIL fp;
            f_open(&fp, "0:/src/main.py", FA_WRITE | FA_CREATE_ALWAYS);
            UINT n;
            f_write(&fp, fresh_main_py, sizeof(fresh_main_py) - 1 /* don't count null terminator */, &n);
            // TODO check we could write n bytes
            f_close(&fp);

            // keep LED on for at least 200ms
            sys_tick_wait_at_least(start_tick, 200);
            led_state(PYB_LED_R2, 0);
        } else if (res == FR_OK) {
            // mount sucessful
        } else {
            __fatal_error("could not access LFS");
        }
    }

    // make sure we have a /boot.py
    {
        FILINFO fno;
#if _USE_LFN
        fno.lfname = NULL;
        fno.lfsize = 0;
#endif
        FRESULT res = f_stat("0:/boot.py", &fno);
        if (res == FR_OK) {
            if (fno.fattrib & AM_DIR) {
                // exists as a directory
                // TODO handle this case
                // see http://elm-chan.org/fsw/ff/img/app2.c for a "rm -rf" implementation
            } else {
                // exists as a file, good!
            }
        } else {
            // doesn't exist, create fresh file

            // LED on to indicate creation of boot.py
            led_state(PYB_LED_R2, 1);
            uint32_t start_tick = HAL_GetTick();

            FIL fp;
            f_open(&fp, "0:/boot.py", FA_WRITE | FA_CREATE_ALWAYS);
            UINT n;
            f_write(&fp, fresh_boot_py, sizeof(fresh_boot_py) - 1 /* don't count null terminator */, &n);
            // TODO check we could write n bytes
            f_close(&fp);

            // keep LED on for at least 200ms
            sys_tick_wait_at_least(start_tick, 200);
            led_state(PYB_LED_R2, 0);
        }
    }

    // run /boot.py
    if (reset_mode == 1) {
        if (!pyexec_file("0:/boot.py")) {
            flash_error(4);
        }
    }

    // turn boot-up LEDs off
    led_state(2, 0);
    led_state(3, 0);
    led_state(4, 0);

#if defined(USE_DEVICE_MODE)
    usb_storage_medium_t usb_medium = USB_STORAGE_MEDIUM_FLASH;
#endif

#if MICROPY_HW_HAS_SDCARD
    // if an SD card is present then mount it on 1:/
    if (reset_mode == 1 && sdcard_is_present()) {
        FRESULT res = f_mount(&fatfs1, "1:", 1);
        if (res != FR_OK) {
            printf("[SD] could not mount SD card\n");
        } else {
            if (first_soft_reset) {
                // use SD card as medium for the USB MSD
#if defined(USE_DEVICE_MODE)
                usb_medium = USB_STORAGE_MEDIUM_SDCARD;
#endif
            }
        }
    }
#else
    // Get rid of compiler warning if no SDCARD is configured.
    (void)first_soft_reset;
#endif

#if defined(USE_HOST_MODE)
    // USB host
    pyb_usb_host_init();
#elif defined(USE_DEVICE_MODE)
    // USB device
    if (reset_mode == 1) {
        usb_device_mode_t usb_mode = USB_DEVICE_MODE_CDC_MSC;
        if (pyb_config_usb_mode != MP_OBJ_NULL) {
            if (strcmp(mp_obj_str_get_str(pyb_config_usb_mode), "CDC+HID") == 0) {
                usb_mode = USB_DEVICE_MODE_CDC_HID;
            }
        }
        pyb_usb_dev_init(usb_mode, usb_medium);
    } else {
        pyb_usb_dev_init(USB_DEVICE_MODE_CDC_MSC, usb_medium);
    }
#endif

#if MICROPY_HW_ENABLE_RNG
    // RNG
    rng_init();
#endif

    // I2C
    i2c_init();

#if MICROPY_HW_HAS_MMA7660
    // MMA accel: init and reset
    accel_init();
#endif

#if MICROPY_HW_ENABLE_SERVO
    // servo
    servo_init();
#endif

#if 0
#if MICROPY_HW_ENABLE_TIMER
    // timer
    timer_init();
#endif
#endif

#if MICROPY_HW_ENABLE_DAC
    // DAC
    dac_init();
#endif

    // run main script
    if (reset_mode == 1) {
        vstr_t *vstr = vstr_new();
        vstr_add_str(vstr, "0:/");
        if (pyb_config_source_dir == MP_OBJ_NULL) {
            vstr_add_str(vstr, "src");
        } else {
            vstr_add_str(vstr, mp_obj_str_get_str(pyb_config_source_dir));
        }
        vstr_add_char(vstr, '/');
        if (pyb_config_main == MP_OBJ_NULL) {
            vstr_add_str(vstr, "main.py");
        } else {
            vstr_add_str(vstr, mp_obj_str_get_str(pyb_config_main));
        }
        if (!pyexec_file(vstr_str(vstr))) {
            flash_error(3);
        }
        vstr_free(vstr);
    }

#if 0
#if MICROPY_HW_HAS_WLAN
    // wifi
    pyb_wlan_init();
    pyb_wlan_start();
#endif
#endif

    // enter REPL
    // REPL mode can change, or it can request a soft reset
    for (;;) {
        if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
            if (pyexec_raw_repl() != 0) {
                break;
            }
        } else {
            if (pyexec_friendly_repl() != 0) {
                break;
            }
        }
    }

    printf("PYB: sync filesystems\n");
    storage_flush();

    printf("PYB: soft reboot\n");

    first_soft_reset = false;
    goto soft_reset;
}
Exemplo n.º 18
0
int main(void)
{
  unsigned int score, high_score;
  char score_s[MAXDIGITNUM+1];

  ROMEMU();
  USE_UI();
  timer_pri_set(0,1);
  random_init();
  lcd_init();
  key_init();
  timer_init();
  sound_init();
  timer_set(1,100);
  timer_start(1);
  ENINT();

  lcd_cursor(0,0);
  lcd_printstr(" 0:Game Start   ");
  lcd_cursor(0,1);
  lcd_printstr(" *:High Score   ");
  high_score = 0;

  lcd_cursor(0,0);

  while(1)
  {
    if (key_check(10) == KEYON){     /* *キー:ハイスコア表示 */
      lcd_cursor(0,0);                   /* LCD にハイスコア表示 */
      lcd_printstr(" High Score is  ");
      lcd_cursor(0,1);
      lcd_printstr("                ");
      lcd_cursor(0,1);
      lcd_printstr(ntos(high_score,score_s));
    }
    if (key_check(10) == KEYOFF){
      lcd_cursor(0,0);
      lcd_printstr(" 0:Game Start   ");
      lcd_cursor(0,1);
      lcd_printstr(" *:High Score   ");
    }
    if (key_check(11) == KEYON){      /* 0キー:ゲームスタート */
	  zanki = 5;
      lcd_cursor(0,0);                   /* LCD に操作方法表示 */
      lcd_printstr("*:Sight  0:Trig.");
      score = game_start();              /* ゲームスタート */
      lcd_cursor(0,1);                   /* 得点表示欄のクリア */
      lcd_printstr("                ");
      if (score > high_score){           /* ハイスコアのとき */
        high_score = score;                /* ハイスコア登録 */
        lcd_cursor(0,0);                   /* ハイスコア表示 */
        lcd_printstr(" High Score !!! ");
        lcd_cursor(0,1);
        lcd_printstr(ntos(high_score,score_s));
      } else {                           /* ハイスコアでないとき*/
        lcd_cursor(0,0);                   /* スコアを表示 */
        lcd_printstr(" Your Score ... ");
        lcd_cursor(0,1);
        lcd_printstr(ntos(score,score_s));
      }
      n_time = 0;
      while (n_time < WAITFEWSEC);       /* 得点表示後にちょっと待つ */
      lcd_cursor(0,0);                     /* LCD にメッセージ表示 */
      lcd_printstr(" 0:Game Start   ");
      lcd_cursor(0,1);
      lcd_printstr(" *:High Score   ");
    }
  }
}
Exemplo n.º 19
0
void* main(void)
{
    int i;
    int btn;
    int num_partitions;
    int crc32;
    char sector[512];
    struct partinfo pinfo;

    system_init();
    kernel_init();
    lcd_init();
    font_init();
    button_init();
    i2c_init();
    backlight_hw_on();
    
    lcd_set_foreground(LCD_WHITE);
    lcd_set_background(LCD_BLACK);
    lcd_clear_display();

    btn = button_read_device();
    verbose = true;

    lcd_setfont(FONT_SYSFIXED);

    printf("Rockbox e200R installer");
    printf("Version: %s", rbversion);
    printf(MODEL_NAME);
    printf("");

    i=storage_init();
    filesystem_init();
    num_partitions = disk_mount_all();

    if (num_partitions<=0)
    {
        error(EDISK, num_partitions, true);
    }

    disk_partinfo(1, &pinfo);

#if 0 /* not needed in release builds */
    printf("--- Partition info ---");
    printf("start: %x", pinfo.start);
    printf("size: %x", pinfo.size);
    printf("type: %x", pinfo.type);
    printf("reading: %x", (START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK)*512);
#endif

    storage_read_sectors(pinfo.start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK,
                         1 , sector);
    crc32 = chksum_crc32 (sector, 512);

#if 0 /* not needed in release builds */
    printf("--- Hack Status ---");
    printf("Sector checksum: %x", crc32);
#endif

    if (crc32 == PATCHED_CRC32)
    {
        /* Bootloader already patched */
        printf("Already unlocked");
        printf("Proceed to Step 2");
    } else if ((crc32 == KNOWN_CRC32) && 
                !memcmp(&sector[HACK_OFFSET], knownBytes, 
                sizeof(knownBytes)/sizeof(*knownBytes)))
    {
        /* E200R bootloader detected - patch it */
        memcpy(&sector[HACK_OFFSET], changedBytes,
                sizeof(changedBytes)/sizeof(*changedBytes));
        storage_write_sectors(
                        pinfo.start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK,
                        1 , sector);
        printf("Firmware unlocked");
        printf("Proceed to Step 2");
    } else if (is_e200(crc32))
    {
        printf("Vanilla E200 detected!");
        printf("Please install using");
        printf("Sansapatcher");
    }
    else
    {
        printf("Unknown bootloader");
        printf("Rockbox installer cannot");
        printf("continue");
    }

    /* Turn button lights off */
    GPIOG_OUTPUT_VAL &=~0x80;

    printf("");

    if (button_hold())
        printf("Release Hold and");

    printf("Press any key to shutdown");

    while(button_read_device() == BUTTON_NONE);

    power_off();

    return NULL;
}
Exemplo n.º 20
0
void start_armboot (void)
{
	init_fnc_t **init_fnc_ptr;
	char *s;
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
	unsigned long addr;
#endif

	/* Pointer is writable since we allocated a register for it */
	gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t));
	/* compiler optimization barrier needed for GCC >= 3.4 */
	__asm__ __volatile__("": : :"memory");

	memset ((void*)gd, 0, sizeof (gd_t));
	gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
	memset (gd->bd, 0, sizeof (bd_t));

	gd->flags |= GD_FLG_RELOC;

	monitor_flash_len = _bss_start - _armboot_start;

	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
		if ((*init_fnc_ptr)() != 0) {
			hang ();
		}
	}

	/* armboot_start is defined in the board-specific linker script */
	mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN,
			CONFIG_SYS_MALLOC_LEN);

#ifndef CONFIG_SYS_NO_FLASH
	/* configure available FLASH banks */
	display_flash_config (flash_init ());
#endif /* CONFIG_SYS_NO_FLASH */

#ifdef CONFIG_VFD
#	ifndef PAGE_SIZE
#	  define PAGE_SIZE 4096
#	endif
	/*
	 * reserve memory for VFD display (always full pages)
	 */
	/* bss_end is defined in the board-specific linker script */
	addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
	vfd_setmem (addr);
	gd->fb_base = addr;
#endif /* CONFIG_VFD */

#ifdef CONFIG_LCD
	/* board init may have inited fb_base */
	if (!gd->fb_base) {
#		ifndef PAGE_SIZE
#		  define PAGE_SIZE 4096
#		endif
		/*
		 * reserve memory for LCD display (always full pages)
		 */
		/* bss_end is defined in the board-specific linker script */
		addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
		lcd_setmem (addr);
		gd->fb_base = addr;
	}
#endif /* CONFIG_LCD */

#if defined(CONFIG_CMD_NAND)
	puts ("NAND:  ");
	nand_init();		/* go init the NAND */
#endif

#if defined(CONFIG_CMD_ONENAND)
	onenand_init();
#endif

#ifdef CONFIG_HAS_DATAFLASH
	AT91F_DataflashInit();
	dataflash_print_info();
#endif

#ifdef CONFIG_GENERIC_MMC
	puts ("MMC:   ");
	mmc_initialize (gd->bd);
#endif

	/* initialize environment */
	env_relocate ();

#ifdef CONFIG_VFD
	/* must do this after the framebuffer is allocated */
	drv_vfd_init();
#endif /* CONFIG_VFD */

#ifdef CONFIG_SERIAL_MULTI
	serial_initialize();
#endif

	/* IP Address */
	gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");

	stdio_init ();	/* get the devices list going. */

	jumptable_init ();

#if defined(CONFIG_API)
	/* Initialize API */
	api_init ();
#endif

	console_init_r ();	/* fully init console as a device */

#if defined(CONFIG_ARCH_MISC_INIT)
	/* miscellaneous arch dependent initialisations */
	arch_misc_init ();
#endif
#if defined(CONFIG_MISC_INIT_R)
	/* miscellaneous platform dependent initialisations */
	misc_init_r ();
#endif
#if defined(CONFIG_CMD_KGDB)
	puts("KGDB:  ");
	kgdb_init();
#endif

	/* enable exceptions */
	enable_interrupts ();

	/* Perform network card initialisation if necessary */
#ifdef CONFIG_DRIVER_TI_EMAC
	/* XXX: this needs to be moved to board init */
extern void davinci_eth_set_mac_addr (const u_int8_t *addr);
	if (getenv ("ethaddr")) {
		uchar enetaddr[6];
		eth_getenv_enetaddr("ethaddr", enetaddr);
		davinci_eth_set_mac_addr(enetaddr);
	}
#endif

#if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
	/* XXX: this needs to be moved to board init */
	if (getenv ("ethaddr")) {
		uchar enetaddr[6];
		eth_getenv_enetaddr("ethaddr", enetaddr);
		smc_set_mac_addr(enetaddr);
	}
#endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */

	/* Initialize from environment */
	if ((s = getenv ("loadaddr")) != NULL) {
		load_addr = simple_strtoul (s, NULL, 16);
	}
#if defined(CONFIG_CMD_NET)
	if ((s = getenv ("bootfile")) != NULL) {
		copy_filename (BootFile, s, sizeof (BootFile));
	}
#endif

#ifdef BOARD_LATE_INIT
	board_late_init ();
#endif

#ifdef CONFIG_BITBANGMII
	bb_miiphy_init();
#endif
#if defined(CONFIG_CMD_NET)
#if defined(CONFIG_NET_MULTI)
	puts ("Net:   ");
#endif
	eth_initialize(gd->bd);
#if defined(CONFIG_RESET_PHY_R)
	debug ("Reset Ethernet PHY\n");
	reset_phy();
#endif
#endif
#ifdef	CONFIG_LCD_AML
	lcd_init();
#endif
    printf("Dcache status %d\n",dcache_status());
    printf("Icache status %d\n",icache_status());
	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;) {
		main_loop ();
	}

	/* NOTREACHED - no way out of command loop except booting */
}
Exemplo n.º 21
0
// *************************************************************************************************
// @fn          init_application
// @brief       Initialize the microcontroller.
// @param       none
// @return      none
// *************************************************************************************************
void init_application(void)
{
	volatile unsigned char *ptr;
	  
	// ---------------------------------------------------------------------
	// Enable watchdog
	
	// Watchdog triggers after 16 seconds when not cleared
#ifdef USE_WATCHDOG		
	WDTCTL = WDTPW + WDTIS__512K + WDTSSEL__ACLK;
#else
	WDTCTL = WDTPW + WDTHOLD;
#endif
	
	// ---------------------------------------------------------------------
	// Configure PMM
	SetVCore(3);
	
	// Set global high power request enable
	PMMCTL0_H  = 0xA5;
	PMMCTL0_L |= PMMHPMRE;
	PMMCTL0_H  = 0x00;	

	// ---------------------------------------------------------------------
	// Enable 32kHz ACLK	
	P5SEL |= 0x03;                            // Select XIN, XOUT on P5.0 and P5.1
	UCSCTL6 &= ~XT1OFF;        				  // XT1 On, Highest drive strength
	UCSCTL6 |= XCAP_3;                        // Internal load cap

	UCSCTL3 = SELA__XT1CLK;                   // Select XT1 as FLL reference
	UCSCTL4 = SELA__XT1CLK | SELS__DCOCLKDIV | SELM__DCOCLKDIV;      
	
	// ---------------------------------------------------------------------
	// Configure CPU clock for 12MHz
	_BIS_SR(SCG0);                  // Disable the FLL control loop
	UCSCTL0 = 0x0000;          // Set lowest possible DCOx, MODx
	UCSCTL1 = DCORSEL_5;       // Select suitable range
	UCSCTL2 = FLLD_1 + 0x16E;  // Set DCO Multiplier
	_BIC_SR(SCG0);                  // Enable the FLL control loop

    // Worst-case settling time for the DCO when the DCO range bits have been
    // changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
    // UG for optimization.
    // 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle
    __delay_cycles(250000);
  
	// Loop until XT1 & DCO stabilizes, use do-while to insure that 
	// body is executed at least once
	do
	{
        UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
		SFRIFG1 &= ~OFIFG;                      // Clear fault flags
	} while ((SFRIFG1 & OFIFG));	

	
	// ---------------------------------------------------------------------
	// Configure port mapping
	
	// Disable all interrupts
	__disable_interrupt();
	// Get write-access to port mapping registers:
	PMAPPWD = 0x02D52;
	// Allow reconfiguration during runtime:
	PMAPCTL = PMAPRECFG;

	// P2.7 = TA0CCR1A or TA1CCR0A output (buzzer output)
	ptr  = &P2MAP0;
	*(ptr+7) = PM_TA1CCR0A;
	P2OUT &= ~BIT7;
	P2DIR |= BIT7;

	// P1.5 = SPI MISO input
	ptr  = &P1MAP0;
	*(ptr+5) = PM_UCA0SOMI;
	// P1.6 = SPI MOSI output
	*(ptr+6) = PM_UCA0SIMO;
	// P1.7 = SPI CLK output
	*(ptr+7) = PM_UCA0CLK;

	// Disable write-access to port mapping registers:
	PMAPPWD = 0;
	// Re-enable all interrupts
	__enable_interrupt();
	
	// ---------------------------------------------------------------------
	// Configure ports

	// ---------------------------------------------------------------------
	// Reset radio core
	radio_reset();
	radio_powerdown();	
	
	// ---------------------------------------------------------------------
	// Init acceleration sensor
	as_init();
	
	// ---------------------------------------------------------------------
	// Init LCD
	lcd_init();
  
	// ---------------------------------------------------------------------
	// Init buttons
	init_buttons();

	// ---------------------------------------------------------------------
	// Configure Timer0 for use by the clock and delay functions
	Timer0_Init();
	
	// ---------------------------------------------------------------------
	// Init pressure sensor
	ps_init();
}
Exemplo n.º 22
0
int misc_init_r(void)
{
	lcd_init();

	return 0;
}
Exemplo n.º 23
0
int misc_init_r (void)
{
	unsigned char *duart0_mcr = (unsigned char *)((ulong)DUART0_BA + 4);
	unsigned char *duart1_mcr = (unsigned char *)((ulong)DUART1_BA + 4);
	unsigned short *lcd_contrast =
		(unsigned short *)((ulong)CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL + 4);
	unsigned short *lcd_backlight =
		(unsigned short *)((ulong)CONFIG_SYS_FPGA_BASE_ADDR + CONFIG_SYS_FPGA_CTRL + 6);
	unsigned char *dst;
	ulong len = sizeof(fpgadata);
	int status;
	int index;
	int i;
	char *str;

	dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
	if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
		printf ("GUNZIP ERROR - must RESET board to recover\n");
		do_reset (NULL, 0, 0, NULL);
	}

	status = fpga_boot(dst, len);
	if (status != 0) {
		printf("\nFPGA: Booting failed ");
		switch (status) {
		case ERROR_FPGA_PRG_INIT_LOW:
			printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
			break;
		case ERROR_FPGA_PRG_INIT_HIGH:
			printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
			break;
		case ERROR_FPGA_PRG_DONE:
			printf("(Timeout: DONE not high after programming FPGA)\n ");
			break;
		}

		/* display infos on fpgaimage */
		index = 15;
		for (i=0; i<4; i++) {
			len = dst[index];
			printf("FPGA: %s\n", &(dst[index+1]));
			index += len+3;
		}
		putc ('\n');
		/* delayed reboot */
		for (i=20; i>0; i--) {
			printf("Rebooting in %2d seconds \r",i);
			for (index=0;index<1000;index++)
				udelay(1000);
		}
		putc ('\n');
		do_reset(NULL, 0, 0, NULL);
	}

	puts("FPGA:  ");

	/* display infos on fpgaimage */
	index = 15;
	for (i=0; i<4; i++) {
		len = dst[index];
		printf("%s ", &(dst[index+1]));
		index += len+3;
	}
	putc ('\n');

	free(dst);

	/*
	 * Reset FPGA via FPGA_INIT pin
	 */
	out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) | FPGA_INIT); /* setup FPGA_INIT as output */
	out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~FPGA_INIT);  /* reset low */
	udelay(1000); /* wait 1ms */
	out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | FPGA_INIT);   /* reset high */
	udelay(1000); /* wait 1ms */

	/*
	 * Reset external DUARTs
	 */
	out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CONFIG_SYS_DUART_RST); /* set reset to high */
	udelay(10); /* wait 10us */
	out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~CONFIG_SYS_DUART_RST); /* set reset to low */
	udelay(1000); /* wait 1ms */

	/*
	 * Set NAND-FLASH GPIO signals to default
	 */
	out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) & ~(CONFIG_SYS_NAND_CLE | CONFIG_SYS_NAND_ALE));
	out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CONFIG_SYS_NAND_CE);

	/*
	 * Setup EEPROM write protection
	 */
	out_be32((void*)GPIO0_OR, in_be32((void*)GPIO0_OR) | CONFIG_SYS_EEPROM_WP);
	out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) | CONFIG_SYS_EEPROM_WP);

	/*
	 * Enable interrupts in exar duart mcr[3]
	 */
	out_8(duart0_mcr, 0x08);
	out_8(duart1_mcr, 0x08);

	/*
	 * Init lcd interface and display logo
	 */
	str = getenv("bd_type");
	if (strcmp(str, "voh405_bw") == 0) {
		lcd_setup(0, 1);
		lcd_init((uchar *)CONFIG_SYS_LCD_SMALL_REG, (uchar *)CONFIG_SYS_LCD_SMALL_MEM,
			 regs_13704_320_240_4bpp,
			 sizeof(regs_13704_320_240_4bpp)/sizeof(regs_13704_320_240_4bpp[0]),
			 logo_bmp_320, sizeof(logo_bmp_320));
	} else if (strcmp(str, "voh405_bwbw") == 0) {
		lcd_setup(0, 1);
		lcd_init((uchar *)CONFIG_SYS_LCD_SMALL_REG, (uchar *)CONFIG_SYS_LCD_SMALL_MEM,
			 regs_13704_320_240_4bpp,
			 sizeof(regs_13704_320_240_4bpp)/sizeof(regs_13704_320_240_4bpp[0]),
			 logo_bmp_320, sizeof(logo_bmp_320));
		lcd_setup(1, 1);
		lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM,
			 regs_13806_320_240_4bpp,
			 sizeof(regs_13806_320_240_4bpp)/sizeof(regs_13806_320_240_4bpp[0]),
			 logo_bmp_320, sizeof(logo_bmp_320));
	} else if (strcmp(str, "voh405_bwc") == 0) {
		lcd_setup(0, 1);
		lcd_init((uchar *)CONFIG_SYS_LCD_SMALL_REG, (uchar *)CONFIG_SYS_LCD_SMALL_MEM,
			 regs_13704_320_240_4bpp,
			 sizeof(regs_13704_320_240_4bpp)/sizeof(regs_13704_320_240_4bpp[0]),
			 logo_bmp_320, sizeof(logo_bmp_320));
		lcd_setup(1, 0);
		lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM,
			 regs_13806_640_480_16bpp,
			 sizeof(regs_13806_640_480_16bpp)/sizeof(regs_13806_640_480_16bpp[0]),
			 logo_bmp_640, sizeof(logo_bmp_640));
	} else {
		printf("Unsupported bd_type defined (%s) -> No display configured!\n", str);
		return 0;
	}

	/*
	 * Set invert bit in small lcd controller
	 */
	out_8((unsigned char *)(CONFIG_SYS_LCD_SMALL_REG + 2),
	      in_8((unsigned char *)(CONFIG_SYS_LCD_SMALL_REG + 2)) | 0x01);

	/*
	 * Set default contrast voltage on epson vga controller
	 */
	out_be16(lcd_contrast, 0x4646);

	/*
	 * Enable backlight
	 */
	out_be16(lcd_backlight, 0xffff);

	/*
	 * Enable external I2C bus
	 */
	out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) | CONFIG_SYS_IIC_ON);

	return (0);
}
Exemplo n.º 24
0
void main() 
{
  unsigned char i;
  unsigned char tmp;
  unsigned int tmpi;

  char str[6];

  ADCON1=0x06;
  TRISA=0xFF;
  TRISB=0x00;
  TRISC=0x01;
  TRISD=0x00;
  TRISE=0x00;

  lcd_init();
  i2c_init();
  serial_init();
  adc_init();

//testa caracter especial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste LCD"));

  lcd_cmd(0x40);//endereço

  lcd_dat(0x11);
  lcd_dat(0x19);
  lcd_dat(0x15);
  lcd_dat(0x13);
  lcd_dat(0x13);
  lcd_dat(0x15);
  lcd_dat(0x19);
  lcd_dat(0x11);

  lcd_dat(0x0E);
  lcd_dat(0x11);
  lcd_dat(0x0E);
  lcd_dat(0x05);
  lcd_dat(0x0E);
  lcd_dat(0x14);
  lcd_dat(0x0A);
  lcd_dat(0x11);


  lcd_cmd(L_L2);

  for(i=0;i<16;i++)
  {
    lcd_dat(i%2);
    atraso_ms(100);
  }

//teste lcd
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste LCD"));
  
  for(i=32;i<128;i++)
  {
    if((i%16) == 0)lcd_cmd(L_L2);
    lcd_dat(i);
    atraso_ms(50);
  }

  atraso_ms(100);
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste LCD"));
  lcd_cmd(L_L2);
  lcd_str(rom2ram("       Ok"));
  atraso_ms(500);




//testa display 7s

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste 7 Seg"));


    PORTBbits.RB7=1;
    for(i=0;i<4;i++)
    {
      PORTB=0x10<<i;  
      for(tmp=0;tmp<16;tmp++)
      {
        PORTD=display7s(tmp);	 
        atraso_ms(200);	
      }
    }

  PORTD=0;

//testa LEDs

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1+3);
  lcd_str(rom2ram("Teste LEDs"));

  for(tmp=0;tmp<3;tmp++)
    {
      for(i=1;i < 16;i=i*2)
      { 
        PORTB=i;
        atraso_ms(200);  
      }
    }
  PORTB=0;
  for(i=0;i<4;i++)
  {
    PORTB^=0x0F;
    atraso_ms(200);
  }  

//testa chaves


  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("  Teste Chaves"));

  tmp=0;

  while((tmp & 0x0F) != 0x0F)
  {
    TRISB=0x0F;

    if(PORTBbits.RB0 == 0)
    {
      tmp|=0x01;
    }
    if(PORTBbits.RB1 == 0)
    {
      tmp|=0x02;
    }
    if(PORTBbits.RB2 == 0)
    {
      tmp|=0x04;
    }
    if(PORTBbits.RB3 == 0)
    {
      tmp|=0x08;
    }
    
    TRISB=0x00;
    PORTB=tmp;
    atraso_ms(10);
  }
  PORTB=0; 


//teste EEPROM INT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste EEPROM INT"));
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(rom2ram(" (s=S1 n=S2) ?"));

  TRISB=0x03;

  while(PORTBbits.RB0 && PORTBbits.RB1);

  if(PORTBbits.RB0 == 0)
  {
    tmp=e2prom_r(10);
    lcd_dat(tmp);

    e2prom_w(10,0xA5);
    e2prom_w(10,0x5A);
    i=e2prom_r(10);

    e2prom_w(10,tmp);

    lcd_cmd(L_CLR);
    lcd_cmd(L_L1);
    lcd_str(rom2ram("Teste EEPROM INT"));
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str(rom2ram("       OK"));
    else
      lcd_str(rom2ram("      ERRO"));

    atraso_ms(1000);
  }
  else
  {
    while(PORTBbits.RB1 == 0);
  }

  TRISB=0x00;
  PORTB=0;

//teste EEPROM EXT
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste EEPROM EXT"));
// testar ? 
  lcd_cmd(L_L2);
  lcd_str(rom2ram(" (s=S1 n=S2) ?"));

  TRISB=0x03;

  while(PORTBbits.RB0 && PORTBbits.RB1);

  if(PORTBbits.RB0 == 0)
  {
    tmp=e2pext_r(10);
    lcd_dat(tmp);

    e2pext_w(10,0xA5);
    e2pext_w(10,0x5A);
    i=e2pext_r(10);

    e2pext_w(10,tmp);

    lcd_cmd(L_CLR);
    lcd_cmd(L_L1);
    lcd_str(rom2ram("Teste EEPROM EXT"));
    lcd_cmd(L_L2);
    if(i == 0x5A) 
      lcd_str(rom2ram("       OK"));
    else
      lcd_str(rom2ram("      ERRO"));

    atraso_ms(1000);
  }
  else
  {
    while(PORTBbits.RB1 == 0);
  }

  TRISB=0x00;
  PORTB=0;

//teste serial
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste Serial TX"));
  lcd_cmd(L_L2+4);
  lcd_str(rom2ram("9600 8N1"));

  serial_tx_str(rom2ram("\r\n Picsimlab\r\n Teste Serial TX\r\n"));

  for(i=0;i<4;i++)
  {
    serial_tx(i+0x30);
    serial_tx_str(rom2ram(" PicsimLab\r\n"));
  }
  atraso_ms(1000);

  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("Teste Serial RX"));
  serial_tx_str(rom2ram(" Digite!\r\n"));
  for(i=0;i<32;i++)
  {
    if(!(i%16))
    {
       lcd_cmd(L_L2);
       serial_tx_str(rom2ram("\r\n"));
    }
    tmp=serial_rx(2000);
    lcd_dat(tmp);
    serial_tx(tmp);
  }
  atraso_ms(100);


//teste ADC
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram(" Teste ADC (P2)"));

  for(i=0; i< 200; i++)
  {
    tmp=((unsigned int)adc_amostra(1)*10)/204;
    lcd_cmd(L_L2+6);
    itoa(tmp,str); 
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('V');
    atraso_ms(10);
  }



//teste TEMP
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste TEMP"));

  for(i=0; i< 100; i++)
  {
    tmpi=((unsigned int) adc_amostra(0)*81)/100;
    lcd_cmd(L_L2+5);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');
    atraso_ms(10);
  }


//teste Aquecimento
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste AQUEC"));
  PORTCbits.RC2=1;
  for(i=0; i< 100; i++)
  {
    tmpi=((unsigned int) adc_amostra(0)*81)/100;
    lcd_cmd(L_L2+5);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');
    atraso_ms(10);
  }
  PORTCbits.RC2=0;


//teste Resfriamento
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("   Teste RESFR"));

//timer0 temporizador

 T0CONbits.T0CS=0;
 T0CONbits.PSA=0;
 T0CONbits.T08BIT=1;
 T0CONbits.T0PS0=0; // divide por 32
 T0CONbits.T0PS1=0;
 T0CONbits.T0PS2=1;
 T0CONbits.TMR0ON=1;

 INTCONbits.T0IE=1;

//T = 32x250x125 = 1segundo;

//timer1 contador
 T1CONbits.TMR1CS=1;
 T1CONbits.T1CKPS1=0;
 T1CONbits.T1CKPS0=0;


 INTCONbits.T0IF=0;
 TMR0H=0;
 TMR0L=6; //250
 cnt=125; 
 INTCONbits.GIE=1;

 TMR1H=0;
 TMR1L=0;
 T1CONbits.TMR1ON=1;

  PORTCbits.RC1=1;
  for(i=0; i< 150; i++)
  {
    tmpi=((unsigned int) adc_amostra(0)*81)/100;
    lcd_cmd(L_L2+2);
    itoa(tmpi,str);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(',');
    lcd_dat(str[4]);
    lcd_dat('C');

    lcd_cmd(L_L2+8);
    itoa(t1cont,str);
    lcd_dat(str[1]);
    lcd_dat(str[2]);
    lcd_dat(str[3]);
    lcd_dat(str[4]);
    lcd_dat('R');
    lcd_dat('P');
    lcd_dat('S');

    atraso_ms(10);
  }

  INTCONbits.GIE=0;
  PORTCbits.RC1=0;

//fim teste 
  lcd_cmd(L_CLR);
  lcd_cmd(L_L1);
  lcd_str(rom2ram("      Fim"));
  lcd_cmd(L_L2);
  lcd_str(rom2ram(" Pressione RST"));

  serial_tx_str(rom2ram("\r\n FIM!\r\n"));


   while(1);

}
Exemplo n.º 25
0
int main(void)
{
    char buffer[7];
    int  num=134;
    unsigned char i;
    
    
    DDRD &=~ (1 << PD2);        /* Pin PD2 input              */
    PORTD |= (1 << PD2);        /* Pin PD2 pull-up enabled    */


    /* initialize display, cursor off */
    lcd_init(LCD_DISP_ON_CURSOR_BLINK);

    for (;;) {                           /* loop forever */
        /* 
         * Test 1:  write text to display
         */

        /* clear display and home cursor */
        lcd_clrscr();
        
        /* put string to display (line 1) with linefeed */
        lcd_puts("LCD Test Line 1\n");

        /* cursor is now on second line, write second line */
        lcd_puts("Line 2");
        
        /* move cursor to position 8 on line 2 */
        lcd_gotoxy(7,1);  
        
        /* write single char to display */
        lcd_putc(':');
        
        /* wait until push button PD2 (INT0) is pressed */
        wait_until_key_pressed();
        
        
        /*
         * Test 2: use lcd_command() to turn on cursor
         */
        
        /* turn on cursor */
        lcd_command(LCD_DISP_ON_CURSOR);

        /* put string */
        lcd_puts( "CurOn");
        
        /* wait until push button PD2 (INT0) is pressed */
        wait_until_key_pressed();


        /*
         * Test 3: display shift
         */
        
        lcd_clrscr();     /* clear display home cursor */

        /* put string from program memory to display */
        lcd_puts_P( "Line 1 longer than 14 characters\n" );
        lcd_puts_P( "Line 2 longer than 14 characters" );
        
        /* move BOTH lines one position to the left */
        lcd_command(LCD_MOVE_DISP_LEFT);
        
        /* wait until push button PD2 (INT0) is pressed */
        wait_until_key_pressed();

        /* turn off cursor */
        lcd_command(LCD_DISP_ON);
        
        
        /*
         *   Test: Display integer values
         */
        
        lcd_clrscr();   /* clear display home cursor */
        
        /* convert interger into string */
        itoa( num , buffer, 10);
        
        /* put converted string to display */
        lcd_puts(buffer);
        
        /* wait until push button PD2 (INT0) is pressed */
        wait_until_key_pressed();
        
        
        /*
         *  Test: Display userdefined characters
         */

       lcd_clrscr();   /* clear display home cursor */
       
       lcd_puts("Copyright: ");
       
       /*
        * load two userdefined characters from program memory
        * into LCD controller CG RAM location 0 and 1
        */
       lcd_command(_BV(LCD_CGRAM));  /* set CG RAM start address 0 */
       for(i=0; i<16; i++)
       {
           lcd_data(pgm_read_byte_near(&copyRightChar[i]));
       }
       
       /* move cursor to position 0 on line 2 */
       /* Note: this switched back to DD RAM adresses */
       lcd_gotoxy(0,1);
       
       /* display user defined (c), built using two user defined chars */
       lcd_putc(0);
       lcd_putc(1);
       

       /* wait until push button PD2 (INT0) is pressed */
       wait_until_key_pressed();
              
    }
}
Exemplo n.º 26
0
void* main(void)
{
    char buf[256];
    int i;
    int btn;
    int rc;
    bool haveramos;
    bool button_was_held;
    struct partinfo* pinfo;
    unsigned short* identify_info;

    /* Check the button hold status as soon as possible - to 
       give the user maximum chance to turn it off in order to
       reset the settings in rockbox. */
    button_was_held = button_hold();

    system_init();
    kernel_init();

#ifndef HAVE_BACKLIGHT_INVERSION
    backlight_init(); /* Turns on the backlight */
#endif

    lcd_init();
    font_init();

#ifdef HAVE_LCD_COLOR
    lcd_set_foreground(LCD_WHITE);
    lcd_set_background(LCD_BLACK);
    lcd_clear_display();
#endif

#if 0
    /* ADC and button drivers are not yet implemented */
    adc_init();
    button_init();
#endif

    btn=key_pressed();

    /* Enable bootloader messages */
    if (btn==BUTTON_RIGHT)
        verbose = true;

    lcd_setfont(FONT_SYSFIXED);

    printf("Rockbox boot loader");
    printf("Version: " RBVERSION);
    printf("IPOD version: 0x%08x", IPOD_HW_REVISION);

    i=ata_init();
    if (i==0) {
      identify_info=ata_get_identify();
      /* Show model */
      for (i=0; i < 20; i++) {
        ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
      }
      buf[40]=0;
      for (i=39; i && buf[i]==' '; i--) {
        buf[i]=0;
      }
      printf(buf);
    } else {
      printf("ATA: %d", i);
    }

    disk_init();
    rc = disk_mount_all();
    if (rc<=0)
    {
        printf("No partition found");
        fatal_error();
    }

    pinfo = disk_partinfo(1);
    printf("Partition 1: 0x%02x %ld sectors", 
           pinfo->type, pinfo->size);

    if (button_was_held || (btn==BUTTON_MENU)) {
        /* If either the hold switch was on, or the Menu button was held, then 
           try the Apple firmware */

        printf("Loading original firmware...");
    
        /* First try an apple_os.ipod file on the FAT32 partition
           (either in .rockbox or the root) 
         */
    
        rc=load_firmware(loadbuffer, "apple_os.ipod", MAX_LOADSIZE);
    
        if (rc == EOK) {
            printf("apple_os.ipod loaded.");
            return (void*)DRAM_START;
        } else if (rc == EFILE_NOT_FOUND) {
            /* If apple_os.ipod doesn't exist, then check if there is an Apple 
               firmware image in RAM  */
            haveramos = (memcmp((void*)(DRAM_START+0x20),"portalplayer",12)==0);
            if (haveramos) {
                /* We have a copy of the retailos in RAM, lets just run it. */
                return (void*)DRAM_START;
            }
        } else if (rc < EFILE_NOT_FOUND) {
            printf("Error!");
            printf("Can't load apple_os.ipod:");
            printf(strerror(rc));
        }
        
        /* Everything failed - just loop forever */
        printf("No RetailOS detected");
        
    } else if (btn==BUTTON_PLAY) {
        printf("Loading Linux...");
        rc=load_raw_firmware(loadbuffer, "/linux.bin", MAX_LOADSIZE);
        if (rc < EOK) {
            printf("Error!");
            printf("Can't load linux.bin:");
            printf(strerror(rc));
        } else {
            return (void*)DRAM_START;
        }
    } else {
        printf("Loading Rockbox...");
        rc=load_firmware(loadbuffer, BOOTFILE, MAX_LOADSIZE);
        if (rc == EOK) {
            printf("Rockbox loaded.");
            return (void*)DRAM_START;
        } else if (rc == EFILE_NOT_FOUND) {
            /* if rockbox.ipod doesn't exist, then check if there is a Rockbox
               image in RAM  */
            haveramos = (memcmp((void*)(DRAM_START+0x20),"Rockbox\1",8)==0);
            if (haveramos) {
                /* We have a copy of Rockbox in RAM, lets just run it. */
                return (void*)DRAM_START;
            }
        }

        printf("Error!");
        printf("Can't load " BOOTFILE ": ");
        printf(strerror(rc));
    }
    
    /* If we get to here, then we haven't been able to load any firmware */
    fatal_error();
    
    /* We never get here, but keep gcc happy */
    return (void*)0;
}
Exemplo n.º 27
0
/*****************************************************************************
 * FUNCTION
 *  gdi_lcd_init
 * DESCRIPTION
 *  Init lcd
 * PARAMETERS
 *  void
 * RETURNS
 *  GDI_RESULT(?)
 *****************************************************************************/
void gdi_lcd_init(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    GDI_ENTER_CRITICAL_SECTION(gdi_lcd_init)
    S32 i = 0;

    memset(GDI_LCD_ARRAY, 0, sizeof(GDI_LCD_ARRAY));

    GDI_LCD_ARRAY[i].act_handle = GDI_LCD_MAIN_LCD_HANDLE;
    GDI_LCD_ARRAY[i].act_width = GDI_LCD_WIDTH;
    GDI_LCD_ARRAY[i].act_height = GDI_LCD_HEIGHT;
    GDI_LCD_ARRAY[i].act_layer_handle = GDI_LAYER_MAIN_BASE_LAYER_HANDLE;
    GDI_LCD_ARRAY[i].cf = gdi_get_color_format(DRV_MAINLCD_BIT_PER_PIXEL);
    GDI_LCD_ARRAY[i].is_freeze = FALSE;
    GDI_LCD_ARRAY[i].lcd_type = GDI_LCD_TYPE_LCD;
    GDI_LCD_ARRAY[i].bind_handle = GDI_NULL_HANDLE;
    GDI_LCD_ARRAY[i].rotate_value = GDI_LCD_LAYER_ROTATE_0;
    GDI_LCD_ARRAY[i].rotate_by_layer = FALSE;

    i++;
#ifdef __MMI_SUBLCD__
    GDI_LCD_ARRAY[i].act_handle = GDI_LCD_SUB_LCD_HANDLE;
    GDI_LCD_ARRAY[i].act_width = GDI_SUBLCD_WIDTH;
    GDI_LCD_ARRAY[i].act_height = GDI_SUBLCD_HEIGHT;
    GDI_LCD_ARRAY[i].act_layer_handle = GDI_LAYER_SUB_BASE_LAYER_HANDLE;
    GDI_LCD_ARRAY[i].cf = gdi_get_color_format(DRV_SUBLCD_BIT_PER_PIXEL);
    GDI_LCD_ARRAY[i].is_freeze = FALSE;
    GDI_LCD_ARRAY[i].lcd_type = GDI_LCD_TYPE_LCD;
    GDI_LCD_ARRAY[i].bind_handle = GDI_NULL_HANDLE;
    GDI_LCD_ARRAY[i].rotate_value = GDI_LCD_LAYER_ROTATE_0;
    GDI_LCD_ARRAY[i].rotate_by_layer = FALSE;
#endif /* __MMI_SUBLCD__ */ 
    i++;
#ifdef GDI_USING_TV_OUTPUT
    GDI_LCD_ARRAY[i].act_handle = GDI_LCD_TVOUT_HANDLE;
    GDI_LCD_ARRAY[i].act_width = 0;
    GDI_LCD_ARRAY[i].act_height = 0;
    GDI_LCD_ARRAY[i].act_layer_handle = 0;
    GDI_LCD_ARRAY[i].cf = GDI_COLOR_FORMAT_16;
    GDI_LCD_ARRAY[i].is_freeze = FALSE;
    GDI_LCD_ARRAY[i].lcd_type = GDI_LCD_TYPE_TVOUT;
    GDI_LCD_ARRAY[i].bind_handle = GDI_NULL_HANDLE;
    GDI_LCD_ARRAY[i].rotate_value = GDI_LCD_LAYER_ROTATE_0;
    GDI_LCD_ARRAY[i].rotate_by_layer = FALSE;
#endif /* GDI_USING_TV_OUTPUT */ 
    /* init LCD */

    lcd_init(MAIN_LCD, DRV_MAINLCD_INIT_COLOR);

    /* sub lcd supported */
#ifdef __MMI_SUBLCD__
    lcd_init(SUB_LCD, DRV_SUBLCD_INIT_COLOR);

#endif /* __MMI_SUBLCD__ */ 

    GDI_LCD = &GDI_LCD_ARRAY[0];

    GDI_EXIT_CRITICAL_SECTION(gdi_lcd_init)
}
Exemplo n.º 28
0
int main()
{
    const float katsayi = 5000.0 / 1024.0;
    unsigned char dereceTam, dereceOndalik;
    float miliVolt, derece, sicaklik;
    int santigrat;
    char sicaklikmesaj[11] = "SICAKLIK =\0";
    char ilkSatir[GENISLIK];
    char ikinciSatir[GENISLIK];
    char dusukmesaj[5] = "Dus:\0";
    unsigned char dusuk = 20;
    char yuksekmesaj[5] = "Yuk:\0";
    unsigned char yuksek = 30;
    

    lcd_init();     // LCD'yi hazırla

    TRISB = 0;
    TRISA = 0b11110001;
	TRISE = 0b111;

    // A0 analog giriş
    ADCON1 = 0b11111110;
    ADCON0 = 0x41;
    //  PORTB = 0b11111111;
    

    for (; ;) {
        ADCON0 = 0x45;
        while ((ADCON0 & 4) != 0);  // analoj dijital çevrim bitene kadar bekle
        sicaklik = ADRESH;
        sicaklik = 256 * sicaklik + ADRESL;
        miliVolt = sicaklik * katsayi;
        derece = miliVolt / 10.0;
        lcd_goto(0);
        dereceTam = (int) derece;
        dereceOndalik = (int) (10.0 * (derece - dereceTam));
        sprintf(ilkSatir, "%s %d.%dC", sicaklikmesaj, dereceTam, dereceOndalik);
        lcd_puts(ilkSatir);
        // alt satır
        lcd_goto(40);

        sprintf(ikinciSatir, "%s %2.2d %s %2.2d", dusukmesaj, dusuk, yuksekmesaj, yuksek);
        lcd_puts(ikinciSatir);

        if (SECIM == 1) {
            if (AZALT == 0) {
                if (dusuk > 0) {
                    dusuk--;
                }
            }
			
            if (ARTTIR == 0) {
                if (dusuk < 99) {
                    dusuk++;
                }
            }

        } else if (SECIM == 0) {
            if (AZALT == 0) {
                if (yuksek > 0) {
                    yuksek--;
                }
            }
            if (ARTTIR == 0) {
                if (yuksek < 99) {
                    yuksek++;
                }
            }
        }


        if (dereceTam < dusuk) {
                MAVILED ^= 1;
         } else if (dereceTam > yuksek) {
                KIRMIZILED ^= 1;
        } else {
            MAVILED = 0;
            KIRMIZILED = 0;
        }
        
        __delay_ms(250);

    }
}
Exemplo n.º 29
0
void main(void)
{
    unsigned char k,ADC_channel;
    char Menu_Index;
    unsigned int ADC_result;
    unsigned long Wait_set_time;
    unsigned char Update_time, temp_Dir;
    unsigned char LcdContrast;
    PSD8xx_reg.VM |= 0x80;                              //Enable peripheral I/O
    timer0_init(); 
    Turbo_ADC_Init(7);
    P4_0=0;
    lcd_init();                 
    printf("DK3300 Demo V0.9\n"
           "STMicroelectric");
    delay_1sec();
    delay_1sec();
    lcd_init();                 
    printf("Turn Encoder R/L\n"
           "Press to Select");
    delay_1sec();
    delay_1sec();
    delay_1sec();
    //-----Initiate PB[4] as MCU input for encoder (PB[2,3] as logic input)-------------
    PSD8xx_reg.CONTROL_B&=0xEF;     // MCU IO/Address OUT: mode 
    PSD8xx_reg.DRIVE_B&=0xEF;       // OpenDrain & SlewRate control
    PSD8xx_reg.DIRECTION_B|=0x10;
    PSD8xx_reg.DATAOUT_B|=0x10;
    PSD8xx_reg.DIRECTION_B&=0xEF;   // IN direction
    //-----Waiting user select a demo to run-----------------------------------------
    //  use OMC_AB[0,1] as a 2-bit counter to identify running of Encoder
    //  use OMC_AB[2] as a running direction indication of Encoder
    //-------------------------------------------------------------------------------
    Menu_Index=0;
    PSD8xx_reg.OMC_AB&=0xF8;
    PSD8xx_reg.OMC_AB|=0x04;
    Show_Menu (Menu_Index);
    while((PSD8xx_reg.DATAIN_B&0x10)!=0)
    {
        temp_Dir=Polling_Encoder();
        if(temp_Dir==2)
        {
            Menu_Index++;
            if(Menu_Index==4)Menu_Index=0;
            Show_Menu (Menu_Index);
        }
        else if(temp_Dir==1)
        {
            Menu_Index--;
            if(Menu_Index==-1)Menu_Index=3;
            Show_Menu (Menu_Index);
        }
        PSD8xx_reg.DIRECTION_B|=0x10;
        PSD8xx_reg.DATAOUT_B|=0x10;
        PSD8xx_reg.DIRECTION_B&=0xEF;   // IN direction
    }
    //-----Running the demo code user selected----------------------------------------
    switch(Menu_Index)
    {
    case 0: 
    //============================ Demo0: PWM ADC ====================================

    PSD8xx_reg.CONTROL_B&=0xF1;     // MCU IO/Address OUT: mode 
    PSD8xx_reg.DRIVE_B&=0xF1;       // OpenDrain & SlewRate control
    PSD8xx_reg.DIRECTION_B|=0x07;
    PSD8xx_reg.DATAOUT_B&=0xF1;

    lcd_init();
    printf("PWM/ADC Demo\n" );
    ADC_channel=7;
    ACON |= 0x20;              // Enable ADC
    k=0;
    while(1){
        if (k == 0) k = 0xff;  // Fix over flow of 0H -> 0FFh
        if (k == 0xf) k = 0;   // Fix over flow from 0FFh -> 0Fh
        PWM_Mode1_Init(0, k);
        delay_1sec();          // wait for voltage to settle

        printf("PWM=%02bX",k);                  //display adc channel and adc value on LCD

        Turbo_ADC_Init(ADC_channel);            // Init & read ADC channel
        ADC_result=Turbo_ADC_Read(ADC_channel);
        printf(" ADC=%03X\r", ADC_result);      // display adc channel and adc value on LCD
        k = k + 0x10;
}
    break;
    case 1:
    //============================ Demo1: I2C RTC =====================================

        //---------------------- Check RTC tamper function -----------------------------------------
        lcd_init();
        Turbo_i2c_init();
        ST87_tamper_init();
        Turbo_SPI_Init();
        Tamper_check();

        //---------------------- Waiting user set time -----------------------------------------
        lcd_init();
        printf("Turn Encoder to\n"
               "set Date & Time" );
        delay_1sec();
        delay_1sec();
        Turbo_i2c_init();
        ST85_read();
        st85.second=i2c_rcv_buf[1];
        st85.minute=i2c_rcv_buf[2];
        st85.hour=i2c_rcv_buf[3];
        st85.day=i2c_rcv_buf[5];
        st85.month=i2c_rcv_buf[6];
        st85.year=i2c_rcv_buf[7];
        lcd_init();
        Menu_Index=0;
        PSD8xx_reg.OMC_AB&=0xF8;
        PSD8xx_reg.OMC_AB|=0x04;
        PSD8xx_reg.DIRECTION_B|=0x10;
        PSD8xx_reg.DATAOUT_B|=0x10;
        PSD8xx_reg.DIRECTION_B&=0xEF;   // IN direction
        Show_time(Menu_Index);
        Wait_set_time=0;
        Update_time=0;
        while((PSD8xx_reg.DATAIN_B&0x10)!=0)
        {
            temp_Dir=Polling_Encoder();
            if(temp_Dir==2) 
            {
                    Menu_Index++;
                    if(Menu_Index==6)Menu_Index=0;
                    Show_time(Menu_Index);
                    Update_time=1;
            }
            else if(temp_Dir==1)
            {
                Adjust_time(Menu_Index);
                Show_time(Menu_Index);
                Update_time=1;
            }
            PSD8xx_reg.DIRECTION_B|=0x10;
            PSD8xx_reg.DATAOUT_B|=0x10;
            PSD8xx_reg.DIRECTION_B&=0xEF;   // IN direction
            if(Update_time==0)Wait_set_time++;
            if(Wait_set_time>200000)break;
        }
        //----------------------------Save time into ST85-------------------------------------
        if(Update_time==1)
        {
            i2c_xmit_buf[2]=st85.second;
            i2c_xmit_buf[3]=st85.minute;
            i2c_xmit_buf[4]=st85.hour;
            i2c_xmit_buf[6]=st85.day;
            i2c_xmit_buf[7]=st85.month;
            i2c_xmit_buf[8]=st85.year;
            ST85_write();
        }
        else
        {
            ST85_config();
        }
        lcd_init();                                 // initialize LCD. 8 bits, 2 lines, 5x7 font,
        while (TRUE){
            ST85_read();                            // Read & Print ST85
            printf("Turbo I2C Demo\n"
                   "Time: %02bX:%02bX:%02bX\n",i2c_rcv_buf[3],i2c_rcv_buf[2],i2c_rcv_buf[1]);
            Tamper_check();
            if(Key_check()==3)
            {
                ST87_tamper_clear();
                lcd_clear();
                printf("Tamper record \n"
                       "has been removed!");
                delay_1sec();
                delay_1sec();
                lcd_clear();
            }
        }
    break;
    case 2:
    //============================ Demo2: PWMLCD =================================================
        lcd_init();                 
        printf("JP3:PWM\n"
               "JP14:Open\n");
        delay_1sec();
        while((PSD8xx_reg.DATAIN_B&0x10)!=0);
        lcd_clear();        
        printf("PWMLCD Demo\n");
        PwmInit_Mode1(0xC0);
        LcdContrast=0xC0;
        while (1)
        {

            temp_Dir=Polling_Encoder();
            if(temp_Dir==2)
            {
                if (++LcdContrast==0) LcdContrast=255;

            }
            else if(temp_Dir==1)
            {
                if (--LcdContrast==0xff) LcdContrast=0;
            }
            PwmSetDuty_Mode1(LcdContrast);
            printf("Brightness:%02bX\r",LcdContrast);
        }
    break;

    case 3:
    //============================ Demo3: IrDA ================================================
        lcd_init(); 
        printf("Under\n"
               "construction...");
        while(1);
    break;

    }
}
Exemplo n.º 30
0
int
main(int argc,char **argv) {
	int tty = 0;				/* Use stdin */
	struct termios sv_ios, ios;
	int rc, quit;
	char ch;

 	rc = tcgetattr(tty,&sv_ios);		/* Save current settings */
	assert(!rc);
	ios = sv_ios;
	cfmakeraw(&ios);			/* Make into a raw config */
	ios.c_oflag = OPOST | ONLCR;		/* Keep output editing */
	rc = tcsetattr(tty,TCSAFLUSH,&ios);	/* Put terminal into raw mode */
	assert(!rc);

	/*
	 * Initialize and configure GPIO pins :
	 */
	gpio_init();
	lcd_init(0);
	lcd_clear();
	lcd_puts("Interactive\nDemo:\n: ");

	/*
	 * Process single character commands :
	 */
	for ( quit=0; !quit; ) {
		/*
		 * Prompt and read input char :
		 */
		write(1,": ",2);
		rc = read(tty,&ch,1);
		if ( rc != 1 ) 
			break;
		if ( islower(ch) )
			ch = toupper(ch);

		write(1,&ch,1);
		write(1,"\n",1);

		/*
		 * Process command char :
		 */
		switch ( ch ) {
		case 'C' :
			puts("C - clear & home.");
			lcd_clear();
			break;
		case 'X' :
			puts("X - putc('X')");
			lcd_putc('X');
			break;
		case 'M' :
			puts("M - Multi-line test message.");
			lcd_puts("Line 1\nLine 2.\n");
			break;
		case 'U' :
			puts("U - Cursor up.");
			rc = lcd_gety() - 1;
			if ( rc < 0 )
				rc = lcd_lines - 1;
			lcd_sety(rc);
			break;
		case 'D' :
			puts("D - Cursor down.");
			rc = lcd_gety() + 1;
			if ( rc >= lcd_lines )
				rc = 0;
			lcd_sety(rc);
			break;
		case 'L' :
			puts("L - Cursor left.");
			rc = lcd_getx() - 1;
			if ( rc < 0 )
				rc = lcd_cols - 1;
			lcd_setx(rc);
			break;
		case 'R' :
			puts("R - Cursor Right.");
			rc = lcd_getx() + 1;
			if ( rc >= lcd_cols )
				rc = 0;
			lcd_setx(rc);
			break;
		case 'E' :
			puts("E - Clear to eol.");
			lcd_clrtoeol();
			break;
		case 'S' :
			puts("S - Clear to end of screen.");
			lcd_clrtobot();
			break;
		case '!' :
			puts("! - Reset.");
			lcd_init(0);
			lcd_puts("Reset:\n");
			break;
		case '+' :
			lcd_init(++lcd_vop);
			printf("+ - Reset: Vop = %02X\n",lcd_vop);
			lcd_printf("Vop = 0x%02X\n",lcd_vop);
			break;
		case '-' :
			lcd_init(--lcd_vop);
			printf("+ - Reset: Vop = %02X\n",lcd_vop);
			lcd_printf("Vop = 0x%02X\n",lcd_vop);
			break;
		case 'Q' :			/* Quit */
			quit = 1;
			break;
		case '?' :
		case 'H' :
			puts(	"Menu:\n"
				"C - clear & home cursor\n"
				"X - putc('X')\n"
				"M - Multi-line test\n"
				"U - cursor Up\n"
				"D - cursor Down\n"
				"L - cursor Left\n"
				"R - cursor Right\n"
				"E - clear to end of line\n"
				"S - clear to end screen\n"
				"! - Reset LCD\n"
				"+ - Reset with increased Vop\n"
				"- - Reset with decreased Vop\n"
				"Q - Quit\n");
			break;
		case '\r' :
		case '\n' :
		case ' ' :
			lcd_putc(ch);
			break;
		default :			/* Unsupported */
			printf("Use '?' for menu. (%c)\n",ch);
			lcd_putc(ch);
		}
	}

	puts("\nExit.");

	tcsetattr(tty,TCSAFLUSH,&sv_ios);	/* Restore terminal mode */
	return 0;
}