示例#1
0
文件: main.c 项目: I-SYST/EHAL
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t ret_val;

    (void) NRF_LOG_INIT(NULL);

    NRF_LOG_INFO("Inside main\r\n");

    leds_init();
    buttons_init();

    ret_val = nrf_bootloader_init();
    APP_ERROR_CHECK(ret_val);

    // Either there was no DFU functionality enabled in this project or the DFU module detected
    // no ongoing DFU operation and found a valid main application.
    // Boot the main application.
    nrf_bootloader_app_start(MAIN_APPLICATION_START_ADDR);

    // Should never be reached.
    NRF_LOG_INFO("After main\r\n");
}
/**@brief Application main function.
 */
int main(void)
{
    // Initialize peripherals
    leds_init();
    timers_init();
    buttons_init();

    // Initialize S310 SoftDevice
    ble_ant_stack_init();
    
    // Initialize Bluetooth stack parameters.
    gap_params_init();
    advertising_init();
    services_init();
    conn_params_init();

    // Initialize ANT HRM recieve channel.
    ant_hrm_rx_init();

#ifdef BONDING_ENABLE
    uint32_t err_code;
    uint32_t count; 

    // Initialize device manager.
    device_manager_init();

    err_code = pstorage_access_status_get(&count);
    if ((err_code == NRF_SUCCESS) && (count == 0))
#endif // BONDING_ENABLE
    {
        storage_access_complete_handler();
    }

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
示例#3
0
文件: main.c 项目: jarodz/otolith
/**@brief Application main function.
 */
int main(void)
{
    uint32_t err_code;

    connected = false;

    mlog_init();
    timers_init();
    gpiote_init();
    buttons_init();
    step_counter_init();
    motor_init();
    led1_init();

    mlog_str("Starting MAIN...\r\n");

    bond_manager_init();
    ble_stack_init();
    radio_notification_init();

    // Initialize Bluetooth Stack parameters
    gap_params_init();
    advertising_init();
    services_init();
    conn_params_init();
    sec_params_init();

    // Actually start advertising
    //advertising_start();
    app_button_enable();

    // Enter main loop
    for (;;)
    {
        // Switch to a low power state until an event is available for the application
        err_code = sd_app_event_wait();
        APP_ERROR_CHECK(err_code);
    }
}
void BLE_Primx_Apps_Int(void)
{
	  leds_init();    // configure LED output
    timers_init();  // configure Timer
    gpiote_init();  // configure maximum no of GPIO external 
    buttons_init(); // configure the button handlering and button proporty
    bond_manager_init();  // load the previous bond data from flash
    ble_stack_init();     // Install BLE event Handler function list
    gap_params_init();     // set gap parameter
    advertising_init(BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE);  //set advertising mode, set UUID service
    services_init();      // add UUID service , and service function handler
    conn_params_init();   // set the connection parameter
    sec_params_init();    // set the security connect parameter
    radio_notification_init();   // active radio

    // Start execution
    advertising_start();    // start state mechine for adversting




}	
示例#5
0
void buttons_runTest() {
  buttons_init();  // Initialize buttons
  display_init();  // Initialize display, which sets Rotation = 1 by default
  display_fillScreen(DISPLAY_BLACK); // blank the screen
  display_setTextColor(DISPLAY_BLACK);  // Change text color to black
  display_setTextSize(BUTTONS_TEXT_SIZE); // Make text larger

  // Set the values of the global variables
  x_max = display_width();
  y_max = display_height();

  // Set the values of screen positions
  x_fourth = FOURTH(x_max);
  x_half = HALF(x_max);
  x_three_fourths = THREE_FOURTHS(x_max);
  y_fourth = FOURTH(y_max);
  y_half = HALF(y_max);
  y_three_fourths = THREE_FOURTHS(y_max);

  // Do an initial read of button values
  int32_t buttonValues = buttons_read();

  // Until all 4 BTNS are pressed simultaneously, write info to the LCD
  while (buttonValues != BUTTONS_ALL_BTNS_ON) {

    // Draw the Rects/Text on the LCD corresponding to current buttons
    buttons_write_LCD(buttonValues);

    // Poll new value of buttons
    buttonValues = buttons_read();
  }

  // After all buttons are pushed simultaneously, finish test.
  display_fillScreen(DISPLAY_BLACK);  // blank screen
  display_setTextColor(DISPLAY_CYAN); // change text color
  display_setCursor(0,0);  // reset cursor to origin
  display_println("Button Test Finished!");  // print that the test is complete
}
int main(void)
{
    // Initialization of various modules.
    timers_init();
    leds_init();
    gpiote_init();
    buttons_init();

    ble_stack_init();
    scheduler_init();
    device_manager_init();

    mb_init();

    // Start scanning for peripherals
    bt_scan_start();

    for (;; )
    {
        app_sched_execute();
        power_manage();
    }
}
/**@brief  Application main function.
 */
int main(void)
{
    // Initialize
    leds_init();
    timers_init();
    buttons_init();
    uart_init();
    ble_stack_init();
    device_manager_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();
    
    simple_uart_putstring(START_STRING);
    
    advertising_start();
    
    // Enter main loop
    for (;;)
    {
        power_manage();
    }
}
示例#8
0
文件: main.c 项目: tve/Espruino
/**@brief Function for bootloader main entry.
 */
int main(void)
{
    uint32_t err_code;
    bool     dfu_start = false;
    bool     app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START);

    if (app_reset)
    {
        NRF_POWER->GPREGRET = 0;
    }

    leds_init();

    // This check ensures that the defined fields in the bootloader corresponds with actual
    // setting in the chip.
    APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START);
    APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE);

    // Initialize.
    timers_init();
    buttons_init();

    (void)bootloader_init();

    if (bootloader_dfu_sd_in_progress())
    {
        nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, UPDATE_IN_PROGRESS_LED_ONSTATE);

        err_code = bootloader_dfu_sd_update_continue();
        APP_ERROR_CHECK(err_code);

        ble_stack_init(!app_reset);
        scheduler_init();

        err_code = bootloader_dfu_sd_update_finalize();
        APP_ERROR_CHECK(err_code);

        nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, !UPDATE_IN_PROGRESS_LED_ONSTATE);
    }
    else
    {
        // If stack is present then continue initialization of bootloader.
        ble_stack_init(!app_reset);
        scheduler_init();
    }

    dfu_start  = app_reset;
    dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == BOOTLOADER_BUTTON_ONSTATE) ? true: false);

    // If button is held down for 3 seconds, don't start bootloader.
    // This means that we go straight to Espruino, where the button is still
    // pressed and can be used to stop execution of the sent code.
    if (dfu_start) {
      nrf_gpio_pin_write(BOOTLOADER_BUTTON_PRESS_LED, BOOTLOADER_BUTTON_PRESS_LED_ONSTATE);
      int count = 3000;
      while (nrf_gpio_pin_read(BOOTLOADER_BUTTON) == BOOTLOADER_BUTTON_ONSTATE && count) {
        nrf_delay_us(999);
        count--;
      }
      if (!count)
        dfu_start = false;
      nrf_gpio_pin_write(BOOTLOADER_BUTTON_PRESS_LED, !BOOTLOADER_BUTTON_PRESS_LED_ONSTATE);
    }

    if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) {
        nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, UPDATE_IN_PROGRESS_LED_ONSTATE);

        // Initiate an update of the firmware.
        err_code = bootloader_dfu_start();
        APP_ERROR_CHECK(err_code);

        nrf_gpio_pin_write(UPDATE_IN_PROGRESS_LED, !UPDATE_IN_PROGRESS_LED_ONSTATE);
    }

    if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress())
    {
        // Select a bank region to use as application region.
        // @note: Only applications running from DFU_BANK_0_REGION_START is supported.
        bootloader_app_start(DFU_BANK_0_REGION_START);
    }

    NVIC_SystemReset();
}
/**@brief Function for application main entry.
 */
