void __init plat_time_init(void) { unsigned int prid = read_c0_prid() & (PRID_COMP_MASK | PRID_IMP_MASK); unsigned int freq; init_rtc(); estimate_frequencies(); freq = mips_hpt_frequency; if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) && (prid != (PRID_COMP_MIPS | PRID_IMP_25KF))) freq *= 2; freq = freqround(freq, 5000); printk("CPU frequency %d.%02d MHz\n", freq/1000000, (freq%1000000)*100/1000000); mips_scroll_message(); #ifdef CONFIG_I8253 /* Only Malta has a PIT. */ setup_pit_timer(); #endif #ifdef CONFIG_MIPS_GIC if (gic_present) { freq = freqround(gic_frequency, 5000); printk("GIC frequency %d.%02d MHz\n", freq/1000000, (freq%1000000)*100/1000000); #ifdef CONFIG_CLKSRC_MIPS_GIC gic_clocksource_init(gic_frequency); #endif } #endif }
void init_cmos(void) { cmos_data = malloc(sizeof(cmos_data_t)); cmos_data->registers.register_a = cmos_read_byte(CMOS_REGISTER_A); cmos_data->registers.register_b = cmos_read_byte(CMOS_REGISTER_B); cmos_data->registers.register_c = cmos_read_byte(CMOS_REGISTER_C); cmos_data->registers.register_d = cmos_read_byte(CMOS_REGISTER_D); init_rtc(); cmos_data->hardware.post_diagnostig_status_byte = cmos_read_byte(0x0E); cmos_data->hardware.shutdown_status_byte = cmos_read_byte(0x0F); cmos_data->hardware.floppy_disk_type = cmos_read_byte(0x10); cmos_data->hardware.hd_type = cmos_read_byte(0x12); cmos_data->hardware.device_byte = cmos_read_byte(0x14); cmos_data->hardware.basememory_size_low = cmos_read_byte(0x15); cmos_data->hardware.basememory_size_high = cmos_read_byte(0x16); cmos_data->hardware.expandablememory_size_low = cmos_read_byte(0x17); cmos_data->hardware.expandablememory_size_high = cmos_read_byte(0x18); cmos_data->hardware.extension_byte_hd1 = cmos_read_byte(0x19); cmos_data->hardware.extension_byte_hd2 = cmos_read_byte(0x1A); cmos_data->hardware.cmos_magic_low = cmos_read_byte(0x2E); cmos_data->hardware.cmos_magic_high = cmos_read_byte(0x2F); cmos_data->hardware.extendedmemory_low = cmos_read_byte(0x30); cmos_data->hardware.extendedmenory_high = cmos_read_byte(0x31); }
static void plug_devices(void) { /* Port ranges 0x0 -> 0xF */ port_map[0x0] = init_control(); port_map[0x1] = init_flash(); port_map[0x2] = init_sha256(); port_map[0x3] = init_usb(); port_map[0x4] = init_lcd(); port_map[0x5] = init_intrpt(); port_map[0x6] = init_watchdog(); port_map[0x7] = init_gpt(); port_map[0x8] = init_rtc(); port_map[0x9] = init_protected(); port_map[0xA] = init_keypad(); port_map[0xB] = init_backlight(); port_map[0xC] = init_cxxx(); port_map[0xD] = init_dxxx(); port_map[0xE] = init_exxx(); port_map[0xF] = init_fxxx(); reset_proc_count = 0; /* Populate reset callbacks */ add_reset_proc(lcd_reset); add_reset_proc(keypad_reset); add_reset_proc(gpt_reset); add_reset_proc(rtc_reset); add_reset_proc(watchdog_reset); add_reset_proc(cpu_reset); gui_console_printf("[CEmu] Initialized APB...\n"); }
void main() { unsigned int i,j,k,l,m,n; PINSEL0=0X00000000; PINSEL1=0X00000000; IO0DIR=0XFFFFFFFF; lcd_init(); init_rtc(); lcd_str("CLOCK:- 24"); cmd(0xc0); lcd_str("00:00:00"); while(1) { if(flag) { flag=0; lcd_pos(2,0); lcd_display(HOUR/10 + '0'); lcd_display(HOUR%10 + '0'); lcd_display(':') ; lcd_display(MIN/10 + '0'); lcd_display(MIN%10 + '0'); lcd_display(':') ; lcd_display(SEC/10 + '0'); lcd_display(SEC%10 + '0'); } } }
void wakeup() { blip(); // serial interrupt detected a char if (wakeup_mode == WAKEON_COM_A) { // while an RTC wakeup has not occured while (wakeup_mode != WAKEON_RTC){ // flash LED blip(); // if serial wake-up is good if (serial_wakeup()){ sleep_mode = FALSE; start_heartbeat(); init_hardware(); init_rtc(); // This is the FAT RTC sd_status = init_sdcard(); bit_set(INTCON,PEIE); // Set Peripheral Interrupt Enable bit sprintf(event_str, ",serial wake-up,SD initialized\r\n"); record_event(); if(sd_status>0) msg_card_fail(); return; } else { // if serial_wakeup() == FALSE, then false alarm wakeup_mode = WAKEON_BAD; blip(); blip(); shutdown(); go_to_sleep(); } } } }
int32_t rtc_open(file_t* file, const uint8_t* filename) { file->file_op = &rtc_jt; //This initializes the file_op file->inode_ptr = NULL; //This initializes the file_op file->file_pos = 0; //This initializes the file position to start from the beginning file->flags = 1; //This initializes flags init_rtc(); //This sets the rtc rate return RET_SUCCESS; //return 0 if all fine }
/******************************************************************************* * Initialize the GIC. ******************************************************************************/ void bl31_platform_setup(void) { /* Initialize the gic cpu and distributor interfaces */ plat_gic_init(); arm_gic_setup(); init_rtc(); hisi_ipc_init(); hisi_pwrc_setup(); }
int main(void) { init_io(); init_rtc(); set_sleep_mode(SLEEP_MODE_IDLE); while(1) { sleep_mode(); //will wake up from time overflow interrupt display(); } }
void init_timers (void) { tsc_calibration (); init_pit (do_pit, HZ); init_lapic_timer (do_lapictim, HZ); init_rtc (); return; }
void main(void) { //Initialize IOs init_IO(); //Initialize the RTC init_rtc(); //Initialize the UART uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) ); //set the Global Interrupt Enable Bit sei(); while(1) { //Blink sekonds LED if (led_state == 1) { PORTB |= (1<<led_pin); // Turn on LED } else { PORTB &= ~(1<<led_pin); // Turn off LED } if (new_tick) { //Convert and display hours char buf [2]; itoa (t.hour,buf,10); uart_puts(buf); uart_puts(":"); //Convert and display minutes itoa (t.minute,buf,10); uart_puts(buf); uart_puts(":"); //Convert and display seconds itoa (t.second,buf,10); uart_puts(buf); uart_puts("\r\n"); new_tick = 0; } } }
/*----------------------------------------------------------------------------*/ void sys_init(void) { #ifdef UART_ENABLE uartInit(); printf("power up \r\n"); #endif #if RTC_ENABLE if (init_rtc()) { work_mode = SYS_RTC; } #else { u8 rtc_reg; rtc_reg=read_rtc_reg(); //printf("RTC reg:%02bx\n",rtc_reg); if (rtc_reg & BIT(6)) ///<RTC是否完全掉电 { #if (MEMORY_STYLE == USE_RTCRAM) reset_rtc_ram(); #endif rtc_reg &= ~(BIT(6)); //清零PDGLG write_rtc_reg(rtc_reg); } } #endif P0IE_init(); keyInit(); timer1Init(); timer3Init(); #ifdef USE_USB_SD_DECODE_FUNC #ifndef NO_SD_DECODE_FUNC sd_speed_init(1,100); init_port_sd(); #endif #endif #if SDMMC_CMD_MODE sd_chk_ctl(SET_SD_H_CHK); #endif DACCON0 |= 0x05; //打开DSP EA = 1; }
int main(int argc, char *argv[]) { unsigned char in_ch=0,get_nib=0; pthread_t uit,sit,cit; char hostname[15],pass[10],grp[12],stat[10]; http.host = &hostname[0]; http.password = &pass[0]; http.name = &grp[0]; http.status = &stat[0]; strcpy(hostname,"129.63.205.75"); http.port = 8000; http.id =2 ; strcpy(pass,"gkrd"); strcpy(grp,"microex"); strcpy(stat,"OK"); init_rtc(); if (-1 == GPIOExport(STB) || -1 == GPIOExport(GP0) || -1 == GPIOExport(GP1) || -1 == GPIOExport(GP2) || -1 == GPIOExport(GP3)) return(1); /* * Set GPIO directions */ if (-1 == GPIODirection(STB, OUT)) return(2); GPIOWrite(STB, LOW); printf("\n intializing processes .... ") ; pthread_create(&uit,NULL,UI_thread,NULL); pthread_create(&sit,NULL,sense_thread,NULL); pthread_create(&cit,NULL,client_thread,NULL); pthread_join(uit,NULL); pthread_join(sit,NULL); pthread_join(cit,NULL); return(4); }
void BIOSCALL int1a_function(pusha_regs_t regs, uint16_t ds, uint16_t es, iret_addr_t iret_addr) { uint8_t val8; BX_DEBUG_INT1A("int1a: AX=%04x BX=%04x CX=%04x DX=%04x DS=%04x\n", regs.u.r16.ax, regs.u.r16.bx, regs.u.r16.cx, regs.u.r16.dx, ds); int_enable(); switch (regs.u.r8.ah) { case 0: // get current clock count int_disable(); regs.u.r16.cx = BiosData->ticks_high; regs.u.r16.dx = BiosData->ticks_low; regs.u.r8.al = BiosData->midnight_flag; BiosData->midnight_flag = 0; // reset flag int_enable(); // AH already 0 ClearCF(iret_addr.flags); // OK break; case 1: // Set Current Clock Count int_disable(); BiosData->ticks_high = regs.u.r16.cx; BiosData->ticks_low = regs.u.r16.dx; BiosData->midnight_flag = 0; // reset flag int_enable(); regs.u.r8.ah = 0; ClearCF(iret_addr.flags); // OK break; case 2: // Read CMOS Time if (rtc_updating()) { SetCF(iret_addr.flags); break; } regs.u.r8.dh = inb_cmos(0x00); // Seconds regs.u.r8.cl = inb_cmos(0x02); // Minutes regs.u.r8.ch = inb_cmos(0x04); // Hours regs.u.r8.dl = inb_cmos(0x0b) & 0x01; // Stat Reg B regs.u.r8.ah = 0; regs.u.r8.al = regs.u.r8.ch; ClearCF(iret_addr.flags); // OK break; case 3: // Set CMOS Time // Using a debugger, I notice the following masking/setting // of bits in Status Register B, by setting Reg B to // a few values and getting its value after INT 1A was called. // // try#1 try#2 try#3 // before 1111 1101 0111 1101 0000 0000 // after 0110 0010 0110 0010 0000 0010 // // Bit4 in try#1 flipped in hardware (forced low) due to bit7=1 // My assumption: RegB = ((RegB & 01100000b) | 00000010b) if (rtc_updating()) { init_rtc(); // fall through as if an update were not in progress } outb_cmos(0x00, regs.u.r8.dh); // Seconds outb_cmos(0x02, regs.u.r8.cl); // Minutes outb_cmos(0x04, regs.u.r8.ch); // Hours // Set Daylight Savings time enabled bit to requested value val8 = (inb_cmos(0x0b) & 0x60) | 0x02 | (regs.u.r8.dl & 0x01); // (reg B already selected) outb_cmos(0x0b, val8); regs.u.r8.ah = 0; regs.u.r8.al = val8; // val last written to Reg B ClearCF(iret_addr.flags); // OK break; case 4: // Read CMOS Date regs.u.r8.ah = 0; if (rtc_updating()) { SetCF(iret_addr.flags); break; } regs.u.r8.cl = inb_cmos(0x09); // Year regs.u.r8.dh = inb_cmos(0x08); // Month regs.u.r8.dl = inb_cmos(0x07); // Day of Month regs.u.r8.ch = inb_cmos(0x32); // Century regs.u.r8.al = regs.u.r8.ch; ClearCF(iret_addr.flags); // OK break; case 5: // Set CMOS Date // Using a debugger, I notice the following masking/setting // of bits in Status Register B, by setting Reg B to // a few values and getting its value after INT 1A was called. // // try#1 try#2 try#3 try#4 // before 1111 1101 0111 1101 0000 0010 0000 0000 // after 0110 1101 0111 1101 0000 0010 0000 0000 // // Bit4 in try#1 flipped in hardware (forced low) due to bit7=1 // My assumption: RegB = (RegB & 01111111b) if (rtc_updating()) { init_rtc(); SetCF(iret_addr.flags); break; } outb_cmos(0x09, regs.u.r8.cl); // Year outb_cmos(0x08, regs.u.r8.dh); // Month outb_cmos(0x07, regs.u.r8.dl); // Day of Month outb_cmos(0x32, regs.u.r8.ch); // Century val8 = inb_cmos(0x0b) & 0x7f; // clear halt-clock bit outb_cmos(0x0b, val8); regs.u.r8.ah = 0; regs.u.r8.al = val8; // AL = val last written to Reg B ClearCF(iret_addr.flags); // OK break; case 6: // Set Alarm Time in CMOS // Using a debugger, I notice the following masking/setting // of bits in Status Register B, by setting Reg B to // a few values and getting its value after INT 1A was called. // // try#1 try#2 try#3 // before 1101 1111 0101 1111 0000 0000 // after 0110 1111 0111 1111 0010 0000 // // Bit4 in try#1 flipped in hardware (forced low) due to bit7=1 // My assumption: RegB = ((RegB & 01111111b) | 00100000b) val8 = inb_cmos(0x0b); // Get Status Reg B regs.u.r16.ax = 0; if (val8 & 0x20) { // Alarm interrupt enabled already SetCF(iret_addr.flags); // Error: alarm in use break; } if (rtc_updating()) { init_rtc(); // fall through as if an update were not in progress } outb_cmos(0x01, regs.u.r8.dh); // Seconds alarm outb_cmos(0x03, regs.u.r8.cl); // Minutes alarm outb_cmos(0x05, regs.u.r8.ch); // Hours alarm outb(0xa1, inb(0xa1) & 0xfe); // enable IRQ 8 // enable Status Reg B alarm bit, clear halt clock bit outb_cmos(0x0b, (val8 & 0x7f) | 0x20); ClearCF(iret_addr.flags); // OK break; case 7: // Turn off Alarm // Using a debugger, I notice the following masking/setting // of bits in Status Register B, by setting Reg B to // a few values and getting its value after INT 1A was called. // // try#1 try#2 try#3 try#4 // before 1111 1101 0111 1101 0010 0000 0010 0010 // after 0100 0101 0101 0101 0000 0000 0000 0010 // // Bit4 in try#1 flipped in hardware (forced low) due to bit7=1 // My assumption: RegB = (RegB & 01010111b) val8 = inb_cmos(0x0b); // Get Status Reg B // clear clock-halt bit, disable alarm bit outb_cmos(0x0b, val8 & 0x57); // disable alarm bit regs.u.r8.ah = 0; regs.u.r8.al = val8; // val last written to Reg B ClearCF(iret_addr.flags); // OK break; default: BX_DEBUG_INT1A("int1a: AX=%04x unsupported\n", regs.u.r16.ax); SetCF(iret_addr.flags); // Unsupported } }
/** This is where it all starts ++++++++++++++++++++++++++++++++++++++++++ main is entered as a result of one of SEVERAL events: - Normal startup from press of reset button. - Battery inserted. - After DFU (Device Firmware Upgrade) at manufacturing Quality Assurance or user DFU. - WatchDogTimer expiration and its interrupt handler didn't feed new value. - Some error occured and - Spontenous unknown reset. All subsystems are initalized and any failures are noted and available later in init_status Since some events occur after tag is deployed and no one can see the LEDs the system continues operating. After initalizition (including setting up interrupts) we loop here calling app_sched_execute and sd_app_evt_wait */ int main(void) { // LEDs first (they're easy and cannot fail) drivers/init/init.c init_leds(); RED_LED_ON; if( init_log() ) { init_status |=LOG_FAILED_INIT; } else { NRF_LOG_INFO("LOG initalized \r\n"); } // subsequent initalizations assume log is working // start watchdog now in case program hangs up. // watchdog_default_handler logs error and resets the tag. init_watchdog(NULL); // Battery voltage initialization cannot fail under any reasonable circumstance. battery_voltage_init(); vbat = getBattery(); if( vbat < BATTERY_MIN_V ) { init_status |=BATTERY_FAILED_INIT; } else NRF_LOG_INFO("BATTERY initalized \r\n"); if(init_sensors() == NRF_SUCCESS ) { model_plus = true; NRF_LOG_INFO("Sensors initialized \r\n"); } // Init NFC ASAP in case we're waking from deep sleep via NFC (todo) // outputs ID:DEVICEID ,MAC:DEVICEADDR, SW:REVision set_nfc_callback(app_nfc_callback); if( init_nfc() ) { init_status |= NFC_FAILED_INIT; } else { NRF_LOG_INFO("NFC init \r\n"); } pin_interrupt_init(); if( pin_interrupt_enable(BSP_BUTTON_0, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIO_PIN_PULLUP, button_press_handler) ) { init_status |= BUTTON_FAILED_INIT; } // Initialize BLE Stack. Starts LFCLK required for timer operation. if( init_ble() ) { init_status |= BLE_FAILED_INIT; } bluetooth_configure_advertisement_type(STARTUP_ADVERTISEMENT_TYPE); bluetooth_tx_power_set(BLE_TX_POWER); bluetooth_configure_advertising_interval(ADVERTISING_INTERVAL_STARTUP); advertisement_delay = NRF_FICR->DEVICEID[0]&0x0F; // Priorities 2 and 3 are after SD timing critical events. // 6, 7 after SD non-critical events. // Triggers ADC, so use 3. ble_radio_notification_init(3, NRF_RADIO_NOTIFICATION_DISTANCE_800US, on_radio_evt); // If GATT is enabled BLE init inits peer manager which uses flash. // BLE init should handle insufficient space gracefully (i.e. erase flash and proceed). // Flash must be initialized after softdevice. if(flash_init()) { NRF_LOG_ERROR("Failed to init flash \r\n"); } size_t flash_space_remaining = 0; flash_free_size_get(&flash_space_remaining); NRF_LOG_INFO("Largest continuous space remaining %d bytes\r\n", flash_space_remaining); if(4000 > flash_space_remaining) { NRF_LOG_INFO("Flash space is almost used, running gc\r\n") flash_gc_run(); flash_free_size_get(&flash_space_remaining); NRF_LOG_INFO("Continuous space remaining after gc %d bytes\r\n", flash_space_remaining); } else if (flash_record_get(FDS_FILE_ID, FDS_RECORD_ID, sizeof(tag_mode), &tag_mode)) { NRF_LOG_INFO("Did not find mode in flash, is this first boot? \r\n"); } else { NRF_LOG_INFO("Loaded mode %d from flash\r\n", tag_mode); } if( init_rtc() ) { init_status |= RTC_FAILED_INIT; } else { NRF_LOG_INFO("RTC initialized \r\n"); } // Initialize lis2dh12 and BME280 - TODO: Differentiate LIS2DH12 and BME280 if (model_plus) { lis2dh12_reset(); // Clear memory. // Enable Low-To-Hi rising edge trigger interrupt on nRF52 to detect acceleration events. if (pin_interrupt_enable(INT_ACC2_PIN, NRF_GPIOTE_POLARITY_LOTOHI, NRF_GPIO_PIN_NOPULL, lis2dh12_int2_handler) ) { init_status |= ACC_INT_FAILED_INIT; } nrf_delay_ms(10); // Wait for LIS reboot. // Enable XYZ axes. lis2dh12_enable(); lis2dh12_set_scale(LIS2DH12_SCALE); lis2dh12_set_sample_rate(LIS2DH12_SAMPLERATE_RAWv1); lis2dh12_set_resolution(LIS2DH12_RESOLUTION); lis2dh12_set_activity_interrupt_pin_2(LIS2DH12_ACTIVITY_THRESHOLD); NRF_LOG_INFO("Accelerometer configuration done \r\n"); // oversampling must be set for each used sensor. bme280_set_oversampling_hum (BME280_HUMIDITY_OVERSAMPLING); bme280_set_oversampling_temp (BME280_TEMPERATURE_OVERSAMPLING); bme280_set_oversampling_press(BME280_PRESSURE_OVERSAMPLING); bme280_set_iir(BME280_IIR); bme280_set_interval(BME280_DELAY); bme280_set_mode(BME280_MODE_NORMAL); NRF_LOG_INFO("BME280 configuration done \r\n"); } // Enter stored mode after boot - or default mode if store mode was not found app_sched_event_put (&tag_mode, sizeof(&tag_mode), change_mode); // Initialize repeated timer for sensor read and single-shot timer for button reset if( init_timer(main_timer_id, APP_TIMER_MODE_REPEATED, MAIN_LOOP_INTERVAL_RAW, main_timer_handler) ) { init_status |= TIMER_FAILED_INIT; } if( init_timer(reset_timer_id, APP_TIMER_MODE_SINGLE_SHOT, BUTTON_RESET_TIME, reboot) ) { init_status |= TIMER_FAILED_INIT; } // Init starts timers, stop the reset app_timer_stop(reset_timer_id); // Log errors, add a note to NFC, blink RED to visually indicate the problem if (init_status) { snprintf((char* )NFC_message, NFC_message_length, "Error: %X", init_status); NRF_LOG_WARNING (" -- Initalization error : %X \r\n", init_status); for ( int16_t i=0; i<13; i++) { RED_LED_ON; nrf_delay_ms(500u); RED_LED_OFF; nrf_delay_ms(500u); } } // Turn green led on if model+ with no errors. // Power manage turns led off if (model_plus & !init_status) { GREEN_LED_ON; } // Turn off red led, leave green on to signal model+ without errors RED_LED_OFF; // Wait for sensors to take first sample nrf_delay_ms(1000); // Get first sample from sensors app_sched_event_put (NULL, 0, main_sensor_task); app_sched_execute(); // Start advertising bluetooth_advertising_start(); NRF_LOG_INFO("Advertising started\r\n"); // Enter main loop. Executes tasks scheduled by timers and interrupts. for (;;) { app_sched_execute(); // Sleep until next event. power_manage(); } }
/* Check if MAGIC is valid and print the Multiboot information structure pointed by ADDR. */ void entry (unsigned long magic, unsigned long addr) { multiboot_info_t *mbi; uint8_t* filesystem_address; /* Clear the screen. */ clear(); /* Am I booted by a Multiboot-compliant boot loader? */ if (magic != MULTIBOOT_BOOTLOADER_MAGIC) { printf ("Invalid magic number: 0x%#x\n", (unsigned) magic); return; } /* Set MBI to the address of the Multiboot information structure. */ mbi = (multiboot_info_t *) addr; /* Print out the flags. */ printf ("flags = 0x%#x\n", (unsigned) mbi->flags); /* Are mem_* valid? */ if (CHECK_FLAG (mbi->flags, 0)) printf ("mem_lower = %uKB, mem_upper = %uKB\n", (unsigned) mbi->mem_lower, (unsigned) mbi->mem_upper); /* Is boot_device valid? */ if (CHECK_FLAG (mbi->flags, 1)) printf ("boot_device = 0x%#x\n", (unsigned) mbi->boot_device); /* Is the command line passed? */ if (CHECK_FLAG (mbi->flags, 2)) printf ("cmdline = %s\n", (char *) mbi->cmdline); if (CHECK_FLAG (mbi->flags, 3)) { int mod_count = 0; int i; module_t* mod = (module_t*)mbi->mods_addr; while(mod_count < mbi->mods_count) { filesystem_address = (uint8_t*)mod->mod_start; printf("Module %d loaded at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_start); printf("Module %d ends at address: 0x%#x\n", mod_count, (unsigned int)mod->mod_end); printf("First few bytes of module:\n"); for(i = 0; i<16; i++) { printf("0x%x ", *((char*)(mod->mod_start+i))); } printf("\n"); mod_count++; mod++; } } /* Bits 4 and 5 are mutually exclusive! */ if (CHECK_FLAG (mbi->flags, 4) && CHECK_FLAG (mbi->flags, 5)) { printf ("Both bits 4 and 5 are set.\n"); return; } /* Is the section header table of ELF valid? */ if (CHECK_FLAG (mbi->flags, 5)) { elf_section_header_table_t *elf_sec = &(mbi->elf_sec); printf ("elf_sec: num = %u, size = 0x%#x," " addr = 0x%#x, shndx = 0x%#x\n", (unsigned) elf_sec->num, (unsigned) elf_sec->size, (unsigned) elf_sec->addr, (unsigned) elf_sec->shndx); } /* Are mmap_* valid? */ if (CHECK_FLAG (mbi->flags, 6)) { memory_map_t *mmap; printf ("mmap_addr = 0x%#x, mmap_length = 0x%x\n", (unsigned) mbi->mmap_addr, (unsigned) mbi->mmap_length); for (mmap = (memory_map_t *) mbi->mmap_addr; (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length; mmap = (memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof (mmap->size))) printf (" size = 0x%x, base_addr = 0x%#x%#x\n" " type = 0x%x, length = 0x%#x%#x\n", (unsigned) mmap->size, (unsigned) mmap->base_addr_high, (unsigned) mmap->base_addr_low, (unsigned) mmap->type, (unsigned) mmap->length_high, (unsigned) mmap->length_low); } /* Construct an LDT entry in the GDT */ { seg_desc_t the_ldt_desc; the_ldt_desc.granularity = 0; the_ldt_desc.opsize = 1; the_ldt_desc.reserved = 0; the_ldt_desc.avail = 0; the_ldt_desc.present = 1; the_ldt_desc.dpl = 0x0; the_ldt_desc.sys = 0; the_ldt_desc.type = 0x2; SET_LDT_PARAMS(the_ldt_desc, &ldt, ldt_size); ldt_desc_ptr = the_ldt_desc; lldt(KERNEL_LDT); } /* Construct a TSS entry in the GDT */ { seg_desc_t the_tss_desc; the_tss_desc.granularity = 0; the_tss_desc.opsize = 0; the_tss_desc.reserved = 0; the_tss_desc.avail = 0; the_tss_desc.seg_lim_19_16 = TSS_SIZE & 0x000F0000; the_tss_desc.present = 1; the_tss_desc.dpl = 0x0; the_tss_desc.sys = 0; the_tss_desc.type = 0x9; the_tss_desc.seg_lim_15_00 = TSS_SIZE & 0x0000FFFF; SET_TSS_PARAMS(the_tss_desc, &tss, tss_size); tss_desc_ptr = the_tss_desc; tss.ldt_segment_selector = KERNEL_LDT; tss.ss0 = KERNEL_DS; tss.esp0 = 0x800000; ltr(KERNEL_TSS); } int z = 0; reset_scr(); //set the IDT set_idt(); lidt(idt_desc_ptr); /* Init the PIC */ i8259_init(); /* Initialize devices, memory, filesystem, enable device interrupts on the * PIC, any other initialization stuff... */ //init paging init_paging(); //init filesystem init_filesys(filesystem_address); //init keyboard init_keyboard(); //init the rtc init_rtc(); //init the mouse init_mouse(); //clear the screen reset_scr(); // boot_screen(); for(z = 0; z < 3; z++) { terminal_init(); } node* buffer = screens[0]; reset_buf(buffer); //display the status bar /* Enable interrupts */ sti(); /* Do not enable the following until after you have set up your * IDT correctly otherwise QEMU will triple fault and simple close * without showing you any output */ boot_screen(); //sample mario sound for(z = 0; z < 500000; z++) play_sound(1000); for(z = 0; z < 500000; z++) play_sound(100); for(z = 0; z < 500000; z++) play_sound(900); for(z = 0; z < 50000; z++) play_sound(200); for(z = 0; z < 500000; z++) play_sound(800); for(z = 0; z < 500000; z++) play_sound(300); for(z = 0; z < 500000; z++) play_sound(700); for(z = 0; z < 500000; z++) play_sound(400); for(z = 0; z < 500000; z++) play_sound(600); for(z = 0; z < 500000; z++) play_sound(500); for(z = 0; z < 500000; z++) play_sound(500); for(z = 0; z < 500000; z++) play_sound(1000); for(z = 0; z < 500000; z++) play_sound(400); for(z = 0; z < 500000; z++) play_sound(300); for(z = 0; z < 500000; z++) play_sound(300); for(z = 0; z < 500000; z++) play_sound(200); //boot_screen(); nosound(); reset_scr(); //init PIT for sound, timer init_pit(0, 100); ///////////////////////////////////////////////////////////// // void imperial(); status_bar(); /* Execute the first program (`shell') ... */ uint8_t fname[33] = "shell"; execute(fname); /* We should never get to this point */ //printf("Initial shell halted."); /* Spin (nicely, so we don't chew up cycles) */ asm volatile(".1: hlt; jmp .1;"); }
rtems_device_driver Clock_initialize( rtems_device_major_number major, rtems_device_minor_number minor, void *pargp ) { unsigned timer_counter_init_value; unsigned char clock_lsb, clock_msb; #ifdef BSP_DEBUG printk("Initializing clock driver in Clock_initialize().\n"); #endif #ifdef LOAD_RTC_AT_START /* Initialize clock from on-board real time clock. This breaks the */ /* test code which assumes which assumes the application will do it. */ { rtems_time_of_day now; #ifdef BSP_DEBUG printk("Loading clock from on-board real-time clock.\n"); #endif init_rtc(); if (rtc_read(&now) >= 0) rtems_clock_set(&now); } #endif Clock_driver_ticks = 0; Clock_isrs = Clock_initial_isr_value = rtems_configuration_get_microseconds_per_tick() / 1000; /* ticks per clock_isr */ /* * configure the counter timer ( should be based on microsecs/tick ) * NB. The divisor(Clock_isrs) resolves the is the same number that appears in confdefs.h * when setting the microseconds_per_tick value. */ ClockOff ( &clockIrqData ); timer_counter_init_value = rtems_configuration_get_microseconds_per_tick() / Clock_isrs; clock_lsb = (unsigned char)timer_counter_init_value; clock_msb = timer_counter_init_value >> 8; outport_byte (TIMER_MODE, TIMER_SEL0|TIMER_16BIT|TIMER_RATEGEN); outport_byte (TIMER_CNTR0, clock_lsb ); /* load LSB first */ outport_byte (TIMER_CNTR0, clock_msb ); /* then MSB */ if (!BSP_install_rtems_irq_handler (&clockIrqData)) { printk("Unable to initialize system clock\n"); rtems_fatal_error_occurred(1); } /* * make major/minor avail to others such as shared memory driver */ rtems_clock_major = major; rtems_clock_minor = minor; return RTEMS_SUCCESSFUL; }
/*----------------------------------------------------------------------------*/ void sys_init(void) { #ifdef UART_ENABLE uartInit(); printf("power up \r\n"); #endif #if RTC_ENABLE if (init_rtc()) { work_mode = SYS_RTC; } #else { u8 rtc_reg; rtc_reg=read_rtc_reg(); //printf("RTC reg:%02bx\n",rtc_reg); if (rtc_reg & BIT(6)) ///<RTC是否完全掉电 { #if (MEMORY_STYLE == USE_RTCRAM) reset_rtc_ram(); #endif rtc_reg &= ~(BIT(6)); //清零PDGLG write_rtc_reg(rtc_reg); } } #endif set_brightness_all_on(); P0IE_init(); keyInit(); timer1Init(); timer3Init(); #ifdef USE_USB_SD_DECODE_FUNC #ifndef NO_SD_DECODE_FUNC sd_speed_init(1,100); init_port_sd(); #endif #endif #if SDMMC_CMD_MODE sd_chk_ctl(SET_SD_H_CHK); #endif #ifdef USE_POWER_KEY sys_power_up(); #endif DACCON0 |= 0x05; //打开DSP EA = 1; #ifdef USE_POWER_KEY sys_power_up(); #endif work_mode = read_info(MEM_SYSMODE); #ifdef CUSTOMED_POWER_ON_AT_RADIO_MODE work_mode = SYS_FMREV; #endif if (work_mode == SYS_MP3DECODE_USB){ #ifdef REMOVE_USE_MODE work_mode = SYS_FMREV; Disp_Con(DISP_TUNER); return; #endif Disp_Con(DISP_SCAN_DISK); } else if ((work_mode == SYS_FMREV) #ifdef AM_RADIO_FUNC ||(work_mode == SYS_AMREV) #endif ){ #ifdef AM_RADIO_FUNC if(work_mode == SYS_AMREV){ cur_sw_fm_band = MW_MODE; } else #endif { cur_sw_fm_band = FM_MODE; } Disp_Con(DISP_TUNER); } else if (work_mode == SYS_MCU_CD){ Disp_Con(DISP_SCAN_TOC); } else if (work_mode == SYS_AUX){ Disp_Con(DISP_AUX); } #if defined(USE_BLUE_TOOTH_FUNC) else if (work_mode == SYS_BLUE_TOOTH){ Disp_Con(DISP_BT); } #endif CD_PWR_GPIO_CTRL_INIT(); CD_PWR_GPIO_OFF(); //TUNER_PWR_GPIO_CTRL_INIT(); //TUNER_PWR_GPIO_OFF(); AUX_GPIO_CTRL_INIT(); AUX_PWR_GPIO_OFF(); BT_GPIO_CTRL_INIT(); BT_PWR_GPIO_OFF(); }
void main() { disable_interrupts(GLOBAL); setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_spi2(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_4V096); setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0); // TIMER 0 is being used to service the WTD setup_timer_0(T0_INTERNAL|T0_DIV_256); /* sets the internal clock as source and prescale 256. At 10 Mhz timer0 will increment every 0.4us (Fosc*4) in this setup and overflows every 6.71 seconds. Timer0 defaults to 16-bit if RTCC_8_BIT is not used. Fosc = 10 MHz, Fosc/4 = 2.5 Mhz, div 256 = 0.0001024 s, 65536 increments = 6.71 sec Fosc = 64 MHz, Fosc/4 = 16 Mhz, div 256 = 0.000016 s, 65536 increments = 1.05 sec .. pre-load with 3036 to get exact 1.0000 sec value */ // TIMER 1 is used to extinguish the LED setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); /* sets the internal clock as source and prescale 4. At 10Mhz timer0 will increment every 0.4us in this setup and overflows every 104.8 ms. Timer1 is 16-bit. Fosc = 10 Mhz ... 2.5 MHz / div 4 = 0.00000160 s * 65536 = 0.104858 sec Fosc = 64 Mhz ... 16 MHz / div 4 = 0.00000025 s * 65536 = 0.016384 sec Fosc = 64 Mhz ... 16 MHz / div 8 = 0.00000200 s * 65536 = 0.032768 sec */ setup_stepper_pwm(); // Uses TIMER 2 // TIMER 3 is used for stepper motor intervals setup_timer_3(T3_INTERNAL | T3_DIV_BY_1); // 16 bit timer // TIMER 4 is use for serial time-outs. 8-bit timer. setup_timer_4(T4_DIV_BY_4, 127, 1); setup_comparator(NC_NC_NC_NC); setup_oscillator(OSC_16MHZ | OSC_PLL_ON); // Fosc = 64 MHz ext_int_edge(0, H_TO_L); // Set up PIC18 EXT0 enable_interrupts(INT_EXT); start_heartbeat(); enable_interrupts(GLOBAL); init_hardware(); motor_sleep_rdy(); sleep_mode = FALSE; busy_set(); init_nv_vars(); get_step_vars(); init_aws(); blink(); //Add for TCP/IP interface //delay_ms(15000); signon(); RTC_read(); RTC_last_power(); RTC_reset_HT(); RTC_read(); RTC_read_flags(); if(nv_sd_status>0) fprintf(COM_A,"@SD=%Lu\r\n", nv_sd_status); init_rtc(); // This is the FAT RTC sd_status = init_sdcard(); if(sd_status>0) msg_card_fail(); reset_event(); if(m_error[0] > 0 || m_error[1] > 0) msg_mer(); if (m_comp[0]==FALSE) { e_port[0]=0; write16(ADDR_E1_PORT,0); fprintf(COM_A, "@MC1,%Lu,%Ld\r\n", m_comp[0],e_port[0]); } if (m_comp[1]==FALSE) { m_lin_pos[1]=-1; write16(ADDR_M2_LIN_POS, -1); fprintf(COM_A, "@MC2,%Lu,%Ld\r\n", m_comp[1],m_lin_pos[1]); } if (nv_cmd_mode == FALSE){ for(dt=0; dt<100; ++dt){ blip(); if (nv_cmd_mode == TRUE) { busy_clear(); fputs("@OK!", COM_A); command_prompt(); dt = 100; } } } else command_prompt(); user_quit = auto_sample_ready(); reset_cpu(); }