Ejemplo n.º 1
0
/* inline since branch is chosen at compile time */
static inline void usb_slave_mode(bool on)
{
    int rc;

    if(on)
    {
        DEBUGF("Entering USB slave mode\n");
        storage_soft_reset();
        storage_init();
        storage_enable(false);
        usb_enable(true);
        cpu_idle_mode(true);
    }
    else
    {
        DEBUGF("Leaving USB slave mode\n");

        cpu_idle_mode(false);

        /* Let the ISDx00 settle */
        sleep(HZ*1);

        usb_enable(false);

        rc = storage_init();
        if(rc)
            panicf("storage: %d",rc);

        rc = disk_mount_all();
        if (rc <= 0) /* no partition */
            panicf("mount: %d",rc);
    }
}
Ejemplo n.º 2
0
DSTATUS disk_initialize (
    BYTE pdrv                /* Physical drive nmuber (0..) */
)
{
    switch (pdrv) {
        case PD_FLASH:
            storage_init();
            return 0;

#if MICROPY_HW_HAS_SDCARD
        case PD_SDCARD:
            if (!sdcard_power_on()) {
                return STA_NODISK;
            }
            // TODO return STA_PROTECT if SD card is read only
            return 0;
#endif

        case PD_USER:
            if (MP_STATE_PORT(fs_user_mount) == NULL) {
                return STA_NODISK;
            }
            if (MP_STATE_PORT(fs_user_mount)->writeblocks[0] == MP_OBJ_NULL) {
                return STA_PROTECT;
            }
            return 0;
    }

    return STA_NOINIT;
}
Ejemplo n.º 3
0
int main(int argc, char* argv[]) {
    int rc;

    /* drop privileges */
    if (drop_privs() < 0) return EXIT_FAILURE;

    /* parse arguments */
    parse_args(argc, argv);

    /* initialize secure storage directory */
    rc = storage_init(ss_data_root);
    if (rc < 0) return EXIT_FAILURE;

    /* open rpmb device */
    rc = rpmb_open(rpmb_devname, dev_type);
    if (rc < 0) return EXIT_FAILURE;

    /* connect to Trusty secure storage server */
    rc = ipc_connect(trusty_devname, ss_srv_name);
    if (rc < 0) return EXIT_FAILURE;

    /* enter main loop */
    rc = proxy_loop();
    ALOGE("exiting proxy loop with status (%d)\n", rc);

    ipc_disconnect();
    rpmb_close();

    return (rc < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
}
Ejemplo n.º 4
0
int main(void)
{
	gpio_init();
	uart_init();
    timers_init();
    __LOG("Timers initialized.");

    ble_stack_init();
    //device_manager_init(erase_bonds);
    gap_params_init();
    services_init();
    advertising_init();
   	__LOG("Radio initialized.");
    conn_params_init();

   	storage_init();
   	contacts_init();
   	__LOG("Application modules initialized");

    // Start execution.
    timers_start();
    advertising_start();
   	__LOG("ADV Started");
   	scan_start();
   	__LOG("Scan Started");

    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
Ejemplo n.º 5
0
int main(void)
{
    _buttonusr_isr = (void *)&buttonisr_usr;
    _timerusr_isr = (void *)&timerisr_usr;
    _mmhusr_isr = (void *)&mmhisr;

    /* Drop privileges */
    drop_privs();

    /* Init board */
    kk_board_init();

    /* Program the model into OTP, if we're not in screen-test mode, and it's
     * not already there
     */
    (void)flash_programModel();

    /* Init for safeguard against stack overflow (-fstack-protector-all) */
    __stack_chk_guard = (uintptr_t)random32();

    /* Bootloader Verification */
    check_bootloader();

    led_func(SET_RED_LED);
    dbg_print("Application Version %d.%d.%d\n\r", MAJOR_VERSION, MINOR_VERSION,
              PATCH_VERSION);

    /* Init storage */
    storage_init();

    /* Init protcol buffer message map and usb msg callback */
    fsm_init();

    led_func(SET_GREEN_LED);

    usbInit();
    u2fInit();
    led_func(CLR_RED_LED);

    reset_idle_time();

    if (is_mfg_mode())
        layout_screen_test();
    else if (!storage_isInitialized())
        layout_standard_notification("Welcome", "keepkey.com/get-started",
                                     NOTIFICATION_LOGO);
    else
        layoutHomeForced();

    while (1) {
        delay_ms_with_callback(ONE_SEC, &exec, 1);
        increment_idle_time(ONE_SEC);
        toggle_screensaver();
    }

    return 0;
}
Ejemplo n.º 6
0
int main() {
    
    STORAGE storage;
    CONFIG *cnf = parseINI("/etc/sybil/sybil.ini");
    
    storage_init(&storage, cnf);
    
    return 0;
}
Ejemplo n.º 7
0
STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
    mp_int_t cmd = mp_obj_get_int(cmd_in);
    switch (cmd) {
        case BP_IOCTL_INIT: storage_init(); return MP_OBJ_NEW_SMALL_INT(0);
        case BP_IOCTL_DEINIT: storage_flush(); return MP_OBJ_NEW_SMALL_INT(0); // TODO properly
        case BP_IOCTL_SYNC: storage_flush(); return MP_OBJ_NEW_SMALL_INT(0);
        case BP_IOCTL_SEC_COUNT: return MP_OBJ_NEW_SMALL_INT(storage_get_block_count());
        case BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(storage_get_block_size());
        default: return mp_const_none;
    }
}
Ejemplo n.º 8
0
void main(void) {
    //leds:
    LED_INIT();

    //init clock source XOSC:
    clocksource_init();

    //init uart
    uart_init();

    //init wdt timer
    wdt_init();

    apa102_init();

    //init storage
    storage_init();

    //enable timeout routines
    timeout_init();

    //apa102_init();

    //init frsky core
    frsky_init();

    //init adc
    adc_init();

    //init output
    #if SBUS_ENABLED
    sbus_init();
    #else
    ppm_init();
    #endif

    //init failsafe
    failsafe_init();

    debug("main: init done\n");

    //run main
    //frsky_frame_sniffer();
    frsky_main();

    LED_RED_ON();
    while (1) {
        LED_RED_ON();
        delay_ms(200);
        LED_RED_OFF();
        delay_ms(200);
    }
}
Ejemplo n.º 9
0
void storage_step()
{
	if (SD_CARD_DETECT)
	{
		if (!sd_avalible)
			storage_init();
	}
	else
	{
		if (sd_avalible)
			storage_deinit();
	}
}
Ejemplo n.º 10
0
int main(void) {
    // leds:
    led_init();

    // init clock sources:
    clocksource_init();

    // init ios
    io_init();

    // init debug
    debug_init();

    // init wdt timer
    wdt_init();

    // enable timeout routines
    timeout_init();

    // init storage
    storage_init();

    // init frsky core
    frsky_init();

    // init adc
    adc_init();

    // init output
#ifdef SBUS_ENABLED
    sbus_init();
#else  // SBUS_ENABLED
    ppm_init();
#endif  // SBUS_ENABLED

    // init failsafe
    failsafe_init();

    // init telemetry
    telemetry_init();

    // run main
    debug("main: init done\n");

    // frsky_frame_sniffer();
    frsky_main();

    debug("main: frsky main ended?! THIS SHOULD NOT HAPPEN!");
    while (1) {}
}
Ejemplo n.º 11
0
// Called during bootloader initialization
void Chip_setup()
{
	// Disable WDT
	WDT->WDT_MR = WDT_MR_WDDIS;

	// Initialize non-volatile storage
	storage_init();

	// Make sure USB transceiver is reset (in case we didn't do a full reset)
	udc_stop();

	// Start USB stack
	udc_start();
}
Ejemplo n.º 12
0
void storage_step()
{
	if (SD_CARD_DETECT)
	{
		if (!sd_avalible && !sd_error)
			storage_init();
	}
	else
	{
		if (sd_avalible)
			storage_deinit();
		sd_error = false;
	}
}
Ejemplo n.º 13
0
void
boot(void)
{
	if (warm_reset())
		force_emif_self_refresh();

	watchdog_init();
	mux_init();
	enable_uart_clocks();
	cons_init();
	scale_vcores();
	clock_init();
	sdram_init();
	bzero(__bss_start, __bss_end - __bss_start);
	timer_init();
	storage_init();
}
Ejemplo n.º 14
0
Archivo: clamb.c Proyecto: irori/clamb
int main(int argc, char *argv[])
{
    Cell root;
    clock_t start;
    char *prog_file = NULL;
    int i;
    int print_stats = 0;
    int parse_only = 0;
    
    for (i = 1; i < argc && argv[i][0] == '-'; i++) {
	if (strcmp(argv[i], "-g") == 0)
	    gc_notify = 1;
	else if (strcmp(argv[i], "-s") == 0)
	    print_stats = 1;
	else if (strcmp(argv[i], "-p") == 0)
	    parse_only = 1;
        else if (strcmp(argv[i], "-u") == 0)
	    setbuf(stdout, NULL);
	else
	    errexit("unknown option %s\n", argv[i]);
    }

    input_init(argv + i);
    storage_init(INITIAL_HEAP_SIZE);
    rs_init();

    root = load_program();
    if (parse_only) {
	unparse(root);
	return 0;
    }

    start = clock();
    eval_print(root);

    if (print_stats) {
	double evaltime = (clock() - start) / (double)CLOCKS_PER_SEC;

	printf("\n%d reductions\n", reductions);
	printf("  total eval time --- %5.2f sec.\n", evaltime - total_gc_time);
	printf("  total gc time   --- %5.2f sec.\n", total_gc_time);
	printf("  max stack depth --- %d\n", rs_max_depth());
    }
    return 0;
}
Ejemplo n.º 15
0
DSTATUS disk_initialize (
    BYTE pdrv                /* Physical drive nmuber (0..) */
)
{
    switch (pdrv) {
        case PD_FLASH:
            storage_init();
            return 0;

        case PD_SDCARD:
            if (!sdcard_power_on()) {
                return STA_NODISK;
            }
            // TODO return STA_PROTECT if SD card is read only
            return 0;
    }

    return STA_NOINIT;
}
Ejemplo n.º 16
0
// Called during bootloader initialization
void Chip_setup()
{
	// Disable WDT
	WDT->WDT_MR = WDT_MR_WDDIS;

	// Enable Debug LED
	const GPIO_Pin debug_led = gpio(B,0);
	GPIO_Ctrl( debug_led, GPIO_Type_DriveSetup, GPIO_Config_None );
	GPIO_Ctrl( debug_led, GPIO_Type_DriveHigh, GPIO_Config_None );

	// Initialize non-volatile storage
	storage_init();

	// Make sure USB transceiver is reset (in case we didn't do a full reset)
	udc_stop();

	// Start USB stack
	udc_start();
}
Ejemplo n.º 17
0
int main (int argc, const char *argv[])
{

    // Check input
    if (argc < 2) {
        printf("Usage: passmate-cli <path_to_storage>\n");
        abort();
    }

    // Get and check storage path
    char * storage_path = argv[1];
    if (fopen(storage_path, "rb") == NULL) {
        printf("Path to a storage file is wrong.\n");
        abort();
    }

    // Save storage path
    __db_path__ = (char *) malloc(sizeof(char) * (strlen(storage_path) + 1));
    strcpy(__db_path__, storage_path);

    // Get and check master key
    char * key = getpass("Enter your master key: ");
    if (strlen(key) < 5) {
        printf("Your master key is too short. It has to be longer than 5 characters.\n");
        abort();
    }

    // Get and check storage
    __storage__ = storage_read_from_file(storage_path, key);
    if (__storage__ == NULL) __storage__ = storage_init(key);

    // Run loop
    printf("Passmate CLI %s\n", PASSMATE_CLI_VERSION);
    printf("Type 'help' for more information\n");
    command_loop();

    return 0;
}
Ejemplo n.º 18
0
/*
 * main() - Application main entry
 *
 * INPUT
 *     none
 * OUTPUT
 *     0 when complete
 */
int main(void)
{
    /* Init for safeguard against stack overflow (-fstack-protector-all) */
    __stack_chk_guard = (uintptr_t)random32();

    /* Init board */
    board_init();
    led_func(SET_RED_LED);
    dbg_print("Application Version %d.%d.%d\n\r", MAJOR_VERSION, MINOR_VERSION,
              PATCH_VERSION);

    /* Init storage */
    storage_init();

    /* Init protcol buffer message map and usb msg callback */
    fsm_init();

    led_func(SET_GREEN_LED);
    
    screen_test();

    /* Enable interrupt for timer */
    cm_enable_interrupts();

    usb_init();
    led_func(CLR_RED_LED);

    reset_idle_time();

    while(1)
    {
        delay_ms_with_callback(ONE_SEC, &exec, 1);
        increment_idle_time(ONE_SEC);
        toggle_screensaver();
    }

    return(0);
}
Ejemplo n.º 19
0
//-----------------------------------------------------------------------------
// Main... process command line parameters, and if we have enough information, then create an empty stash.
int main(int argc, char **argv) 
{
	int c;
	storage_t *storage = NULL;
	stash_t *stash = NULL;
	int result;
	const char *basedir = NULL;
	const char *newuser = NULL;
	const char *newpass = NULL;
	const char *host = NULL;
	const char *username = NULL;
	const char *password = NULL;
	user_t *user;
	stash_result_t res;
	
	
	assert(argc >= 0);
	assert(argv);
	
	// process arguments
	/// Need to check the options in here, there're possibly ones that we dont need.
	while ((c = getopt(argc, argv, "hvd:u:p:H:U:P:")) != -1) {
		switch (c) {
			case 'h':
				usage();
				exit(EXIT_SUCCESS);
			case 'v':
				verbose++;
				break;
			case 'd':
				basedir = optarg;
				break;
			case 'u':
				newuser = optarg;
				break;
			case 'p':
				newpass = optarg;
				break;

			case 'H':
				host = optarg;
				break;
			case 'U':
				username = optarg;
				break;
			case 'P':
				password = optarg;
				break;
				
			default:
				fprintf(stderr, "Illegal argument \"%c\"\n", c);
				exit(1);
				
		}
	}
	
	// check that our required params are there:
	if (basedir == NULL && host == NULL) {
		fprintf(stderr, "missing required option, either -d or -H\n");
		exit(1);
	}
	else if (basedir && host) {
		fprintf(stderr, "cannot specify both a directory and a host.\n");
		exit(1);
	}
	else if (newpass == NULL) {
		fprintf(stderr, "missing required parameter: -p\n");
		exit(1);
	}
	else if (newuser == NULL) {
		fprintf(stderr, "missing required parameter: -u\n");
		exit(1);
	}
	
	result = 0;
	
	if (basedir) {
		// we are using a basedir direct method.  For this we will need to use 
		// the stash_storage functionality (that is part of the libstash 
		// library).
		
		storage = storage_init(NULL);
		assert(storage);
		
		// process the main meta file;
		assert(basedir);
		storage_lock_master(storage, basedir);
		storage_process(storage, basedir, KEEP_OPEN, IGNORE_DATA);
		
		// if the namespace is available, then create it.
		assert(newuser);
		user = storage_getuser(storage, NULL_USER_ID, newuser);
		if (user == NULL) {
			fprintf(stderr, "Username '%s' does not exist.\n", newuser);
			result = 1;
		}
		else {
			assert(user->uid > 0);
			
			storage_set_password(storage, NULL_USER_ID, user->uid, newpass);

			if (verbose) {
				printf("Password for user '%s' changed.\n", newuser);
				assert(result == 0);
			}
		}
		
		storage_unlock_master(storage, basedir);
		
		// cleanup the storage 
		storage_free(storage);
		storage = NULL;		
	}
	else {
		// network version.
		
		stash = stash_init(NULL);
		assert(stash);
		
		// add our username and password to the authority... in future 
		// versions, private and public keys may be used instead.
		assert(username);
		assert(password);
		stash_authority(stash, username, password);

		// add our known host to the server list.
		assert(host);
		stash_addserver(stash, host, 10);
		
		// connect to the database... check error code.
		// although it is not necessary to connect now, because if we dont, 
		// the first operation we do will attempt to connect if we are not 
		// already connected.  However, it is useful right now to attempt to 
		// connect so that we can report the error back to the user.  Easier 
		// to do it here and it doesn't cost anything.
		res = stash_connect(stash);
		if (res != 0) {
			fprintf(stderr, "Unable to connect: %04X:%s\n", res, stash_err_text(res));
		}
		else {

			res = stash_set_password(stash, 0, newuser, newpass);
			if (res != STASH_ERR_OK) {
				switch(res) {
					case STASH_ERR_OK:
						if (verbose) { printf("Password set for user '%s'.\n", newuser); }
						break;
					
					case STASH_ERR_USERNOTEXIST:
						fprintf(stderr, "Username '%s' does not exist.\n", newuser);
						break;
					case STASH_ERR_INSUFFICIENTRIGHTS:
						fprintf(stderr, "Insufficient rights to change passwords.\n");
						break;
					default:
						fprintf(stderr, "Unexpected error: %04X:%s\n", res, stash_err_text(res));
						break;
				}
				result = 1;
			}
		}
		
		// cleanup the storage 
		stash_free(stash);
		stash = NULL;		
	}

	assert(stash == NULL);
	assert(storage == NULL);
	
	return(result);
}
Ejemplo n.º 20
0
Archivo: main.c Proyecto: eerimoq/simba
static void init(void)
{
    long number;
    struct fat16_dir_t dir;
    struct fat16_dir_entry_t entry;
    struct song_t *song_p;
    uint32_t seconds;
    fat16_read_t read;
    fat16_write_t write;
    void * arg_p;

    sys_start();
    uart_module_init();

    uart_init(&uart, &uart_device[0], 38400, qinbuf, sizeof(qinbuf));
    uart_start(&uart);

    sys_set_stdout(&uart.chout);

    std_printf(sys_get_info());

    fs_command_init(&cmd_list, FSTR("/list"), cmd_list_cb, NULL);
    fs_command_register(&cmd_list);
    fs_command_init(&cmd_play, FSTR("/play"), cmd_play_cb, NULL);
    fs_command_register(&cmd_play);
    fs_command_init(&cmd_pause, FSTR("/pause"), cmd_pause_cb, NULL);
    fs_command_register(&cmd_pause);
    fs_command_init(&cmd_next, FSTR("/next"), cmd_next_cb, NULL);
    fs_command_register(&cmd_next);
    fs_command_init(&cmd_prev, FSTR("/prev"), cmd_prev_cb, NULL);
    fs_command_register(&cmd_prev);
    fs_command_init(&cmd_stop, FSTR("/stop"), cmd_stop_cb, NULL);
    fs_command_register(&cmd_stop);
    fs_command_init(&cmd_repeat, FSTR("/repeat"), cmd_repeat_cb, NULL);
    fs_command_register(&cmd_repeat);
    fs_command_init(&cmd_set_bits_per_sample,
                    FSTR("/set_bits_per_sample"),
                    cmd_set_bits_per_sample_cb,
                    NULL);
    fs_command_register(&cmd_set_bits_per_sample);

    if (storage_init(&read, &write, &arg_p) != 0) {
        std_printf(FSTR("storage init failed\r\n"));
        return;
    }

    std_printf(FSTR("initializing fat16\r\n"));
    fat16_init(&fs, read, write, arg_p, 0);

    std_printf(FSTR("fat16 initialized\r\n"));

    if (fat16_mount(&fs) != 0) {
        std_printf(FSTR("failed to mount fat16\r\n"));
        return;
    }

    std_printf(FSTR("fat16 mounted\r\n"));

    event_init(&event);

    exti_module_init();

    /* Initialize the buttons. */
    exti_init(&buttons[0],
              &exti_d18_dev,
              EXTI_TRIGGER_FALLING_EDGE,
              on_button_play,
              NULL);
    exti_start(&buttons[0]);
    exti_init(&buttons[1],
              &exti_d19_dev,
              EXTI_TRIGGER_FALLING_EDGE,
              on_button_prev,
              NULL);
    exti_start(&buttons[1]);
    exti_init(&buttons[2],
              &exti_d20_dev,
              EXTI_TRIGGER_FALLING_EDGE,
              on_button_next,
              NULL);
    exti_start(&buttons[2]);
    exti_init(&buttons[3],
              &exti_d21_dev,
              EXTI_TRIGGER_FALLING_EDGE,
              on_button_stop,
              NULL);
    exti_start(&buttons[3]);

    dac_init(&dac,
             &dac_0_dev,
             &pin_dac0_dev,
             &pin_dac1_dev,
             2 * SAMPLES_PER_SOCOND);

    hash_map_init(&song_map,
                  buckets,
                  membersof(buckets),
                  entries,
                  membersof(entries),
                  hash_number);

    sem_init(&sem, 0, 1);

    music_player_init(&music_player,
                      &fs,
                      &dac,
                      get_current_song_path,
                      get_next_song_path,
                      NULL);

    /* Initialize the song number. */
    current_song = FIRST_SONG_NUMBER;
    number = FIRST_SONG_NUMBER;

    /* Add songs to the hash map. */
    fat16_dir_open(&fs, &dir, ".", O_READ);

    while (fat16_dir_read(&dir, &entry) == 1) {
        if (number - FIRST_SONG_NUMBER == membersof(songs)) {
            std_printf("Maximum number of songs already added. "
                       "Skipping the rest of the songs.\r\n");
            break;
        }

        /* Skip folders. */
        if (entry.is_dir == 1) {
            continue;
        }

        song_p = &songs[number - FIRST_SONG_NUMBER];

        /* Initialize the song entry. */
        song_p->number = number;
        strcpy(song_p->name, entry.name);
        seconds = (entry.size / 4 / SAMPLES_PER_SOCOND);
        song_p->minutes = (seconds / 60);
        song_p->seconds = (seconds % 60);

        std_printf("Adding song %s to playlist.\r\n",
                   entry.name);

        hash_map_add(&song_map, number, song_p);
        number++;
    }

    fat16_dir_close(&dir);

    last_song_number = (number - 1);

    music_player_start(&music_player);
}
Ejemplo n.º 21
0
void main(void)
{
    int rc;

    power_init();
    system_init();
    kernel_init();
    lcd_init();
    show_logo();
    enable_irq();
    adc_init();
    usb_init();
    button_init();
    powermgmt_init();

#if CONFIG_CHARGING && (CONFIG_CPU == SH7034)
    if (charger_inserted()
#ifdef ATA_POWER_PLAYERSTYLE
        && !ide_powered() /* relies on probing result from bootloader */
#endif
        )
    {
        charging_screen(); /* display a "charging" screen */
        show_logo();  /* again, to provide better visual feedback */
    }
#endif

    rc = storage_init();
    if(rc)
    {
#ifdef HAVE_LCD_BITMAP
        char str[32];
        lcd_clear_display();
        snprintf(str, 31, "ATA error: %d", rc);
        lcd_puts(0, 1, str);
        lcd_update();
        while(!(button_get(true) & BUTTON_REL));
#endif
        panicf("storage: %d", rc);
    }

    usb_start_monitoring();
    while (usb_detect() == USB_INSERTED)
    {   /* enter USB mode early, before trying to mount */
        if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED)
        {
            usb_screen();
        }
    }

    rc = disk_mount_all();
    if (rc<=0)
    {
        prompt_usb("No partition", "found.");
    }

    {   // rolo the firmware
        static const char filename[] = "/" BOOTFILE;
        rolo_load((char*)filename); /* won't return if started */

        prompt_usb("No firmware", filename);
    }


}
Ejemplo n.º 22
0
void* main(void)
{
    int i;
    int rc;
    int fd;
    char buffer[80];
    unsigned char* framebuffer = (unsigned char*)0x11e00000;

#if 0
    lcd_init();
    font_init();

    printf("Hello World!");
#endif

    i=storage_init();

    disk_init();
    rc = disk_mount_all();

#if 0
    /* Dump the flash */
    fd=open("/flash.bin",O_CREAT|O_RDWR, 0666);
    write(fd,(char*)0,1024*1024);
    close(fd);
#endif

#if 1
    /* Dump what may be the framebuffer */
    fd=open("/framebuffer.bin",O_CREAT|O_RDWR|O_TRUNC, 0666);
    write(fd,framebuffer,220*176*4);
    close(fd);
#endif


    fd=open("/gpio.txt",O_CREAT|O_RDWR|O_TRUNC, 0666);
    unsigned int gpio_a = GPIOA_INPUT_VAL;
    unsigned int gpio_b = GPIOB_INPUT_VAL;
    unsigned int gpio_c = GPIOC_INPUT_VAL;
    unsigned int gpio_d = GPIOD_INPUT_VAL;
    unsigned int gpio_e = GPIOE_INPUT_VAL;
    unsigned int gpio_f = GPIOF_INPUT_VAL;
    unsigned int gpio_g = GPIOG_INPUT_VAL;
    unsigned int gpio_h = GPIOH_INPUT_VAL;
    unsigned int gpio_i = GPIOI_INPUT_VAL;
    unsigned int gpio_j = GPIOJ_INPUT_VAL;
    unsigned int gpio_k = GPIOK_INPUT_VAL;
    unsigned int gpio_l = GPIOL_INPUT_VAL;

    snprintf(buffer, sizeof(buffer), "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",gpio_a,gpio_b,gpio_c,gpio_d,gpio_e,gpio_f,gpio_g,gpio_h,gpio_i,gpio_j,gpio_k,gpio_l);
    write(fd,buffer,strlen(buffer)+1);
    close(fd);

    /* Wait for FFWD button to be pressed */
    while((GPIOA_INPUT_VAL & 0x04) != 0);


    /* Now reboot */
    DEV_RS |= 0x4;

    return 0;
}
Ejemplo n.º 23
0
int
main (void)
{
  int t, firstrun;
  volatile int i;

  /* Initialize GPIO (sets up clock) */
  GPIOInit ();
  /* initialize  pins */
  pin_init ();
  /* setup SPI chipselect pins */
  spi_init_pin (SPI_CS_NRF);

  /* blink as a sign of boot to detect crashes */
  for (t = 0; t < 10; t++)
    {
      pin_led (GPIO_LED0);
      for (i = 0; i < 100000; i++);
      pin_led (GPIO_LEDS_OFF);
      for (i = 0; i < 100000; i++);
    }

  /* Init USB HID interface */
  hid_init ();
  /* Init SPI */
  spi_init ();
  /* Init OpenBeacon nRF24L01 interface */
  nRFAPI_Init (81, broadcast_mac, sizeof (broadcast_mac), 0);
  /* Init 3D acceleration sensor */
  acc_init ();
  /* Init Storage */
  storage_init ();
  /* Init Bluetooth */
  bt_init ();

  /* main loop */
  t = 0;
  firstrun = 1;
  while (1)
    {
      /* blink LED0 on every 32th run - FIXME later with sleep */
      if ((t++ & 0x1F) == 0)
	{
	  pin_led (GPIO_LED0);
	  for (i = 0; i < 100000; i++);
	  pin_led (GPIO_LEDS_OFF);
	}
      for (i = 0; i < 200000; i++);

      if (UARTCount)
	{
	  /* blink LED1 upon Bluetooth command */
	  pin_led (GPIO_LED1);

	  /* show help screen upon Bluetooth connect */
	  if (firstrun)
	    {
	      debug_printf ("press 'H' for help...\n# ");
	      firstrun = 0;
	    }
	  else
	    /* execute menue command with last character received */
	    main_menue (UARTBuffer[UARTCount - 1]);

	  /* LED1 off again */
	  pin_led (GPIO_LEDS_OFF);

	  /* clear UART buffer */
	  UARTCount = 0;
	}
    }
}
void main(void)
{
    unsigned char* loadbuffer;
    int buffer_size;
    int rc;
    int(*kernel_entry)(void);

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

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

    adc_init();

    lcd_setfont(FONT_SYSFIXED);

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

    printf("Rockbox boot loader");
    printf("Version %s", rbversion);

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

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

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

        usb_enable(false);

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

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

    printf("filesystem");
    filesystem_init();

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

    printf("Loading firmware");

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

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

    kernel_entry = (void*) loadbuffer;
    rc = kernel_entry();

    /* Should not get here! */
    return rc;
}
Ejemplo n.º 25
0
int main(void)
{
    unsigned char* loadbuffer;
    int buffer_size;
    int rc;
    int(*kernel_entry)(void);

    led_init();
    clear_leds(LED_ALL);
    /* NB: something in system_init() prevents H-JTAG from downloading */
/*    system_init(); */ 
    kernel_init();
/*    enable_interrupt(IRQ_FIQ_STATUS); */
    backlight_init();
    lcd_init();
    lcd_setfont(FONT_SYSFIXED);
    button_init();
    dma_init();
    
    uart_init();
    uart_init_device(DEBUG_UART_PORT);

/*    mini2440_test(); */  
        
    /* Show debug messages if button is pressed */
    int touch_data;
    if(button_read_device(&touch_data) & BUTTON_MENU) 
        verbose = true;
        
    printf("Rockbox boot loader");
    printf("Version " RBVERSION);

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

    disk_init(IF_MD(0));
    rc = disk_mount_all();
    if (rc<=0)
    {
        error(EDISK,rc, true);
    }

    printf("Loading firmware");

    /* Flush out anything pending first */
    commit_discard_idcache();

    loadbuffer = (unsigned char*) 0x31000000;
    buffer_size = (unsigned char*)0x31400000 - loadbuffer;

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

    printf("Loaded firmware %d\n", rc);
    
/*    storage_close(); */
    system_prepare_fw_start();

    commit_discard_idcache();
    kernel_entry = (void*) loadbuffer;
    rc = kernel_entry();
        
    /* end stop - should not get here */
    led_flash(LED_ALL, LED_NONE);
    while (1); /* avoid warning */
}
Ejemplo n.º 26
0
int pre_server_startup(void)
{
    pvpgn_greeting();
    if (oom_setup() < 0) {
	eventlog(eventlog_level_error, __FUNCTION__, "OOM init failed");
	return STATUS_OOM_FAILURE;
    }
    if (storage_init(prefs_get_storage_path()) < 0) {
	eventlog(eventlog_level_error, "pre_server_startup", "storage init failed");
	return STATUS_STORAGE_FAILURE;
    }
    if (psock_init() < 0) {
	eventlog(eventlog_level_error, __FUNCTION__, "could not initialize socket functions");
	return STATUS_PSOCK_FAILURE;
    }
    if (support_check_files(prefs_get_supportfile()) < 0) {
        eventlog(eventlog_level_error, "pre_server_startup","some needed files are missing");
	eventlog(eventlog_level_error, "pre_server_startup","please make sure you installed the supportfiles in %s",prefs_get_filedir());
	return STATUS_SUPPORT_FAILURE;
    }
    if (anongame_maplists_create() < 0) {
	eventlog(eventlog_level_error, "pre_server_startup", "could not load maps");
	return STATUS_MAPLISTS_FAILURE;
    }
    if (anongame_matchlists_create() < 0) {
	eventlog(eventlog_level_error, "pre_server_startup", "could not create matchlists");
	return STATUS_MATCHLISTS_FAILURE;
    }
    if (fdwatch_init(prefs_get_max_connections())) {
	eventlog(eventlog_level_error, __FUNCTION__, "error initilizing fdwatch");
	return STATUS_FDWATCH_FAILURE;
    }
    connlist_create();
    gamelist_create();
    timerlist_create();
    server_set_hostname();
    channellist_create();
    if (helpfile_init(prefs_get_helpfile())<0)
	eventlog(eventlog_level_error,__FUNCTION__,"could not load helpfile");
    ipbanlist_create();
    if (ipbanlist_load(prefs_get_ipbanfile())<0)
	eventlog(eventlog_level_error,__FUNCTION__,"could not load IP ban list");
    if (adbannerlist_create(prefs_get_adfile())<0)
	eventlog(eventlog_level_error,__FUNCTION__,"could not load adbanner list");
    if (autoupdate_load(prefs_get_mpqfile())<0)
	eventlog(eventlog_level_error,__FUNCTION__,"could not load autoupdate list");
    if (versioncheck_load(prefs_get_versioncheck_file())<0)
	eventlog(eventlog_level_error,__FUNCTION__,"could not load versioncheck list");
   if (news_load(prefs_get_newsfile())<0)
	eventlog(eventlog_level_error,__FUNCTION__,"could not load news list");
    watchlist_create();
    output_init();
    attrlayer_init();
    accountlist_create();
    if (ladder_createxptable(prefs_get_xplevel_file(),prefs_get_xpcalc_file())<0) {
        eventlog(eventlog_level_error, "pre_server_startup", "could not load WAR3 xp calc tables");
        return STATUS_WAR3XPTABLES_FAILURE;
    }
    ladders_init();
    ladders_load_accounts_to_ladderlists();
    ladder_update_all_accounts();
    if (characterlist_create("")<0)
	eventlog(eventlog_level_error,__FUNCTION__,"could not load character list");
    if (prefs_get_track()) /* setup the tracking mechanism */
        tracker_set_servers(prefs_get_trackserv_addrs());
    if (command_groups_load(prefs_get_command_groups_file())<0)
	eventlog(eventlog_level_error,__FUNCTION__,"could not load command_groups list");
    aliasfile_load(prefs_get_aliasfile());
    if (trans_load(prefs_get_transfile(),TRANS_BNETD)<0)
	eventlog(eventlog_level_error,__FUNCTION__,"could not load trans list");
    tournament_init(prefs_get_tournament_file());
    anongame_infos_load(prefs_get_anongame_infos_file());
    clanlist_load();
    teamlist_load();
    if (realmlist_create(prefs_get_realmfile())<0)
	eventlog(eventlog_level_error,__FUNCTION__,"could not load realm list");
    topiclist_load(prefs_get_topicfile());
    return 0;
}
Ejemplo n.º 27
0
void main(void)
{
    unsigned char* loadbuffer;
    int buffer_size;
    int rc;
    int(*kernel_entry)(void);

    system_init();
    kernel_init(); /* Need the kernel to sleep */

    enable_interrupt(IRQ_FIQ_STATUS);

    lcd_init();
    backlight_init();
    button_init();
    font_init();
    adc_init();

    lcd_setfont(FONT_SYSFIXED);
    
    /* These checks should only run if the bootloader is flashed */
    if(GSTATUS3&0x02)
    {
        GSTATUS3&=0xFFFFFFFD;
        if(!(GPGDAT&BUTTON_POWER) && charger_inserted())
        {
            while(!(GPGDAT&BUTTON_POWER) && charger_inserted())
            {
                char msg[20];
                if(charging_state())
                {
                    snprintf(msg,sizeof(msg),"Charging");
                }
                else
                {
                    snprintf(msg,sizeof(msg),"Charge Complete");
                }
                reset_screen();
                lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                        (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
                lcd_update();
                
#if defined(HAVE_RTC_ALARM)            
                /* Check if the alarm went off while charging */
                if(rtc_check_alarm_flag())
                {
                    GSTATUS3=1; /* Normally this is set in crt0.s */
                    break;
                }
#endif
            }
            if(!(GPGDAT&BUTTON_POWER) 
#if defined(HAVE_RTC_ALARM)
                && !GSTATUS3
#endif
                )
            {
                shutdown();
            }
        }

        if(button_hold())
        {
            const char msg[] = "HOLD is enabled";
            reset_screen();
            lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2,
                        (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg);
            lcd_update();
            
            sleep(2*HZ);
            
            shutdown();
        }
    }

    power_init();
    usb_init();

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

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

        while (usb_detect() == USB_INSERTED)
            sleep(HZ);

        usb_enable(false);

        reset_screen();
        lcd_update();
    }
    
    reset_screen();

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

    printf("Rockbox boot loader");
    printf("Version %s", rbversion);

    sleep(50); /* ATA seems to error without this pause */

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

    filesystem_init();

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

    printf("Loading firmware");

    /* Flush out anything pending first */
    commit_discard_idcache();

    loadbuffer = (unsigned char*) 0x31000000;
    buffer_size = (unsigned char*)0x31400000 - loadbuffer;

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

    storage_close();
    system_prepare_fw_start();

    commit_discard_idcache();
    kernel_entry = (void*) loadbuffer;
    rc = kernel_entry();

#if 0
    /* Halt */
    while (1)
        core_idle();
#else
    /* Return and restart */
#endif
}
Ejemplo n.º 28
0
/**
  * @brief  Initialize the storage medium
  * @param  lun : logical unit number
  * @retval Status
  */