int main(void)
{

    // Initialize	
//		nrf_gpio_cfg_output(23);
//		nrf_gpio_pin_write(23, 0);
//		nrf_gpio_pin_write(23, 1);
//		nrf_delay_ms(1000);
//		nrf_gpio_pin_write(23, 0);
		uart_init();
    leds_init();
    timers_init();
    gpiote_init();
    buttons_init();
		app_button_enable();
		wdt_init();	
#ifdef  DEBUG_LOG
		printf("uart_init\r\n");
		printf("leds_init\r\n");
		printf("timers_init\r\n");
		printf("gpiote_init\r\n");
		printf("buttons_init\r\n");
		printf("wdt_init\r\n");
#endif	
	
    bond_manager_init();
    ble_stack_init();
    gap_params_init();
#ifdef  DEBUG_LOG
		printf("bond_manager_init\r\n");
		printf("ble_stack_init\r\n");
		printf("gap_params_init\r\n");
#endif


    advertising_init(BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE);
    services_init();
    conn_params_init();
    sec_params_init();	
    radio_notification_init();
#ifdef  DEBUG_LOG
		printf("advertising_init\r\n");
		printf("services_init\r\n");
		printf("conn_params_init\r\n");
		printf("radio_notification_init\r\n");
#endif

    advertising_start();
#ifdef  DEBUG_LOG
		printf("advertising_start\r\n");
#endif		
		
		
			
		HTU21D_Init();
		
#ifdef  DEBUG_LOG
		printf("HTU21D_Init\r\n");
		printf("OLED_Init\r\n");
#endif		
		
		my_timer_init();
		Auto_Time_Set();
		
#ifdef  DEBUG_LOG
		printf("rtc my_timer_init\r\n");
		printf("Auto_Time_Set\r\n");
#endif
	
		wdt_start();
#ifdef  DEBUG_LOG
		printf("wdt_start\r\n");
		printf("Enter main loop\r\n");		
#endif	

		OLED_POWER_CONTROL(1);
		nrf_delay_ms(2000);
		OLED_POWER_CONTROL(0);
    for (;;)
    {
			
			updata_by_min();
			updata_by_hour();
			power_manage();
    }
}
示例#10
0
int main(void){
	adc_init();
	init_3lb();
	timer1_init();
    buttons_init();
	pi_shutdown_init();
	set_sleep_mode(SLEEP_MODE_IDLE);
	ZV_count = 10;
	USART_Init(MYUBRR);
	sei();
	while(1){
		//*
		if(buttons_active){
			if((AMP_PIN & (1<<AMP_ON))){
				start_pi();
				switch(aux_check()){
					case AUX:{
						buttons_task();
						uart_task();
						break;
					}
					case NOT_AUX:{
						USART_Transmit(0x01);
						_delay_ms(250);
						uint8_t i;
						for(i=1; i<17; i++){
							USART_Transmit(data_3lb[i]);
							_delay_ms(25);
						}
						USART_Transmit(0x00);
						_delay_ms(250);
						break;
					}
					case AUX_INFO:{
						USART_Transmit(0x01);
						_delay_ms(250);
						break;
					}
				}
				mfd_active = true;
			}else{
//				pi_shutdown_task();
//*
				if(ZV_PIN & (1<<ZV_ZU)){
					pi_shutdown_task();
				}else{
					start_pi();
					USART_Transmit(0x02);
					_delay_ms(250);
				}
//*/
			}
			buttons_active = false;
		}
		if(!(PISTARTPORT & (1<<PISTART))){
			sleep_mode();
			buttons_active = true;
		}	
		//*/		
    }
	return 0;
}
示例#11
0
/**@brief Function for application main entry.
 */
