int main (int argc, char *argv[]) { lua_State *L = NULL; char *file = NULL; int ret = 1; enum ExecutionPath path; path = handle_args(argc, argv); file = argv[argc - 1]; L = luaL_newstate(); if (!L) { fprintf(stderr, "No memory for the main Lua state!\n"); goto exit; } luaL_openlibs(L); luaL_requiref(L, "Dialogue", luaopen_Dialogue, 1); lua_pop(L, 1); switch (path) { case MAIN_SCRIPT: if (luaL_loadfile(L, file) || lua_pcall(L, 0, 0, 0)) { fprintf(stderr, "%s: %s\n", file, lua_tostring(L, -1)); lua_close(L); goto exit; } else { lua_close(L); } break; case MAIN_WORKER: if (console_start(L, file, CONSOLE_THREADED) != 0) { fprintf(stderr, "Failed to start console's thread!\n"); goto exit; } director_process_work(); wait_for_console_exit(); break; case MAIN_CONSOLE: console_start(L, file, CONSOLE_NON_THREADED); break; default: break; } ret = 0; exit: return ret; }
static void gsm_on_off(struct device *dev, int on) { if (!on) { s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPIO_INPUT); s3c2410_gpio_cfgpin(S3C2410_GPH2, S3C2410_GPIO_INPUT); pcf50633_gpio_set(gta02_pcf, PCF50633_GPIO2, 0); if (gta02_gsm.con) { s3c24xx_serial_console_set_silence(0); console_start(gta02_gsm.con); dev_dbg(dev, "powered down gta02 GSM, enabling " "serial console\n"); } return; } if (gta02_gsm.con) { dev_dbg(dev, "powering up GSM, thus " "disconnecting serial console\n"); console_stop(gta02_gsm.con); s3c24xx_serial_console_set_silence(1); } /* allow UART to talk to GSM side now we will power it */ s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPH1_nRTS0); s3c2410_gpio_cfgpin(S3C2410_GPH2, S3C2410_GPH2_TXD0); pcf50633_gpio_set(gta02_pcf, PCF50633_GPIO2, 7); msleep(100); s3c2410_gpio_setpin(GTA02_GPIO_MODEM_ON, 1); msleep(500); s3c2410_gpio_setpin(GTA02_GPIO_MODEM_ON, 0); /* * workaround for calypso firmware moko10 and earlier, * without this it will leave IRQ line high after * booting */ s3c2410_gpio_setpin(S3C2410_GPH1, 1); s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPH1_OUTP); msleep(1000); s3c2410_gpio_cfgpin(S3C2410_GPH1, S3C2410_GPH1_nRTS0); }
/** * Executes the issued command */ void console_exec(char *buf) { if(strncmp(buf, "cd", 2) == 0) { console_cd(dir, buf); } else if(strncmp(buf, "start", 5) == 0) { console_start(dir, buf); } else if(strncmp(buf, "read", 4) == 0) { console_read(dir, buf); } else if(strncmp(buf, "write", 5) == 0) { console_write(dir, buf); } else if(strncmp(buf, "touch", 5) == 0) { console_touch(dir, buf); } else if(strncmp(buf, "delete", 6) == 0) { console_delete(dir, buf); } else if(strcmp(buf, "hoho") == 0) { printk("hoho\n"); } else if(strcmp(buf, "help") == 0) { printk("Help:\nhoho - prints hoho\nhelp - shows help\nmeminfo - prints RAM info\ncpuinfo - shows CPU info\nls - shows filesystem devices\nread - reads a file\nstart - starts a program\nclear - clears the screen\nhalt - shuts down\nreboot - reboots the pc\n"); } else if(strcmp(buf, "meminfo") == 0) { print_meminfo(); } else if(strcmp(buf, "cpuinfo") == 0) { printk("%s\n", get_cpu_vendor(0)); } else if(strcmp(buf, "ls") == 0) { if(dir[0] == 0) { vfs_ls(); } else { vfs_ls_dir(dir); } } else if(strcmp(buf, "clear") == 0) { clear(); } else if(strcmp(buf, "proc") == 0) { print_procs(); } else if(strcmp(buf, "halt") == 0) { printk("Shutting down\n"); halt(); while(1); } else if(strcmp(buf, "reboot") == 0) { printk("Rebooting\n"); reboot(); } else { printk("Command not found\n"); } }
int uart_resume_port(struct uart_driver *drv, struct uart_port *uport) { struct uart_state *state = drv->state + uport->line; struct tty_port *port = &state->port; struct device *tty_dev; struct uart_match match = {uport, drv}; struct ktermios termios; mutex_lock(&port->mutex); tty_dev = device_find_child(uport->dev, &match, serial_match_port); if (!uport->suspended && device_may_wakeup(tty_dev)) { if (uport->irq_wake) { disable_irq_wake(uport->irq); uport->irq_wake = 0; } put_device(tty_dev); mutex_unlock(&port->mutex); return 0; } put_device(tty_dev); uport->suspended = 0; if (uart_console(uport)) { memset(&termios, 0, sizeof(struct ktermios)); termios.c_cflag = uport->cons->cflag; if (port->tty && port->tty->termios && termios.c_cflag == 0) termios = *(port->tty->termios); if (console_suspend_enabled) uart_change_pm(state, 0); uport->ops->set_termios(uport, &termios, NULL); if (console_suspend_enabled) console_start(uport->cons); } if (port->flags & ASYNC_SUSPENDED) { const struct uart_ops *ops = uport->ops; int ret; uart_change_pm(state, 0); spin_lock_irq(&uport->lock); ops->set_mctrl(uport, 0); spin_unlock_irq(&uport->lock); if (console_suspend_enabled || !uart_console(uport)) { struct tty_struct *tty = port->tty; ret = ops->startup(uport); if (ret == 0) { if (tty) uart_change_speed(tty, state, NULL); spin_lock_irq(&uport->lock); ops->set_mctrl(uport, uport->mctrl); ops->start_tx(uport); spin_unlock_irq(&uport->lock); set_bit(ASYNCB_INITIALIZED, &port->flags); } else { uart_shutdown(tty, state); } } clear_bit(ASYNCB_SUSPENDED, &port->flags); } mutex_unlock(&port->mutex); return 0; }
int main(int argc, char **argv, char **envp) { console_start(1); return 0; }
int bsp_usb_console_init(void) { struct console* uart_console; struct usb_cdc_line_coding coding; int status = 0; /* alloc first tty driver for console */ gs_console_tty_driver = alloc_tty_driver(1); if (!gs_console_tty_driver) return -ENOMEM; gs_console_tty_driver->driver_name = "console_ser"; gs_console_tty_driver->name = g_acm_tty_type_table[ACM_CONSOLE_IDX].name; /* uses dynamically assigned dev_t values */ gs_console_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; gs_console_tty_driver->subtype = SERIAL_TYPE_NORMAL; gs_console_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; gs_console_tty_driver->init_termios = tty_std_termios; /* 9600-8-N-1 ... matches defaults expected by "usbser.sys" on * MS-Windows. Otherwise, most of these flags shouldn't affect * anything unless we were to actually hook up to a serial line. */ gs_console_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; gs_console_tty_driver->init_termios.c_ispeed = 9600; gs_console_tty_driver->init_termios.c_ospeed = 9600; gs_console_tty_driver->num = 1; coding.dwDTERate = cpu_to_le32(9600); coding.bCharFormat = 8; coding.bParityType = USB_CDC_NO_PARITY; coding.bDataBits = USB_CDC_1_STOP_BITS; tty_set_operations(gs_console_tty_driver, &gs_tty_ops); /* export the driver ... */ status = tty_register_driver(gs_console_tty_driver); if (status) { pr_err("%s: cannot register, err %d\n", __func__, status); goto console_init_fail; } mutex_init(&ports[0].lock); status = gs_port_alloc(0, &coding); if (status) { goto console_init_fail; } if (gs_acm_is_console_enable()) { /* reg from uart shell to usb shell */ uart_console = bsp_get_uart_console(); if (uart_console) { unregister_console(uart_console); } register_console(&gs_console); console_start(&gs_console); } return 0; console_init_fail: put_tty_driver(gs_console_tty_driver); return status; }
void reset_handler() { // Disable Exceptions and Interrupts asm volatile ("cpsid f"); asm volatile ("cpsid i"); // Initialize the RTT and Event Timer timer_init(); // Reset and Disable the Watchdog Timer WDT_CR = WDT_CR_WDRSTT | WDT_CR_KEY; WDT_MR = WDT_MR_WDDIS; // Enable Peripheral Clocks for the PIOs PMC_PCER = (1 << PMC_ID_PIOA); PMC_PCER = (1 << PMC_ID_PIOB); PMC_PCER = (1 << PMC_ID_PIOC); // Clear the PIO Interrupt Status Registers PIO_ISR(PIOA); PIO_ISR(PIOB); PIO_ISR(PIOC); // Configure the High-Voltage Pin and Disable the PSU (HV Off) PIO_PER(PIN_HV5530_HVEN_PIO) = (1 << PIN_HV5530_HVEN_IDX); // Enable PIO on Pin PIO_OER(PIN_HV5530_HVEN_PIO) = (1 << PIN_HV5530_HVEN_IDX); // Enable Output PIO_PUDR(PIN_HV5530_HVEN_PIO) = (1 << PIN_HV5530_HVEN_IDX); // Disable Pull-Up PIO_CODR(PIN_HV5530_HVEN_PIO) = (1 << PIN_HV5530_HVEN_IDX); // Clear Output Data Register // Configure the initial state of the 5v PSU (5v On) PIO_PER(PIN_5VPSU_EN_PIO) = (1 << PIN_5VPSU_EN_IDX); // Enable PIO on Pin PIO_OER(PIN_5VPSU_EN_PIO) = (1 << PIN_5VPSU_EN_IDX); // Enable Output PIO_PUER(PIN_5VPSU_EN_PIO) = (1 << PIN_5VPSU_EN_IDX); // Enable Pull-Up PIO_CODR(PIN_5VPSU_EN_PIO) = (1 << PIN_5VPSU_EN_IDX); // Clear Output Data Register // Configure the ZigBee Shutdown Pin (ZigBee On) PIO_PER(PIN_ZIGBEE_SHDN_PIO) = (1 << PIN_ZIGBEE_SHDN_IDX); // Enable PIO on Pin PIO_OER(PIN_ZIGBEE_SHDN_PIO) = (1 << PIN_ZIGBEE_SHDN_IDX); // Enable Output PIO_PUER(PIN_ZIGBEE_SHDN_PIO) = (1 << PIN_ZIGBEE_SHDN_IDX); // Enable Pull-Up PIO_SODR(PIN_ZIGBEE_SHDN_PIO) = (1 << PIN_ZIGBEE_SHDN_IDX); // Set Output Data Register // Enable User Resets by Asserting the NRST Pin // Assert NRST for 2^(11+1) Slow Clock Cycles (32 kHz * 4096 = 128ms) RSTC_MR = RSTC_MR_URSTEN | (11 << RSTC_MR_ERSTL_Off) | RSTC_MR_KEY; // Set the Flash Read/Write Cycles to 4 (for stable operation at 96MHz) EEFC_FMR(EEFC0) = ((EEFC_FMR(EEFC0) & ~EEFC_FMR_FWS_Msk) | (4 << (EEFC_FMR_FWS_Off))); EEFC_FMR(EEFC1) = ((EEFC_FMR(EEFC1) & ~EEFC_FMR_FWS_Msk) | (4 << (EEFC_FMR_FWS_Off))); // Configure Clock Generator Main Clock (External 12MHz Xtal) // Startup time 15625uS for Xtal (65 for 65*8 cycles at slow clock, ~32000Hz) CKGR_MOR = CKGR_MOR_KEY | (CKGR_MOR & ~(CKGR_MOR_MOSCXTBY)) | CKGR_MOR_MOSCXTEN | (65 << CKGR_MOR_MOSCXTST_Off); // Wait the main Xtal to stabilize while ((PMC_SR & PMC_SR_MOSCXTS) == 0); // Select Xtal as the Main Clock Source CKGR_MOR |= CKGR_MOR_KEY | CKGR_MOR_MOSCSEL; // Wait for the selection to complete while (!(PMC_SR & PMC_SR_MOSCSELS)); // Configure Clock Generator PLLA Clock (12MHz Xtal * (15+1) = 192MHz) // Disable the PLL CKGR_PLLAR = CKGR_PLLAR_ONE; // Enable with the correct settings CKGR_PLLAR = CKGR_PLLAR_ONE | (1 << CKGR_PLLAR_DIVA_Off) | (15 << CKGR_PLLAR_MULA_Off) | (0x3F << CKGR_PLLAR_PLLACOUNT_Off); // Wait for a lock while (!(PMC_SR & PMC_SR_LOCKA)); // Configure Clock Generator USB UTMI PLL (12MHz Xtal * 40 = 480MHz) // Enable the UTMI PLLA CKGR_UCKR = CKGR_UCKR_UPLLEN | (0xF << CKGR_UCKR_UPLLCOUNT_Off); // Wait for a lock while (!(PMC_SR & PMC_SR_LOCKU)); // Configure Master Clock Controller (MCK = PLLA / 2 = 96MHz) // Program clock divider as 2 PMC_MCKR = (PMC_MCKR & ~(PMC_MCKR_PRES_Msk)) | PMC_MCKR_PRES_CLK_2; // Program clock source as PLLA PMC_MCKR = (PMC_MCKR & ~(PMC_MCKR_CSS_Msk)) | PMC_MCKR_CSS_PLLA_CLK; // Wait for the master clock to be ready while (!(PMC_SR & PMC_SR_MCKRDY)); // Zero the uninitialized data segment if (&bss_end - &bss_start > 0) { memset(&bss_start, 0, &bss_end - &bss_start); } // Load the initialized data segment if (&data_start != &data_load) { memcpy(&data_start, &data_load, &data_end - &data_start); } // Divide the interrupts into 4 groups of 4; 0-3, 4-7, 8-11, 12-15. // Interrupts within the same group will not preempt each other but an // interrupt from a group with a lower priority will. When two interrupts // within the same group are received at the same time, the one with the // lower priority number will be serviced first. AIRCR = AIRCR_VECTKEY | (0x5 << AIRCR_PRIGROUP_Off); // Set SVC Interrupt Priority to 4 SHPR2 = ((SHPR2 & ~SHPR2_PRI_11_Msk) | (0x40 << SHPR2_PRI_11_Off)); // Trap Divide-by-0 as Hard Fault CCR |= CCR_DIV_0_TRP; // Enable Exceptions asm volatile ("cpsie f"); // Enable the Serial Console console_init(); // Initialize the TWI Driver twi_init(); // Enable Interrupts asm volatile ("cpsie i"); // Print terminal headline kputs("\r\n\r\n"); kputs("nixieclock-firmware: Nixie Clock Main Firmware Program\r\n"); kputs("Copyright (C) 2013 - 2015 Joe Ciccone and Ed Koloski\r\n"); kputs("This program comes with ABSOLUTELY NO WARRANTY; for details type 'license show'.\r\n"); kputs("This is free software, and you are welcome to redistribute it\r\n"); kputs("under certain conditions; type 'license show' for details.\r\n"); kputs("\r\n"); // Print the reset cause kputs("Reset Reason: "); switch (RSTC_SR & RSTC_SR_RSTTYP_Msk) { case RSTC_SR_RSTTYP_GENERAL: kputs("General"); break; case RSTC_SR_RSTTYP_BACKUP: kputs("Backup"); break; case RSTC_SR_RSTTYP_WATCHDOG: kputs("Watchdog"); break; case RSTC_SR_RSTTYP_SOFTWARE: kputs("Software"); break; case RSTC_SR_RSTTYP_USER: kputs("User"); break; default: kprintf("Unknown (%lu)", ((RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Off)); } kputs("\r\n"); // Initialize Services clock_init(); audio_init(); display_init(); keyboard_init(); // Enable the Interactive Console console_start(); // Play a sine-wave to debugging audio_play_sine(); // Initialization Complete while (1) {} }