int8_t FLASH_STORAGE_Init(uint8_t lun) {
    storage_init();
    return 0;
}
Ejemplo n.º 29
0
void Storage_init() {
	storage_init();
	storage_default_settings();
	CLI_registerDictionary( storageCLIDict, storageCLIDictName );
}
Ejemplo n.º 30
0
int main(void) {
    // TODO disable JTAG

    // update the SystemCoreClock variable
    SystemCoreClockUpdate();

    // set interrupt priority config to use all 4 bits for pre-empting
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

    // enable the CCM RAM and the GPIO's
    RCC->AHB1ENR |= RCC_AHB1ENR_CCMDATARAMEN | RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN;

#if MICROPY_HW_HAS_SDCARD
    {
        // configure SDIO pins to be high to start with (apparently makes it more robust)
        // FIXME this is not making them high, it just makes them outputs...
        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_Init(GPIOC, &GPIO_InitStructure);

        // Configure PD.02 CMD line
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_Init(GPIOD, &GPIO_InitStructure);
    }
#endif
#if defined(NETDUINO_PLUS_2)
    {
        GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

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

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

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

#if MICROPY_HW_ENABLE_RTC
    rtc_init();
#endif

    // turn on LED to indicate bootup
    led_state(PYB_LED_G1, 1);

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

    // uncomment these 2 lines if you want REPL on USART_6 (or another usart) as well as on USB VCP
    //pyb_usart_global_debug = PYB_USART_YA;
    //usart_init(pyb_usart_global_debug, 115200);

    int first_soft_reset = true;

soft_reset:

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

    // Micro Python init
    qstr_init();
    mp_init();
    mp_obj_list_init(mp_sys_path, 0);
    mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_));
    mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_0_colon__slash_lib));
    mp_obj_list_init(mp_sys_argv, 0);

    exti_init();