int main(void)
{
    bool is_notification_mode    = false;
    bool is_non_connectable_mode = false;

    buttons_init();

    // Check button states.
    // Notification Start button.
    if (nrf_gpio_pin_read(NOTIF_BUTTON_PIN_NO) == 0)
    {
        is_notification_mode = true;
    }
    // Non-connectable advertisement start button.
    else if (nrf_gpio_pin_read(NON_CONN_ADV_BUTTON_PIN_NO) == 0)
    {
        is_non_connectable_mode = true;
    }
    // Un-configured button.
    else
    {
    }

    // Initialize SoftDevice.
    ble_stack_init();

    if (!is_notification_mode && !is_non_connectable_mode)
    {
        uint32_t err_code;

        // The startup was not because of button presses. This is the first start.
        // Go into System-Off mode. Button presses will wake the chip up.
        err_code = sd_power_system_off();
        APP_ERROR_CHECK(err_code);
    }

    // If we reach this point, the application was woken up by pressing one of the two configured
    // buttons.

    timers_init();
    gap_params_init();

    if (is_notification_mode)
    {
        // Notification button is pressed. Start connectable advertisement.
        connectable_adv_init();
        service_add();
    }
    else
    {
        non_connectable_adv_init();
    }

    advertising_data_init();
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
void vControl ( void *pvParameters )
{
	portTickType xLastWakeTime;
	signed char valx, valy;
	unsigned char ls, rs, lb, rb;

	can_frame_t out_frame;
	can_frame_t in_frame;
	out_frame.id = 1;
	out_frame.dlc = 6;

	xLastWakeTime = xTaskGetTickCount ();

	/* Button init */
	buttons_init ();

	/* FSM init */
	fsm_init ();

	/* CAN init */
	can_init ();

	/* ADC init */
	adc_init ( ctrlNUM_ADC_VALUES );

	/* Touch init */
	touch_init ( 30, 30, 30, 30 );

	while (1)
	{
		vTaskDelayUntil ( &xLastWakeTime, ctrlTASK_FREQUENCY );

		if ( adc_conversion_complete () == pdTRUE )
		{
			adc_disable ();
			adc_get_value ( &valx, 0 );
			adc_get_value ( &valy, 0 );
			touch_measure ( &ls, &rs, &lb, &rb );

			out_frame.data[0] = valx;
			out_frame.data[1] = valy;
			out_frame.data[2] = ls;
			out_frame.data[3] = rs;
			out_frame.data[4] = lb;
			out_frame.data[5] = rb;

			if (fsm_get_state() == ST_PLAY)
			{
				can_transmit (&out_frame);
			}
						
			can_receive (&in_frame, 0);

			if (in_frame.data[0] == GAME_SENSOR_TRIGGERED)
			{
				// TODO: set triggered state
				fsm_event_t *event = pvPortMalloc (sizeof (fsm_event_t));
				event->type = EV_STOP;
				event->ptr = NULL;
				fsm_event_put (event, portMAX_DELAY);
				in_frame.data[0] = 0;
			}
			else if (in_frame.data[0] == GAME_SENSOR_CLEARED)
			{
				// TODO: set cleared state
				in_frame.data[0] = 0;
			}

			adc_enable ();
			adc_conversion_start ();
		}

		fsm_update ();
	}
}
示例#13
0
void uart_task(){
//*
	if(buttons_old._1) USART_Transmit('1');
	if(buttons_old._2) USART_Transmit('2');
	if(buttons_old._3) USART_Transmit('3');
	if(buttons_old._4) USART_Transmit('4');
	if(buttons_old._5) USART_Transmit('5');
	if(buttons_old._6) USART_Transmit('6');
	if(buttons_old.next) USART_Transmit('n');
	if(buttons_old.prev) USART_Transmit('p');
	if(buttons_old.eject) USART_Transmit('e');
	if(buttons_old.tim) USART_Transmit('t');
	if(buttons_old.info) USART_Transmit('i');
	if(buttons_old.as) USART_Transmit('a');
	if(buttons_old.scan) USART_Transmit('s');
	if(buttons_old.flag) USART_Transmit('f');
	if(buttons_old.light) USART_Transmit('l');
	if(buttons_old.navi) USART_Transmit('N');
	if(buttons_old.back) USART_Transmit('b');
	if(buttons_old.audio) USART_Transmit('A');
	if(buttons_old.tone) USART_Transmit('T');
	if(buttons_old.left_right){
		int8_t c = buttons_old.left_right;
		if(c > 0){
			//while(c--){
				USART_Transmit('+');
				_delay_us(WAIT);
				USART_Transmit(c);
				_delay_us(WAIT);
				USART_Transmit('0');
			//}
		}else{
			//while(c++){
				c *= -1;
				USART_Transmit('-');
				_delay_us(WAIT);
				USART_Transmit(c);
				_delay_us(WAIT);
				USART_Transmit('0');
			//}							
		}
	}	
	if(buttons_old.enter) USART_Transmit('E');
	if(buttons_old.traffic){ 
		
		if(PIPIN & (1<<PIACTIVE)){
			PIPORT |= (1<<PISHUTDOWN);
			_delay_ms(1000);
			PIPORT &= ~(1<<PISHUTDOWN);
		}else{
			PISTARTPORT &= ~(1<<PISTART);
			_delay_ms(1000);
		}

	}
	if(buttons.next == false && buttons.prev == false && buttons.eject == false && buttons.tim == false && buttons.info == false && buttons.as == false && buttons.scan == false && buttons._1 == false &&	buttons._2 == false && buttons._3 == false && buttons.flag == false && buttons.light == false && buttons.navi == false && buttons.back == false && buttons.audio == false && buttons.tone == false && buttons.left_right == 0 && buttons.enter == false && buttons._4 == false && buttons._5 == false && buttons._6 == false && buttons.traffic == false){
		USART_Transmit('0');
	}
	buttons_old = buttons;
//*/	
	buttons_init();
	
}
示例#14
0
文件: main.c 项目: cbmeeks/sd2iec
int main(void) {
  /* Early system initialisation */
  board_init();
  system_init_early();
  leds_init();

  set_busy_led(1);
  set_dirty_led(0);

  /* Due to an erratum in the LPC17xx chips anything that may change */
  /* peripheral clock scalers must come before system_init_late()    */
  uart_init();
#ifndef SPI_LATE_INIT
  spi_init(SPI_SPEED_SLOW);
#endif
  timer_init();
  bus_interface_init();
  i2c_init();

  /* Second part of system initialisation, switches to full speed on ARM */
  system_init_late();
  enable_interrupts();

  /* Internal-only initialisation, called here because it's faster */
  buffers_init();
  buttons_init();

  /* Anything that does something which needs the system clock */
  /* should be placed after system_init_late() */
  bus_init();    // needs delay
  rtc_init();    // accesses I2C
  disk_init();   // accesses card
  read_configuration();

  fatops_init(0);
  change_init();

  uart_puts_P(PSTR("\r\nsd2iec " VERSION " #"));
  uart_puthex(device_address);
  uart_putcrlf();

#ifdef CONFIG_REMOTE_DISPLAY
  /* at this point all buffers should be free, */
  /* so just use the data area of the first to build the string */
  uint8_t *strbuf = buffers[0].data;
  ustrcpy_P(strbuf, versionstr);
  ustrcpy_P(strbuf+ustrlen(strbuf), longverstr);
  if (display_init(ustrlen(strbuf), strbuf)) {
    display_address(device_address);
    display_current_part(0);
  }
#endif

  set_busy_led(0);

#if defined(HAVE_SD) && BUTTON_PREV != 0
  /* card switch diagnostic aid - hold down PREV button to use */
  if (!(buttons_read() & BUTTON_PREV)) {
    while (buttons_read() & BUTTON_NEXT) {
      set_dirty_led(sdcard_detect());
# ifndef SINGLE_LED
      set_busy_led(sdcard_wp());
# endif
    }
    reset_key(0xff);
  }
#endif

  bus_mainloop();

  while (1);
}
示例#15
0
int main(void)
{
	uint32_t start_time;
	uint32_t end_time;
	uint16_t max_current;
	uint16_t max_voltage;
	uint8_t on_off = 0;
	const button_status_t* bstatus;
	
	// safety delay
	_delay_ms(200);
	
	load_fuses_from_eeprom(&max_current,&max_voltage);
		
	systime_init();
	sound_init();
	uart_init();
	ui_measure_init();
	buttons_init();
	lcd_init();
	sei();
	
	lcd_write("abcdefghijklmnop","ABCDEFGHIJKLMNOP");
	
	dbg_trace1("Project name: %s\r\n", FIRMWARE_NAME);
	dbg_trace1("Version: %s\r\n", FIRMWARE_VERSION);
	dbg_trace1("Last update date: %s\r\n", FIRMWARE_LAST_UPDATE_DATE);
	dbg_trace1("Last update time: %s\r\n", FIRMWARE_LAST_UPDATE_TIME);
	dbg_trace1("Author: %s\r\n\r\n", FIRMWARE_AUTHOR);
	
	dbg_trace1("Maximal current is: %u\r\n", max_current);
	dbg_trace1("Maximal voltage is: %u\r\n\r\n", max_voltage);
	
	sound_play_intro();
	
	start_time = systime_get_time();
	end_time = start_time + 100; 
	 
    while (1)
    {	
		if ((bstatus = buttons_routine(&bstatus)))
		{
		
		if (bstatus->butt1_redge)
		{
			increment_current(&max_current);
			sound_beep_high();
			store_fuses_to_eeprom(max_current,max_voltage);
			dbg_trace1("current fuse set to %u mA\n", max_current);
		}
		else if (bstatus->butt2_redge)
		{
			decrement_current(&max_current);
			sound_beep_low();
			store_fuses_to_eeprom(max_current,max_voltage);
			dbg_trace1("current fuse set to %u mA\n", max_current);
		}
		else if (bstatus->butt3_redge)
		{
			increment_voltage(&max_voltage);
			sound_beep_high();
			store_fuses_to_eeprom(max_current,max_voltage);
			dbg_trace1("voltage fuse set to %u mV\n", max_voltage);
		}
		else if (bstatus->butt4_redge)
		{
			decrement_voltage(&max_voltage);
			sound_beep_low();
			store_fuses_to_eeprom(max_current,max_voltage);
			dbg_trace1("voltage fuse set to %u mV\n", max_voltage);
		}
		else if (bstatus->butt5_redge)
		{
			if (on_off)
			{
				on_off = 0;
				dbg_trace0("power supply is off\n");
				sound_beep_low();
			}
			else                                  
			{
				on_off = 1;
				dbg_trace0("power supply is on\n");
				sound_beep_high();
			}
		}
		}
		
        
		if (systime_is_time_passed(start_time, end_time))
		{
			start_time = end_time;
			end_time = start_time + 100;
			
			uint16_t voltage = ui_measure_get_voltage();
			uint16_t current = ui_measure_get_current();			
			
			char c[32];
			char v[32];
			
			sprintf(v,"%u",voltage);
			sprintf(c,"%u",current);
			
			lcd_write(v,c);
			
			dbg_trace2("%u\t %u\n", current, voltage);
		}
		
		sound_routine();
		
		// watch dog reset a sleep
    }
}
示例#16
0
int main(int argc, char *argv[])
{
    errval_t err;

    // Parse CMD Arguments
    bool got_apic_id = false;
    bool do_video_init = false;
    vtd_force_off = false;
    for (int i = 1; i < argc; i++) {
        if(sscanf(argv[i], "apicid=%" PRIuPTR, &my_apic_id) == 1) {
            got_apic_id = true;
        }

        if (strcmp(argv[i], "video_init") == 0) {
            do_video_init = true;
        } else if (strncmp(argv[i], "vtd_force_off", strlen("vtd_force_off")) == 0) {
            vtd_force_off = true;
 	}
    }

    if(got_apic_id == false) {
        fprintf(stderr, "Usage: %s APIC_ID\n", argv[0]);
        fprintf(stderr, "Wrong monitor version?\n");
        return EXIT_FAILURE;
    }

    err = oct_init();
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "Initialize dist");
    }

    //connect to the SKB
    ACPI_DEBUG("acpi: connecting to the SKB...\n");
    skb_client_connect();
    skb_execute("[pci_queries].");


    err = setup_skb_info();
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "Populating SKB failed.");
    }

    err = init_allocators();
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "Init memory allocator");
    }

    err = copy_bios_mem();
    if (err_is_fail(err)) {
        USER_PANIC_ERR(err, "Copy BIOS Memory");
    }

    int r = init_acpi();
    assert(r == 0);

    buttons_init();

    if (do_video_init) {
        video_init();
    }

    start_service();

    messages_handler_loop();
}
/**@brief Function for application main entry.
 */
