////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// // // UARTInit - Initialize serial port // // This routine initializes the UART to BAUDRATE/7,1,n. Called from init. Also // enables the Rx interrupts, disables the Tx interrupt and clears the FIFOs. // // Inputs: None. // // Outputs: None. // void UARTInit(void) { memset(&UART,0,sizeof(UART)); _CLR_BIT(PRR,PRUSART0); // Power up the UART // // Set the baud rate // #include <util/setbaud.h> UBRR0H = UBRRH_VALUE; UBRR0L = UBRRL_VALUE; #if USE_2X _SET_BIT(UCSR0A,U2X0); #else _CLR_BIT(UCSR0A,U2X0); #endif // // Enable port I/O and Rx interrupt // UCSR0C = (1<<UCSZ00) | (1<<UCSZ01); // 8,n,1 UCSR0B = (1<< RXEN0) | (1<< TXEN0) | (1<<RXCIE0); // // Enable internal pull-up resistor on pin D0 (RX), to supress line noise // _CLR_BIT( DDRD,PIND0); _SET_BIT(PORTD,PIND0); }
int _PUMP::Poll(void) { int e=0; if(timeout==INT_MAX) DAC_SetChannel1Data(DAC_Align_12b_R,0); else { DAC_SetChannel1Data(DAC_Align_12b_R,__ramp(Th2o(),ftl*100,fth*100,fpl*0xfff/100,fph*0xfff/100)); if(tacho && pressure && current && __time__ > timeout) { if(abs(tacho->Eval(Rpm()) - Tau()) > Tau()/10) _SET_BIT(e,pumpTacho); if(abs(pressure->Eval(Rpm()) - adf.cooler) > adf.cooler/10) _SET_BIT(e,pumpPressure); if(abs(current->Eval(Rpm()) - adf.Ipump) > adf.Ipump/10) _SET_BIT(e,pumpCurrent); } if(__time__ % (5*(Tau()/100)) == 0) _BLUE2(20); } return e; }
////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// // // InputsInit - Initialize inputs // // Inputs: None. // // Outputs: None. // void InputsInit(void) { _SET_BIT(PCMSK_I1,PCINT_I1); _SET_BIT(PCMSK_I2,PCINT_I2); _CLR_BIT( _DDR(INPUT_I1_PORT),INPUT_I1_BIT); // Inputs are inputs _SET_BIT(_PORT(INPUT_I1_PORT),INPUT_I1_BIT); // With internal pullup _CLR_BIT( _DDR(INPUT_I2_PORT),INPUT_I2_BIT); // Inputs are inputs _SET_BIT(_PORT(INPUT_I2_PORT),INPUT_I2_BIT); // With internal pullup Input1Changed = false; Input2Changed = false; Input1On = INPUT1_PIN; Input2On = INPUT2_PIN; Input1Debounce = 0; Input2Debounce = 0; }
////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// // // GetUARTByte - Get one char from the serial port // // Get a char from the serial port. The interrupt handler already received the // character for us, so this just pulls the char out of the receive FIFO. // // Inputs: None // // Outputs: ASCII char, if one was available // NUL (binary value = 0) if no chars available // char GetUARTByte(void) { char OutChar = 0; _CLR_BIT(UCSR0B,RXCIE0); // Disable UART interrupts if( UART.Rx_FIFO_In != UART.Rx_FIFO_Out ) { OutChar = UART.Rx_FIFO[UART.Rx_FIFO_Out]; UART.Rx_FIFO_Out = (UART.Rx_FIFO_Out+1) & IFIFO_WRAP; } _SET_BIT(UCSR0B,RXCIE0); // Enable UART interrupts return(OutChar); }
////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// // // TIMERx_CAPT_vect - Input capture causes an interrupt // // Inputs: None. (ISR) // // Outputs: None. // ISR(TIMER1_CAPT_vect,ISR_NOBLOCK) { ////////////////////////////////////////////////////////////////////////////////////// // // Save CPU time by only measuring 1-in-10 cycles // if( --PWM.SkipCount > 0 ) return; ////////////////////////////////////////////////////////////////////////////////////// // // FALLING EDGE // // Note the ICP of the falling edge. Set next round to interrupt on rising edge. // if( _BIT_OFF(TCCRBx,RISING_EDGE) ) { PWM.CaptLow = ICRx; PWM.FreqEnd = false; _SET_BIT(TCCRBx,RISING_EDGE); return; } ////////////////////////////////////////////////////////////////////////////////////// // // 1ST RISING EDGE // // Note the ICP of the rising edge. Set next round to interrupt on rising edge. // if( !PWM.FreqEnd ) { PWM.CaptHigh = ICRx; PWM.FreqEnd = true; return; } ////////////////////////////////////////////////////////////////////////////////////// // // 2ND RISING EDGE // // Total the PWM and FREQ counts // uint16_t FreqCount = ICRx - PWM.CaptHigh; PWM.FreqTotal += FreqCount; PWM.PWMTotal += FreqCount - (PWM.CaptHigh - PWM.CaptLow); PWM.FreqCycles++; PWM.SkipCount = SKIP_MAX; _CLR_BIT(TCCRBx,RISING_EDGE); }
////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// // // PutUARTByte - Send one char out the serial port // // Send a char out the serial port. We stuff the char into the FIFO and enable // interrupts - at some point the interrupt handler will get serviced and // send the char out for us. // // Inputs: Byte to send // // Outputs: TRUE if char was sent OK, // FALSE if buffer full // bool PutUARTByte(char OutChar) { uint8_t NewIn; bool Success = false; _CLR_BIT(UCSR0B,UDRIE0); // Disable UART interrupts // // If there's room in the buffer, add the new char // NewIn = (UART.Tx_FIFO_In+1) & OFIFO_WRAP; if( NewIn != UART.Tx_FIFO_Out ) { UART.Tx_FIFO[UART.Tx_FIFO_In] = OutChar; UART.Tx_FIFO_In = NewIn; Success = true; } _SET_BIT(UCSR0B,UDRIE0); // Enable UART interrupts return(Success); }
int F950041(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg) { int ret; T_t_pif_device tDevice; T_t_cif_shop_pos tShopPos; T_t_cif_shop tShop; T_t_tif_meslist tMsg; T_t_pif_feetype tFeeType; int rate = 0; int retries = 0; int msgid; unsigned char buf[32] = ""; char cardlist[100] = ""; int rows = 0; int i,j; memset(&tDevice,0,sizeof tDevice); memset(&tFeeType,0,sizeof tFeeType); ST_CPACK aPack; ST_PACK *out_pack = &(aPack.pack); memset(&aPack,0,sizeof aPack); ResetNormalCPack(&aPack,0,1); SetCol(handle,0); SetCol(handle,F_VSVARSTR0,F_VSMESS,0); if(rPack->lcert_code < 1) { *pRetCode = E_DEVICE_NOT_EXIST; } else if((ret = DB_t_pif_device_read_by_device_id(rPack->lcert_code,&tDevice))) { if(DB_NOTFOUND == ret) *pRetCode = E_DB_DEVICE_N; else *pRetCode = E_DB_DEVICE_R; } else if(tDevice.state_id == DEVISTAT_LOGOUT) { *pRetCode = E_DEVICE_NOT_EXIST; } // 如果是 39 的充值机 else if(strcmp(tDevice.devtype,"0201") == 0 && tDevice.phytype == 1000) { des2src(rPack->sdate0,tDevice.devphy999_id); ret = F930006(handle,iRequest,rPack,pRetCode,szMsg); if(ret) { goto LRet; } return 0; } else if((ret = DB_t_cif_shop_pos_open_select_by_c0_and_device_id(rPack->lcert_code))) { *pRetCode = E_DB_SHOP_POS_R; } else { while(1) { memset(&tShopPos,0,sizeof tShopPos); memset(&tShop,0,sizeof tShop); if((ret = DB_t_cif_shop_pos_fetch_select_by_c0(&tShopPos))) { if(ret == DB_NOTFOUND) { writelog(LOG_DEBUG,"shop doesn't find [%d]!"); *pRetCode = 0; } else *pRetCode = E_DB_SHOP_POS_R; break; } writelog(LOG_DEBUG,"find shop [%d]",tShopPos.shop_id); if((ret = DB_t_cif_shop_read_by_shop_id(tShopPos.shop_id,&tShop))) { *pRetCode = ret; break; } if('1' == tShop.is_leaf[0] && '1' == tShop.is_getfee[0] && amtcmp(tShop.ratio,0.00)>0 ) { writelog(LOG_DEBUG,"shop rate [%.02f]",tShop.ratio); int newrate = D2I(tShop.ratio * 100); if(newrate > rate) rate = newrate; } } } if(*pRetCode) return -1; ret = DB_t_pif_feetype_open_select_by_cur1(); if(ret) { if(DB_NOTFOUND == ret) *pRetCode = E_DB_FEETYPE_N; else *pRetCode = E_DB_FEETYPE_R; return -1; } memset(buf,0,sizeof buf); while(1) { memset(&tFeeType,0,sizeof &tFeeType); ret = DB_t_pif_feetype_fetch_select_by_cur1(&tFeeType); if(ret) { if(DB_NOTFOUND == ret) { if(rows > 0) break; *pRetCode = E_DB_FEETYPE_N; } else *pRetCode = E_DB_FEETYPE_R; } rows++; if(tFeeType.fee_type < 0 || tFeeType.fee_type > 255 || tFeeType.is_outfee[0] != '1' ) continue; writelog(LOG_DEBUG,"fee[%s][%d][%c]",tFeeType.fee_name,tFeeType.fee_type ,tFeeType.is_outfee[0]); _SET_BIT(buf,tFeeType.fee_type-1); } //writelog(LOG_DEBUG,"bit length %d",BIT_LENGTH); memset(&tMsg,0,sizeof tMsg); tMsg.funid = 950041; tMsg.level = 1; tMsg.devid = tDevice.device_id; for(i = 0,j = 0;i < sizeof buf;++i) { j += sprintf(cardlist+j,"%02x",buf[i]); } AddXmlItemInt(tMsg.incontent,XML_KEY_FEE,rate); AddXmlItemStr(tMsg.incontent,XML_KEY_CARDRIGHTTYPE,cardlist); tMsg.max_send_cnt = 5; if((ret = AddMsgLst(&tMsg))) { *pRetCode = ret; } else { if(db_commit()) { *pRetCode = E_DB_COMMIT; return -1; } retries = 10; msgid = tMsg.mesid; for(retries=0;(retries<10)&&(tMsg.ecode!=0);retries++) { memset(&tMsg,0,sizeof tMsg); ret = DB_t_tif_meslist_read_by_mesid(msgid,&tMsg); if(ret) { strcpy(out_pack->vsvarstr0,"读取指令失败"); *pRetCode=E_DB_MESLIST_R; strcpy(szMsg,"读取指令失败"); return -1; } // 等待1秒 sleep(1); } switch(tMsg.ecode) { case 0: //成功 des2src(out_pack->vsmess,"成功"); strcpy(szMsg,"成功"); break; case 9999: //交易未处理 des2src(out_pack->vsmess,"前置机无应答"); strcpy(szMsg,"前置机无应答"); goto LRet; default: //交易已经处理,但结果是失败 des2src(out_pack->vsmess,tMsg.emsg); goto LRet; } PutRow(handle,out_pack,pRetCode,szMsg); AnswerData(handle,*pRetCode,szMsg); return 0; } LRet: return -1; }
// // BuzzerSet - Turn on buzzer // // Inputs: TRUE to set buzzer ON // FALSE otherwise // // Outputs: None. // void BuzzerSet(bool Set) { if( Set ) { _SET_BIT(_PORT(BUZZER_PORT),BUZZER_BIT); } else { _CLR_BIT(_PORT(BUZZER_PORT),BUZZER_BIT); } }
////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// // // BuzzerInit - Initialize buzzer // // Inputs: None. // // Outputs: None. // void BuzzerInit(void) { _SET_BIT( _DDR(BUZZER_PORT),BUZZER_BIT); // Set as output _CLR_BIT(_PORT(BUZZER_PORT),BUZZER_BIT); // Set low for now }
/*********************************************************************************** Переривання від System peripherals ***********************************************************************************/ void Sys_IrqHandler(void) { if (AT91C_BASE_PITC->PITC_PISR & AT91C_PITC_PITS) { AT91C_BASE_PITC->PITC_PIVR; //Робота з клавіатурою handle_kbd(); unsigned int threshold_timeout_LCD = ((unsigned int)eeprom_bs_settings_tbl.chSleepTmVal)*60*100; if (hldScanCode.UNFKeyField.arUl[0] || hldScanCode.UNFKeyField.arUl[1]) { timeout_LCD = 0; } else { if (timeout_LCD < threshold_timeout_LCD) timeout_LCD++; } if ((state_command_power_LCD & ((unsigned int)(1 << 31))) == 0) { //LCD vymknutyj if (timeout_LCD == 0) state_command_power_LCD |= (1 << 0); //Komanda na vvimknennja LCD } else { //LCD vimknutyj if ( (timeout_LCD >= threshold_timeout_LCD) && (timeout_LCD > 0) ) { state_command_power_LCD |= (1 << 1); //Komanda na vymknennja LCD } } /***********************************************************/ //Лічильник ресурсу + періодичні операції раз у секунду /***********************************************************/ static unsigned int number_ticks_for_OF_bit_reset; if (etap_reset_of_bit == ETAP_CLEAR_OF_ST_START_WAITING_5S) { etap_reset_of_bit = ETAP_CLEAR_OF_ST_WAITING_5S; number_ticks_for_OF_bit_reset = 0; } else if (etap_reset_of_bit == ETAP_CLEAR_OF_ST_WAITING_5S) { number_ticks_for_OF_bit_reset++; if (number_ticks_for_OF_bit_reset > 500) etap_reset_of_bit = ETAP_CLEAR_OF_WRITE_OF_0; } if (++tick_for_1s >= 100) { //Запусаємо раз у секунду самоконтроль важливих змінних periodical_tasks_TEST_SETTINGS_PRT = periodical_tasks_TEST_SETTINGS_BS = periodical_tasks_TEST_USTUVANNJA = periodical_tasks_TEST_TRG_FUNC = periodical_tasks_TEST_INFO_REJESTRATOR_AR = periodical_tasks_TEST_INFO_REJESTRATOR_DR = periodical_tasks_TEST_INFO_REJESTRATOR_PR_ERR = true; /*Зафікосваний період в 1(с) = 100 х 10(мс)*/ tick_for_1s = 0; //Vystavljaemo praporec pro peremaljovuvannja paneli statusu redraw_status_bar = 1; //Komanda chytannja danykh z RTC _SET_BIT(control_spi1_taskes, TASK_START_READ_RTC_BIT); //Ресурс resurs_global = resurs_temp; resurs_temp = 0; if (restart_resurs_count != 0) { restart_resurs_count = 0; resurs_global_min = 0xffffffff; resurs_global_max = 0; } if (resurs_global < resurs_global_min) resurs_global_min = resurs_global; if (resurs_global > resurs_global_max) resurs_global_max = resurs_global; if ( ((Clock_FrameWin != WM_UNATTACHED) && (current_ekran.edition == 0)) || (TM_FrameWin != WM_UNATTACHED) || (Diagnostics_FrameWin != WM_UNATTACHED) || (Resurs_FrameWin != WM_UNATTACHED) ) { command_menu |= (1 << REFRESH_ACTIVE_PANELS); } //Вызов ф-ции обновления значений на панэли измерений if (!gui_update && ((state_command_power_LCD & ( (unsigned int) ((1 << 31) | (1 << 1)) )) == (unsigned int) (1 << 31) ) ) { gui_tmr_routines(); } } if (++tick_for_2s >= 200) { /*Зафікосваний період в 2(с) = 200 х 10(мс)*/ tick_for_2s = 0; } if (++tick_for_3s >= 300) { /*Зафікосваний період в 3(с) = 300 х 10(мс)*/ tick_for_3s = 0; } Ici10msRing(); //Зафіксовано період в 10мс period_10ms = true; } }
int _SPRAY::Poll() { static int acc=0,accin=0,accout=0; int err=0; if(AirLevel) { Bottle_P += (Bottle_ref - (int)buffer.bottle)/16; if(Bottle_P < -_P_THRESHOLD) { Bottle_P=0; acc=adf.bottle; accout = offset.bottle-adf.bottle; BottleIn->Off(); BottleOut->Off(150,750); } if(Bottle_P > _P_THRESHOLD) { Bottle_P=0; acc=adf.bottle; accin = adf.compressor-adf.bottle; BottleIn->On(50,750); BottleOut->On(); } } else { BottleIn->Off(); BottleOut->Off(); } Air_ref = offset.air + AirLevel*gain.air/10; Bottle_ref = offset.bottle + AirLevel*gain.bottle*(100+4*WaterLevel)/100/10; if(!BottleIn->Busy() && !BottleOut->Busy()) { if(accin) { // printf("\r\n in %d,%d",adf.bottle-acc,adf.bottle); WaterLeft += (adf.bottle-acc-WaterLeft)/4; acc=accin=0; } if(accout) { // printf("\r\n out %d,%d",adf.bottle-acc,adf.bottle); acc=accout=0; } } if(WaterLevel && mode.On) Water->On(); else Water->Off(); if(AirLevel && mode.On) { Air_P += (Air_ref-(int)buffer.air); Air_P=__max(0,__min(_A_THRESHOLD*_PWM_RATE, Air_P)); if(vibrate && __time__ % 50 < 10) Air->On(); else Air->Set(Air_P/_A_THRESHOLD); if(abs(adf.compressor - 4*offset.compressor) > offset.compressor/2) _SET_BIT(err,InputPressure); } else Air->Off(); return err; }