#if MICROPY_HW_HAS_SWITCH
    switch_init();
#endif

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

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

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

#if MICROPY_HW_ENABLE_RNG
    // RNG
    RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
    RNG_Cmd(ENABLE);
#endif

    pin_map_init();

    // add some functions to the builtin Python namespace
    mp_store_name(MP_QSTR_help, mp_make_function_n(0, pyb_help));
    mp_store_name(MP_QSTR_open, mp_make_function_n(2, pyb_io_open));

    // load the pyb module
    mp_module_register(MP_QSTR_pyb, (mp_obj_t)&pyb_module);

    // check if user switch held (initiates reset of filesystem)
    bool reset_filesystem = false;
#if MICROPY_HW_HAS_SWITCH
    if (switch_get()) {
        reset_filesystem = true;
        for (int i = 0; i < 50; i++) {
            if (!switch_get()) {
                reset_filesystem = false;
                break;
            }
            sys_tick_delay_ms(10);
        }
    }
#endif
    // local filesystem init
    {
        // try to mount the flash
        FRESULT res = f_mount(&fatfs0, "0:", 1);
        if (!reset_filesystem && res == FR_OK) {
            // mount sucessful
        } else if (reset_filesystem || res == FR_NO_FILESYSTEM) {
            // no filesystem, so create a fresh one
            // TODO doesn't seem to work correctly when reset_filesystem is true...

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

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

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

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

            // keep LED on for at least 200ms
            sys_tick_wait_at_least(stc, 200);
            led_state(PYB_LED_R2, 0);
        } else {
            __fatal_error("could not access LFS");
        }
    }

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

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

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

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

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

    if (first_soft_reset) {
#if MICROPY_HW_HAS_MMA7660
        // MMA accel: init and reset address to zero
        accel_init();
#endif
    }

    // turn boot-up LED off
    led_state(PYB_LED_G1, 0);