int main(void)
{
    uint32_t err_code;

    // Initialize
    app_trace_init();
    leds_init();
    timers_init();

#ifdef COMMISSIONING_ENABLED
    err_code = pstorage_init();
    APP_ERROR_CHECK(err_code);

    buttons_init();
#endif // COMMISSIONING_ENABLED

    static ipv6_medium_init_params_t ipv6_medium_init_params;
    memset(&ipv6_medium_init_params, 0x00, sizeof(ipv6_medium_init_params));
    ipv6_medium_init_params.ipv6_medium_evt_handler    = on_ipv6_medium_evt;
    ipv6_medium_init_params.ipv6_medium_error_handler  = on_ipv6_medium_error;
    ipv6_medium_init_params.use_scheduler              = false;
#ifdef COMMISSIONING_ENABLED
    ipv6_medium_init_params.commissioning_id_mode_cb   = commissioning_id_mode_cb;
    ipv6_medium_init_params.commissioning_power_off_cb = commissioning_power_off_cb;
#endif // COMMISSIONING_ENABLED

    err_code = ipv6_medium_init(&ipv6_medium_init_params, \
                                IPV6_MEDIUM_ID_BLE,       \
                                &m_ipv6_medium);
    APP_ERROR_CHECK(err_code);

    eui48_t ipv6_medium_eui48;
    err_code = ipv6_medium_eui48_get(m_ipv6_medium.ipv6_medium_instance_id, \
                                     &ipv6_medium_eui48);

    // Hardcode EUI_48.
    uint8_t mac[EUI_48_SIZE] = {0xD9, 0xDA, 0x27, 0x2F, 0x6D, 0x00};
    memcpy(&ipv6_medium_eui48.identifier, mac, EUI_48_SIZE);

    //ipv6_medium_eui48.identifier[EUI_48_SIZE - 1] = 0x00;

    err_code = ipv6_medium_eui48_set(m_ipv6_medium.ipv6_medium_instance_id, \
                                     &ipv6_medium_eui48);
    APP_ERROR_CHECK(err_code);

    ip_stack_init();

    coap_port_t local_port_list[COAP_PORT_COUNT] = 
    {
        {.port_number = LOCAL_PORT_NUM}
    };
    
    coap_transport_init_t port_list;
    port_list.p_port_table = &local_port_list[0];

    err_code = coap_init(17, &port_list);
    APP_ERROR_CHECK(err_code);

    err_code = coap_error_handler_register(coap_error_handler);
    APP_ERROR_CHECK(err_code);

    coap_endpoints_init();

    iot_timer_init();

    APPL_LOG("\r\n");
    APPL_LOG("[APPL]: Init complete.\r\n");

    // Start execution
    connectable_mode_enter();

    // Enter main loop
    for (;;)
    {
        power_manage();
    }
}
示例#18
0
int main(void)
{
    log_init();

    leds_init();
    timer_init();
    counter_init();
    buttons_init();

    ble_stack_init();

    gap_params_init();
    conn_params_init();
    gatt_init();
    advertising_data_set();

    server_init();
    client_init();

    // Default ATT MTU size and connection interval are set at compile time.
    gatt_mtu_set(m_test_params.att_mtu);
    // Data Length Extension (DLE) is on by default.
    // Enable the Connection Event Length Extension.
    conn_evt_len_ext_set(m_test_params.conn_evt_len_ext_enabled);

    NRF_LOG_INFO("ATT MTU example started.\r\n");
    NRF_LOG_INFO("Press button 3 on the board connected to the PC.\r\n");
    NRF_LOG_INFO("Press button 4 on other board.\r\n");
    NRF_LOG_FLUSH();

    board_role_select();

    if (m_board_role == BOARD_TESTER)
    {
        m_print_menu = true;
    }
    if (m_board_role == BOARD_DUMMY)
    {
        advertising_start();
        scan_start();
    }

    // Enter main loop.
    NRF_LOG_DEBUG("Entering main loop.\r\n");
    for (;;)
    {
        if (m_print_menu)
        {
            menu_print();
        }

        if (is_test_ready())
        {
            m_run_test = true;
            test_run();
        }

        if (!NRF_LOG_PROCESS())
        {
            wait_for_event();
        }

    }
}
示例#19
0
/*
 *  Function for bootloader main entry.
 */
