static int proc_volt_cpu(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { size_t len; int ret; char temp[VOLT_CPU_LEN+4]; int voltage; if (write) { if (*lenp>VOLT_CPU_LEN) return 0; len = read_voltage((char*)buffer,*lenp,temp,&voltage); if (len) { if (set_volt_cpu(voltage*1000)) { memcpy(volt_cpu_str,temp,len); strcpy(&(volt_cpu_str[len]),"mV\n"); } } } else { len = strlen(volt_cpu_str) - *ppos; len = *lenp < len ? *lenp : len; if (len) { ret = copy_to_user(buffer,volt_cpu_str,len); len = ret ? 0 : len; } *lenp = len; *ppos +=len; } return 0; }
void main(void) { configure(); //set up hardware peripherals mode=default_mode; initialize_mode(); pressed=0; new_press=0; switch_count=10; GIE=1; //turn on interrupts while(1){ if(v_sample){ v_sample=0; if(mode==max){ //if battery goes below 3.0V in max mode, force down to medium mode if(read_voltage()>87){ mode=med; initialize_mode(); } } } if(new_press){ new_press=0; mode++; if(mode>max_mode) mode=0; initialize_mode(); } if(mode==off) { shutdown(); //shutdown will lock up here until a press wakes the device } } }
main(int argc,char *argv[]) { int op; op = atoi(argv[3]); printf("op is %d\n",op); spi_modules_init(argv[1]); if(!strcmp(argv[2],"-r")) { } else if(!strcmp(argv[2],"-g")) { printf("the voltage is %d\n",read_voltage()); } else if(!strcmp(argv[2],"-p")) { } else if(!strcmp(argv[2],"-c")) { poweroff_now(); } else if(!strcmp(argv[2],"-l1")) { operation_lm1(op); } else if(!strcmp(argv[2],"-o")) { out_12(op); } else if(!strcmp(argv[2],"-l2")) { operation_lm2(op); } else if(!strcmp(argv[2],"-l3")) { operation_lm2(op); } else if(!strcmp(argv[2],"-b")) { printf("operation_bark\n"); operation_backlight(op); }else if(!strcmp(argv[2],"-k")) { open_key(); }else if(!strcmp(argv[2],"-re")) { restart_system(); } }
void __ISR(_TIMER_5_VECTOR, IPL3AUTO) Timer5Handler(void) //~75hz { Orientation_Update(); INTClearFlag(INT_T5); // Be sure to clear the Timer1 interrupt status getSensorValues(); determineZeroYaw(); computePIDValues(); adjustOCValues(); read_voltage(); //LATFINV = BIT_1; }
static int open_jpsystem_init(void) { int i; int voltage = 0; struct timespec rem = { 0, 5000000}; for (i = 0; i < 4; i++) { voltage = read_voltage(); nanosleep(&rem, &rem); DEBUG_OUT(DEBUG_GZQ, "read voltage = %d\n", voltage); } operation_lm2(1); operation_12v(1); open_key(); return 0; }
int main(int argc, char **argv){ setvbuf (stdout, NULL, _IONBF, 0); // needed to print to the command line while (1){ clearscreen(); printf("Pin 1: %G \n", read_voltage(0x68,1, 18, 1, 1)); // read from adc chip 1, channel 1, 18 bit, pga gain set to 1 and continuous conversion mode printf("Pin 2: %G \n", read_voltage(0x68,2, 16, 1, 1)); // read from adc chip 1, channel 2, 16 bit, pga gain set to 1 and continuous conversion mode printf("Pin 3: %G \n", read_voltage(0x68,3, 14, 1, 1)); // read from adc chip 1, channel 3, 14 bit, pga gain set to 1 and continuous conversion mode printf("Pin 4: %G \n", read_voltage(0x68,4, 12, 1, 1)); // read from adc chip 1, channel 4, 12 bit, pga gain set to 1 and continuous conversion mode printf("Pin 5: %G \n", read_voltage(0x69,1, 12, 1, 1)); // read from adc chip 2, channel 1, 12 bit, pga gain set to 1 and continuous conversion mode printf("Pin 6: %G \n", read_voltage(0x69,2, 12, 1, 1)); // read from adc chip 2, channel 2, 12 bit, pga gain set to 1 and continuous conversion mode printf("Pin 7: %G \n", read_voltage(0x69,3, 12, 1, 1)); // read from adc chip 2, channel 3, 12 bit, pga gain set to 1 and continuous conversion mode printf("Pin 8: %G \n", read_voltage(0x69,4, 12, 1, 1)); // read from adc chip 2, channel 4, 12 bit, pga gain set to 1 and continuous conversion mode usleep(200000); // sleep 0.2 seconds } return (0); }
void ZX_Handler(uint32_t id, uint32_t mask) { ioport_toggle_pin_level(LED1_GPIO); ioport_toggle_pin_level(FP_LED2_GPIO); if (zx_count == 60) { zx_count = 0; epoch++; } zx_count++; read_voltage(); read_current(); read_period(); char* measurement = create_measurement_string(); printf("%s\r\n", measurement); free(measurement); }
// Beep and blink every once in a while if battery is low static void low_battery_check(void) { if (--batt_check_counter == 0) { adc_init(); uint8_t voltage = read_voltage(); adc_disable(); set_extra_url_data(voltage); if (is_battery_low(voltage)) { beep_n_times_and_wait(4); // The battery_dead threshold should be set high enough to avoid dropping // the AVR into BOD when the RF field is on, because the processor may // stop with the field on, which drains the battery rapidly. if (is_battery_dead(voltage)) { // Turn off the NFC module to minimize power consumption module_power_down(); wdt_disable(); sleep_forever(); } } batt_check_counter = SECS2COUNT(CHECK_BATT_EVERY_NSECS); } }
int main(void) { disable_unused_circuits(); _delay_ms(50); #ifdef HAS_CHARGER reset_on_power_change(); #endif /* HAS_CHARGER */ /* Shut off right away if battery is very low. Do not power on NFC module */ adc_init(); (void)read_voltage(); // Read one more time in case first reading is corrupted uint8_t voltage = read_voltage(); adc_disable(); if (is_battery_dead(voltage)) { //beep_n_times_and_wait(4); //sleep_forever(); } lcd_init(); print_idle(); // Initialize and self-test module_power_up(); led_on(); #ifdef WITH_TARGET // We may have come out of target power down mode //(void)pasori_wake_up(); #endif while (!rcs956_reset()) {}; if (!eeprom_has_station_info()) { beep_n_times_and_wait(3); sleep_forever(); } if (is_on_external_power()) { play_song_and_wait(melody_start_up_external, sizeof(melody_start_up_external) / sizeof(struct note)); } else { play_song_and_wait(melody_start_up_battery, sizeof(melody_start_up_battery) / sizeof(struct note)); } led_off(); initiator_set_defaults(); watchdog_start(); for (;;) { watchdog_reset(); // initiator exits after polling times out (false) or URL is pushed (true) if (initiator(PUSH_URL_LABEL)) { lcd_puts(0, "PUSH SLEEP"); play_url_push_success_song_and_wait(); } #ifdef WITH_TARGET uint8_t loop; // Loop here to not skip watchdog timer for (loop = 0; loop < TARGET_MODE_RETRY; loop++) { watchdog_reset(); (void)rcs956_reset(); enum target_res res = target(PUSH_URL_LABEL_ENGLISH); if (res == TGT_COMPLETE) { led_off(); play_url_push_success_song_and_wait(); break; } else if (res == TGT_TIMEOUT || res == TGT_ERROR) { break; } // loop on TGT_RETRY } led_off(); (void)rcs956_reset(); low_battery_check(); #else /* !WITH_TARGET */ // Check battery level while RF field is still on low_battery_check(); sleep_after_timeout(); #endif /* WITH_TARGET */ // Reconfigure Felica module if communication timed out, // e.g. due to temporary disconnect. if (protocol_errno == TIMEOUT) { initiator_set_defaults(); eeprom_increment_usart_fail(); } protocol_errno = SUCCESS; } /* NOT REACHABLE */ return 0; }