void ckps_init_state(void) { _BEGIN_ATOMIC_BLOCK(); ckps_init_state_variables(); CLEARBIT(flags, F_ERROR); MCUCR|=_BV(ISC11); //falling edge for INT1 MCUCR|=_BV(ISC10); //set flag indicating that Hall sensor input is available WRITEBIT(flags, F_HALLSIA, IOCFG_CHECK(IOP_PS)); GICR|= CHECKBIT(flags, F_HALLSIA) ? _BV(INT1) : 0; //INT1 enabled only when Hall sensor input is available //Compare channels do not connected to lines of ports (normal port mode) //(Каналы Compare не подключены к линиям портов (нормальный режим портов)) TCCR1A = 0; //Tune timer 1 (clock = 250kHz) TCCR1B = _BV(CS11)|_BV(CS10); //enable overflow interrupt of timer 0 //(разрешаем прерывание по переполнению таймера 0) TIMSK|= _BV(TOIE0); _END_ATOMIC_BLOCK(); }
void cams_init_state(void) { _BEGIN_ATOMIC_BLOCK(); cams_init_state_variables(); camstate.cam_error = 0; //no errors //set flag indicating that cam sensor input is available WRITEBIT(flags, F_CAMSIA, IOCFG_CHECK(IOP_PS)); #ifdef SECU3T /*SECU-3T*/ //interrupt by rising edge MCUCR|= _BV(ISC11) | _BV(ISC10); MCUCR|= _BV(ISC01) | _BV(ISC00); #ifdef PHASE_SENSOR if (CHECKBIT(flags, F_CAMSIA)) GICR|= _BV(INT0) | _BV(INT1); //INT1 enabled only when cam sensor is utilized in the firmware or input is available else GICR|= _BV(INT0); #else GICR|= _BV(INT0); //это нам нужно для ДНО #endif #endif _END_ATOMIC_BLOCK(); }
void pwrrelay_control(struct ecudata_t* d) { //if this feature is disabled, then do nothing if (!IOCFG_CHECK(IOP_PWRRELAY)) return; //apply power management logic if (pwrs.pwrdown) { //ignition is off //We will wait while temperature is high only if temperature sensor is enabled //and control of electric cooling fan is used. uint8_t temperature_ok = 1; if (d->param.tmp_use && IOCFG_CHECK(IOP_ECF)) { #ifdef COOLINGFAN_PWM if (d->param.vent_pwm) //PWM is available and enabled temperature_ok = (d->sens.temperat <= (d->param.vent_on - TEMPERATURE_MAGNITUDE(2.0))); else //PWM is available, but disabled temperature_ok = (d->sens.temperat <= (d->param.vent_off)); #else //PWM is not available temperature_ok = (d->sens.temperat <= (d->param.vent_off)); #endif //set timeout if (0==pwrs.state) { pwrs.state = 1; s_timer16_set(powerdown_timeout_counter, 6000); //60 sec. } } if ((temperature_ok && eeprom_is_idle() #ifdef SM_CONTROL && choke_is_ready() #endif ) || s_timer16_is_action(powerdown_timeout_counter)) IOCFG_SET(IOP_PWRRELAY, 0); //turn off relay } else pwrs.state = 0; //if IGN input is not available, then we will check board voltage pwrs.pwrdown = IOCFG_CHECK(IOP_IGN) ? (!IOCFG_GET(IOP_IGN)) : (d->sens.voltage < VOLTAGE_MAGNITUDE(4.5)); }
void bc_indication_mode(struct ecudata_t *d) { uint8_t i = 5; if (!IOCFG_CHECK(IOP_BC_INPUT)) return; //normal program execution //Check 5 times do { if (IOCFG_GET(IOP_BC_INPUT)) return; //normal program execution }while(--i); //We are entered to the blink codes indication mode _DISABLE_INTERRUPT(); ce_set_state(CE_STATE_OFF); vent_turnoff(d); //turn off ventilator starter_set_blocking_state(1); //block starter IOCFG_INIT(IOP_FL_PUMP, 0); //turn off fuel pump IOCFG_INIT(IOP_IE, 0); //turn off IE valve solenoid IOCFG_INIT(IOP_FE, 0); //turn off power valve solenoid wdt_reset_timer(); //delay 2 sec. delay_hom(20); //main loop for(;;) { uint16_t errors = 0; disp_start(); delay_hom(7); //read errors eeprom_read(&errors, EEPROM_ECUERRORS_START, sizeof(uint16_t)); for(i = 0; i < 16; ++i) { if (0 == PGM_GET_BYTE(&blink_codes[i])) continue; if (errors & (1 << i)) { disp_code(PGM_GET_BYTE(&blink_codes[i])); delay_hom(20); } } delay_hom(20); wdt_reset_timer(); } }
void choke_control(struct ecudata_t* d) { switch(chks.state) { case 0: //Initialization of choke position if (!IOCFG_CHECK(IOP_PWRRELAY)) //Skip initialization if power management is enabled initial_pos(INIT_POS_DIR, d->param.sm_steps); chks.state = 2; break; case 1: //system is being preparing to power-down initial_pos(INIT_POS_DIR, d->param.sm_steps); chks.state = 2; break; case 2: //wait while choke is being initialized if (!stpmot_is_busy()) //ready? { if (chks.pwdn) chks.state = 3; //ready to power-down else chks.state = 5; //normal working chks.smpos = 0; } break; case 3: //power-down if (pwrrelay_get_state()) { chks.pwdn = 0; chks.state = 5; } break; case 5: //normal working mode if (d->choke_testing) { initial_pos(INIT_POS_DIR, d->param.sm_steps); chks.state = 6; //start testing } else { int16_t tmp_pos = (((int32_t)d->param.sm_steps) * choke_closing_lookup(d)) / 200; int16_t rpm_cor = 0, diff; int16_t pos = tmp_pos + rpm_cor; restrict_value_to(&pos, 0, d->param.sm_steps); diff = pos - chks.smpos; if (!stpmot_is_busy() && diff != 0) { stpmot_dir(diff < 0 ? SM_DIR_CW : SM_DIR_CCW); stpmot_run(abs(diff)); //start stepper motor chks.smpos += diff; } } goto check_pwr; // Testing modes case 6: //initialization of choke if (!stpmot_is_busy()) //ready? { stpmot_dir(SM_DIR_CCW); stpmot_run(d->param.sm_steps); chks.state = 7; } goto check_tst; case 7: if (!stpmot_is_busy()) //ready? { stpmot_dir(SM_DIR_CW); stpmot_run(d->param.sm_steps); chks.state = 6; } goto check_tst; default: check_tst: if (!d->choke_testing) chks.state = 1; //exit choke testing mode check_pwr: if (!pwrrelay_get_state()) { //power-down chks.pwdn = 1; chks.state = 1; } break; } }