int main(void)
{
    uint32_t err_code;
    bool     dfu_start = false;
    bool     app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START);

    if (app_reset) {
        NRF_POWER->GPREGRET = 0;
    }

    leds_init();

#if defined(DBGLOG_SUPPORT)
    uart_init();
#endif

    PUTS("\nBootloader *** " __DATE__ "  " __TIME__ " ***");

    // This check ensures that the defined fields in the bootloader 
    // corresponds with actual setting in the nRF51 chip.
    APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START);
    APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE);

    // Initialize.
    timers_init();

#if defined(BUTTON_SUPPORT)
    buttons_init();
#endif

    (void)bootloader_init();

    if (bootloader_dfu_sd_in_progress()) {
        nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED);

        err_code = bootloader_dfu_sd_update_continue();
        APP_ERROR_CHECK(err_code);

        ble_stack_init(!app_reset);
        scheduler_init();

        err_code = bootloader_dfu_sd_update_finalize();
        APP_ERROR_CHECK(err_code);

        nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED);
    }
    else {
        // If stack is present then continue initialization of bootloader.
        ble_stack_init(!app_reset);
        scheduler_init();
        dis_init();
    }

    dfu_start  = app_reset;

#if defined(BUTTON_SUPPORT)
    dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0) ? true: false);
