STATIC ssize_t swstate_store(struct device *_dev, struct device_attribute *attr, const char *buf, size_t count) { uint32_t val = simple_strtoul(buf, NULL, 16); if (val == 0) { if (g_hiusb_info->cdma_usb_enable == -1) { pr_err("%s: no cdma_usb_enable gpio!\n", __func__); } else { gpio_direction_output(g_hiusb_info->cdma_usb_enable, 0); } switch_off(); msleep(1000); switch_reset(); } else if(val == 1) { if (g_hiusb_info->cdma_usb_enable == -1) { pr_err("%s: no cdma_usb_enable gpio!\n", __func__); } else { gpio_direction_output(g_hiusb_info->cdma_usb_enable, 1); } switch_off(); msleep(1000); switch_cdma(); } else { if (g_hiusb_info->cdma_usb_enable == -1) { pr_err("%s: no cdma_usb_enable gpio!\n", __func__); } else { gpio_direction_output(g_hiusb_info->cdma_usb_enable, 0); } switch_off(); } return count; }
void power_off(AsebaVMState *vm) { unsigned int flags; // Protect against two racing poweroff: // One from the softirq (button) // One from the VM RAISE_IPL(flags,1); behavior_stop(B_ALL); play_sound_block(SOUND_POWEROFF); // Shutdown all peripherals ... switch_off(); // Switch off USB // If we are connected to a PC, disconnect. // If we are NOT connected to a PC but 5V is present // ( == charger ) we need to keep the transciever on if(usb_uart_configured()) USBDeviceDetach(); // In any case, disable the usb interrupt. It's safer _USB1IE = 0; CHARGE_ENABLE_DIR = 1; analog_enter_poweroff_mode(); }
int switch_action(struct config *c) { char *statew; char state; if (0 < login(c)) { return 1; } switch (c->device.actor_command) { case CMD_ON: state = switch_on(c->avm.hostname, session_id, c->device.ain); break; case CMD_OFF: state = switch_off(c->avm.hostname, session_id, c->device.ain); break; case CMD_TOGGLE: state = switch_toggle(c->avm.hostname, session_id, c->device.ain); break; default: break; } if (SWITCH_STATE_ON == state) { statew = "on"; } else { statew = "off"; } utlog(LOG_NOTICE, " %s was turned %s\n", c->device.ain, statew); session_end(c->avm.hostname, session_id); session_id = NULL; return 0; }
// 9 ->Light2 //10 LASER //11 LED //12 PWM light 1 // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. WDT_Stop(); digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(light1, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(light2, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(laser, LOW); // turn the LED on (HIGH is the voltage level) pinMode(led, OUTPUT); pinMode(led2, OUTPUT); pinMode(laser, OUTPUT); pinMode(btn, INPUT); pinMode(batadc, INPUT); //ADC prescaler sbi(ADCSRA,ADPS2); sbi(ADCSRA,ADPS1); sbi(ADCSRA,ADPS0); // digitalWrite(light1, LOW); // turn the LED on (HIGH is the voltage level) if(dosystemtest&&!digitalRead(btn)) systemtest(); dosystemtest=0; switch_off(); sleepcounter=0; check_bat(); // attachInterrupt(0, int0f, FALLING); //state=0; //int0(); //WDT_Init(); // toggle_led(led2,&ledstate2); }
void morse_glyph(char c) { switch(c) { case '.': switch_on(dot_pause); break; case '-': switch_on(dash_pause); break; default: raspi_timer_wait(word_pause); break; } switch_off(gap_pause); }
/* Spoof Limit Checking: There is a known issue with the Vsense values, but we should at least get the framework set up for limit checking on arbitrary values. The power board should have upper and lower limits for vsense and csense data, and turn off components if their voltage/current is too high. ONLY CHECKS BATTERY 1 VOLTAGE LINE RIGHT NOW. */ void limit_check( void ) { unsigned char sw; SVIT_t *component; // turn off all switches and send ack_command w/ value of SAFE_MODE if (percent < SAFE_MODE) { safe_mode = 1; for (sw = 0; sw < sizeof(components); sw++) { component = &svit[components[sw]]; switch_off( component->switch_num ); component->switch_state = SW_OFF; } component = &svit[TORQUER_1]; component->switch_state = SW_OFF; component = &svit[TORQUER_2]; component->switch_state = SW_OFF; component = &svit[TORQUER_3]; component->switch_state = SW_OFF; torquer_off(TORQUER_1); torquer_off(TORQUER_2); torquer_off(TORQUER_3); // Only transmit once if (!transmit_safe && !been_to_safe) { transmit_packet( 0, VCP_ACK, SAFE_MODE); transmit_safe = 1; } else {} been_to_safe = 1; transmit_safe = 1; } else if (percent > SHUNT_MODE) { safe_mode = 0; // turn on the maestro and send ack_command w/ value of SHUNT_MODE component = &svit[MAESTRO]; switch_on( component->switch_num ); component->switch_state = SW_ON; // Only transmit once if (!transmit_shunt && !been_to_shunt) { transmit_packet( 0, VCP_ACK, SHUNT_MODE); } else {} been_to_shunt = 1; transmit_shunt = 1; } else {} // To avoid annoying compile warning }
void Engine_State::change(double RPM) { const double rpmOff = 50; // 50 const double rpmIdle = 2000; // 150 if ( RPM < rpmOff ) { switch_off(); set_to_idle(); } else if ( RPM < rpmIdle ) { switch_on(); set_to_idle(); } else { switch_on(); unset_idle(); } }
/** * Kill the second X server if any, turn card off if requested. */ void stop_secondary() { char driver[BUFFER_SIZE]; // kill X if it is running if (bb_is_running(bb_status.x_pid)) { bb_log(LOG_INFO, "Stopping X server\n"); bb_stop_wait(bb_status.x_pid); } if (bb_config.pm_method == PM_DISABLED && bb_status.runmode != BB_RUN_EXIT) { /* do not disable the card if PM is disabled unless exiting */ return; } //if card is on and can be switched, switch it off if (switcher) { if (switcher->need_driver_unloaded) { /* do not unload the drivers nor disable the card if the card is not on */ if (switcher->status() != SWITCH_ON) { return; } if (pci_config_save(pci_bus_id_discrete, &pci_config_state_discrete)) { bb_log(LOG_WARNING, "Could not save PCI configuration space: %s\n", strerror(errno)); } /* unload the driver loaded by the graphica card */ if (pci_get_driver(driver, pci_bus_id_discrete, sizeof driver)) { module_unload(driver); } //only turn card off if no drivers are loaded if (pci_get_driver(NULL, pci_bus_id_discrete, 0)) { bb_log(LOG_DEBUG, "Drivers are still loaded, unable to disable card\n"); return; } } if (switch_off() != SWITCH_OFF) { bb_log(LOG_WARNING, "Unable to disable discrete card."); } } }//stop_secondary
// Start Of Program - this is where we setup everything before getting into the main loop void main(void) { // Oscillator setup OSCCON = 0b11100000; // device enters idle on Sleep(), 8Mhz Clock, OSCTUNE = 0b00000000; // Internal oscillator low freq comes from 31Khz clock from LFINTOSC, PLL disabled // Analog / Digital pins setup ANSEL = 0b00000000; // disable all analog inputs (make them all digital) must do this! ANSELH = 0b00000000; // disable all analog inputs (make them all digital) must do this! // Tristate setup TRISA = 0b00000011; TRISB = 0b11111110; TRISC = 0b00000000; TRISD = 0b00000000; TRISE = 0b00000000; // configure TIMER2: // prescaler 16, period register for 1ms, timer stopped T2CON = 0b00000010; TMR2 = 0; PR2 = _XTAL_FREQ / 1000 / 16 / 4; // initialize subsystems btn_init(); init_all(); // disable INT1, config for raising endge INT1IE = 0; INTEDG1 = 1; // enable interrupts TMR2IE = 1; // TIMER2 interrupt PEIE = 1; // peripheral interrupt GIE = 1; // global interrupt enable // start TIMER2 TMR2ON = 1; // main loop while (true) { off_flag = false; // go to idle and wait for timer Sleep(); // read button inputs btn_update(); // check for commands check_select(); check_off(); check_idle(); // execute mode task switch (mode) { case modeSelect: mode_select(); break; case modeSparkle: sparkle_leds(); break; case modeShiftReg: shiftreg_task(); break; case modeLightTest: led_group(LED_ALL, true); break; case modePOV: povmsg_task(); break; case modeBinDice: case modeDecDice: dice_task(mode == modeDecDice); break; case modeGame: game_task(); break; case mode4BitLogic: logic_4bit_task(); break; default: logic_task(); flipflop_task(); counter_task(mode == modeGrayCnt); } if (off_flag) { switch_off(); } } }
/****************************************************************************** * Function name : main * Description : Main testing loop * Input param : None * Return : None * See also : None *******************************************************************************/ void main (void) { /* peripheral initialization */ #ifdef FAST_I2C_MODE CLK->CKDIVR = 0x00; // sys clock / 1 #else CLK->CKDIVR = 0x01; // sys clock / 2 #endif // Set GPIO for LED uses GPIOH->DDR |= 0x0F; GPIOH->CR1 |= 0x0F; // initialize timer 4 mandatory for timout and tick measurement TIM4_Init(); // Initialize I2C for communication I2C_Init(); // initialization of dummy field for test purpose memcpy(Dummy, DUMMY_INIT, MAX_DUMMY); #ifndef _COSMIC_ err_save= 0; TIM4_tout= loop_count= 0; #endif // Enable all interrupts enableInterrupts(); /* main test loop */ while(1) { // switch on LED1 at the beginning of test switch_on(LED1); // write 1 data bytes with offset 8 from Dummy filed to slave memory set_tout_ms(10); I2C_WriteRegister(8, 1, &Dummy[8]); // read 1 byte with offset 8 back from the image at slave memory if(tout()) { set_tout_ms(10); I2C_ReadRegister(8, 1, &Dummy[8]); } // write 6 bytes with offset 2 from Dummy filed to slave memory if(tout()) { set_tout_ms(10); I2C_WriteRegister(2, 6, &Dummy[2]); } // read 6 bytes with offset 2 back from the image at slave memory if(tout()) { set_tout_ms(10); I2C_ReadRegister(2, 6, &Dummy[2]); } // write 1 byte with offset 9 from Dummy filed to slave memory if(tout()) { set_tout_ms(10); I2C_WriteRegister(9, 1, &Dummy[9]); } // read 1 byte with offset 9 back from the image at slave memory if(tout()) { set_tout_ms(10); I2C_ReadRegister(9, 1, &Dummy[9]); } // write 2 bytes with offset 0 from Dummy filed to slave memory if(tout()) { set_tout_ms(10); I2C_WriteRegister(0, 2, &Dummy[0]); } // read 2 bytes with offset 0 back from the image at slave memory if(tout()) { set_tout_ms(10); I2C_ReadRegister(0, 2, &Dummy[0]); } // if a timout error occures switch on LED2 if(!tout()) switch_on(LED2); // switch off LED1 at the end of test switch_off(LED1); // check if dummy field is not corrupted => switch on LED 4 if test not successful if(memcmp(Dummy, DUMMY_INIT, MAX_DUMMY) != 0) switch_on(LED4); delay(1); } }
void initialize( void ) { // pin initialization DDRA = 0b11111111; PORTA = 0b00000111; DDRB = 0b11111111; PORTB = 0b11100000; DDRC = 0b11111111; PORTC = 0b11111111; DDRD = 0b11111011; PORTD = 0b11110000; DDRE = 0b11111110; PORTE = 0b00000000; DDRF = 0b11110000; PORTF = 0b00000000; DDRG = 0b00011111; PORTG = 0b00000100; //--------------------------------------------------------------------- // timer 0 //--------------------------------------------------------------------- // used for transmitting telemetry packet at 1 Hz // // mode = clear on match // prescalar = 1024 // compare value = 124 // compare match interrupt freq = (14.7456 MHz / 1024 / 100) = 144 Hz // use timer0_counter to get 144 / 144 = 1 Hz // enable clear on match interrupt TIMSK = ( 1 << OCIE0 ); OCR0 = 71; // enable clear on match mode, set prescalar to 1024 TCCR0 = ( 1 << WGM01 ) | ( 1 << CS02 ) | ( 1 << CS01 ) | ( 1 << CS00 ); timer0_counter[0] = 99; timer0_counter[1] = 199; //--------------------------------------------------------------------- // timer 1 //--------------------------------------------------------------------- /* used for waiting up to 24 hours if the power board does not receive a command Ex: mode = clear on match prescalar = 1024 Timer counts up to OCR1B = 28800 and enters ISR(TIMER1_COMPB_vect) clock frequency after prescaling = (14.7456 MHz / 1024) = 14.4 kHz period of interrupts = 28800 / 14400 Hz = 2 s/interrupt use timer1_counter to get a total period of 2*65535 = s (24 hours is 86400 seconds) */ // Enable clear on match interrupt for the 16 bit timer/counter 1, register A OCR1A = 28800; //28800 corresponds to 2 seconds // Enable clear on match mode, set prescalar to 1024. // CS[2:0] = 101 (1024 prescalar) // WGM[3:0] = 0100 (Clear Timer on Compare (CTC) when timer matches OCR1A) TCCR1B = ( 1 << WGM12 ) | ( 1 << CS12 ) | ( 1 << CS10 ); // Explicit Default Defs // TCCR1A |= 0; // TCNT1 = 0; timer1_counter[0] = CYCLE_COUNTER; //CYCLE_COUNTER = 900 for 2 seconds interrupt handler = 1800 secs (30 minutes) //--------------------------------------------------------------------- // End of timer 1 Setup //--------------------------------------------------------------------- // communication uart_init(); // for use in debugging // stdout = stdin = stderr = &uart_str; tel_packet_size[0] = 0; tel_packet_size[1] = 0; tel_packet_index[0] = 0; tel_packet_index[1] = 0; uart_vcp_buff[0] = (vcp_ptrbuffer*)malloc( sizeof( vcp_ptrbuffer ) ); uart_vcp_buff[1] = (vcp_ptrbuffer*)malloc( sizeof( vcp_ptrbuffer ) ); vcpptr_init( uart_vcp_buff[0], uart_message_buff[0], BUFFER_SIZE ); vcpptr_init( uart_vcp_buff[1], uart_message_buff[1], BUFFER_SIZE ); rx_flag[0] = 0; rx_flag[1] = 0; // svit initialize_svit(); // rev up those interrupts sei(); //ADC conversions adc_flag = 1; adc_component = 0; adc_sensor_type = ADC_INIT;//get default case on first interation as to not enter switch ADC_high = 0; V_upper_val_change = 0; I_upper_val_change = 0; //--------------------------------------------------------------------- // SOC Initializations //--------------------------------------------------------------------- // and shunt and safe transmit flags safe_mode = 0; transmit_safe = 0; transmit_shunt = 0; been_to_safe = 0; been_to_shunt = 0; assign_charge_fit(); assign_discharge_fit(); // First get battery voltage so that the SoC can // accurately determine whether batteries are charging or discharging batt1_voltage = 0xff; batt2_voltage = 0xff; charging = 0xff; chargeforward = 0; chargebackward = 0; debug = 0; debug2 = 0; percent = 0; soc = 0; high = 0; low = 0; limit_check_overriden = 0; // Initially limit checking is NOT OVERRIDEN //--------------------------------------------------------------------- // END SOC Initializations //--------------------------------------------------------------------- //--------------------------------------------------------------------- // Timer Initializations //--------------------------------------------------------------------- rad_torq_flag = 1; SVIT_t *component; // Initialize Radios to be OFF component = &svit[components[RADIO_1]]; switch_off( component->switch_num ); component = &svit[components[RADIO_2]]; switch_off( component->switch_num ); component = &svit[TORQUER_1]; // Initialize Torque Coils to be OFF component->switch_state = SW_OFF; component = &svit[TORQUER_2]; component->switch_state = SW_OFF; component = &svit[TORQUER_3]; component->switch_state = SW_OFF; torquer_off(TORQUER_1); torquer_off(TORQUER_2); torquer_off(TORQUER_3); //--------------------------------------------------------------------- // END Timer Initializations //--------------------------------------------------------------------- }
inline void receive_message( uint8_t uart, uint8_t* message, uint8_t message_size )//was inline { uint8_t command = message[VCP_COMMAND_FIELD]; uint8_t payload = message[VCP_PAYLOAD_FIELD]; switch(command) { case VCP_COMPONENT_ON: // Reset CDH IB Heartbeat timer if ( svit[payload].switch_num != SW_NULL ) { switch_on( svit[payload].switch_num ); svit[payload].switch_state = 1; } transmit_packet( uart, VCP_ACK, command ); break; case VCP_COMPONENT_OFF: if ( svit[payload].switch_num != SW_NULL ) { switch_off( svit[payload].switch_num ); svit[payload].switch_state = 0; } transmit_packet( uart, VCP_ACK, command ); break; case VCP_POWER_CYCLE: if ( svit[payload].switch_num != SW_NULL ) { switch_off( svit[payload].switch_num ); svit[payload].switch_state = 0; } _delay_us(1); if ( svit[payload].switch_num != SW_NULL ) { switch_on( svit[payload].switch_num ); svit[payload].switch_state = 1; } transmit_packet( uart, VCP_ACK, command ); break; case VCP_TORQ_CTRL: transmit_packet( uart, VCP_ACK, command ); break; case VCP_GET_TELEMETRY: transmit_packet( uart, VCP_POWER_TELEMETRY, 0); break; case VCP_FORCE_ON: if ( svit[payload].switch_num != SW_NULL ) { switch_on( svit[payload].switch_num ); svit[payload].switch_state = 1; svit[payload].force_on = 1; } transmit_packet( uart, VCP_ACK, command ); break; case VCP_CRIT_V_CHANGE: if ( svit[payload].switch_num != SW_NULL ) { svit[payload].V_upper_limit = message[VCP_PAYLOAD_FIELD + 1]; V_upper_val_change= message[VCP_PAYLOAD_FIELD + 1]; } //transmit_packet( uart, VCP_ACK, 0); break; case VCP_CRIT_I_CHANGE: if ( svit[payload].switch_num != SW_NULL ) { svit[payload].I_upper_limit = message[VCP_PAYLOAD_FIELD + 1]; I_upper_val_change= message[VCP_PAYLOAD_FIELD + 1]; } //transmit_packet( uart, VCP_ACK, 0); break; default: transmit_packet( uart, VCP_INVALID_COMMAND, 0 ); break; } }