void initialize_zigbee_module(HANDLE* fdr, char* serial_port, address source) { int res; char buff[1024]; HANDLE fd; /* Initialize serial port. */ fd = initialize_serial(serial_port); printf("Initializing ZigBee module...\n"); change_local_address(fd, source); write_AT_command(fd, "ATDH0000"); /* DEST. ADDRESS */ write_AT_command(fd, "ATDLFFFF"); /* DEST. ADDRESS */ write_AT_command(fd, "ATCH0x0C"); /* CHANNEL ID */ write_AT_command(fd, "ATID0000"); /* PAN ID */ write_AT_command(fd, "ATMM2"); /* ACK */ *fdr = fd; }
void test_process_1() { kprintf("Initializing serial logging.\n"); initialize_serial(); logger_initialize(); kprintf("Initialized kernel logger process.\n"); terminal_writestring("Initializing ACPI.\n"); initialize_acpi(); kprintf("Initializing APICs.\n"); logger_flush_buffer(); initialize_apics(); //logger_flush_buffer(); //kprintf("Done initializing APICs.\n"); //logger_flush_buffer(); /* unsigned long long int last_ticked = get_sys_time_counter(); kprintf("Current system timer = %llu.\n", last_ticked); logger_flush_buffer(); while(true) { if( last_ticked != get_sys_time_counter() ) { kprintf("Tick.\nCurrent system timer = %llu.\n", last_ticked); logger_flush_buffer(); last_ticked = get_sys_time_counter(); } } */ //while(true) { asm volatile("pause"); }; kprintf("Starting kernel worker thread.\n"); k_work::start(); kprintf("Initializing PS/2 controller.\n"); ps2_controller_init(); kprintf("Initializing PS/2 keyboard.\n"); ps2_keyboard_initialize(); kprintf("Initializing I/O.\n"); io_initialize(); kprintf("Initializing PCI.\n"); //pci_initialize(); pci_check_all_buses(); pci_get_int_routing(); //while(true) { asm volatile("pause"); }; kprintf("Initializing ATA storage.\n"); ata::initialize(); io_detect_disk( io_get_disk( 1 ) ); kprintf("Scheduling work...\n"); logger_flush_buffer(); k_work::work* wk = k_work::schedule( &k_worker_thread_test ); kprintf("Test work function returned: %u\n", wk->wait()); uint32_t child_pid = fork(); if( child_pid == -1 ) { kprintf("Whoops, something went wrong with fork!"); } else if( child_pid == 0 ) { kprintf("Hello from (child) process %u!\n", (unsigned int)process_current->id); /* set_message_listen_status( "keypress", true ); while(true) { unique_ptr<ps2_keypress> kp; kp = ps2_keyboard_get_keystroke(); if( !kp->released ) { if( kp->key == KEY_CurUp ) { kprintf("Process %u: Up!\n", process_current->id); } else if( kp->key == KEY_CurDown ) { kprintf("Process %u: Down!\n", process_current->id); /*} else if( kp->key == KEY_Enter ) { kprintf("Process %u: Forcing ATA cache flush...\n", process_current->id); ata_do_cache_flush(); *//* } } } */ /* unsigned long long int last_ticked = 0; while(true) { if(last_ticked+1000 <= get_sys_time_counter()) { kprintf("Tick."); last_ticked = get_sys_time_counter(); } } */ } else { kprintf("Hello from (parent) process %u!\n", process_current->id); kprintf("Starting lua interpretation.\n"); lua_State *st = luaL_newstate(); //kprintf("Opened state..\n"); luaL_openlibs( st ); //kprintf("Opened libs..\n"); lua_register( st, "writeout", lua_writeout_proxy ); //kprintf("Registered writeout..\n"); int stat = luaL_loadstring( st, "writeout(\"hello from lua version \",_VERSION,\"!\") return 0xC0DE" ); //kprintf("Loaded test program..\n"); if( stat == 0 ) { // was it loaded successfully? //kprintf("Performing call..\n"); stat = lua_pcall( st, 0, 1, 0 ); if( stat == 0 ) { // get return values int retval = lua_tonumber(st, -1); kprintf("Test program returned successfully, returned value: 0x%x\n", retval); lua_pop(st, 1); } } if( stat != 0 ) { // was there an error? const char *err = lua_tostring(st, -1); kprintf("lua-error: %s\n", err); lua_pop(st, 1); } lua_close(st); //kprintf("Closed state..\n"); //kprintf("Initializing AHCI.\n"); //ahci_initialize(); // format partition 1 as FAT (using our own code): //fat32_do_format( 1 ); const char* test_file_name = "test2.txt"; char *test_file_data = "Hello world! This is a test file!"; fat_fs::fat_fs f( 1 ); iso9660::iso9660_fs f2(2); device_manager::dev_fs f3; vfs::vfs_root = f.base; vfs::vfs_status fop_stat = vfs::mount(&f2, (unsigned char*)(const_cast<char*>("/cd"))); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS mount failed with error: %s.\n", vfs::status_description(fop_stat)); } else { kprintf("FS mount succeeded.\n"); } fop_stat = vfs::mount(&f3, (unsigned char*)(const_cast<char*>("/dev"))); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS mount failed with error: %s.\n", vfs::status_description(fop_stat)); } else { kprintf("FS mount succeeded.\n"); } while(true) { kprintf(">"); logger_flush_buffer(); unsigned int len; char* line = ps2_keyboard_readline( &len ); unsigned int cmd_len = 0; unsigned int arg1_start = 0; unsigned int arg1_end = 0; unsigned int arg2_start = 0; bool found_cmd = false; bool found_arg1 = false; bool stopped_arg1 = false; bool found_arg2 = false; for(unsigned int i=0;i<len;i++) { if(line[i] == ' ') { if( !found_cmd ) { cmd_len = i; found_cmd = true; } else if( found_arg1 && !stopped_arg1 ) { arg1_end = i; stopped_arg1 = true; } } else { if( found_cmd && !found_arg1 ) { arg1_start = i; found_arg1 = true; } else if( found_arg1 && stopped_arg1 ) { arg2_start = i; found_arg2 = true; break; } } } if( found_cmd ) { char* cmd = NULL; char* arg1 = NULL; char* arg2 = NULL; cmd = (char*)kmalloc( cmd_len+1 ); for(unsigned int i=0;i<cmd_len;i++) { cmd[i] = line[i]; } cmd[cmd_len] = '\0'; if( found_arg1 ) { if( stopped_arg1 ) { arg1 = (char*)kmalloc( (arg1_end - arg1_start)+1 ); for(unsigned int i=arg1_start;i<arg1_end;i++) { arg1[ i - arg1_start ] = line[i]; } arg1[ arg1_end - arg1_start ] = '\0'; if( found_arg2 ) { arg2 = (char*)kmalloc( (len - arg2_start)+1 ); for(unsigned int i=arg2_start;i<len;i++) { arg2[i-arg2_start] = line[i]; } arg2[len-arg2_start] = '\0'; } } else { arg1 = (char*)kmalloc( (len - arg1_start)+1 ); for(unsigned int i=arg1_start;i<len;i++) { arg1[ i - arg1_start ] = line[i]; } arg1[ len - arg1_start ] = '\0'; } } if( arg1 != NULL ) { if( strcmp( cmd, const_cast<char*>("ls") ) || strcmp( cmd, const_cast<char*>("list") ) ) { vector<vfs_node*> dls; vfs::vfs_status fop_stat = vfs::list_directory( (unsigned char*)arg1, &dls ); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS list failed with error: %s\n", vfs::status_description(fop_stat)); } else { kprintf("FS list succeeded.\n"); } kprintf( "Directory listing:\n" ); for( unsigned int i=0;i<dls.count();i++) { kprintf( "%s\n", dls[i]->name ); } } else if( (arg2 != NULL) && strcmp( cmd, const_cast<char*>("write") ) ) { vfs::vfs_status fop_stat = vfs::write_file( (unsigned char*)arg1, (void*)arg2, strlen(arg2)+1); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS write failed with error: %s\n", vfs::status_description(fop_stat)); } else { kprintf("FS write succeeded.\n"); } } else if( strcmp( cmd, const_cast<char*>("read") ) ) { vfs_node* node = NULL; vfs::vfs_status fop_stat = vfs::get_file_info( (unsigned char*)arg1, &node ); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS get info failed with error: %s\n", vfs::status_description(fop_stat)); } else { kprintf("FS get info succeeded.\n"); } if( node != NULL ) { if( node->type != vfs_node_types::file ) { kprintf("FS read failed with error: incorrect type\n"); continue; } } vfs_file* fn = (vfs_file*)node; void* buffer = kmalloc( fn->size ); fop_stat = vfs::read_file( (unsigned char*)arg1, buffer ); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS read failed with error: %s\n", vfs::status_description(fop_stat)); } else { kprintf("FS read succeeded.\n"); } kprintf("file data: %s\n", (unsigned char*)buffer ); } else if( strcmp( cmd, const_cast<char*>("delete") ) || strcmp( cmd, const_cast<char*>("rm") ) ) { vfs::vfs_status fop_stat = vfs::delete_file( (unsigned char*)arg1 ); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS delete failed with error: %s\n", vfs::status_description(fop_stat)); } else { kprintf("FS delete succeeded.\n"); } } else if( ( arg2 != NULL ) && (strcmp( cmd, const_cast<char*>("copy") ) || strcmp( cmd, const_cast<char*>("cp") ) ) ) { vfs::vfs_status fop_stat = vfs::copy_file( (unsigned char*)arg2, (unsigned char*)arg1 ); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS copy failed with error: %s\n", vfs::status_description(fop_stat)); } else { kprintf("FS copy succeeded.\n"); } } else if( ( arg2 != NULL ) && (strcmp( cmd, const_cast<char*>("move") ) || strcmp( cmd, const_cast<char*>("mv") ) ) ) { vfs::vfs_status fop_stat = vfs::move_file( (unsigned char*)arg2, (unsigned char*)arg1 ); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS move failed with error: %s\n", vfs::status_description(fop_stat)); } else { kprintf("FS move succeeded.\n"); } } } } } /* vfs_directory *root = f.base; vfs_file *test_file = NULL; kprintf( "Directory listing:\n" ); for( unsigned int i=0;i<root->files.count();i++) { vfs_node *fn = root->files[i]; kprintf( "* %u - %s\n", i, fn->name ); if( strcmp(const_cast<char*>(test_file_name), (char*)(fn->name), 0) ) { test_file = new vfs_file(const_cast<vfs_node*>(fn)); } } if(test_file == NULL) { test_file = f.create_file( (unsigned char*)(test_file_name), f.base ); kprintf("test file created\n"); test_file->size = strlen(test_file_data)+1; f.write_file(test_file, (void*)test_file_data, strlen(test_file_data)+1); kprintf("File written out to %s\n", test_file_name); } else { //f.write_file(test_file, (void*)test_file_data, strlen(test_file_data)+1); //kprintf("File written out to %s\n", test_file_name); void *readback = kmalloc(strlen(test_file_data)+1); f.read_file(test_file, readback); char* readback_data = (char*)readback; kprintf("Readback data: %s (%#p)\n", readback_data, readback); } unsigned char f2_mountpoint[] = { '/', 'c', 'd', '\0' }; root = f2.base; kprintf( "Directory listing (ISO 9660):\n" ); for( unsigned int i=0;i<root->files.count();i++) { vfs_node *fn = root->files[i]; kprintf( "* %u - %s\n", i, fn->name ); } vfs::vfs_status fop_stat = vfs::mount(&f2, f2_mountpoint); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS mount failed with error: %s.\n", vfs::status_description(fop_stat)); } else { kprintf("FS mount succeeded.\n"); } vector<vfs_node*> dls; fop_stat = vfs::list_directory( (unsigned char*)(const_cast<char*>("/")), &dls ); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS list failed with error: %s\n", vfs::status_description(fop_stat)); } else { kprintf("FS list succeeded.\n"); } kprintf( "Directory listing (VFS root):\n" ); for( unsigned int i=0;i<dls.count();i++) { kprintf("* %u - %s\n", i, dls[i]->name); } dls.clear(); fop_stat = vfs::list_directory( (unsigned char*)(const_cast<char*>("/cd")), &dls ); if( fop_stat != vfs::vfs_status::ok ) { kprintf("FS list failed with error: %s\n", vfs::status_description(fop_stat)); } else { kprintf("FS list succeeded.\n"); } kprintf( "Directory listing (VFS, /cd):\n" ); for( unsigned int i=0;i<dls.count();i++) { kprintf("* %u - %s\n", i, dls[i]->name); } logger_flush_buffer(); while(true) { asm volatile("pause"); } */ /* f.write_file(test_file, (void*)test_file_data, strlen(test_file_data)+1); kprintf("File written out to %s\n", test_file_name); logger_flush_buffer(); system_halt; */ /* test_file = f.create_file( (unsigned char*)(test_file_name), f.base ); kprintf("test file created\n"); logger_flush_buffer(); system_halt; */ /* logger_flush_buffer(); system_halt; if( test_file == NULL ) { test_file = f.create_file( (unsigned char*)(test_file_name), f.base ); kprintf("test file created\n"); logger_flush_buffer(); system_halt; } f.write_file(test_file, (void*)test_file_data, strlen(test_file_data)+1); kprintf("File written out to %s\n", test_file_name); logger_flush_buffer(); system_halt; void *readback = kmalloc(strlen(test_file_data)+1); f.read_file(test_file, readback); char* readback_data = (char*)readback; kprintf("Readback data: %s\n", readback_data); logger_flush_buffer(); system_halt; */ /* fat32_fs f2(1); root = f2.root_dir_vfs; kprintf( "Directory listing:\n" ); for( unsigned int i=0;i<root->files.count();i++) { vfs_node *fn = root->files[i]; kprintf( "* %u - %s\n", i, fn->name ); } logger_flush_buffer(); system_halt; */ // hacked-together raw disk function: /* while( true ) { unsigned int len = 0; kprintf("sector_n > "); char* sector_str = ps2_keyboard_readline(&len); if( len > 0 ) { uint32_t sector = atoi( sector_str ); void *buf = kmalloc(512); io_read_partition( 1, buf, sector*512, 512 ); uint8_t *buf2 = (uint8_t*)buf; for( int i=0;i<512;i+=16 ) { kprintf("%#02x: ", i); for( int j=0;j<16;j++ ) { kprintf("%02x ", buf2[i+j]); } kprintf("\n"); set_message_listen_status( "keypress", true ); while(true) { unique_ptr<ps2_keypress> kp; kp = ps2_keyboard_get_keystroke(); if( !kp->released ) { if( kp->key == KEY_Enter ) { break; } } } } kfree(buf); } kfree(sector_str); } */ // hacked-together ls: /* kprintf("Reading partition 1 as FAT32..."); fat32_fs *fs = new fat32_fs( 1 ); kprintf("Reading root directory...\n"); vfs_directory *root = fs->read_directory(0); for( int i=0;i<root->files.count();i++ ) { kprintf("* %u - %s\n", i, root->files[i]->name); } */ } }
void PE_init_kprintf(__unused boolean_t vm_initialized) { unsigned int boot_arg; int32_t serial_baud = -1; unsigned int size; DTEntry options; char *str, baud[7]; if (PE_state.initialized == FALSE) panic("Platform Expert not initialized"); if (PE_parse_boot_argn("debug", &boot_arg, sizeof (boot_arg))) if(boot_arg & DB_KPRT) disable_serial_output = FALSE; if (DTLookupEntry(NULL, "/options", &options) == kSuccess) { if (DTGetProperty(options, "input-device", (void **)&str, &size) == kSuccess) { if ((size > 5) && !strncmp("scca:", str, 5)) { size -= 5; str += 5; if (size <= 6) { strncpy(baud, str, size); baud[size] = '\0'; gPESerialBaud = strtol(baud, NULL, 0); } } } if (DTGetProperty(options, "output-device", (void **)&str, &size) == kSuccess) { if ((size > 5) && !strncmp("scca:", str, 5)) { size -= 5; str += 5; if (size <= 6) { strncpy(baud, str, size); baud[size] = '\0'; gPESerialBaud = strtol(baud, NULL, 0); } } } } /* Check the boot-args for new serial baud. */ if (PE_parse_boot_argn("serialbaud", &serial_baud, sizeof (serial_baud))) if (serial_baud != -1) gPESerialBaud = serial_baud; if( (scc = PE_find_scc())) { /* See if we can find the serial port */ scc = io_map_spec(scc, 0x1000, VM_WIMG_IO); /* Map it in */ initialize_serial((void *)scc, gPESerialBaud); /* Start up the serial driver */ PE_kputc = serial_putc; simple_lock_init(&kprintf_lock, 0); } else PE_kputc = cnputc; #if 0 /* * FUTURE: eventually let the boot command determine where * the debug output will be, serial, video, etc. */ switch (PE_state.debug_video.v_display) { case kDebugTypeSerial: PE_kputc = serial_putc; break; case kDebugTypeDisplay: init_display_putc( (unsigned char*)PE_state.debug_video.v_baseAddr, PE_state.debug_video.v_rowBytes, PE_state.debug_video.v_height); PE_kputc = display_putc; break; default: PE_state.debug_video.v_baseAddr = 0; } #endif }
int config_init() { const unsigned char str_init_sky[2] = {0x5a, 0x5a}; unsigned char key = 0; int i, val; /*初始化 增益 阻尼 功率 双晶 在skyworks 之后*/ switch (VAL(damping)) { case 0: ioctl(pt->fd_gpio, DAMPING_4, &val);break; case 1: ioctl(pt->fd_gpio, DAMPING_3, &val);break; case 2: ioctl(pt->fd_gpio, DAMPING_2, &val);break; case 3: ioctl(pt->fd_gpio, DAMPING_1, &val);break; default: break; } write_db_val(VAL(db), 1200); /*初始化增益*/ if (VAL(dual) == 1) ioctl(pt->fd_gpio, DUAL_ON, &val); else ioctl(pt->fd_gpio, DUAL_OFF, &val); if (VAL(power) == 1) ioctl(pt->fd_gpio, POWER_HIGH, &val); else ioctl(pt->fd_gpio, POWER_LOW, &val); if (initialize_serial() != 0) { perror("initialize_serial error"); return 1; } val = 0; ioctl(pt->fd_gpio, FREEZE, &val); /*等待FPGA初始化 tandenghua*/ write(pt->fd_key, str_init_sky, 1); // while (key != 0x5a) { // if (read(pt->fd_key, &key, 1) > 0); // } /*果用户在开机时,在按KEY_DB_REG键就恢复出厂默认设置*/ for (i = 0; i < 100; i++) { if (read(pt->fd_key, &key, 1) > 0 ) { if (key == KEY_DB_REG) { //运行恢复默认配置函数 recall_set_config(); break; } } Sleep(0, 100); } if (VAL(power) == 1) *(pt->trans_data + 1024*2 + 4*2) = 0x01; else *(pt->trans_data + 1024*2 + 4*2) = 0x00; /*液晶屏 亮度*/ switch (VAL(light)) { case 2: write(pt->fd_key, key_light_high, 1); break; case 1: write(pt->fd_key, key_light_mid, 1); break; case 0: write(pt->fd_key, key_light_low, 1); break; default: break; } /*语言设置*/ if (VAL(lang) == 1) bmp = bmp2; else bmp = bmp1; /*初始化范围 延时 检波*/ pt->trans_data = (unsigned short *) pt->map_base; if (1 == VAL(magnify)) { pt->delay_tmp=(unsigned long)((VAL(astart)*2/(VAL(mtlvel)/1000.0)+VAL(p_delay))/10+16384); *(pt->trans_data+1024*2)=pt->delay_tmp&0xffff; *(pt->trans_data+1024*2+1)=(pt->delay_tmp>>16)&0xffff; *(pt->trans_data+1024*2+3*2)=VAL(rectify); pt->true_delay=VAL(astart); pt->true_range=VAL(awidth); } else if (0 == VAL(magnify)) {