#endif

    if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START))) {

        nrf_gpio_pin_clear(UPDATE_IN_PROGRESS_LED);

        PUTS("Start DFU");

        // Initiate an update of the firmware.
        err_code = bootloader_dfu_start();
        APP_ERROR_CHECK(err_code);

        nrf_gpio_pin_set(UPDATE_IN_PROGRESS_LED);
    }

    if (bootloader_app_is_valid(DFU_BANK_0_REGION_START) && !bootloader_dfu_sd_in_progress()) {

        PUTS("Start App");

        // Select a bank region to use as application region.
        // @note: Only applications running from DFU_BANK_0_REGION_START is supported.
        bootloader_app_start(DFU_BANK_0_REGION_START);
    }

    NVIC_SystemReset();
}
示例#20
0
void input_init(void) {
    buttons_init();
    joystick_init();
    adc_init();
}
示例#21
0
文件: main.c 项目: albedium/homeauto
void main()
{
    di();
    OSCCON = 0x78;
    microlan_init();
    usart_init();
    buttons_init();
    ei();
    usart_pkt_send('I', 1);
    while (1) {
        usart_check();
        if (microlan_task != 0) {
            char fail = 0;
            char c;
            switch (microlan_task) {
                case MICROLAN_CMD_READROM:
                    if (!microlan_reset(microlan_line)) {
                        usart_pkt_send('M', 2);
                        usart_pkt_put(MICROLAN_ERROR_PRESENCE);
                    } else {
                        microlan_send(microlan_line, 0x33);
                        microlan_crc = 0;
                        for (c = 0; c < 8; c++) {
                            if (!microlan_recv(microlan_line,
                                    &microlan_buf[c])) {
                                fail = 1;
                                break;
                            }
                        }
                        if (fail) {
                            usart_pkt_send('M', 2);
                            usart_pkt_put(MICROLAN_ERROR_RECV);
                        } else if (microlan_crc != 0) {
                            usart_pkt_send('M', 2);
                            usart_pkt_put(MICROLAN_ERROR_CRC);
                        } else {
                            usart_pkt_send('M', 10);
                            usart_pkt_put(0);
                            for (c = 0; c < 8; c++)
                                usart_pkt_put(microlan_buf[c]);
                        }
                    }
                    break;
                case MICROLAN_CMD_CONVERTT:
                    if (!microlan_reset(microlan_line)) {
                        usart_pkt_send('M', 2);
                        usart_pkt_put(MICROLAN_ERROR_PRESENCE);
                    } else {
                        microlan_send(microlan_line, 0xcc);
                        microlan_send(microlan_line, 0x44);
                        usart_pkt_send('M', 2);
                        usart_pkt_put(0);
                    }
                    break;
                case MICROLAN_CMD_READTEMP:
                    if (!microlan_reset(microlan_line)) {
                        usart_pkt_send('M', 2);
                        usart_pkt_put(MICROLAN_ERROR_PRESENCE);
                    } else {
                        microlan_send(microlan_line, 0x55);
                        for (c = 0; c < 8; c++)
                            microlan_send(microlan_line, microlan_buf[c]);
                        microlan_send(microlan_line, 0xbe);
                        microlan_crc = 0;
                        for (c = 0; c < 8; c++) {
                            if (!microlan_recv(microlan_line,
                                    &microlan_buf[c])) {
                                fail = 1;
                                break;
                            }
                        }
                        if (fail || !microlan_recv(microlan_line, &c)) {
                            usart_pkt_send('M', 2);
                            usart_pkt_put(MICROLAN_ERROR_RECV);
                        } else if (microlan_crc != 0) {
                            usart_pkt_send('M', 2);
                            usart_pkt_put(MICROLAN_ERROR_CRC);
                        } else {
                            usart_pkt_send('M', 4);
                            usart_pkt_put(0);
                            usart_pkt_put(microlan_buf[0]);
                            usart_pkt_put(microlan_buf[1]);
                        }
                    }
                    break;
                case MICROLAN_CMD_SEARCHROM:
                    if (!microlan_reset(microlan_line)) {
                        usart_pkt_send('M', 2);
                        usart_pkt_put(MICROLAN_ERROR_PRESENCE);
                    } else {
                        microlan_send(microlan_line, 0xf0);
                        for (c = 0; c < 64; c++) {
                            unsigned char *buf = &microlan_buf[c / 8];
                            unsigned char mask = (1 << (c & 7));
                            char selectBit = (*buf & mask) ? 1 : 0;
                            char dataBit = microlan_search_bit(microlan_line,
                                    selectBit);
                            if (dataBit == 0xff) {
                                // Devices hold 0 too long
                                fail = 1;
                                usart_pkt_send('M', 2);
                                usart_pkt_put(MICROLAN_ERROR_RECV);
                                break;
                            } else if (dataBit == 3) {
                                // No devices replied
                                fail = 1;
                                usart_pkt_send('M', 2);
                                usart_pkt_put(MICROLAN_ERROR_NODEVICES);
                                break;
                            } else if (c < microlan_prefix_len) {
                                // Known bit
                                if (dataBit != 2 && dataBit != selectBit) {
                                    fail = 1;
                                    usart_pkt_send('M', 2);
                                    usart_pkt_put(MICROLAN_ERROR_SEARCH);
                                    break;
                                }
                            } else if (dataBit == 2) {
                                // Bit read conflict
                                fail = 2;
                                microlan_prefix_len = c;
                                break;
                            } else {
                                *buf = (*buf & ~mask) | (dataBit ? mask : 0);
                            }
                        }
                        if (fail == 1) {
                            // Error already sent
                        } else {
                            usart_pkt_send('M', 11);
                            usart_pkt_put(0);
                            if (fail == 2)
                                usart_pkt_put(microlan_prefix_len);
                            else
                                usart_pkt_put(64);
                            for (c = 0; c < 8; c++)
                                usart_pkt_put(microlan_buf[c]);
                        }
                    }
                    break;
            }
            microlan_task = 0;
        }
    }
}
示例#22
0
void buttons_runTest() {
    buttons_init();
    // Initialize the display for writing.
    display_init();
    // Clear the screen; make the whole thing black.
    display_fillScreen(DISPLAY_BLACK);
    // Set up a var for storing the current value of the buttons.
    // This will be updated every time our while loop cycles.
    uint32_t newVal = 0;
    // Set up a var for storing the previous value of the buttons.
    // This will be updated every time our while loop cycles.
    uint32_t lastVal = 0;
    // Set the text size to a value of 2.
    display_setTextSize(BUTTONS_TEXT_SIZE);

    // As long as all four buttons are not all pressed at once, do this:
    while(newVal ^ BUTTONS_ARE_ALL_PRESSED) {
        // Copy newVal into lastVal because we're going to update newVal.
        lastVal = newVal;
        // Read the state of the buttons into newVal.
        newVal = buttons_read();
        // We need to check whether BUTTONS_BUTTON1's corresponding square has
        // already been drawn. We don't want to draw it again if it's
        // already there.
        if(!(lastVal & BUTTONS_BUTTON1) && (newVal & BUTTONS_BUTTON1)) {
            // Fill the far right square with yellow.
            display_fillRect(BUTTONS_BUTTON1_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_YELLOW);
            // Set our text cursor to a good place in the center of the square.
            display_setCursor(BUTTONS_BUTTON1_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD);
            // Make the text color black.
            display_setTextColor(DISPLAY_BLACK);
            // Write BTN0 in the center of the square.
            display_println(BUTTONS_BUTTON1_TEXT);
        }
        // If the square is drawn, and button 1 is no longer pressed:
        else if((lastVal & BUTTONS_BUTTON1) && !(newVal & BUTTONS_BUTTON1)) {
            // Write a black square on top of the yellow square.
            display_fillRect(BUTTONS_BUTTON1_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK);
        }
        // Repeat the process for BUTTONS_BUTTON1 for all other buttons:
        if(!(lastVal & BUTTONS_BUTTON2) && (newVal & BUTTONS_BUTTON2)) {
            // Draw a green square
            display_fillRect(BUTTONS_BUTTON2_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_GREEN);
            // Set the cursor
            display_setCursor(BUTTONS_BUTTON2_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD);
            // Set text color to black
            display_setTextColor(DISPLAY_BLACK);
            // Write BTN1
            display_println(BUTTONS_BUTTON2_TEXT);
        }
        // If the BUTTONS_BUTTON2 square is there and BUTTONS_BUTTON2 is no longer pressed:
        else if((lastVal & BUTTONS_BUTTON2) && !(newVal & BUTTONS_BUTTON2)) {
            // Draw a black square over the top of the green one
            display_fillRect(BUTTONS_BUTTON2_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK);
        }
        // If BUTTONS_BUTTON3 is pressed and the square is not already drawn:
        if(!(lastVal & BUTTONS_BUTTON3) && (newVal & BUTTONS_BUTTON3)) {
            // Draw a red rectangle
            display_fillRect(BUTTONS_BUTTON3_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_RED);
            // Set the cursor
            display_setCursor(BUTTONS_BUTTON3_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD);
            // Set the text color to white
            display_setTextColor(DISPLAY_WHITE);
            // Write BTN2 to the screen
            display_println(BUTTONS_BUTTON3_TEXT);
        }
        // If BUTTONS_BUTTON3 is no longer pressed and the square is on the screen:
        else if((lastVal & BUTTONS_BUTTON3) && !(newVal & BUTTONS_BUTTON3)) {
            // Draw a black rectangle over the top of the red one
            display_fillRect(BUTTONS_BUTTON3_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK);
        }
        // If BUTTONS_BUTTON4 is pressed and the square isn't on the screen:
        if(!(lastVal & BUTTONS_BUTTON4) && (newVal & BUTTONS_BUTTON4)) {
            // Draw a blue rectangle
            display_fillRect(0, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLUE);
            // Set the cursor
            display_setCursor(BUTTONS_BUTTON4_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD);
            // Set the text to be white
            display_setTextColor(DISPLAY_WHITE);
            // Write BTN3 to the screen
            display_println(BUTTONS_BUTTON4_TEXT);
        }
        // If BUTTONS_BUTTON4 is no longer pressed and the square is on the screen:
        else if((lastVal & BUTTONS_BUTTON4) && !(newVal & BUTTONS_BUTTON4)) {
            // Draw a black square over the blue one
            display_fillRect(0, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK);
        }
    }
    // Once all 4 buttons are pressed simultaneously,
    // Draw a black square over the top part of the screen
    // To reset it.
    display_fillRect(0, 0, BUTTONS_SCREEN_WIDTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK);
}
示例#23
0
/*****************************************************************************
**   Main Function  main()
******************************************************************************/
int main (void) {

   /* Setup SysTick Timer for 10 msec interrupts  */
   if (SysTick_Config(SystemCoreClock / 100)) {
		while (1); /* Capture error */
   }

   if (!(SysTick->CTRL & SysTick_CTRL_CLKSOURCE_Msk)) {
        /* When external reference clock is used(CLKSOURCE in
		Systick Control and register bit 2 is set to 0), the
		SYSTICKCLKDIV must be a non-zero value and 2.5 times
		faster than the reference clock.
		When core clock, or system AHB clock, is used(CLKSOURCE
		in Systick Control and register bit 2 is set to 1), the
		SYSTICKCLKDIV has no effect to the SYSTICK frequency. See
		more on Systick clock and status register in Cortex-M3
		technical Reference Manual. */
		LPC_SYSCON->SYSTICKCLKDIV = 0x08;
	}


   GPIOInit();

   init_timers();


   // The LED on Xpresso
   /* Set port 0_7 to output */
   GPIOSetDir( LED_PORT, LED_BIT, 1 );
   GPIOSetValue( 0, 7, LEDvalue );

   // buttons
   buttons_init();

   power_mgr_init();

   // check for 'next' button
   if (GPIOGetValue(0, 6)) {
	   led_digits_init();
	   led_digits_enable();
	   //led_digits_set_blink(1);
	   led_red_set(1);
	   led_green_set(1);
   }
   else {
	   GPIOSetValue( 0, 7, 1 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 0 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 1 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 0 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 1 );
	   delay32Ms(0,500);
	   GPIOSetValue( 0, 7, 0 );
	   delay32Ms(0,500);
   }


   // BARCODE reader
   barcode_init();
   barcode_reset();

   // RFID reader
   rdm630_init();
   rdm630_reset();

   // UART
   UARTInit(115200);
   // Enable the UART Interrupt
   NVIC_EnableIRQ(UART_IRQn);
   LPC_UART->IER = IER_RBR | IER_RLS;

   logger_setEnabled(1);
   logger_logStringln("/O:entering main loop..."); // send online message (means i'm online)

   uint8_t counter = 0;
   for(counter = 0; counter < 100; counter++) {
	   led_digits_set_value(counter);
	   delay32Ms(0, 20);
   }

   for(counter = 0; counter < 10; counter++) {
	   led_digits_set_value_by_chars('0' + counter, '0' + counter);
	   delay32Ms(0, 200);
   }
   delay32Ms(0, 200);
   led_digits_enable();

   signal_boot_up();

   int8_t last_remaining_seconds = -1;
   while (1) {

       /* process logger */
       if (logger_dataAvailable() && UARTTxEmpty) {
         uint8_t iCounter;
         // fill transmit FIFO with 14 bytes
         for (iCounter = 0; iCounter < 14 && logger_dataAvailable(); iCounter++) {
            UARTSendByte(logger_read());
         }
       }

       power_mgr_process(msTicks);

       barcode_process(msTicks);

       rdm630_process(msTicks);

       buttons_process(msTicks);

       led_digits_process(msTicks);


       /*
	   if (power_mgr_is_shutting_down()) {
		   if (power_mgr_get_remaining_player_seconds() != last_remaining_seconds) {
			   last_remaining_seconds = power_mgr_get_remaining_player_seconds();
			   led_digits_set_value(last_remaining_seconds);
		   }
		   if (last_remaining_seconds == 0) {
			   led_green_set(0);
			   led_red_set(1);
			   led_digits_disable();
		   }
		   continue;
	   }
	   */


       main_process_barcode();

       main_process_rfid();

       main_process_buttons();

       main_process_uart();

   }
}
//#pragma FUNC_NEVER_RETURNS(main);
void
main(void)
{
  _disable_interrupts();
  msp430_init();
  clock_init();
	
  // initialize uip_variables
  memset(uip_buf, 0, UIP_CONF_BUFFER_SIZE);
  uip_len = 0;
	
  leds_init();
  buttons_init();
  usb_init_proc();
	
	/* Create MAC addresses based on a hash of the unique id (wafle id + x-pos 
	 * in wafel + y-pos in wafel).
	 * We use rime addresses in order to use useful rime address handling
	 * functions.
	 */
	/* The sicslowmac layer requires the mac address to be placed in the global 
	 * (extern) variable rimeaddr_node_addr (declared rimeaddr.h).
	 */
  rimeaddr_node_addr.u8[0] = NODE_BASE_ADDR0;
  rimeaddr_node_addr.u8[1] = NODE_BASE_ADDR1;
  rimeaddr_node_addr.u8[2] = NODE_BASE_ADDR2;
  rimeaddr_node_addr.u8[3] = NODE_BASE_ADDR3;
  rimeaddr_node_addr.u8[4] = NODE_BASE_ADDR4;
  rimeaddr_node_addr.u8[5] = *((unsigned char*)(WAFERID+2));	// lowest byte of wafer id
  rimeaddr_node_addr.u8[6] = *((unsigned char*)(WAFERIPOSX));	// lowest byte of x-pos in wafer
  rimeaddr_node_addr.u8[7] = *((unsigned char*)(WAFERIPOSY));	// lowest byte of y-pos in wafer

	/* The following line sets the link layer address. This must be done
 	 * before the tcpip_process is started since in its initialization
 	 * routine the function uip_netif_init() will be called from inside 
 	 * uip_init()and there the default IPv6 address will be set by combining
 	 * the link local prefix (fe80::/64)and the link layer address. 
 	 */ 
  rimeaddr_copy((rimeaddr_t*)&uip_lladdr.addr, &rimeaddr_node_addr);
  
  /* Initialize the process module */ 
  process_init();
  /* etimers must be started before ctimer_init */
  // clock_init();
  process_start(&etimer_process, NULL);
  	
  /* Start radio and radio receive process */
	if (NETSTACK_RADIO.init() == FAILED) {
		led_on(LED_RED);
		_disable_interrupts();
		LPM4; // die
	}
	
	/* Initialize stack protocols */
	queuebuf_init();
	NETSTACK_RDC.init();
	NETSTACK_MAC.init();
	NETSTACK_NETWORK.init();
    
  /* Initialize tcpip process */
	process_start(&tcpip_process, NULL);
	
	/* Initialize our application(s) */
	process_start(&rfid_find_tags, NULL);
	process_start(&usb_input_process, NULL);
	
	process_start(&coap_app_client, NULL);
	//process_start(&coap_app, NULL);
	
  /* Enter main loop */	
	while(1) {
		/* poll every running process which has requested to be polled */
    process_run();
    /* 
     * Enter low power mode 3 safely. The CPU will wake up in the timer 
     * interrupt or whenever a packet arrives. In the timer interrupt
     * routine, we check wether an etimer has expired and, if so,
     * we call the etimer_request_poll() function
     */
    //LPM3;
  }
}
示例#25
0
static void init(void) {
  config_load();

#ifdef ENABLE_LOCALIZE
  locale_init();
#endif
  heartrate_init();
  s_gpsdata.heartrate = 255; // no data at startup
  bg_color_data_main = BG_COLOR_DATA_MAIN;

#ifdef ENABLE_NAVIGATION_FULL
  for (uint16_t i = 0; i < NAV_NB_POINTS_STORAGE - 1; i++) {
    s_gpsdata.nav_xpos[i] = s_gpsdata.nav_ypos[i] = INT16_MAX;
  }
#endif

#ifdef ENABLE_DEBUG_FIELDS_SIZE
  strcpy(s_data.speed, "188.8");
  strcpy(s_data.distance, "88.8");
  strcpy(s_data.avgspeed, "888.8");
  strcpy(s_data.altitude, "888.8");
  strcpy(s_data.ascent, "1342");
  strcpy(s_data.ascentrate, "548");
  strcpy(s_data.slope, "5");
  strcpy(s_data.accuracy, "9");
  strcpy(s_data.bearing, "270");
  strcpy(s_data.elapsedtime, "1:05:28");
  strcpy(s_data.maxspeed, "25.3");
  strcpy(s_data.heartrate, "128");
  strcpy(s_data.cadence, "90");
#endif
#ifdef ENABLE_DEMO
  strcpy(s_data.maxspeed, "26.1");
  strcpy(s_data.distance, "2.0");
  strcpy(s_data.avgspeed, "14.0");
  strcpy(s_data.altitude, "1139");
  strcpy(s_data.accuracy, "4");
  strcpy(s_data.steps, "7548");
  strcpy(s_data.elapsedtime, "1:15:28");
  strcpy(s_data.heartrate, "154");
  s_gpsdata.heartrate = 154;
  heartrate_new_data(s_gpsdata.heartrate);
  s_data.live = 1;
  s_data.state = STATE_START;

  s_gpsdata.nav_distance_to_destination100 = 12100;
  s_gpsdata.nav_next_distance1000 = 1345;
  s_gpsdata.nav_error1000 = 55;
  snprintf(s_data.nav_next_distance,   sizeof(s_data.nav_next_distance),   "%d",   s_gpsdata.nav_next_distance1000);
#else
  strcpy(s_data.speed, "0.0");
  strcpy(s_data.distance, "-");
  strcpy(s_data.avgspeed, "-");
  strcpy(s_data.altitude, "-");
  strcpy(s_data.ascent, "-");
  strcpy(s_data.ascentrate, "-");
  strcpy(s_data.slope, "-");
  strcpy(s_data.accuracy, "-");
  strcpy(s_data.bearing, "-");
  strcpy(s_data.elapsedtime, "00:00:00");
  strcpy(s_data.maxspeed, "-");
  strcpy(s_data.heartrate, "-");
  strcpy(s_data.cadence, "-");
  strcpy(s_data.nav_next_distance, "-");
  strcpy(s_data.nav_distance_to_destination, "-");
  strcpy(s_data.nav_ttd, "-");
  strcpy(s_data.nav_eta, "-");
#endif
  //strcpy(s_data.lat, "-");
  //strcpy(s_data.lon, "-");
  //strcpy(s_data.nbascent, "-");

  s_data.phone_battery_level = -1;

#ifdef PBL_PLATFORM_CHALK
  font_roboto_bold_16 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_16));
