UTIL_TimerType UTIL_CreateTimer( void* pFunctionPtr, UINT16 iTime ) { UTIL_TimerType xTimerId; /* ** Creates a new timer. ** Check that we have timers available. */ if( util_s.sTimerSystem.iAllocatedTimers >= UTIL_NUMBER_OF_TIMERS ) { /* ** We are out of timers. Generate a FATAL error to the application. */ ABCC_CbfDriverError( ABCC_SEV_FATAL, ABCC_EC_OUT_OF_TIMERS ); return( UTIL_INVALID_TIMER_ID ); } /* ** Check if the pointer is OK */ if( pFunctionPtr == NULL ) { /* ** The pointer is probably not correct. Generate a FATAL error to the application. */ ABCC_CbfDriverError( ABCC_SEV_FATAL, ABCC_EC_TIMER_SYSTEM_MALFUNCTION ); return( UTIL_INVALID_TIMER_ID ); } /* ** Increase the number of allocated timers and fill in the timer information. */ xTimerId = (UTIL_TimerType)util_s.sTimerSystem.iAllocatedTimers; util_s.sTimerSystem.asTimerEntries[ xTimerId ].fEnabled = FALSE; util_s.sTimerSystem.asTimerEntries[ xTimerId ].iTimeInMs = iTime; util_s.sTimerSystem.asTimerEntries[ xTimerId ].pFunctionPtr = (ABCC_TD_pFuncType)pFunctionPtr; util_s.sTimerSystem.iAllocatedTimers++; /* ** Return the index of the allocated timer as the TimerId. */ return( xTimerId ); } /* End of UTIL_CreateTimer() */
UTIL_QueueType UTIL_CreateMessageQueue( UTIL_BufMsgType** ppasStartOfBuffer, UINT16 iNumberOfElements ) { util_OneQueueEntry* psQEntry; UTIL_QueueType xQueueId; SYS_UseCritical(); /* ** Create a new message queue abstraction. ** Check that there are any queues available. */ if( util_s.sQueueSystem.iAllocatedQueues >= UTIL_NUMBER_OF_QUEUES ) { /* ** We are out of message queues. Generate a FATAL error to the application. */ ABCC_CbfDriverError( ABCC_SEV_FATAL, ABCC_EC_OUT_OF_QUEUES ); return( UTIL_INVALID_MSG_Q_ID ); } /* End if( Out of queues? ) */ /* ** Set-up the Message queue structure. */ xQueueId = util_s.sQueueSystem.iAllocatedQueues; util_s.sQueueSystem.iAllocatedQueues++; /* ** Enter a critical section. */ SYS_EnterCritical(); psQEntry = &util_s.sQueueSystem.asQueueEntries[ xQueueId ]; psQEntry->ppsStartPtr = ppasStartOfBuffer; psQEntry->ppsInsertPtr = ppasStartOfBuffer; psQEntry->ppsRemovePtr = ppasStartOfBuffer; psQEntry->iCurrentNbrOfEntries = 0; psQEntry->iMaxNbrOfEntries = iNumberOfElements; /* ** ...and exit the critical section. */ SYS_ExitCritical(); return( xQueueId ); } /* End of UTIL_CreateMessageQueue() */
void APDR_ServiceInterruptParallel( void ) { UINT8 bNewAbccStatus; /* ** Parallel interrupt received, read the ABCC status register. */ SYS_ReadParallel( &bNewAbccStatus, APDR_DPRAM_STAT_REG_OFFSET, 1 ); /* ** Check if toggle bit is changed. */ if( ( bNewAbccStatus & ABP_STAT_T_BIT ) != ( apdr_s.bCurrentStatusReg & ABP_CTRL_T_BIT ) ) { /* ** The toggle bit is toggled, that is, a new telegram is posted by the ** ABCC. */ apdr_s.bCurrentStatusReg = bNewAbccStatus; /* ** Signal reception of a new telegram. */ apdr_s.fTelegramReceived = TRUE; /* ** Signal to application that we have received a new telegram. */ #ifdef ABCC_TX_RX_CALLBACK_ENABLE ABCC_CbfTelegramReceived(); #endif } else { /* ** Nothing new, do nothing... */ ABCC_CbfDriverError( ABCC_SEV_INFORMATION, ABCC_EC_FALSE_PARALLEL_INT_GENERATED ); } /* End if( Toggle bit changed? ) */ } /* End of APDR_ServiceInterruptParallel() */
void APDR_Init( void ) { #ifdef ABCC_ACCESS_MODE_SERIAL /* ** Assign the timeout timer for the serial telegram reception. */ if( ( ABCC_GET_OPERATION_MODE_OM0 == 1 ) && ( ABCC_GET_OPERATION_MODE_OM1 == 0 ) && ( ABCC_GET_OPERATION_MODE_OM2 == 0 ) ) { /* ** 19200. */ apdr_s.iTelegramToTime = APDR_TELEGRAM_TIMEOUT_19200; } else if( ( ABCC_GET_OPERATION_MODE_OM0 == 0 ) && ( ABCC_GET_OPERATION_MODE_OM1 == 1 ) && ( ABCC_GET_OPERATION_MODE_OM2 == 0 ) ) { /* ** 57600. */ apdr_s.iTelegramToTime = APDR_TELEGRAM_TIMEOUT_57600; } else if( ( ABCC_GET_OPERATION_MODE_OM0 == 1 ) && ( ABCC_GET_OPERATION_MODE_OM1 == 1 ) && ( ABCC_GET_OPERATION_MODE_OM2 == 0 ) ) { /* ** 115200. */ apdr_s.iTelegramToTime = APDR_TELEGRAM_TIMEOUT_115200; } else if( ( ABCC_GET_OPERATION_MODE_OM0 == 0 ) && ( ABCC_GET_OPERATION_MODE_OM1 == 0 ) && ( ABCC_GET_OPERATION_MODE_OM2 == 1 ) ) { /* ** 625000 */ apdr_s.iTelegramToTime = APDR_TELEGRAM_TIMEOUT_625000; } else { /* ** Unknown/reserved baud rate setting. */ ABCC_CbfDriverError( ABCC_SEV_FATAL, ABCC_EC_INCORRECT_OPERATING_MODE ); } /* End if( Serial mode ) */ /* ** Create the Telegram timeout timer. */ apdr_s.xTelegramToTimer = UTIL_CreateTimer( (void*)apdr_TelegramTimeout, apdr_s.iTelegramToTime ); #endif /* End #ifdef ABCC_ACCESS_MODE_SERIAL */ #ifdef ABCC_ACCESS_MODE_PARALLEL /* ** Setup pointers to the DPRAM. We only need this if we can directly access ** the dpram without special DPRAM functions. */ #ifdef ABCC_PARALLEL_DIRECT_ACCESS_THROUGH_PTR apdr_s.sDpram.pabWritePd = (UINT8*)( ABCC_PARALLEL_BASE_ADDRESS + ABCC_PARALLEL_OFFSET + APDR_DPRAM_PD_WRITE_LOC ); apdr_s.sDpram.pabReadPd = (UINT8*)( ABCC_PARALLEL_BASE_ADDRESS + ABCC_PARALLEL_OFFSET + APDR_DPRAM_PD_READ_LOC ); apdr_s.sDpram.psWriteMsg = (ABP_MsgType*)( ABCC_PARALLEL_BASE_ADDRESS + ABCC_PARALLEL_OFFSET + APDR_DPRAM_MESSAGE_WRITE_LOC ); apdr_s.sDpram.psReadMsg = (ABP_MsgType*)( ABCC_PARALLEL_BASE_ADDRESS + ABCC_PARALLEL_OFFSET + APDR_DPRAM_MESSAGE_READ_LOC ); #endif #ifdef ABCC_PARALLEL_POLL_MODE /* ** Disable polling initially. */ apdr_s.fParallelPollEnabled = FALSE; #endif /* end #ifdef ABCC_PARALLEL_POLL_MODE */ #endif /* End #ifdef ABCC_ACCESS_MODE_PARALLEL */ /* ** Create the ABCC watchdog timeout timer. */ apdr_s.xAbccWdTimer = UTIL_CreateTimer( (void*)apdr_AbccWatchdogTimeout, (UINT16)ABCC_WATCHDOG_TIMEOUT_TIME_MS ); /* ** Create the initil handshake timer. */ apdr_s.xInitHsTimer = UTIL_CreateTimer( (void*)apdr_InitHsTimerExpired, (UINT16)ABCC_INTIAL_HANDSHAKE_DELAY_TIME_MS ); /* ** Set the state of the state-machine to INIT. */ apdr_s.eState = APDR_SM_INIT; } /* End of APDR_Init() */