static void run_usb_msc_test(const struct test_case *test) { memories_initialization(); // Start USB stack to authorize VBus monitoring udc_start(); if (!udc_include_vbus_monitoring()) { // VBUS monitoring is not available on this product // thereby VBUS has to be considered as present main_vbus_action(true); } // The main loop manages only the power mode // because the USB management is done by interrupt while (!main_b_msc_read) { if (main_b_msc_enumerated) { if (!udi_msc_process_trans()) { sleepmgr_enter_sleep(); } }else{ sleepmgr_enter_sleep(); } } test_assert_true(test, main_b_msc_enumerated, "MSC enumeration fails"); udc_stop(); }
void main_hid_set_feature(uint8_t* report) { if (*((uint32_t*)report)==0x55AA55AA) { // Disconnect USB Device udc_stop(); ui_powerdown(); } }
void main_start_dfu_session(void) { udc_stop(); adc_sensors_stop(); ui_dfu_session(); EIND = BOOT_SECTION_START>>17; start_bootloader(); }
static void cmd_continue(struct protocol_handle *phandle, const char *arg) { fastboot_okay(phandle, ""); #if 0 udc_stop(); boot_linux_from_flash(); #endif }
void main_hid_set_feature(uint8_t* report) { if (report[0] == 0xAA && report[1] == 0x55 && report[2] == 0xAA && report[3] == 0x55) { // Disconnect USB Device udc_stop(); ui_powerdown(); } }
void cmd_continue(const char *arg, void *data, unsigned sz) { g_boot_mode = NORMAL_BOOT; fastboot_okay(""); udc_stop(); mtk_wdt_init(); //re-open wdt /*Will not return*/ boot_linux_from_storage(); }
// 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(); }
/** * USB ID pin change handler */ static void usb_id_handler(void) { extint_chan_disable_callback(USB_ID_EIC_LINE, EXTINT_CALLBACK_TYPE_DETECT); if (_usb_is_id_device()) { uhc_stop(false); UHC_MODE_CHANGE(false); udc_start(); } else { udc_stop(); UHC_MODE_CHANGE(true); uhc_start(); } extint_chan_enable_callback(USB_ID_EIC_LINE, EXTINT_CALLBACK_TYPE_DETECT); }
void cmd_continue(const char *arg, void *data, unsigned sz) { g_boot_mode = NORMAL_BOOT; if(has_set_p2u) { set_p2u(has_set_p2u); fastboot_info("phone will continue boot up after 5s..."); fastboot_okay(""); mdelay(5000); } else { fastboot_okay(""); } udc_stop(); mtk_wdt_init(); //re-open wdt /*Will not return*/ boot_linux_from_storage(); }
// 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(); }
void cmd_boot(const char *arg, void *data, unsigned sz) { unsigned kernel_actual; unsigned ramdisk_actual; static struct boot_img_hdr hdr; char *ptr = ((char*) data); if (sz < sizeof(hdr)) { fastboot_fail("invalid bootimage header"); return; } memcpy(&hdr, data, sizeof(hdr)); /* ensure commandline is terminated */ hdr.cmdline[BOOT_ARGS_SIZE-1] = 0; if(target_is_emmc_boot() && hdr.page_size) { page_size = hdr.page_size; page_mask = page_size - 1; } kernel_actual = ROUND_TO_PAGE(hdr.kernel_size, page_mask); ramdisk_actual = ROUND_TO_PAGE(hdr.ramdisk_size, page_mask); if (page_size + kernel_actual + ramdisk_actual < sz) { fastboot_fail("incomplete bootimage"); return; } memmove((void*) KERNEL_ADDR, ptr + page_size, hdr.kernel_size); memmove((void*) RAMDISK_ADDR, ptr + page_size + kernel_actual, hdr.ramdisk_size); fastboot_okay(""); target_battery_charging_enable(0, 1); udc_stop(); boot_linux((void*) KERNEL_ADDR, (void*) TAGS_ADDR, (const char*) hdr.cmdline, board_machtype(), (void*) RAMDISK_ADDR, hdr.ramdisk_size); }
static void run_usb_cdc_test(const struct test_case *test) { UNUSED(test); // Start USB stack to authorize VBus monitoring udc_start(); if (!udc_include_vbus_monitoring()) { // VBUS monitoring is not available on this product // thereby VBUS has to be considered as present main_vbus_action(true); } // The main loop manages only the power mode // because the USB management is done by interrupt while (!main_b_cdc_configurated) { sleepmgr_enter_sleep(); // No test_assert_true() call // because it must be a timeout from server } while (!main_b_cdc_enumerated); udc_stop(); }
void VBusMon_check(void) { static volatile uint8_t r = 0; if(1==r) return; r = 1; if(ioport_pin_is_low(USB_PROBE_PIN)) { vbus_action(false); udc_stop(); OSC.DFLLCTRL = 2; DFLLRC32M.CTRL = 1; statusled_blink(2); debug_string(VERBOSE,PSTR("[EVENT] USB off\r\n"),true); } else { OSC.DFLLCTRL = 4; DFLLRC32M.CTRL = 1; udc_start(); vbus_action(true); statusled_blink(2); debug_string(VERBOSE,PSTR("[EVENT] USB on\r\n"),true); } r=0; }
/*! \brief Main function. Execution starts here. */ int main(void) { irq_initialize_vectors(); cpu_irq_enable(); /* Initialize ASF services */ sleepmgr_init(); sysclk_init(); board_init(); gfx_mono_init(); sd_mmc_init(); rtc_init(); stdio_usb_init(); /* Initialize STDIO and start USB */ udc_stop(); /* Stop USB by default */ main_introduction(); /* Initialize tasks */ app_touch_init(); app_cpu_load_init(); app_sampling_init(); /* The main loop */ while (true) { /* Enter in sleep mode */ app_cpu_load_enter_sleep(); sleepmgr_enter_sleep(); /* Execute tasks */ app_usb_task(); app_microsd_task(); app_sampling_task(); app_touch_task(); app_cpu_load_task(); } }
void cmd_boot(const char *arg, void *data, unsigned sz) { unsigned kernel_actual; unsigned ramdisk_actual; static struct boot_img_hdr hdr; char *ptr = ((char*) data); unsigned page_size = 0; unsigned page_mask = 0; int strlen = 0; if (sz < sizeof(hdr)) { fastboot_fail("invalid bootimage header"); return; } memcpy(&hdr, data, sizeof(hdr)); printf("\n============================================================\n"); hdr.magic[7] = '\0'; printf("[%s] Android Boot IMG Hdr - Magic : %s\n",MODULE_NAME,hdr.magic); printf("[%s] Android Boot IMG Hdr - Kernel Size : 0x%x\n",MODULE_NAME,hdr.kernel_size); printf("[%s] Android Boot IMG Hdr - Rootfs Size : 0x%x\n",MODULE_NAME,hdr.ramdisk_size); printf("[%s] Android Boot IMG Hdr - Page Size : 0x%x\n",MODULE_NAME,hdr.page_size); printf("============================================================\n"); /* ensure commandline is terminated */ hdr.cmdline[BOOT_ARGS_SIZE-1] = 0; if(hdr.page_size) { page_size = hdr.page_size; page_mask = page_size - 1; //page_mask = 2*1024 ; /*FIXME*/ } else { printf("[FASTBOOT] Please specify the storage page-size in the boot header!\n"); fastboot_fail("Please specify the storage page-size in the boot header!\n"); return; } kernel_actual = ROUND_TO_PAGE(hdr.kernel_size, page_mask); ramdisk_actual = ROUND_TO_PAGE(hdr.ramdisk_size, page_mask); /* sz should have atleast raw boot image */ if (page_size + kernel_actual + ramdisk_actual > sz) { fastboot_fail("incomplete bootimage"); return; } memmove((void*) hdr.kernel_addr, (ptr + MKIMG_HEADER_SZ + BIMG_HEADER_SZ), hdr.kernel_size); memmove((void*) hdr.ramdisk_addr, (ptr + MKIMG_HEADER_SZ + BIMG_HEADER_SZ + kernel_actual), hdr.ramdisk_size); strlen += sprintf((const char*) hdr.cmdline, "%s lcm=%1d-%s", hdr.cmdline, DISP_IsLcmFound(), mt_disp_get_lcm_id()); strlen += sprintf((const char*) hdr.cmdline, "%s fps=%1d", hdr.cmdline, mt_disp_get_lcd_time()); fastboot_okay(""); udc_stop(); mtk_wdt_init(); //re-open wdt g_boot_mode = NORMAL_BOOT; boot_linux((void*) hdr.kernel_addr, (void*) hdr.tags_addr, (const char*) hdr.cmdline, board_machtype(), (void*) hdr.ramdisk_addr, hdr.ramdisk_size); #if 0 unsigned kernel_actual; unsigned ramdisk_actual; struct boot_img_hdr boot_hdr; unsigned int k_pg_cnt = 0; unsigned int r_pg_cnt = 0; unsigned int b_pg_cnt = 0; unsigned int size_b = 0; unsigned int pg_sz = 2*1024 ; int strlen = 0; /*copy hdr data from download_base*/ memcpy(&boot_hdr, data, sizeof(boot_hdr)); /* ensure commandline is terminated */ boot_hdr.cmdline[BOOT_ARGS_SIZE-1] = 0; printf("\n============================================================\n"); boot_hdr.magic[7] = '\0'; printf("[%s] Android Boot IMG Hdr - Magic : %s\n",MODULE_NAME,boot_hdr.magic); printf("[%s] Android Boot IMG Hdr - Kernel Size : 0x%x\n",MODULE_NAME,boot_hdr.kernel_size); printf("[%s] Android Boot IMG Hdr - Rootfs Size : 0x%x\n",MODULE_NAME,boot_hdr.ramdisk_size); printf("[%s] Android Boot IMG Hdr - Page Size : 0x%x\n",MODULE_NAME,boot_hdr.page_size); printf("============================================================\n"); //*************** //* check partition magic //* if (strncmp(boot_hdr.magic,BOOT_MAGIC, sizeof(BOOT_MAGIC))!=0) { printf("[%s] boot image header magic error\n", MODULE_NAME); return -1; } g_kmem_off = (unsigned int)target_get_scratch_address(); g_kmem_off = g_kmem_off + MKIMG_HEADER_SZ + BIMG_HEADER_SZ; if(boot_hdr.kernel_size % pg_sz == 0) { k_pg_cnt = boot_hdr.kernel_size / pg_sz; } else { k_pg_cnt = (boot_hdr.kernel_size / pg_sz) + 1; } if(boot_hdr.ramdisk_size % pg_sz == 0) { r_pg_cnt = boot_hdr.ramdisk_size / pg_sz; } else { r_pg_cnt = (boot_hdr.ramdisk_size / pg_sz) + 1; } printf(" > page count of kernel image = %d\n",k_pg_cnt); g_rmem_off = g_kmem_off + k_pg_cnt * pg_sz; printf(" > kernel mem offset = 0x%x\n",g_kmem_off); printf(" > rootfs mem offset = 0x%x\n",g_rmem_off); //*************** //* specify boot image size //* g_bimg_sz = (k_pg_cnt + r_pg_cnt + 2)* pg_sz; printf(" > boot image size = 0x%x\n",g_bimg_sz); memmove((void*)CFG_BOOTIMG_LOAD_ADDR , g_kmem_off, boot_hdr.kernel_size); memmove((void*)CFG_RAMDISK_LOAD_ADDR , g_rmem_off, boot_hdr.ramdisk_size); //custom_port_in_kernel(g_boot_mode, commanline); //strlen += sprintf(commanline, "%s lcm=%1d-%s", commanline, DISP_IsLcmFound(), mt_disp_get_lcm_id()); //strlen += sprintf(commanline, "%s fps=%1d", commanline, mt_disp_get_lcd_time()); fastboot_okay(""); udc_stop(); mtk_wdt_init(); boot_linux((void *)CFG_BOOTIMG_LOAD_ADDR, (unsigned *)CFG_BOOTARGS_ADDR, (const char*) boot_hdr.cmdline, board_machtype(), (void *)CFG_RAMDISK_LOAD_ADDR, boot_hdr.ramdisk_size); #endif }
void usb_stop(void) { udc_stop(); clock_set(CLK_32KHZ); }
void SerialCDC::end() { isConnected = false; udc_stop(); }
void app_usb_task(void) { static bool sw0_released = true; static bool usb_running = false; static bool cdc_running = false; static bool toggle = true; if (sw0_released && ioport_pin_is_low(GPIO_PUSH_BUTTON_0)) { /* A new press has been done */ sw0_released = false; /* Switch USB state */ if (usb_running) { udc_stop(); gfx_mono_draw_filled_rect(DISPLAY_USB_STA_POS_X, DISPLAY_USB_STA_POS_Y, DISPLAY_USB_STA_SIZE_X, DISPLAY_USB_STA_SIZE_Y, GFX_PIXEL_CLR); app_microsd_start(); } else { /* Stop FatFS on uSD card if enabled */ app_microsd_stop(); stdio_usb_init(); /* Start USB */ gfx_mono_generic_put_bitmap(&bitmap_usb, DISPLAY_USB_STA_POS_X, DISPLAY_USB_STA_POS_Y); } usb_running = !usb_running; cdc_running = true; } else { /* Wait switch release */ sw0_released = ioport_pin_is_high(GPIO_PUSH_BUTTON_0); } if (!usb_running) { return; } /* USB MSC task */ while (udi_msc_process_trans()) { } if (app_usb_cdc_open && !cdc_running) { printf("\x0CSensor data logs:\r\n"); cdc_running = true; } if (!app_usb_cdc_open && cdc_running) { cdc_running = false; } /* Toggle USB icon */ if ((app_usb_cdc_open && app_usb_rec_toggle) || (toggle && app_usb_rec_toggle)) { app_usb_rec_toggle = false; toggle = !toggle; gfx_mono_draw_rect(DISPLAY_USB_STACDC_POS_X, DISPLAY_USB_STACDC_POS_Y, DISPLAY_USB_STACDC_SIZE_X, DISPLAY_USB_STACDC_SIZE_Y, toggle ? GFX_PIXEL_SET : GFX_PIXEL_CLR); } }
void main_generic_run_bootloader(void) { // Here reset target in bootloader mode udc_stop(); }