#endif
  font_roboto_bold_62 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_62));

  // set default unit of measure
  change_units(UNITS_IMPERIAL, true);

  buttons_init();

  s_data.window = window_create();
  window_set_background_color(s_data.window, BG_COLOR_WINDOW);
#ifdef PBL_SDK_2
  window_set_fullscreen(s_data.window, true);
#endif
  topbar_layer_init(s_data.window);

  screen_data_layer_init(s_data.window);
  //screen_altitude_layer_init(s_data.window);
#ifdef ENABLE_FUNCTION_LIVE
  screen_live_layer_init(s_data.window);
#endif
  screen_map_layer_init(s_data.window);

  #ifdef PRODUCTION
    #ifndef ENABLE_DEMO
      screen_reset_instant_data();
    #endif
  #endif

  action_bar_init(s_data.window);
  menu_init();

  // Reduce the sniff interval for more responsive messaging at the expense of
  // increased energy consumption by the Bluetooth module
  // The sniff interval will be restored by the system after the app has been
  // unloaded
  //app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
  
  communication_init();

  screen_data_update_config(true);
  //screen_altitude_update_config();
  graph_init();
  
  window_stack_push(s_data.window, true /* Animated */);
  
  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);
  bluetooth_connection_service_subscribe(bt_callback);
  
  send_version(true);
}
示例#26
0
int main(void) {
  /* Early system initialisation */
  early_board_init();
  system_init_early();
  leds_init();

  set_busy_led(1);
  set_dirty_led(0);

  /* Due to an erratum in the LPC17xx chips anything that may change */
  /* peripheral clock scalers must come before system_init_late()    */
  uart_init();
#ifndef SPI_LATE_INIT
  spi_init(SPI_SPEED_SLOW);
#endif
  timer_init();
  i2c_init();

  /* Second part of system initialisation, switches to full speed on ARM */
  system_init_late();
  enable_interrupts();

  /* Prompt software name and version string */
  uart_puts_P(PSTR("\r\nNODISKEMU " VERSION "\r\n"));

  /* Internal-only initialisation, called here because it's faster */
  buffers_init();
  buttons_init();

  /* Anything that does something which needs the system clock */
  /* should be placed after system_init_late() */
  rtc_init();    // accesses I2C
  disk_init();   // accesses card
  read_configuration(); // restores configuration, may change device address

  filesystem_init(0);
  // FIXME: change_init();

#ifdef CONFIG_REMOTE_DISPLAY
  /* at this point all buffers should be free, */
  /* so just use the data area of the first to build the string */
  uint8_t *strbuf = buffers[0].data;
  ustrcpy_P(strbuf, versionstr);
  ustrcpy_P(strbuf+ustrlen(strbuf), longverstr);
  if (display_init(ustrlen(strbuf), strbuf)) {
    display_address(device_address);
    display_current_part(0);
  }
#endif

  set_busy_led(0);

#if defined(HAVE_SD)
  /* card switch diagnostic aid - hold down PREV button to use */
  if (menu_system_enabled && get_key_press(KEY_PREV))
    board_diagnose();
#endif

  if (menu_system_enabled)
    lcd_splashscreen();

  bus_interface_init();
  bus_init();
  read_configuration();
  late_board_init();

  for (;;) {
    if (menu_system_enabled)
      lcd_refresh();
    else {
      lcd_clear();
      lcd_printf("#%d", device_address);
    }
    /* Unit number may depend on hardware and stored settings */
    /* so present it here at last */
    printf("#%02d\r\n", device_address);
    bus_mainloop();
    bus_interface_init();
    bus_init();    // needs delay, inits device address with HW settings
  }
}
示例#27
0
/**@brief Function for bootloader main entry.
 */
