Ejemplo n.º 1
0
static int setup_openiboot() {
	arm_setup();
	mmu_setup();
	tasks_setup();
	setup_devices();

	LeaveCriticalSection();

#ifndef CONFIG_IPHONE_4
	clock_set_sdiv(0);

	aes_setup();

	nor_setup();
	syscfg_setup();
	images_setup();
	nvram_setup();

	lcd_setup();
	framebuffer_setup();

	audiohw_init();
#endif
    isMultitouchLoaded = 0;
	return 0;
}
Ejemplo n.º 2
0
static int setup_openiboot() {
	arm_setup();
	mmu_setup();
	tasks_setup();
	setup_devices();

	LeaveCriticalSection();

	clock_set_sdiv(0);

	aes_setup();

	nor_setup();
	images_setup();
	nvram_setup();

	lcd_setup();
	framebuffer_setup();

	audiohw_init();

	camera_setup();

	return 0;
}
Ejemplo n.º 3
0
void lcd_writebuffer()
{
	lcd_setup();
	for (int i=0; i<LCD_LINE_LENGTH; i++) _lcd_write(1,charTable[lcd_line_1[i]]);
	
	_lcd_write(0,0b11000000);
	for (int i=0; i<LCD_LINE_LENGTH; i++) _lcd_write(1,charTable[lcd_line_2[i]]);
}
Ejemplo n.º 4
0
Archivo: lcd.c Proyecto: onivan/jazda
int main(void) {
    uint8_t stamp; // uninitialized - the actual value at start doesn't matter
    lcd_setup();
    lcd_init();
    for (;;stamp+=7) {
        _delay_ms(20);
        send_raw_byte(stamp, true);
    }
}
void main(void) {
    /* put your own code here */
    unsigned int res = 8;

    float butter_feedback[] = {-1.7786f, 0.8008f};                        // float butterworth A scalars
    float butter_feedforward[] = {0.0055427, 0.011085, 0.0055427};        // float butterworth B scalars

    long butter_feedbackF[] = {-116562, 52481};                          // scaling factor Q16.16
    long butter_feedforwardF[] = {363, 726, 363};                        // scaling factor Q16.16


    SYNR = 2;                 // 24mHz clock
    REFDV = 0;
    while (!(CRGFLG&0x08)) {};
    CLKSEL |= 0x80;

    RTICTL = 0b01110101;     // every 50ms
    CRGINT = 0b10000000;

    TSCR1 = 0x80;            // set up MT
    TSCR2 = 0x82;

    atd0_powerOn();              // Powers on ATD module 0
    atd0_setFFC(1);              // set fast flag clearing on/off
    atd0_setLength(1);           // sets conversion sequence length of ATD module 0
    atd0_setFifo(0);             // turns FIFO mode on or off (1/0)
    atd0_setResolution(res);     // sets ATD module 0 resolution to 8/10bit
    atd0_setJustification('r');  // 'L' for left, 'R for right
    atd0_setScan(1);             // sets ATD Module 0 SCAN bit on/off (1/0)
    atd0_setMulti(0);            // sets ATD Module 0 MULT bit on/off (1/0)
    atd0_setStart(2);            // sets starting ch

    butterworth_2pole_initF(&butterF, butter_feedbackF, butter_feedforwardF);
    butterworth_2pole_init(&butter, butter_feedback, butter_feedforward);

    EnableInterrupts;

    lcd_setup();     // set up the LCD to write

    for(;;) {

        if(distance1 > FAR)
        {
            motor_stepForward(1,1,600);
        }

        //val = atd0_readChX(0);
        //sliding_window_50_put(&slide, val);
        //butterworth_2pole_put(&butter, val);
        _FEED_COP(); /* feeds the dog */
    } /* loop forever */
    /* please make sure that you never leave main */
}
Ejemplo n.º 6
0
static void lcd_task(void *params)
{
    LcdMessage msg;
    const char *string;
    const char **bitmaps;

    // Initialise the hardware.  This uses delays so must not be called prior
    // to the scheduler being started.
    lcd_setup();

    while (TRUE) {
        // Wait for a message to arrive that requires displaying
        while (queue_receive(lcd_queue, &msg, PORT_MAX_DELAY) != TRUE);

        switch (msg.type) {
        case LCD_MESSAGE_CLEAR:
            lcd_command(LCD_CLEAR_DISPLAY_CMD);
            break;

        case LCD_MESSAGE_PUT_STRING:
            lcd_goto(msg.row, msg.offset);
            string = msg.data;
            if (msg.length < 0) {
                while (*string) {
                    lcd_data(*string++);
                }
            } else {
                while (msg.length--) {
                    lcd_data(*string++);
                }
            }
            break;

        case LCD_MESSAGE_SET_CUSTOM_CHARS:
            lcd_command(LCD_CUSTOM_CHARS_CMD + msg.offset);
            bitmaps = (const char **) msg.data;
            while (msg.length--) {
                lcd_data(*bitmaps[0]);
                lcd_data(*bitmaps[1]);
                lcd_data(*bitmaps[2]);
                lcd_data(*bitmaps[3]);
                lcd_data(*bitmaps[4]);
                lcd_data(*bitmaps[5]);
                lcd_data(*bitmaps[6]);
                lcd_data(*bitmaps[7]);
                bitmaps++;
            }
            break;
        }
    }
}
void main(void) {
  /* put your own code here */
  unsigned int res = 10;
  unsigned int i, j, val;

    
  SYNR = 2;                    // 24mHz clock
  REFDV = 0;
  while (!(CRGFLG&0x08)){};
  CLKSEL |= 0x80;
  
  RTICTL = 0b01110101;         // rti every 50ms
  CRGINT = 0b10000000;

  atd0_powerOn();              // Powers on ATD module 0
  atd0_setFFC(1);              // set fast flag clearing on/off
  atd0_setLength(1);           // sets conversion sequence length of ATD module 0
  atd0_setFifo(0);             // turns FIFO mode on or off (1/0)
  atd0_setResolution(res);     // sets ATD module 0 resolution to 8/10bit
  atd0_setJustification('r');  // 'L' for left, 'R for right
  atd0_setScan(1);             // sets ATD Module 0 SCAN bit on/off (1/0)
  atd0_setMulti(0);            // sets ATD Module 0 MULT bit on/off (1/0)
  atd0_setStart(2);            // sets starting ch
  
	EnableInterrupts;
	
  lcd_setup();                 // sets up LCD to write
  	
	
  while(1)
  {   
    if(i > 7)
      i = 0; 
    if(j > 49)
      j = 0;
    
    val = atd0_readChX(0);      // reads the IR sensors atd channel
    distances8[i] = val;        // store value in 8 element array
    distances50[j] = val;	      // store value in 50 element array
    i++;
    j++;   
  }
	

  for(;;) {
    _FEED_COP(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}
Ejemplo n.º 8
0
Archivo: lcd.c Proyecto: leckardt/glcd
int main()
{
	lcd_setup();
	lcd_init();
	lcd_clear();

	draw_bitmap_fullscreen(logo);

	while(1)
	{
		uint8_t t=0;
		t++;
	}

}
Ejemplo n.º 9
0
//**************************************************
// セットアップします
//**************************************************
void setup(void)
{
	Serial.begin(9600);
    //Serial.begin( 9600, SCI_AUTO );	//何か押されるまで待つ
	Serial.setDefault();				//現在のシリアルポートを標準出力とするprintfでも出力する
	setvbuf(stdout,NULL,_IONBF,0);

	//sakuluaの初期化
	init_sakulua();

	//lcdの初期化
	lcd_setup();

	// RTCを起動します
	RTC::begin();
}
Ejemplo n.º 10
0
/**
 * Initialize the LCD driver.
 * 
 * @param cur Cursor ON/OFF.
 * @param blk Blinking cursor ON/OFF.
 */
void lcd_init(bool cur, bool blk) {
	// Setup the pins and wait for the driver to stabilize.
	lcd_setup();
	delay_ms(45);

	// Initialization. For more information about this madness check page
	// 46 of the datasheet.
	lcd_init_function_set();
	delay_us(4500);
	lcd_init_function_set();
	delay_us(150);
	lcd_init_function_set();
	lcd_function_set();  // The last madness.

	lcd_display_control(TRUE, cur, blk);
	_lcd_clear();
	lcd_entry_mode();
}
Ejemplo n.º 11
0
void platform_init()
{
	arm_setup();
	mmu_setup();
	tasks_setup();

	// Basic prerequisites for everything else
	miu_setup();
	power_setup();

	clock_setup();

	// Need interrupts for everything afterwards
	interrupt_setup();

	gpio_setup();

	// For scheduling/sleeping niceties
	timer_setup();
	event_setup();
	wdt_setup();

	// Other devices
	uart_setup();
	i2c_setup();

	dma_setup();

	spi_setup();

	LeaveCriticalSection();

	clock_set_sdiv(0);

	aes_setup();

	lcd_setup();
	framebuffer_setup();

	audiohw_init();

	framebuffer_setdisplaytext(TRUE);
}
Ejemplo n.º 12
0
void configure_system() {
	    
	kill_interrupts();	// turn off interrupts just in case

	turn_analog_inputs_off();	// kill those pesky analogue inputs
	
	lcd_setup();	// Setup the pins (output / input)
	lcd_init ();	// Configure chip ready for display

	sure_2416_setup();
	
	serial_setup(BRGH_HIGH_SPEED, SPBRG_19200);

	turn_peripheral_ints_on();
	turn_global_ints_on();

	// Currently this does debug, so do it after the serial port is up
	sure_2416_init();
}
Ejemplo n.º 13
0
void main()
{
    adcon1 = 00001110b; // Bit 0 is an analog input for the A/D, the 1's are digital inputs.
    rbnpu = 0; // enable weak pullups - so pins don't float
    lcd_setup();
    lcd_clear();
    
    rbie = 1; // Change of state (COS) on RB4 to RB7
    int0ie = 1; // interrupt0 on RB0
    int1ie = 1; // interrupt1 on RB1
    int2ie = 1; // interrupt2 on RB2
    
    ipen = 1; // turn on interrupt priorities
    gieh = 1;
    giel = 1;
    
    lcd_gotoxy( 0, 0 );
    lprintf( "edge0:%1d", int0edge );
    delay_ms( 100 );
    
    lcd_gotoxy( 0, 0 );
    lprintf( "edge1:%1d", int1edge );
    delay_ms( 100 );
    
    lcd_gotoxy( 0, 0 );
    lprintf( "edge2:%1d", int2edge );
    delay_ms( 100 );
    
    
    volatile bit ra4 @ PORTA.4;
    bit ra4Prev = !ra4;
    char loopCnt = 0;
    while( 1 )
    {
        lcd_gotoxy( 0, 0 );
        lprintf( "hi:%04d", hpIntCnt );
        lprintf( " lo:%04d", lpIntCnt );
        lprintf( "\nlcnt:%04d ", loopCnt++ );
        
        lprintf( intSrcNames[ intSrc ] );
        
        // set interrupt priority when its changed
        if( ra4 != ra4Prev )
        {
            gieh = 0;
            giel = 0;
            
            ra4Prev = ra4;
            
            // int0ip = ra4; - alway hi priority for int0
            int1ip = 0;
            int2ip = ra4;
            rbip = ra4;
            
            
            gieh = 1;
            giel = 1;
            
            lcd_clear();
            lcd_gotoxy( 0, 0 );
            lprintf( "ip1:%1d ", int1ip );
            lprintf( "ip2:%1d", int2ip );            
            lprintf( "\nrbip:%1d ", rbip );
            delay_ms( 100 );

        }
    }
    
    
}
Ejemplo n.º 14
0
void setup(void)
{
   unsigned char adr, flags, d;
   unsigned short i;
   unsigned char *p;

   _flkey = 0;
   
   /* first disable watchdog */
   watchdog_disable();

   /* avoid any blocking of RS485 bus */
   RS485_ENABLE = RS485_ENABLE_OFF;

   /* Port and oscillator configuration */

#if defined(CPU_C8051F120)

   SFRPAGE   = CONFIG_PAGE;
  
   XBR0 = 0x04;                 // Enable XBar, UART0 & UART1
   XBR1 = 0x00;
   XBR2 = 0x44;

  #ifdef CLK_25MHZ
   /* Select internal quartz oscillator */
   SFRPAGE   = LEGACY_PAGE;
   FLSCL     = 0x00;            // set flash read time for <25 MHz

   SFRPAGE   = CONFIG_PAGE;
   OSCICN    = 0x83;            // divide by 1
   CLKSEL    = 0x00;            // select internal oscillator
  #else          // 98 MHz
   /* Select internal quartz oscillator */
   SFRPAGE   = LEGACY_PAGE;
   FLSCL     = 0xB0;            // set flash read time for 100 MHz

   SFRPAGE   = CONFIG_PAGE;
   OSCICN    = 0x83;            // divide by 1
   CLKSEL    = 0x00;            // select internal oscillator

   PLL0CN    |= 0x01;
   PLL0DIV   = 0x01;
   PLL0FLT   = 0x01;
   PLL0MUL   = 0x04;
   for (i = 0 ; i < 15; i++);   // Wait 5us for initialization
   PLL0CN    |= 0x02;
   for (i = 0 ; i<50000 && ((PLL0CN & 0x10) == 0) ; i++);

   CLKSEL    = 0x02;            // select PLL as sysclk src
  #endif

#elif defined(CPU_C8051F020)

   XBR0 = 0x04;                 // Enable UART0 & UART1
   XBR1 = 0x00;
   XBR2 = 0x44;

   /* Select external quartz oscillator */
   OSCXCN = 0x67;               // Crystal mode, Power Factor 22E6
   OSCICN = 0x08;               // CLKSL=1 (external)

#elif defined(CPU_C8051F310) || defined(CPU_C8051F320)

   XBR0 = 0x01;                 // Enable RX/TX
   XBR1 = 0x40;                 // Enable crossbar

   /* Select internal quartz oscillator */
   OSCICN = 0x83;               // IOSCEN=1, SYSCLK=24.5 MHz
   CLKSEL = 0x00;               // derive SYSCLK from internal source

#else

   XBR0 = 0x04;                 // Enable RX/TX
   XBR1 = 0x00;
   XBR2 = 0x40;                 // Enable crossbar

   PRT0CF = 0x01;               // P0.0: TX = Push Pull
   PRT1CF = 0x00;               // P1
   PRT2CF = 0x00;               // P2  Open drain for 5V LCD
   PRT3CF = 0x20;               // P3.5: RS485 enable = Push Pull

   /* Select external quartz oscillator */
   OSCXCN = 0x67;               // Crystal mode, Power Factor 22E6
   OSCICN = 0x08;               // CLKSL=1 (external)

#endif
        
#ifdef CFG_HAVE_LCD
   lcd_setup();
#endif

#ifdef CFG_HAVE_EMIF
   /* initialize external memory interface */
   d = emif_init();

   /* do memory test on cold start */
   SFRPAGE = LEGACY_PAGE;
   if (d > 0 && (RSTSRC & 0x02) > 0)
      emif_test(d);
#endif

   /* start system clock */
   sysclock_init();

   /* enable watchdog with default timeout */
   watchdog_enable(0);

   /* enable missing clock detector */
   RSTSRC |= 0x04;

   /* default LED mode */
   for (i=0 ; i<N_LED ; i++)
      led_mode(i, 1);
   
   /* initialize all memory */
   CSR = 0;
   addressed = 0;
   flash_param = 0;
   flash_program = 0;
   flash_allowed = 0;
   wrong_cpu = 0;
   _flkey = 0;

#ifdef CFG_HAVE_RTC
   rtc_set = 0;
#endif

   i_in = i_out = n_out = 0;
   _cur_sub_addr = 0;
   for (i=0 ; i<sizeof(in_buf) ; i++)
      in_buf[i] = 0;
   for (i=0 ; i<sizeof(out_buf) ; i++)
      out_buf[i] = 0;

   /* check if we got reset by watchdog */
#if defined(CPU_C8051F120)
   SFRPAGE   = LEGACY_PAGE;
#endif
   WD_RESET = ((RSTSRC & 0x02) == 0 && (RSTSRC & 0x08) > 0);

   /* initialize UART(s) */
   uart_init(0, BD_115200);

#ifdef CFG_UART1_MSCB
   uart_init(1, BD_115200);
#endif

#ifdef CFG_DYN_VARIABLES
   setup_variables();
#endif

   /* count variables */
   for (n_variables = _var_size = 0;; n_variables++) {
      _var_size += variables[n_variables].width;
      if (variables[n_variables].width == 0)
         break;
   }

   /* check if variables are in xdata and xdata is present */
   if (n_variables > 0) {
      p = variables[0].ud;
      d = *p;
      *p = 0x55;
      if (*p != 0x55)
         wrong_cpu = 1;
      *p = 0xAA;
      if (*p != 0xAA)
         wrong_cpu = 1;
      *p = d;
   }

   /* retrieve EEPROM data */
#ifdef CPU_C8051F120
   SFRPAGE = LEGACY_PAGE;
#endif
   if ((RSTSRC & 0x02) > 0)
      flags = eeprom_retrieve(1); // vars on cold start
   else
      flags = eeprom_retrieve(0);

   if ((flags & (1 << 0)) == 0) {
      configured_addr = 0;
   
      /* set initial values */
      sys_info.node_addr = 0xFFFF;
      sys_info.group_addr = 0xFFFF;
      memset(sys_info.node_name, 0, sizeof(sys_info.node_name));
      strncpy(sys_info.node_name, node_name, sizeof(sys_info.node_name));
   } else
      configured_addr = 1;

   /* store SVN revision */
   sys_info.svn_revision = (svn_rev_main[6]-'0')*1000+
                           (svn_rev_main[7]-'0')*100+
                           (svn_rev_main[8]-'0')*10+
                           (svn_rev_main[9]-'0');

   if ((flags & (1 << 1)) == 0) {

      /* init variables */
      for (i = 0; variables[i].width; i++)
         if (!(variables[i].flags & MSCBF_DATALESS)) {
            /* do it for each sub-address */
            for (adr = 0 ; adr < _n_sub_addr ; adr++) {
               memset((char*)variables[i].ud + _var_size*adr, 0, variables[i].width);
            }
         }

      /* call user initialization routine with initialization */
      user_init(1);

      /* write current variables to flash later in main routine */
      configured_vars = 0;
   } else {
      /* call user initialization routine without initialization */
      user_init(0);
      configured_vars = 1;
   }

   /* Blink LEDs */
   for (i=0 ; i<N_LED ; i++)
      led_blink(i, 3, 150);

}
Ejemplo n.º 15
0
void Task1()
{
  uint8_t secret = 0;
  char* s = "Screen 1\\nWelcome!\\nScreen 2\\nDriver\\r\\nScreen 3\\n \\dTest\\d";
  char* s_secret = "Congrats\\ndude\\nYou\\nfound it\\nSecret\\ncode!";

  // Initialize FireFly LCD v1.2 board
  lcd_setup();

  // Set LEDs
  lcd_led_set(1, 0);
  lcd_led_set(2, 0);
  lcd_led_set(3, 1);

  lcd_string_display_escape("FireFly\\nLCD v1.2");
  lcd_wait_us(2000000); // Wait 2 seconds

  lcd_string_display_escape("Basic\\nLCD");
  lcd_wait_us(2000000); // Wait 2 seconds

  lcd_string_display_escape("Driver\\nTest");
  lcd_wait_us(2000000); // Wait 2 seconds

  // Load initial string array
  lcd_string_array_load(s);

  // Switch input loop
  while(1)
  {
    if(lcd_switch_pressed(1)) // If switch 1 is pressed
    {
      if(!secret)
        lcd_led_set(1, 1); // Set LED 1

      // Buzz
      lcd_buzz(30);

      if(lcd_switch_pressed(2)) // If both switches are pressed
      {
        // Load new string array
        lcd_string_array_load(s_secret);

        // Set LEDs
        lcd_led_set(1, 1);
        lcd_led_set(2, 1);
        lcd_led_set(3, 1);

        secret = 1;
      }
      else
      {
        // Cycle string array
        lcd_string_array_cycle();
      }
    }
    else if(lcd_switch_pressed(2)) // If switch 2 is pressed
    {
      if(!secret)
        lcd_led_set(2, 1); // Set LED 2

      // Buzz
      lcd_buzz(30);

      // Reverse cycle string array
      lcd_string_array_cycle_reverse();
    }
    else if(!secret) // If no switches pressed
    {
      lcd_led_set(1, 0); // Clear LED 1
      lcd_led_set(2, 0); // Clear LED 2
    }

    if(secret)
    {
      // Toggle LEDs
      lcd_led_toggle(1);
      lcd_led_toggle(2);
      lcd_led_toggle(3);
    }

    nrk_wait_until_next_period();
  }
}
Ejemplo n.º 16
0
Archivo: main.c Proyecto: alexpriem/avr
int main(void)
{
    int j=0, vol_l, vol_r,d;
	
	
	uart_init();
	uart_puts ("\r\nreset -- init2\r\n");
	//void lcd_setup (uint8_t rs, uint8_t rw, uint8_t enable,
	//			uint8_t db0, uint8_t db1, uint8_t db2, uint8_t db3 ) 
	/* lcd_setup (0, P_PC2, P_PC4, P_PC6, P_PC0,
			  P_PC1, P_PC3, P_PC5, P_PC7);	 */
	// lcd_setup  (uint8_t chip,  uint8_t strobe, uint8_t clock, uint8_t io)
	lcd_setup (0, P_PA2, P_PA4, P_PA0);
	lcd_setup_info (0, HD44780, 20, 2);

	//a2311_setup (uint8_t chip, uint8_t zcen, uint8_t cs, uint8_t sdi, uint8_t clk, uint8_t mute)	
	/* pga2311_setup (0, P_PA0, P_PA1, P_PA2, P_PA3, P_PA4);
	pga2311_init (0); */
	lcd_init (0, LCD_DISP_ON_CURSOR_BLINK);
	
//	lcd_puts (0,"abcdef\n1234");
	//lcd_clrscr(0);
	lcd_puts (0,"abcdefghijklmnopqrstuvwxyz");
	lcd_puts (0,"\nok");
	/*
	lcd_puts (0, "xbcde 1");
	lcd_puts (0, "\nfghij 2");
	lcd_puts (0, "\nklmno 3");
	lcd_puts (0, "\npqrst 4");
	lcd_puts (0, "\nuvw 5");
	lcd_puts (0, "\nzAB 6");
	lcd_puts (0, "\nEFG 7");
	lcd_puts (0, "\nKLM 8");
	lcd_puts (0, "\n# 9"); */
	
	/*
	lcd_puts (0, "##234567890abcdefghijklmno##rstuvwxyz\n");
	lcd_puts (0, "12##$567890abcdefghijklmnopq##tuvwxyz\n");
	lcd_puts (0, "12345##7890abcdefghijklmnopqs##vwxyz\n");
	lcd_puts (0, "1234567##90abcdefghijklmnopqrstu##yz\n");
	*/
	
	
	/*
	lcd_init (1, LCD_DISP_ON_CURSOR_BLINK);
	lcd_puts (1, "regel 1");
	lcd_puts (1, "\nregel 2");
	lcd_puts (1, "\nregel 3");
	lcd_puts (1, "\nregel 4");
	lcd_puts (1, "\nregel 5");
	lcd_puts (1, "\nregel 6");
	lcd_puts (1, "\nregel 7");
	*/
	j=0;
	
	vol_l=128;
	vol_r=128;
	encoder_setup (0,P_PD2, P_PD3);
	encoder_setup (1,P_PD4, P_PD5);
	
	for (;;) {
		d=encoder_poll (0);
		if (d>0) {
			vol_l++; vol_r--;
			}
		if (d<0) {
			vol_l--; vol_r--;
		}
		
		pga2311_set_gain (0, vol_l, vol_r);
		}
 return 0;
}
Ejemplo n.º 17
0
Archivo: main.c Proyecto: nycdarren/mrk
// This task listens for messages and if it receives an XMPP
// message addressed to broadcast or this node, it will print it out
void rx_task ()
{
    uint8_t len;
    int8_t rssi, val;
    uint8_t *local_rx_buf;
    XMPP_PKT_T rxp;
    nrk_time_t check_period;
    printf ("rx_task PID=%d\r\n", nrk_get_pid ());

    // Initialize FireFly LCD v1.2 board
    lcd_setup();
    lcd_string_display_escape("Waiting\\nfor msg.");

    while (!bmac_started ())
        nrk_wait_until_next_period ();

    check_period.secs = 0;
    check_period.nano_secs = 100 * NANOS_PER_MS;
    val = bmac_set_rx_check_rate (check_period);

    while (1) {

        // Wait for new packet if one isn't already available
        if (bmac_rx_pkt_ready () == 0) {
            val = bmac_wait_until_rx_pkt ();
        }

        // Get the RX packet
        local_rx_buf = bmac_rx_pkt_get (&len, &rssi);
        // Check the packet type from raw buffer before unpacking
        if ((local_rx_buf[CTRL_FLAGS] & (MOBILE_MASK)) != 0) {

            // Set the buffer
            p2p_pkt.buf = local_rx_buf;
            p2p_pkt.buf_len = len;
            p2p_pkt.rssi = rssi;
            unpack_peer_2_peer_packet (&p2p_pkt);
            // just check the last part of the address because we are lazy
            // In the future you should check the whole address so that you
            // don't accidentally get someone elses messages

            if ((p2p_pkt.dst_subnet_mac[2] == MY_SUBNET_MAC_2 &&
                    p2p_pkt.dst_subnet_mac[1] == MY_SUBNET_MAC_1 &&
                    p2p_pkt.dst_subnet_mac[0] == MY_SUBNET_MAC_0 &&
                    p2p_pkt.dst_mac == MY_MAC )
                    || p2p_pkt.dst_mac == BROADCAST)
            {
                nrk_led_set (GREEN_LED);
                // Packet arrived and is good to go
#ifdef TXT_DEBUG
                printf ("full mac: %d %d %d %d ", p2p_pkt.src_subnet_mac[0],
                        p2p_pkt.src_subnet_mac[1], p2p_pkt.src_subnet_mac[2],
                        p2p_pkt.src_mac);
                printf ("rssi: %d ", p2p_pkt.rssi);
                printf ("type: %d ", p2p_pkt.pkt_type);
                nrk_kprintf (PSTR ("payload: ["));
                for (i = p2p_pkt.payload_start; i < p2p_pkt.buf_len; i++)
                    printf ("%d ", p2p_pkt.buf[i]);
                nrk_kprintf (PSTR ("]\r\n"));
#endif
                // If it is an XMPP message
                if (p2p_pkt.pkt_type == XMPP_PKT) {
                    nrk_kprintf (PSTR ("XMPP packet for me!\r\n"));

                    // Unpack the message
                    xmpp_pkt_unpack (&rxp, p2p_pkt.payload, 0);

                    // Print it out
                    printf ("XMPP msg:\r\n");
                    printf ("  seq-num=%d\r\n", p2p_pkt.seq_num);
                    printf ("  from-jid=%s\r\n", rxp.src_jid);
                    printf ("  msg=%s\r\n", rxp.msg);

                    // Load and display message
                    lcd_string_array_load(rxp.msg);
                }

            }
        }
        // Release the RX buffer so future packets can arrive
        bmac_rx_pkt_release ();

    }
}
Ejemplo n.º 18
0
Archivo: main.c Proyecto: alexpriem/avr
int main(void)
{
	uint8_t i;
	
		  
#ifdef DEBUG
	uart_init();
	uart_puts ("\r\nreset\r\ninit port 1\r\n");	
#endif
	
	//
/*
	uart_puts ("a123\n");
	uart_puts ("b456\n");
	uart_puts ("c789\n");
	uart_puts ("d20\n");
*/	
	init_keypad_4x4s (P_PORTC);
	init_count_switch();
    init_timer ();

	lcd_setup (0, P_PA2, P_PA4, P_PA6, P_PA0,
			  P_PA1, P_PA3, P_PA5, P_PA7);	 

 //lcd_setup  (uint8_t chip,  uint8_t strobe, uint8_t clock, uint8_t io)
	lcd_setup_info (0, HD44780, 20, 2);
	
	lcd_init (0, LCD_DISP_ON);

  // relays
		//	sh_cp:11 (geel)    st_cp:12(paars)    ds:14(wit)
	//void hc595_setup (uint8_t chip, uint8_t clk, uint8_t cs, uint8_t data)

	DDRD|=P_BIT7 | P_BIT6 | P_BIT5 | P_BIT4;
#ifdef DEBUG
    test_relais();
#endif


	c=0;
	prevc=0;
	num=0;
	turns_done=0;
	turns_prog=0;	
	total_turns_done=0;
	for (i=0; i<80; i++) layer[i]=0;
	stop_motor();
	set_wind_dir_none();

	lcd_clrscr(0);
	lcd_puts (0,"*    Winding controller 20140114");
	lcd_gotoxy(0,39,0);
	lcd_puts (0,"*");
	lcd_gotoxy(0,0,3);
	lcd_puts (0,"*");
	lcd_gotoxy(0,39,3);
	lcd_puts (0,"*");
	lcd_gotoxy(0,2,2);
	lcd_printf(0,"Free RAM:%d b",freeRam());
	sleep(1);


	lcd_clrscr(0);
	update_info ();
    update_command();
	update_num ();
	update_speed ();
	update_turns();

	for (;;) {

		c=keypad_w_getch();

		if (c!=prevc)  {
			/*a=PINC;
			uart_printf ("%x %x %d\r\n",a,c,num); */
			prevc=c;

			if ((action==FILL) || (action==WIND_LEFT) || (action==WIND_RIGHT)) {
				switch (c) {
					case 0x0c: 	stop_winding();
								action=INACTIVE; //dubbel maar extra voor readability
							   	break;
				}
			}  // if !INACTIVE

			if (action==HELP) {

			switch (c) {
					case 0x0f: 	if (helppage<MAX_HELPPAGES) helppage++;
								show_help();
							   	break;
					case 0x0e: 	if (helppage>0) helppage--;
								show_help();
							   	break;
					case 0x0c: 	action=INACTIVE;
								lcd_clrscr(0);
							   	break;
					}
			}  // if HELP

			if (action==CORR) {
			switch (c) {  //corrmode is wat we de *vorige* keer gedaan hebben
					char buf[10];

					case 0x0c: 	turns_done=turns_before_corr;
								total_turns_done=total_turns_done_before_corr;
								action=INACTIVE;
								break;
					case 0x0e: 	turns_done=turns_before_corr;
								total_turns_done=total_turns_done_before_corr;
								if (corrmode==SUB) {
									turns_done+=corr;
									total_turns_done+=corr;
									corrmode=ADD;
									break;
								}
								if (corrmode==ADD) {
									if (turns_done>=corr) {
											turns_done-=corr;
											total_turns_done-=corr;
									}
									corrmode=SUB;
								}
								break;
					case 0x0f: 	turns_done=0;
							 	total_turns_done=0;
								turns_before_corr=0;
								total_turns_done_before_corr=0;
								action=INACTIVE;
								break;
			   		case 0xff:
			   		case 0xfd:
			   		case 0xfe: break;
					default:
								num=0;
								action=INACTIVE;
								itoa(corr,buf,10);
								if (corrmode==SUB) strcat(layer,"+");
								if (corrmode==ADD) strcat(layer,"+");
 								strcat (layer,buf);
								update_layer();
								break;
					}
    				update_command();
					update_turns();
							 
			}


			if (action==INACTIVE) {
				switch (c) {
					case 0x0a: 	wind_left();
								turns_prog=num;
								num=0;
								break;
					case 0x0b:  wind_right ();	
								turns_prog=num;
								num=0;
								break;
					case 0x0d:  fill ();	
								turns_prog=num;
								num=0;
								break;
					case 0x0c: 	num=0;					   
								stop_motor();
							   	break;
					case 0x0e: 	corr=num;
								turns_before_corr=turns_done;
								if (turns_done>=corr) turns_done-=corr;
								action=CORR;
								corrmode=SUB;
							   	break;
					case 0x0f:  helppage=0;
								show_help();
								action=HELP;
								break;
			   		case 0xff:
			   		case 0xfd:
			   		case 0xfe: break;

					default: if (num<1000)  {
							num=num*10 + c;						
							update_num();
							update_speed();
						}
				}
				if (action!=HELP)  {
    				update_command();
					update_turns();
					update_num();
					update_speed();
				}
			  } // if INACTIVE

		
			} // if c==prevc
	}  // mainloop
	
 return 0;
}
Ejemplo n.º 19
0
int misc_init_r (void)
{
	unsigned char *dst;
	ulong len = sizeof(fpgadata);
	int status;
	int index;
	int i;
	char *str;
	unsigned long contrast0 = 0xffffffff;

	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
	 */
	/* setup FPGA_INIT as output */
	out_be32((void *)GPIO0_TCR,
		 in_be32((void *)GPIO0_TCR) | FPGA_INIT);
	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 */

	/*
	 * Write Board revision into FPGA
	 */
	out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) | (gd->board_type & 0x0003));

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

	/*
	 * Reset touch-screen controller
	 */
	out_be32((void *)GPIO0_OR,
		 in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_TOUCH_RST);
	udelay(1000);
	out_be32((void *)GPIO0_OR,
		 in_be32((void *)GPIO0_OR) | CONFIG_SYS_TOUCH_RST);

	/*
	 * Enable power on PS/2 interface (with reset)
	 */
	out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) & ~FPGA_CTRL_PS2_PWR);
	for (i=0;i<500;i++)
		udelay(1000);
	out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) | FPGA_CTRL_PS2_PWR);

	/*
	 * Get contrast value from environment variable
	 */
	str = getenv("contrast0");
	if (str) {
		contrast0 = simple_strtol(str, NULL, 16);
		if (contrast0 > 255) {
			printf("ERROR: contrast0 value too high (0x%lx)!\n",
			       contrast0);
			contrast0 = 0xffffffff;
		}
	}

	/*
	 * Init lcd interface and display logo
	 */

	str = getenv("bd_type");
	if (strcmp(str, "ppc230") == 0) {
		/*
		 * Switch backlight on
		 */
		out_be16(FPGA_CTRL,
			 in_be16(FPGA_CTRL) | FPGA_CTRL_VGA0_BL);
		out_be16(FPGA_BL, 0x0000);

		lcd_setup(1, 0);
		lcd_init((uchar *)CONFIG_SYS_LCD_BIG_REG, (uchar *)CONFIG_SYS_LCD_BIG_MEM,
			 regs_13806_1024_768_8bpp,
			 sizeof(regs_13806_1024_768_8bpp)/sizeof(regs_13806_1024_768_8bpp[0]),
			 logo_bmp_1024, sizeof(logo_bmp_1024));
	} else if (strcmp(str, "ppc220") == 0) {
		/*
		 * Switch backlight on
		 */
		out_be16(FPGA_CTRL,
			 in_be16(FPGA_CTRL) & ~FPGA_CTRL_VGA0_BL);
		out_be16(FPGA_BL, 0x0000);

		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 if (strcmp(str, "ppc215") == 0) {
		/*
		 * Set default display contrast voltage
		 */
		if (contrast0 == 0xffffffff) {
			out_be16(FPGA_CTR, 0x0082);
		} else {
			out_be16(FPGA_CTR, contrast0);
		}
		out_be16(FPGA_BL, 0xffff);
		/*
		 * Switch backlight on
		 */
		out_be16(FPGA_CTRL,
			 in_be16(FPGA_CTRL) |
			 FPGA_CTRL_VGA0_BL |
			 FPGA_CTRL_VGA0_BL_MODE);
		/*
		 * Set lcd clock (small epson)
		 */
		out_be16(FPGA_CTRL, in_be16(FPGA_CTRL) | LCD_CLK_06250);
		udelay(100);               /* wait for 100 us */

		lcd_setup(0, 1);
		lcd_init((uchar *)CONFIG_SYS_LCD_SMALL_REG, (uchar *)CONFIG_SYS_LCD_SMALL_MEM,
			 regs_13705_320_240_8bpp,
			 sizeof(regs_13705_320_240_8bpp)/sizeof(regs_13705_320_240_8bpp[0]),
			 logo_bmp_320_8bpp, sizeof(logo_bmp_320_8bpp));
	} else if (strcmp(str, "ppc210") == 0) {
		/*
		 * Set default display contrast voltage
		 */
		if (contrast0 == 0xffffffff) {
			out_be16(FPGA_CTR, 0x0060);
		} else {
			out_be16(FPGA_CTR, contrast0);
		}
		out_be16(FPGA_BL, 0xffff);
		/*
		 * Switch backlight on
		 */
		out_be16(FPGA_CTRL,
			 in_be16(FPGA_CTRL) |
			 FPGA_CTRL_VGA0_BL |
			 FPGA_CTRL_VGA0_BL_MODE);
		/*
		 * Set lcd clock (small epson), enable 1-wire interface
		 */
		out_be16(FPGA_CTRL,
			 in_be16(FPGA_CTRL) |
			 LCD_CLK_08330 |
			 FPGA_CTRL_OW_ENABLE);

		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));
#ifdef CONFIG_VIDEO_SM501
	} else {
		pci_dev_t devbusfn;

		/*
		 * Is SM501 connected (ppc221/ppc231)?
		 */
		devbusfn = pci_find_device(PCI_VENDOR_SM, PCI_DEVICE_SM501, 0);
		if (devbusfn != -1) {
			puts("VGA:   SM501 with 8 MB ");
			if (strcmp(str, "ppc221") == 0) {
				printf("(800*600, %dbpp)\n", BPP);
				out_be16(FPGA_BL, 0x002d); /* max. allowed brightness */
			} else if (strcmp(str, "ppc231") == 0) {
				printf("(1024*768, %dbpp)\n", BPP);
				out_be16(FPGA_BL, 0x0000);
			} else {
				printf("Unsupported bd_type defined (%s) -> No display configured!\n", str);
				return 0;
			}
		} else {
			printf("Unsupported bd_type defined (%s) -> No display configured!\n", str);
			return 0;
		}
#endif /* CONFIG_VIDEO_SM501 */
	}

	cf_enable();

	return (0);
}
Ejemplo n.º 20
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);
}
Ejemplo n.º 21
0
void lcd_init()
{
	_delay_ms(500);
	lcd_setup();
}