/*********************************************************************** * FUNCTION: GetFormatedDist * DESCRIPTION: Re-Formats the content of the distance variable * PARAMETER: addr of source distance value * addr of formated target distance value * format type * RETURN: ERR_OK * COMMENT: - *********************************************************************** */ ERRCODE GetFormatedDist( DIST_TYPE far * fpDistSrc, DIST_TYPE far * fpDistTrgt, MEASUNITS_TYPE RUnits) { /* GET value ------------------ */ UINT32 dwCopy; UINT16 wScratch; /* get current value */ INT_GLOB_DISABLE dwCopy = fpDistSrc->dkm; INT_GLOB_ENABLE /* format return value */ switch (RUnits) { case MR_KM: fpDistTrgt->km = dwCopy / 100L; break; /* 1 kilometer per digit */ case MR_HM: fpDistTrgt->hm = dwCopy / 10L; break; /* 1 hectometer (=0,1 km) per digit */ case MR_DKM: fpDistTrgt->dkm = dwCopy; break; /* 1 dekameter (=0,01 km) per digit */ case MR_KM_ONLY: fpDistTrgt->km_o = (UINT16) (dwCopy/100L); break; /* 1 kilometer per digit */ /* 1 kilometer per digit LIMITED to 65.536 km */ case MR_HM_ONLY: wScratch = (UINT16) (dwCopy/10L); /* 1 hectometer (=0,1 km) per digit WITHOUT leading km's */ fpDistTrgt->hkm_o = wScratch - ((wScratch/10)*10); break; case MR_DKM_ONLY: wScratch = (UINT16) dwCopy; /* 1 dekameter (=0,01 km) per digit WITHOUT leading km's */ fpDistTrgt->dkm_o = wScratch - ((wScratch/100)*100); break; default: ODS1(DBG_MEAS,DBG_ERROR,"Unknown measurement type [%u]!", RUnits); break; } return ERR_OK; }
/*********************************************************************** * FUNCTION: MeasGetTripB * DESCRIPTION: interface to get the current TRIP B counter value * PARAMETER: eUnits type of return value * RETURN: formated distance value * COMMENT: - *********************************************************************** */ UINT16 MeasGetTripB( MEASUNITS_TYPE eUnits ) { DIST_TYPE ResultDist; /* get formated value */ GetFormatedDist( &TripB, &ResultDist, eUnits); switch (eUnits) { case MR_KM_ONLY: return ResultDist.km_o; break; case MR_HM_ONLY: return ResultDist.hkm_o; break; case MR_DKM_ONLY: return ResultDist.dkm_o; break; default: ODS1(DBG_MEAS,DBG_ERROR,"Illegal measurement type [%u]!", eUnits); break; } return ERR_OK; }
/*********************************************************************** * FUNCTION: LED_GetState() * DESCRIPTION: Returns current state of single LED * PARAMETER: eLED LED indicator * RETURN: fActivate TRUE = LED on * FALSE = LED off * COMMENT: - *********************************************************************** */ BOOL LED_GetState( LED_ENUM eLed ) { BOOL RValue; /* check: valid LED index? */ if ( ( eLed < eDIGOUT_LED_NEUTR ) ||( eLed > eDIGOUT_LED_ERROR ) ) { ODS1(DBG_SYS,DBG_WARNING,"LED_GetState() Invalid index %u", eLed ); RValue = FALSE; } else { /* ok - now map to the driver function */ RValue = DigOutDrv_GetPin( eLed ); } return (RValue); }
/*********************************************************************** * FUNCTION: LED_SetNewState * DESCRIPTION: setup of LED PWM signal (granularity in ticks = 20 ms) * PARAMETER: eLed index of LE to be controlled * wOn_ms cyclic LED ON time in millisec (max. 3 sec.) * wOff_ms cyclic LED OFF time in millisec (max. 3 sec.) * wDur_ms overall duration of PWM in millisec (max 60 s) * RETURN: error code * COMMENT: wOff_ms = 0 eq. 'permanent ON' * wOn_ms = 0 eq. 'permanent OFF' * wDur_ms = 0 eg. 'permanent ON/OFF' * * If 'wDur_ms' has been set to 0 at LED_SetNewState(), * no further change will done, until next LED_SetNewState() * call! * * Might be called repetive with same parameters (e.g. OIL-SWITCH). * so we early check any changes to prevent irrelvant setup/debugouts. *********************************************************************** */ ERRCODE LED_SetNewState(LED_ENUM eLed, UINT16 wOn_ms, UINT16 wOff_ms, UINT16 wDur_ms ) { ERRCODE RValue = ERR_OK; /* check: valid LED index? */ if ( ( eLed < eDIGOUT_LED_NEUTR ) ||( eLed > eDIGOUT_LED_ERROR ) ) { ODS1(DBG_SYS,DBG_WARNING,"LED_SetNewState() Invalid index %u", eLed ); RValue = ERR_OUT_OF_RANGE; } else { /* ok - now map to the driver function */ RValue = DigOutDrv_SetNewState( eLed, wOn_ms, wOff_ms, wDur_ms ); } return (RValue); }
/*********************************************************************** * FUNCTION: MeasGetWheelSpeed * DESCRIPTION: Interface to calculate the real wheel speed from * wheel size and wheel sensor impuls period * PARAMETER: MEASUNITS_TYPE eUnit requested return value units * RETURN: wheel speed in requested units * OR Error Code * COMMENT: Uses this calculation, based on 200µsec/digit of * wheel sensors period time: * * s WS (wheel size) [mm] * v = --- = -------------------------- * t WP (wheel period) [200µs] * * * v [km/h] = (WS * 18) / WP [km/h] * * v [m/s] = (WS * 5) / WP [m/s] * *********************************************************************** */ UINT16 MeasGetWheelSpeed(MEASUNITS_TYPE eUnit) { UINT32 dwScratch; UINT16 wWheelPeriod; UINT16 RValue = 0; /* get averaged wheel period in 200 µsec/digit */ wWheelPeriod = MeasDrvGetWheelPeriod(FALSE); /* check, wether wheel stands still */ if (wWheelPeriod == UINT16_MAX) return 0; /* get the current base value */ dwScratch = ((UINT32)wWheelSize * 18) / wWheelPeriod; /* check: slow vehicle speed < ? */ if (dwScratch < SLOW_WHEELSPEED) /* update wheel period with only the last period value */ wWheelPeriod = MeasDrvGetWheelPeriod(TRUE); /* choice of return value units */ switch (eUnit) { case MR_KM_PER_H: { dwScratch = ((UINT32)wWheelSize * 18) / wWheelPeriod; } break; case MR_HM_PER_H: { dwScratch = ((UINT32)wWheelSize * 180) / wWheelPeriod; } break; case MR_M_PER_S: { dwScratch = ((UINT32)wWheelSize * 5) / wWheelPeriod; } break; case MR_DM_PER_S: { dwScratch = ((UINT32)wWheelSize * 50) / wWheelPeriod; } break; case MR_CM_PER_S: { dwScratch = ((UINT32)wWheelSize * 500) / wWheelPeriod; } break; default: { ODS1(DBG_MEAS,DBG_ERROR,"MeasGetWheelSpeed(eUnit): Unknown eUnit = %u", eUnit); return UINT16_MAX; } } /* cast into correct space */ if (dwScratch <= UINT16_MAX) RValue = (UINT16) dwScratch; else { ODS(DBG_MEAS,DBG_ERROR,"MeasGetWheelSpeed() Overflow! "); return UINT16_MAX; } /* get it ... */ return RValue; }
/*********************************************************************** * FUNCTION: MeasCyclicSaveValues * DESCRIPTION: Cyclicly called routine to asure all necessary * measurement data to be saved in NVRAM * PARAMETER: - * RETURN: error code * COMMENT: - Does only write into nvram if any changes made in value * - Reduces sytem load by only saving one value every 200 ms. * - init values are valid after reading initial reading * from nvram. *********************************************************************** */ ERRCODE MeasCyclicSaveValues(void) { static BOOL fInit = FALSE; /* to check for initialized static vars */ static PARAM_ID_TYPE PID = PID_NVRAM_START; static UINT16 wLastCall = 0; UINT16 wThisCall = 0; ERRCODE RValue = ERR_OK; static DIST_TYPE VehicDistCopy; static DIST_TYPE TripACopy; static DIST_TYPE TripBCopy; static DIST_TYPE FuelDistCopy; static SPEED_TYPE SpeedMaxCopy; static SPEED_TYPE SpeedAvrMCopy; static SPEED_TYPE SpeedAvrPCopy; /* first init local copies at first call */ if (fInit == FALSE) { VehicDistCopy = VehicDist; TripACopy = TripA; TripBCopy = TripB; SpeedMaxCopy = SpeedMax; SpeedAvrMCopy = SpeedAvrM; SpeedAvrPCopy = SpeedAvrP; FuelDistCopy = FuelDist; fInit = TRUE; } /* check: time to save one system parameter? */ TimerGetSys_msec(wThisCall); if (wThisCall - wLastCall > NVRAM_CYCLE) { wLastCall = wThisCall; /* update time stamp */ switch (PID) /* choice of system parameter to be saved */ { case PID_VEHIC_KM: if (VehicDistCopy.dkm != VehicDist.dkm) { RValue = ParWriteSysParam( PID, &VehicDist); VehicDistCopy = VehicDist; ODS2(DBG_MEAS,DBG_INFO,"VehicDist: %lu,%.2lu km", VehicDist.dkm/100L, VehicDist.dkm-(VehicDist.dkm/100L)*100); } break; case PID_TRIPA_KM: if (TripACopy.dkm != TripA.dkm) { RValue = ParWriteSysParam( PID, &TripA); TripACopy = TripA; ODS2(DBG_MEAS,DBG_INFO,"TripA: %lu,%.2lu km", TripA.dkm/100L, TripA.dkm-(TripA.dkm/100L)*100); } break; case PID_TRIPB_KM: if (TripBCopy.dkm != TripB.dkm) { RValue = ParWriteSysParam( PID, &TripB); TripBCopy = TripB; ODS2(DBG_MEAS,DBG_INFO,"TripB: %lu,%.2lu km", TripB.dkm/100L, TripB.dkm-(TripB.dkm/100L)*100); } break; case PID_FUEL_KM: if (FuelDistCopy.dkm != FuelDist.dkm) { RValue = ParWriteSysParam( PID, &FuelDist); FuelDistCopy = FuelDist; ODS2(DBG_MEAS,DBG_INFO,"FuelDist: %lu,%.2lu km", FuelDist.dkm/100L, FuelDist.dkm-(FuelDist.dkm/100L)*100); } break; case PID_SPEED_MAX: if (SpeedMaxCopy != SpeedMax) { RValue = ParWriteSysParam( PID, &SpeedMax); SpeedMaxCopy = SpeedMax; ODS2(DBG_MEAS,DBG_INFO,"SpeedMax: %u,%.2u km/h", SpeedMax/100, SpeedMax-(SpeedMax/100)*100); } break; case PID_SPEED_AVR_M: if (SpeedAvrMCopy != SpeedAvrM) { RValue = ParWriteSysParam( PID, &SpeedAvrM); SpeedAvrMCopy = SpeedAvrM; ODS2(DBG_MEAS,DBG_INFO,"SpeedAvrM: %u,%.2u km/h", SpeedAvrM/100, SpeedAvrM-(SpeedAvrM/100)*100); } break; case PID_SPEED_AVR_P: if (SpeedAvrPCopy != SpeedAvrP) { RValue = ParWriteSysParam( PID, &SpeedAvrP); SpeedAvrPCopy = SpeedAvrP; ODS2(DBG_MEAS,DBG_INFO,"SpeedAvrP: %u,%.2u km/h", SpeedAvrP/100, SpeedAvrP-(SpeedAvrP/100)*100); } break; default: ODS1(DBG_MEAS,DBG_ERROR,"Unknown PID: %u", PID); break; } /* next system parameter for next call */ PID++; /* inkr PID */ if (PID >= PID_NVRAM_END) PID = PID_NVRAM_START; /* start at the begining again */ } return RValue; }
/*********************************************************************** * FUNCTION: MeasGetEngineSpeed * DESCRIPTION: Interface to calculate the real engine speed from * cylinder correctur factor and RPM sensor impuls period * PARAMETER: MEASUNITS_TYPE eUnit requested return value units * RETURN: engine speed in requested units * OR Error Code * COMMENT: Uses this calculation, based on 10 µsec/digit of * RPM sensors period time and the 'Cylinder-Correctur- * Factor' (CCF): * * # of ignitions per round * CCF = -------------------------------------- * # of cylinders sharing this ignition * * * const 6.000.000 * CCF (Cylinder-Factor) * n [1/Min] = --------------------------------------- * RP (RPM period) [10µs] * * c * CCF c * CCF(Nom) * = --------- = ---------------- * RP RP * CCF(Denom) * * n [1/Min] = (c * CCF-Nom) / (RP * CCF-Denom) [1/Min] * *********************************************************************** */ UINT16 MeasGetEngineSpeed(MEASUNITS_TYPE eUnit) { const UINT32 dwConst = 6000000L; /* = 60 sec/Min / 10µsec */ UINT32 dwScratch; UINT16 wRPMPeriod; UINT16 RValue = 0; /* get current rpm period in 10 µsec/digit */ wRPMPeriod = MeasDrvGetRPMPeriod(TRUE); /* check, wether engine stands still */ if (wRPMPeriod == UINT16_MAX) return 0; /* get the RPM base value (units: rounds per minute) */ dwScratch = (dwConst * CCF.nibble.nom) / ((UINT32)wRPMPeriod * (UINT32)CCF.nibble.denom); /* check: Low engine speed? */ if (dwScratch < SLOW_ENGSPEED) { /* get a more averaged filter value */ wRPMPeriod = MeasDrvGetRPMPeriod(FALSE); /* do calculations again */ dwScratch = (dwConst * CCF.nibble.nom) / ((UINT32)wRPMPeriod * (UINT32)CCF.nibble.denom); } /* choice of return value units */ switch (eUnit) { case MR_RPS: /* rounds per second */ { dwScratch = dwScratch / 60; } break; case MR_RPM: /* rounds per minute */ { /* nothing to do, value already computed! */ } break; case MR_RPM_R10:/* rounds per minute rounded to ten's */ { dwScratch = (dwScratch / 10) * 10; } break; default: { ODS1(DBG_MEAS,DBG_ERROR,"MeasGetEngineSpeed(): Unknown eUnit = %u", eUnit); return UINT16_MAX; } } /* cast into correct space */ if (dwScratch <= UINT16_MAX) RValue = (UINT16) dwScratch; else { ODS(DBG_MEAS,DBG_ERROR,"MeasGetEngineSpeed() Overflow! "); return UINT16_MAX; } /* get it ... */ return RValue; }
int WSPAPI WSPStartup( WORD wVersionRequested, LPWSPDATA lpWSPData, LPWSAPROTOCOL_INFO lpProtocolInfo, WSPUPCALLTABLE UpcallTable, LPWSPPROC_TABLE lpProcTable ) { int i; ODS1(L"WSPStartup... %s \n", g_szCurrentApp); if(lpProtocolInfo->ProtocolChain.ChainLen <= 1) { return WSAEPROVIDERFAILEDINIT; } g_pUpCallTable = UpcallTable; WSAPROTOCOL_INFOW NextProtocolInfo; int nTotalProtos; LPWSAPROTOCOL_INFOW pProtoInfo = GetProvider(&nTotalProtos); DWORD dwBaseEntryId = lpProtocolInfo->ProtocolChain.ChainEntries[1]; for(i=0; i<nTotalProtos; i++) { if(pProtoInfo[i].dwCatalogEntryId == dwBaseEntryId) { memcpy(&NextProtocolInfo, &pProtoInfo[i], sizeof(NextProtocolInfo)); break; } } if(i >= nTotalProtos) { ODS(L" WSPStartup: Can not find underlying protocol \n"); return WSAEPROVIDERFAILEDINIT; } int nError; TCHAR szBaseProviderDll[MAX_PATH]; int nLen = MAX_PATH; if(::WSCGetProviderPath(&NextProtocolInfo.ProviderId, szBaseProviderDll, &nLen, &nError) == SOCKET_ERROR) { ODS1(L" WSPStartup: WSCGetProviderPath() failed %d \n", nError); return WSAEPROVIDERFAILEDINIT; } if(!::ExpandEnvironmentStrings(szBaseProviderDll, szBaseProviderDll, MAX_PATH)) { ODS1(L" WSPStartup: ExpandEnvironmentStrings() failed %d \n", ::GetLastError()); return WSAEPROVIDERFAILEDINIT; } HMODULE hModule = ::LoadLibrary(szBaseProviderDll); if(hModule == NULL) { ODS1(L" WSPStartup: LoadLibrary() failed %d \n", ::GetLastError()); return WSAEPROVIDERFAILEDINIT; } LPWSPSTARTUP pfnWSPStartup = NULL; pfnWSPStartup = (LPWSPSTARTUP)::GetProcAddress(hModule, "WSPStartup"); if(pfnWSPStartup == NULL) { ODS1(L" WSPStartup: GetProcAddress() failed %d \n", ::GetLastError()); return WSAEPROVIDERFAILEDINIT; } LPWSAPROTOCOL_INFOW pInfo = lpProtocolInfo; if(NextProtocolInfo.ProtocolChain.ChainLen == BASE_PROTOCOL) pInfo = &NextProtocolInfo; int nRet = pfnWSPStartup(wVersionRequested, lpWSPData, pInfo, UpcallTable, lpProcTable); if(nRet != ERROR_SUCCESS) { ODS1(L" WSPStartup: underlying provider's WSPStartup() failed %d \n", nRet); return nRet; } g_NextProcTable = *lpProcTable; lpProcTable->lpWSPSocket = WSPSocket; lpProcTable->lpWSPCloseSocket = WSPCloseSocket; lpProcTable->lpWSPConnect = WSPConnect; lpProcTable->lpWSPAccept = WSPAccept; lpProcTable->lpWSPSend = WSPSend; lpProcTable->lpWSPSendTo = WSPSendTo; lpProcTable->lpWSPRecv = WSPRecv; lpProcTable->lpWSPRecvFrom = WSPRecvFrom; lpProcTable->lpWSPAddressToString = WSPAddressToString; lpProcTable->lpWSPAsyncSelect = WSPAsyncSelect; lpProcTable->lpWSPBind = WSPBind; lpProcTable->lpWSPCancelBlockingCall = WSPCancelBlockingCall; lpProcTable->lpWSPCleanup = WSPCleanup; lpProcTable->lpWSPDuplicateSocket = WSPDuplicateSocket; lpProcTable->lpWSPEnumNetworkEvents = WSPEnumNetworkEvents; lpProcTable->lpWSPEventSelect = WSPEventSelect; lpProcTable->lpWSPGetOverlappedResult = WSPGetOverlappedResult; lpProcTable->lpWSPGetPeerName = WSPGetPeerName; lpProcTable->lpWSPGetQOSByName = WSPGetQOSByName; lpProcTable->lpWSPGetSockName = WSPGetSockName; lpProcTable->lpWSPGetSockOpt = WSPGetSockOpt; lpProcTable->lpWSPIoctl = WSPIoctl; lpProcTable->lpWSPJoinLeaf = WSPJoinLeaf; lpProcTable->lpWSPListen = WSPListen; lpProcTable->lpWSPRecvDisconnect = WSPRecvDisconnect; lpProcTable->lpWSPSelect = WSPSelect; lpProcTable->lpWSPSendDisconnect = WSPSendDisconnect; lpProcTable->lpWSPSetSockOpt = WSPSetSockOpt; lpProcTable->lpWSPShutdown = WSPShutdown; lpProcTable->lpWSPStringToAddress = WSPStringToAddress; FreeProvider(pProtoInfo); return nRet; }
void TimerInterrupt(void) { UINT16 wEntry_ms = 0; UINT16 wExit_ms = 0; UINT8 bActLoad = 0; UINT8 i; TOGGLE_PAD28; // get current last time TimerGetSys_msec(wEntry_ms); // !!! Re-Enable higher interrupts than this interrupt! // (for use of MilliSecCounter) INT_GLOB_ENABLE // ----------------------------------------- // increment internal system time gdwTicks++; // ----------------------------------------- // call all registered timer entry functions for( i = 0; i < gbFuncs; i++ ) { UINT16 wEntry_ms = 0; UINT16 wExit_ms = 0; EntryFunction pFn; TimerGetSys_msec(wEntry_ms); if( (pFn = gaEntryFunctions[i]) != NULL ) { (*pFn)(); // execute registered entry function } TimerGetSys_msec(wExit_ms); if ((wExit_ms - wEntry_ms) > WARN_TIMERLOAD_MS) ODS2( DBG_SYS, DBG_WARNING, "TimerEntryFct 0x%lx took %u ms!", pFn, (wExit_ms - wEntry_ms)); } // ----------------------------------------- // check for any expired message timer for( i = 0; i < gbLastTimer; i++ ) { if ( gaMessageQueueTimer[i].time == 0 ) { // try to post message with HIGH priority if ( MsgQPostMsg(gaMessageQueueTimer[i].msg, MSGQ_PRIO_HIGH) == ERR_OK ) { gbLastTimer--; gaMessageQueueTimer[i] = gaMessageQueueTimer[gbLastTimer]; } else { /* posting not successful, try again next time */ } } else { /* not expired, decrement time */ gaMessageQueueTimer[i].time--; } } // of checking timers // check last use of this isr TimerGetSys_msec(wExit_ms); // calculate processor load by this isr in percent // (should be about 10%) bActLoad = ((wExit_ms - wEntry_ms) * TICKS_PER_SECOND) / 10; // safe max load if (bActLoad > gbTimerInterruptLoad) gbTimerInterruptLoad = bActLoad; // 'out of echtzeit' warning: Load > 100% if (bActLoad >= 100) ODS1(DBG_SYS, DBG_WARNING, "TimerInterrupt overloaded! (Load: %d \x25)", bActLoad); }