int main(void)
{
    uint32_t err_code;
    bool     dfu_start = false;
    bool     app_reset = (NRF_POWER->GPREGRET == BOOTLOADER_DFU_START);

    leds_init();

    // This check ensures that the defined fields in the bootloader corresponds with actual
    // setting in the nRF51 chip.
    APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START);
    APP_ERROR_CHECK_BOOL(NRF_FICR->CODEPAGESIZE == CODE_PAGE_SIZE);

    // Initialize.
    timers_init();
    gpiote_init();
    buttons_init();
    (void)bootloader_init();

    if (bootloader_dfu_sd_in_progress())
    {
        err_code = bootloader_dfu_sd_update_continue();
        APP_ERROR_CHECK(err_code);

        ble_stack_init(!app_reset);
        scheduler_init();

        err_code = bootloader_dfu_sd_update_finalize();
        APP_ERROR_CHECK(err_code);
    }
    else
    {
        // If stack is present then continue initialization of bootloader.
        ble_stack_init(!app_reset);
        scheduler_init();
    }

    dfu_start  = app_reset;
   // dfu_start |= ((nrf_gpio_pin_read(BOOTLOADER_BUTTON_PIN) == 0) ? true: false);
    
    if (dfu_start || (!bootloader_app_is_valid(DFU_BANK_0_REGION_START)))
    {
        err_code = sd_power_gpregret_clr(POWER_GPREGRET_GPREGRET_Msk);
        APP_ERROR_CHECK(err_code);

        nrf_gpio_pin_set(LED_0);

        // Initiate an update of the firmware.
        err_code = bootloader_dfu_start();
        APP_ERROR_CHECK(err_code);

        nrf_gpio_pin_clear(LED_0);
    }

    if (bootloader_app_is_valid(DFU_BANK_0_REGION_START))
    {
        leds_off();

        // Select a bank region to use as application region.
        // @note: Only applications running from DFU_BANK_0_REGION_START is supported.
        bootloader_app_start(DFU_BANK_0_REGION_START);
    }

    nrf_gpio_pin_clear(LED_0);
    nrf_gpio_pin_clear(LED_1);
    
    NVIC_SystemReset();
}
示例#28
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 ();
    }
}