#if MICROPY_HW_HAS_SDCARD
    // if an SD card is present then mount it on 1:/
    if (sdcard_is_present()) {
        FRESULT res = f_mount(&fatfs1, "1:", 1);
        if (res != FR_OK) {
            printf("[SD] could not mount SD card\n");
        } else {
            if (first_soft_reset) {
                // use SD card as medium for the USB MSD
                usbd_storage_select_medium(USBD_STORAGE_MEDIUM_SDCARD);
            }
        }
    }
#endif

#ifdef USE_HOST_MODE
    // USB host
    pyb_usb_host_init();
#elif defined(USE_DEVICE_MODE)
    // USB device
    pyb_usb_dev_init(PYB_USB_DEV_VCP_MSC);
#endif

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


#if MICROPY_HW_HAS_MMA7660
    // HID example
    if (0) {
        uint8_t data[4];
        data[0] = 0;
        data[1] = 1;
        data[2] = -2;
        data[3] = 0;
        for (;;) {
        #if MICROPY_HW_HAS_SWITCH
            if (switch_get()) {
                data[0] = 0x01; // 0x04 is middle, 0x02 is right
            } else {
                data[0] = 0x00;
            }
        #else
            data[0] = 0x00;
        #endif
            accel_start(0x4c /* ACCEL_ADDR */, 1);
            accel_send_byte(0);
            accel_restart(0x4c /* ACCEL_ADDR */, 0);
            for (int i = 0; i <= 1; i++) {
                int v = accel_read_ack() & 0x3f;
                if (v & 0x20) {
                    v |= ~0x1f;
                }
                data[1 + i] = v;
            }
            accel_read_nack();
            usb_hid_send_report(data);
            sys_tick_delay_ms(15);
        }
    }
#endif

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

    pyexec_repl();

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

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

    first_soft_reset = false;
    goto soft_reset;
}