William Kane / Generic

Dependents:   LaserioLib

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers abcc_handler.c Source File

abcc_handler.c

00001 /*******************************************************************************
00002 ********************************************************************************
00003 **                                                                            **
00004 ** ABCC Driver version 4.01.01 (2015-12-14)                                   **
00005 **                                                                            **
00006 ** Delivered with:                                                            **
00007 **    ABP         7.16.01 (2015-10-14)                                        **
00008 **                                                                            */
00009 /*******************************************************************************
00010 ********************************************************************************
00011 ** COPYRIGHT NOTIFICATION (c) 2013 HMS Industrial Networks AB                 **
00012 **                                                                            **
00013 ** This code is the property of HMS Industrial Networks AB.                   **
00014 ** The source code may not be reproduced, distributed, or used without        **
00015 ** permission. When used together with a product from HMS, permission is      **
00016 ** granted to modify, reproduce and distribute the code in binary form        **
00017 ** without any restrictions.                                                  **
00018 **                                                                            **
00019 ** THE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. HMS DOES NOT    **
00020 ** WARRANT THAT THE FUNCTIONS OF THE CODE WILL MEET YOUR REQUIREMENTS, OR     **
00021 ** THAT THE OPERATION OF THE CODE WILL BE UNINTERRUPTED OR ERROR-FREE, OR     **
00022 ** THAT DEFECTS IN IT CAN BE CORRECTED.                                       **
00023 ********************************************************************************
00024 ********************************************************************************
00025 ** File Description:
00026 ** Implementation of operation mode independent parts of the abcc handler.
00027 ********************************************************************************
00028 ********************************************************************************
00029 */
00030 
00031 #include "abcc_drv_cfg.h"
00032 #include "abcc_td.h"
00033 #include "abcc_drv_if.h"
00034 #include "abp.h"
00035 #include "abcc.h"
00036 #include "abcc_link.h"
00037 #include "abcc_mem.h"
00038 #include "abcc_sys_adapt.h"
00039 #include "abcc_debug_err.h"
00040 #include "abcc_handler.h"
00041 #include "abcc_timer.h"
00042 #include "abcc_setup.h"
00043 #include "abcc_port.h"
00044 
00045 #if( ABCC_CFG_DRV_SPI )
00046 #include "spi/abcc_drv_spi_if.h"
00047 #endif
00048 #if( ABCC_CFG_DRV_PARALLEL )
00049 #include "par/abcc_drv_par_if.h"
00050 #endif
00051 #if( ABCC_CFG_DRV_PARALLEL_30 )
00052 #include "par30/abcc_drv_par30_if.h"
00053 #endif
00054 #if( ABCC_CFG_DRV_SERIAL )
00055 #include "serial/abcc_drv_ser_if.h"
00056 #endif
00057 
00058 /*
00059 ** Registerd handler functions
00060 */
00061 EXTFUNC ABCC_ErrorCodeType ABCC_SpiRunDriver( void );
00062 EXTFUNC void ABCC_SpiISR( void );
00063 
00064 EXTFUNC ABCC_ErrorCodeType ABCC_ParRunDriver( void );
00065 EXTFUNC void ABCC_ParISR( void );
00066 
00067 EXTFUNC ABCC_ErrorCodeType ABCC_Par30RunDriver( void );
00068 EXTFUNC void ABCC_Par30ISR( void );
00069 
00070 EXTFUNC ABCC_ErrorCodeType ABCC_SerRunDriver( void );
00071 EXTFUNC void ABCC_SerISR( void );
00072 
00073 
00074 
00075 
00076 /*
00077  ** Default USER defines
00078  */
00079 #ifndef ABCC_CFG_STARTUP_TIME_MS
00080 #define ABCC_CFG_STARTUP_TIME_MS ( 1500 )
00081 #endif
00082 
00083 /********************************************************************************
00084 ** Public Globals
00085 ********************************************************************************
00086 */
00087 
00088 /*
00089 ** Registered handler functions
00090 */
00091 
00092 ABCC_ErrorCodeType ( *ABCC_RunDriver )( void );
00093 void ( *ABCC_ISR )( void );
00094 void ( *ABCC_TriggerWrPdUpdate )( void );
00095 
00096 /*
00097 ** The interrupt mask that has been set to the ABCC at start up.
00098 */
00099 UINT16 ABCC_iInterruptEnableMask;
00100 
00101 /*
00102 ** Registerd driver functions
00103 */
00104 
00105 void  ( *pnABCC_DrvInit )( UINT8 bOpmode );
00106 UINT16 ( *pnABCC_DrvISR )( void );
00107 void ( *pnABCC_DrvRunDriverTx )( void );
00108 ABP_MsgType* ( *pnABCC_DrvRunDriverRx )( void );
00109 BOOL ( *pnABCC_DrvWriteMessage) ( ABP_MsgType* psWriteMsg );
00110 void ( *pnABCC_DrvWriteProcessData )( void* pbProcessData );
00111 BOOL ( *pnABCC_DrvISReadyForWrPd )( void );
00112 BOOL ( *pnABCC_DrvISReadyForWriteMessage )( void );
00113 BOOL ( *pnABCC_DrvISReadyForCmd )( void );
00114 void ( *pnABCC_DrvSetNbrOfCmds )( UINT8 bNbrOfCmds );
00115 void ( *pnABCC_DrvSetAppStatus )( ABP_AppStatusType eAppStatus );
00116 void ( *pnABCC_DrvSetPdSize )( const UINT16 iReadPdSize, const UINT16 iWritePdSize );
00117 void ( *pnABCC_DrvSetIntMask )( const UINT16 iIntMask );
00118 void* ( *pnABCC_DrvGetWrPdBuffer )( void );
00119 UINT16 ( *pnABCC_DrvGetModCap )( void );
00120 UINT16 ( *pnABCC_DrvGetLedStatus )( void );
00121 UINT16 ( *pnABCC_DrvGetIntStatus )( void );
00122 UINT8 ( *pnABCC_DrvGetAnybusState )( void );
00123 void* ( *pnABCC_DrvReadProcessData )( void );
00124 ABP_MsgType* ( *pnABCC_DrvReadMessage )( void );
00125 BOOL ( *pnABCC_DrvIsSupervised )( void );
00126 UINT8 ( *pnABCC_DrvGetAnbStatus )( void );
00127 
00128 #if( ABCC_CFG_SYNC_MEASUREMENT_IP )
00129 BOOL fAbccUserSyncMeasurementIp;
00130 #endif
00131 
00132 /*******************************************************************************
00133 ** Private Globals
00134 ********************************************************************************
00135 */
00136 
00137 static volatile UINT8 abcc_bAnbState = 0xff;
00138 
00139 static ABCC_MainStateType abcc_eMainState = ABCC_DRV_INIT;
00140 
00141 /*
00142 ** Pointer to WRPD buffer.
00143 */
00144 static void* abcc_pbWrPdBuffer;
00145 
00146 /*
00147  ** Tmo handler for
00148  */
00149 static ABCC_TimerHandle abcc_TmoHandle;
00150 
00151 /*
00152  ** Indicate ready for communication
00153  */
00154 static BOOL abcc_fReadyForCommunicationTmo = FALSE;
00155 static BOOL abcc_fReadyForCommunication = FALSE;
00156 
00157 /*
00158  ** Current operation mode
00159  */
00160 static UINT8 abcc_bOpmode = 0;
00161 
00162 #if( ABCC_CFG_DRV_SPI || ABCC_CFG_DRV_PARALLEL_30 || ABCC_CFG_DRV_SERIAL )
00163 /*
00164  ** Flag to indicate that WrPD update shall be done
00165  */
00166 static BOOL abcc_fDoWrPdUpdate = FALSE;
00167 #endif
00168 
00169 /*
00170 ** The Application status register value of the Anybus module
00171 */
00172 static volatile ABP_AppStatusType abcc_eAppStatus = ABP_APPSTAT_NO_ERROR;
00173 
00174 /*******************************************************************************
00175 ** Private Services
00176 ********************************************************************************
00177 */
00178 
00179 static void TriggerWrPdUpdateNow( void )
00180 {
00181    if( ABCC_GetMainState() == ABCC_DRV_RUNNING )
00182    {
00183       /*
00184       ** Send new "write process data" to the Anybus-CC.
00185       ** The data format of the process data is network specific.
00186       ** The application converts the data accordingly.
00187       */
00188       if( pnABCC_DrvISReadyForWrPd() )
00189       {
00190          if( ABCC_CbfUpdateWriteProcessData( abcc_pbWrPdBuffer ) )
00191          {
00192             pnABCC_DrvWriteProcessData( abcc_pbWrPdBuffer );
00193 #if( ABCC_CFG_SYNC_MEASUREMENT_IP )
00194             if( ABCC_GetOpmode() == ABP_OP_MODE_SPI )
00195             {
00196                fAbccUserSyncMeasurementIp = TRUE;
00197             }
00198             else
00199             {
00200                ABCC_SYS_GpioReset();
00201             }
00202 #endif
00203          }
00204       }
00205    }
00206 }
00207 
00208 #if( ABCC_CFG_DRV_SPI || ABCC_CFG_DRV_PARALLEL_30 || ABCC_CFG_DRV_SERIAL )
00209 static void TriggerWrPdUpdateLater( void )
00210 {
00211    abcc_fDoWrPdUpdate = TRUE;
00212 }
00213 #endif
00214 
00215 static BOOL IsInterruptInUse( void )
00216 {
00217    BOOL fReturn;
00218 
00219    fReturn = FALSE;
00220 #if( ABCC_CFG_INT_ENABLED )
00221    switch( abcc_bOpmode )
00222    {
00223    case ABP_OP_MODE_16_BIT_PARALLEL:
00224    case ABP_OP_MODE_8_BIT_PARALLEL:
00225    case ABP_OP_MODE_SPI:
00226       fReturn = TRUE;
00227       break;
00228 
00229    default:
00230       break;
00231    }
00232 
00233    return( fReturn );
00234 #else
00235    return( fReturn );
00236 #endif /* End of #if ABCC_CFG_INT_ENABLED */
00237 }
00238 
00239 static BOOL IsPolledInterruptInUse( void )
00240 {
00241    BOOL fReturn;
00242 
00243    fReturn = FALSE;
00244 #if( ABCC_CFG_POLL_ABCC_IRQ_PIN )
00245    switch( abcc_bOpmode )
00246    {
00247    case ABP_OP_MODE_16_BIT_PARALLEL:
00248    case ABP_OP_MODE_8_BIT_PARALLEL:
00249    case ABP_OP_MODE_SPI:
00250       fReturn = TRUE;
00251       break;
00252 
00253    default:
00254 
00255       break;
00256    }
00257 
00258    return( fReturn );
00259 #else
00260    return( fReturn );
00261 #endif /* End of #if ABCC_CFG_POLL_ABCC_IRQ_PIN */
00262 }
00263 
00264 static void SetReadyForCommunicationTmo( void )
00265 {
00266    abcc_fReadyForCommunicationTmo = TRUE;
00267 }
00268 
00269 /*******************************************************************************
00270 ** Public Service
00271 ********************************************************************************
00272 */
00273 
00274 #if( ABCC_CFG_DRV_SPI || ABCC_CFG_DRV_PARALLEL_30 || ABCC_CFG_DRV_SERIAL )
00275 void ABCC_CheckWrPdUpdate( void )
00276 {
00277    if( abcc_fDoWrPdUpdate )
00278    {
00279       abcc_fDoWrPdUpdate = FALSE;
00280       TriggerWrPdUpdateNow();
00281    }
00282 }
00283 #endif
00284 
00285 void ABCC_SetReadyForCommunication( void )
00286 {
00287    abcc_fReadyForCommunication = TRUE;
00288 }
00289 
00290 void ABCC_SetMainStateError( void )
00291 {
00292    abcc_eMainState = ABCC_DRV_ERROR;
00293 }
00294 
00295 ABCC_MainStateType ABCC_GetMainState( void )
00296 {
00297    return( abcc_eMainState );
00298 }
00299 
00300 void ABCC_TriggerAnbStatusUpdate( void )
00301 {
00302    UINT8 bAnbState;
00303 
00304    bAnbState = pnABCC_DrvGetAnybusState();
00305    if( bAnbState != abcc_bAnbState )
00306    {
00307       abcc_bAnbState = bAnbState;
00308       ABCC_CbfAnbStateChanged( (ABP_AnbStateType)bAnbState );
00309    }
00310 }
00311 
00312 void ABCC_TriggerTransmitMessage( void )
00313 {
00314    ABCC_LinkCheckSendMessage();
00315 }
00316 
00317 #if ( ABCC_CFG_SYNC_MEASUREMENT_OP || ABCC_CFG_SYNC_MEASUREMENT_IP )
00318 void ABCC_GpioReset( void )
00319 {
00320    ABCC_SYS_GpioReset();
00321 }
00322 #endif
00323 
00324 #if ( ABCC_CFG_SYNC_MEASUREMENT_OP || ABCC_CFG_SYNC_MEASUREMENT_IP )
00325 void ABCC_GpioSet( void )
00326 {
00327    ABCC_SYS_GpioSet();
00328 }
00329 #endif
00330 
00331 ABCC_ErrorCodeType ABCC_HwInit( void )
00332 {
00333    if( !ABCC_SYS_HwInit() )
00334    {
00335       return( ABCC_EC_HW_INIT_FAILED );
00336    }
00337    return( ABCC_EC_NO_ERROR );
00338 }
00339 
00340 
00341 ABCC_ErrorCodeType ABCC_StartDriver( UINT32 lMaxStartupTimeMs )
00342 {
00343    UINT8 bModuleId;
00344    UINT8 bOpmode;
00345 
00346    if( lMaxStartupTimeMs == 0 )
00347    {
00348       lMaxStartupTimeMs = ABCC_CFG_STARTUP_TIME_MS;
00349    }
00350 
00351    SetErrorReporter( ABCC_CbfDriverError );
00352 
00353    bModuleId = ABCC_ReadModuleId();
00354 
00355 #if( ABCC_CFG_DRV_SERIAL || ABCC_CFG_DRV_PARALLEL_30 )
00356    if( ( bModuleId != ABP_MODULE_ID_ACTIVE_ABCC40 ) && ( bModuleId != ABP_MODULE_ID_ACTIVE_ABCC30 ) )
00357 #elif( ABCC_CFG_DRV_SPI || ABCC_CFG_DRV_PARALLEL )
00358    if( bModuleId != ABP_MODULE_ID_ACTIVE_ABCC40 )
00359 #endif
00360    {
00361       ABCC_ERROR( ABCC_SEV_FATAL, ABCC_EC_MODULE_ID_NOT_SUPPORTED, (UINT32)bModuleId );
00362 
00363       return( ABCC_EC_MODULE_ID_NOT_SUPPORTED );
00364    }
00365 
00366    bOpmode = ABCC_GetOpmode();
00367    abcc_bOpmode = bOpmode;
00368 
00369    switch( bOpmode )
00370    {
00371 #if( ABCC_CFG_DRV_SERIAL )
00372    case ABP_OP_MODE_SERIAL_19_2:
00373    case ABP_OP_MODE_SERIAL_57_6:
00374    case ABP_OP_MODE_SERIAL_115_2:
00375    case ABP_OP_MODE_SERIAL_625:
00376 
00377       ABCC_ISR                   = NULL;
00378       ABCC_RunDriver             = &ABCC_SerRunDriver;
00379       ABCC_TriggerWrPdUpdate     = &TriggerWrPdUpdateLater;
00380 
00381       pnABCC_DrvInit               = &ABCC_DrvSerInit;
00382       pnABCC_DrvISR                = &ABCC_DrvSerISR;
00383       pnABCC_DrvRunDriverTx        = &ABCC_DrvSerRunDriverTx;
00384       pnABCC_DrvRunDriverRx        = &ABCC_DrvSerRunDriverRx;
00385       pnABCC_DrvWriteMessage       = &ABCC_DrvSerWriteMessage;
00386       pnABCC_DrvWriteProcessData   = &ABCC_DrvSerWriteProcessData;
00387       pnABCC_DrvISReadyForWrPd     = &ABCC_DrvSerIsReadyForWrPd;
00388       pnABCC_DrvISReadyForWriteMessage = &ABCC_DrvSerIsReadyForWriteMessage;
00389       pnABCC_DrvISReadyForCmd      = &ABCC_DrvSerIsReadyForCmd;
00390       pnABCC_DrvSetNbrOfCmds       = &ABCC_DrvSerSetNbrOfCmds;
00391       pnABCC_DrvSetAppStatus       = &ABCC_DrvSerSetAppStatus;
00392       pnABCC_DrvSetPdSize          = &ABCC_DrvSerSetPdSize;
00393       pnABCC_DrvSetIntMask         = &ABCC_DrvSerSetIntMask;
00394       pnABCC_DrvGetWrPdBuffer      = &ABCC_DrvSerGetWrPdBuffer;
00395       pnABCC_DrvGetModCap          = &ABCC_DrvSerGetModCap;
00396       pnABCC_DrvGetLedStatus       = &ABCC_DrvSerGetLedStatus;
00397       pnABCC_DrvGetIntStatus       = &ABCC_DrvSerGetIntStatus;
00398       pnABCC_DrvGetAnybusState     = &ABCC_DrvSerGetAnybusState;
00399       pnABCC_DrvReadProcessData    = &ABCC_DrvSerReadProcessData;
00400       pnABCC_DrvReadMessage        = &ABCC_DrvSerReadMessage;
00401       pnABCC_DrvIsSupervised       = &ABCC_DrvSerIsSupervised;
00402       pnABCC_DrvGetAnbStatus       = &ABCC_DrvSerGetAnbStatus;
00403 
00404       ABCC_iInterruptEnableMask = 0;
00405 
00406       break;
00407 #endif /* End of #if ABCC_CFG_DRV_SERIAL */
00408 #if( ABCC_CFG_DRV_SPI )
00409    case ABP_OP_MODE_SPI:
00410 
00411       if( bModuleId == ABP_MODULE_ID_ACTIVE_ABCC40 )
00412       {
00413          ABCC_ISR                   = &ABCC_SpiISR;
00414          ABCC_RunDriver             = &ABCC_SpiRunDriver;
00415          ABCC_TriggerWrPdUpdate     = &TriggerWrPdUpdateLater;
00416 
00417          pnABCC_DrvInit               = &ABCC_DrvSpiInit;
00418          pnABCC_DrvISR                = NULL;
00419          pnABCC_DrvRunDriverTx        = &ABCC_DrvSpiRunDriverTx;
00420          pnABCC_DrvRunDriverRx        = &ABCC_DrvSpiRunDriverRx;
00421          pnABCC_DrvWriteMessage       = &ABCC_DrvSpiWriteMessage;
00422          pnABCC_DrvWriteProcessData   = &ABCC_DrvSpiWriteProcessData;
00423          pnABCC_DrvISReadyForWrPd     = &ABCC_DrvSpiIsReadyForWrPd;
00424          pnABCC_DrvISReadyForWriteMessage = &ABCC_DrvSpiIsReadyForWriteMessage;
00425          pnABCC_DrvISReadyForCmd      = &ABCC_DrvSpiIsReadyForCmd;
00426          pnABCC_DrvSetNbrOfCmds       = &ABCC_DrvSpiSetNbrOfCmds;
00427          pnABCC_DrvSetAppStatus       = &ABCC_DrvSpiSetAppStatus;
00428          pnABCC_DrvSetPdSize          = &ABCC_DrvSpiSetPdSize;
00429          pnABCC_DrvSetIntMask         = &ABCC_DrvSpiSetIntMask;
00430          pnABCC_DrvGetWrPdBuffer      = &ABCC_DrvSpiGetWrPdBuffer;
00431          pnABCC_DrvGetModCap          = &ABCC_DrvSpiGetModCap;
00432          pnABCC_DrvGetLedStatus       = &ABCC_DrvSpiGetLedStatus;
00433          pnABCC_DrvGetIntStatus       = &ABCC_DrvSpiGetIntStatus;
00434          pnABCC_DrvGetAnybusState     = &ABCC_DrvSpiGetAnybusState;
00435          pnABCC_DrvReadProcessData    = &ABCC_DrvSpiReadProcessData;
00436          pnABCC_DrvReadMessage        = &ABCC_DrvSpiReadMessage;
00437          pnABCC_DrvIsSupervised       = &ABCC_DrvSpiIsSupervised;
00438          pnABCC_DrvGetAnbStatus       = &ABCC_DrvSpiGetAnbStatus;
00439 
00440          ABCC_iInterruptEnableMask = ABCC_CFG_INT_ENABLE_MASK_SPI;
00441       }
00442       else
00443       {
00444          ABCC_ERROR( ABCC_SEV_FATAL, ABCC_EC_INCORRECT_OPERATING_MODE, (UINT32)bOpmode );
00445       }
00446 
00447       break;
00448 #endif /* End of #if ABCC_CFG_DRV_SPI */
00449 #if( ABCC_CFG_DRV_PARALLEL || ABCC_CFG_DRV_PARALLEL_30 )
00450    case ABP_OP_MODE_8_BIT_PARALLEL:
00451 #if( ABCC_CFG_DRV_PARALLEL )
00452       if( bModuleId == ABP_MODULE_ID_ACTIVE_ABCC30 )
00453 #endif /* End of #if ABCC_CFG_DRV_PARALLEL */
00454       {
00455 #if( ABCC_CFG_DRV_PARALLEL_30 )
00456          ABCC_ISR                   = &ABCC_Par30ISR;
00457          ABCC_RunDriver             = &ABCC_Par30RunDriver;
00458          ABCC_TriggerWrPdUpdate     = &TriggerWrPdUpdateLater;
00459 
00460          pnABCC_DrvInit               = &ABCC_DrvPar30Init;
00461          pnABCC_DrvISR                = &ABCC_DrvPar30ISR;
00462          pnABCC_DrvRunDriverTx        = &ABCC_DrvPar30RunDriverTx;;
00463          pnABCC_DrvRunDriverRx        = &ABCC_DrvPar30RunDriverRx;
00464          pnABCC_DrvWriteMessage       = &ABCC_DrvPar30WriteMessage;
00465          pnABCC_DrvWriteProcessData   = &ABCC_DrvPar30WriteProcessData;
00466          pnABCC_DrvISReadyForWrPd     = &ABCC_DrvPar30IsReadyForWrPd;
00467          pnABCC_DrvISReadyForWriteMessage = &ABCC_DrvPar30IsReadyForWriteMessage;
00468          pnABCC_DrvISReadyForCmd      = &ABCC_DrvPar30IsReadyForCmd;
00469          pnABCC_DrvSetNbrOfCmds       = &ABCC_DrvPar30SetNbrOfCmds;
00470          pnABCC_DrvSetAppStatus       = &ABCC_DrvPar30SetAppStatus;
00471          pnABCC_DrvSetPdSize          = &ABCC_DrvPar30SetPdSize;
00472          pnABCC_DrvSetIntMask         = &ABCC_DrvPar30SetIntMask;
00473          pnABCC_DrvGetWrPdBuffer      = &ABCC_DrvPar30GetWrPdBuffer;
00474          pnABCC_DrvGetModCap          = &ABCC_DrvPar30GetModCap;
00475          pnABCC_DrvGetLedStatus       = &ABCC_DrvPar30GetLedStatus;
00476          pnABCC_DrvGetIntStatus       = &ABCC_DrvPar30GetIntStatus;
00477          pnABCC_DrvGetAnybusState     = &ABCC_DrvPar30GetAnybusState;
00478          pnABCC_DrvReadProcessData    = &ABCC_DrvPar30ReadProcessData;
00479          pnABCC_DrvReadMessage        = &ABCC_DrvPar30ReadMessage;
00480          pnABCC_DrvIsSupervised       = &ABCC_DrvPar30IsSupervised;
00481          pnABCC_DrvGetAnbStatus       = &ABCC_DrvPar30GetAnbStatus;
00482 
00483          ABCC_iInterruptEnableMask = ABCC_CFG_INT_ENABLE_MASK_PAR30;
00484 #else
00485          ABCC_ERROR( ABCC_SEV_FATAL, ABCC_EC_INCORRECT_OPERATING_MODE, (UINT32)bOpmode );
00486 #endif /* End of #if ABCC_CFG_DRV_PARALLEL_30 */
00487          break;
00488       }
00489 
00490       /*
00491       ** If event driven parallel operating mode is enabled and an ABCC 40
00492       ** module is mounted fall through to the 16-bit parallel operating mode
00493       ** case which sets up the event driven parallel operating mode.
00494       */
00495 #endif /* End of #if ABCC_CFG_DRV_PARALLEL or ABCC_CFG_DRV_PARALLEL_30 */
00496 #if( ABCC_CFG_DRV_PARALLEL )
00497    case ABP_OP_MODE_16_BIT_PARALLEL:
00498 
00499       if( bModuleId == ABP_MODULE_ID_ACTIVE_ABCC30 )
00500       {
00501          ABCC_ERROR( ABCC_SEV_FATAL, ABCC_EC_INCORRECT_OPERATING_MODE, (UINT32)bOpmode );
00502 
00503          break;
00504       }
00505 
00506       ABCC_ISR                   = &ABCC_ParISR;
00507       ABCC_RunDriver             = &ABCC_ParRunDriver;
00508       ABCC_TriggerWrPdUpdate     = &TriggerWrPdUpdateNow;
00509 
00510       pnABCC_DrvInit               = &ABCC_DrvParInit;
00511       pnABCC_DrvISR                = &ABCC_DrvParISR;
00512       pnABCC_DrvRunDriverTx        = NULL;
00513       pnABCC_DrvRunDriverRx        = &ABCC_DrvParRunDriverRx;
00514       pnABCC_DrvWriteMessage       = &ABCC_DrvParWriteMessage;
00515       pnABCC_DrvWriteProcessData   = &ABCC_DrvParWriteProcessData;
00516       pnABCC_DrvISReadyForWrPd     = &ABCC_DrvParIsReadyForWrPd;
00517       pnABCC_DrvISReadyForWriteMessage = &ABCC_DrvParIsReadyForWriteMessage;
00518       pnABCC_DrvISReadyForCmd      = &ABCC_DrvParIsReadyForCmd;
00519       pnABCC_DrvSetNbrOfCmds       = &ABCC_DrvParSetNbrOfCmds;
00520       pnABCC_DrvSetAppStatus       = &ABCC_DrvParSetAppStatus;
00521       pnABCC_DrvSetPdSize          = &ABCC_DrvParSetPdSize;
00522       pnABCC_DrvSetIntMask         = &ABCC_DrvParSetIntMask;
00523       pnABCC_DrvGetWrPdBuffer      = &ABCC_DrvParGetWrPdBuffer;
00524       pnABCC_DrvGetModCap          = &ABCC_DrvParGetModCap;
00525       pnABCC_DrvGetLedStatus       = &ABCC_DrvParGetLedStatus;
00526       pnABCC_DrvGetIntStatus       = &ABCC_DrvParGetIntStatus;
00527       pnABCC_DrvGetAnybusState     = &ABCC_DrvParGetAnybusState;
00528       pnABCC_DrvReadProcessData    = &ABCC_DrvParReadProcessData;
00529       pnABCC_DrvReadMessage        = &ABCC_DrvParReadMessage;
00530       pnABCC_DrvIsSupervised       = &ABCC_DrvParIsSupervised;
00531       pnABCC_DrvGetAnbStatus       = &ABCC_DrvParGetAnbStatus;
00532 
00533 #if ABCC_CFG_INT_ENABLED
00534       ABCC_iInterruptEnableMask = ABCC_CFG_INT_ENABLE_MASK_PAR;
00535 
00536 #if ABCC_CFG_SYNC_ENABLE && !ABCC_CFG_USE_ABCC_SYNC_SIGNAL
00537       ABCC_iInterruptEnableMask |= ABP_INTMASK_SYNCIEN;
00538 #endif
00539 #else
00540       ABCC_iInterruptEnableMask = 0;
00541 #endif
00542 
00543       break;
00544 #endif /* End of #if ABCC_CFG_DRV_PARALLEL */
00545    default:
00546 
00547       ABCC_ERROR( ABCC_SEV_FATAL, ABCC_EC_INCORRECT_OPERATING_MODE, (UINT32)bOpmode );
00548 
00549       return( ABCC_EC_INCORRECT_OPERATING_MODE );
00550    }
00551 
00552    if ( !( ( abcc_eMainState == ABCC_DRV_INIT )  ||
00553            ( abcc_eMainState == ABCC_DRV_SHUTDOWN ) ) )
00554    {
00555       ABCC_ERROR(ABCC_SEV_FATAL, ABCC_EC_INCORRECT_STATE, (UINT32)abcc_eMainState );
00556       abcc_eMainState = ABCC_DRV_ERROR;
00557 
00558       return( ABCC_EC_INCORRECT_STATE );
00559    }
00560 
00561    if ( !ABCC_SYS_Init() )
00562    {
00563       return( ABCC_EC_INTERNAL_ERROR );
00564    }
00565 
00566    ABCC_TimerInit();
00567    pnABCC_DrvInit( bOpmode );
00568 
00569    ABCC_LinkInit();
00570    ABCC_SetupInit();
00571 
00572    abcc_bAnbState = 0xff;
00573 
00574    abcc_TmoHandle = ABCC_TimerCreate( SetReadyForCommunicationTmo );
00575 
00576    abcc_pbWrPdBuffer = pnABCC_DrvGetWrPdBuffer();
00577 
00578    if( !ABCC_ModuleDetect() )
00579    {
00580       ABCC_ERROR(ABCC_SEV_WARNING, ABCC_EC_MODULE_NOT_DECTECTED, 0);
00581 
00582       return( ABCC_EC_MODULE_NOT_DECTECTED );
00583    }
00584 
00585 #if( ABCC_CFG_OP_MODE_SETTABLE )
00586    ABCC_SYS_SetOpmode( bOpmode );
00587 #endif
00588 
00589    abcc_fReadyForCommunicationTmo = FALSE;
00590    abcc_fReadyForCommunication = FALSE;
00591 
00592 #if( ABCC_CFG_SYNC_ENABLE && ABCC_CFG_USE_ABCC_SYNC_SIGNAL )
00593    ABCC_SYS_SyncInterruptEnable();
00594 #endif
00595 
00596 #if( ABCC_CFG_INT_ENABLED )
00597    if( IsInterruptInUse() )
00598    {
00599          ABCC_SYS_AbccInterruptEnable();
00600    }
00601 #endif /* End of #if ABCC_CFG_INT_ENABLED */
00602 
00603    abcc_eMainState = ABCC_DRV_WAIT_COMMUNICATION_RDY;
00604 
00605    ABCC_TimerStart( abcc_TmoHandle, lMaxStartupTimeMs );
00606 
00607    return( ABCC_EC_NO_ERROR );
00608 }
00609 
00610 ABCC_CommunicationStateType ABCC_isReadyForCommunication( void )
00611 {
00612    if( abcc_eMainState > ABCC_DRV_WAIT_COMMUNICATION_RDY )
00613    {
00614       return( ABCC_READY_FOR_COMMUNICATION );
00615    }
00616 
00617    if( abcc_eMainState < ABCC_DRV_WAIT_COMMUNICATION_RDY )
00618    {
00619       return( ABCC_NOT_READY_FOR_COMMUNICATION );
00620    }
00621 
00622    if( abcc_fReadyForCommunicationTmo == TRUE )
00623    {
00624       if( IsInterruptInUse() || IsPolledInterruptInUse() )
00625       {
00626          return( ABCC_COMMUNICATION_ERROR );
00627       }
00628       else
00629       {
00630          abcc_fReadyForCommunication = TRUE;
00631       }
00632    }
00633 
00634 #if( !ABCC_CFG_INT_ENABLED ) && ( ABCC_CFG_POLL_ABCC_IRQ_PIN )
00635    if( IsPolledInterruptInUse() )
00636    {
00637       abcc_fReadyForCommunication = ABCC_SYS_IsAbccInterruptActive();
00638    }
00639 #endif
00640 
00641    if( abcc_fReadyForCommunication == TRUE )
00642    {
00643       pnABCC_DrvSetIntMask( ABCC_iInterruptEnableMask );
00644       abcc_eMainState = ABCC_DRV_SETUP;
00645       pnABCC_DrvSetNbrOfCmds( ABCC_CFG_MAX_NUM_APPL_CMDS );
00646 
00647       ABCC_SetupCommands();
00648       return( ABCC_READY_FOR_COMMUNICATION );
00649    }
00650 
00651    return( ABCC_NOT_READY_FOR_COMMUNICATION );
00652 }
00653 
00654 
00655 void ABCC_NewWrPdEvent( void )
00656 {
00657    if( ABCC_GetMainState() == ABCC_DRV_RUNNING )
00658    {
00659       /*
00660       ** Send new "write process data" to the Anybus-CC.
00661       ** The data format of the process data is network specific.
00662       ** The application converts the data accordingly.
00663       */
00664       if ( pnABCC_DrvISReadyForWrPd() )
00665       {
00666          if( ABCC_CbfUpdateWriteProcessData( abcc_pbWrPdBuffer ) )
00667          {
00668             pnABCC_DrvWriteProcessData( abcc_pbWrPdBuffer );
00669 #if( ABCC_CFG_SYNC_MEASUREMENT_IP )
00670             if( ABCC_GetOpmode() == ABP_OP_MODE_SPI )
00671             {
00672                fAbccUserSyncMeasurementIp = TRUE;
00673             }
00674             else
00675             {
00676                ABCC_SYS_GpioReset();
00677             }
00678 #endif
00679          }
00680       }
00681    }
00682 }
00683 
00684 
00685 
00686 void ABCC_TriggerRdPdUpdate( void )
00687 {
00688    void* bpRdPd;
00689 
00690 #if( ABCC_CFG_SYNC_MEASUREMENT_OP )
00691    ABCC_SYS_GpioSet();
00692 #endif
00693 
00694    bpRdPd = pnABCC_DrvReadProcessData();
00695 
00696    if( bpRdPd )
00697    {
00698       if( pnABCC_DrvGetAnybusState() == ABP_ANB_STATE_PROCESS_ACTIVE  )
00699       {
00700          /*
00701          ** The "read process data" is only valid in the PROCESS_ACTIVE state.
00702          ** Retrieve the new "read process data" from the Anybus-CC.
00703          ** The data format of the process data is network specific.
00704          ** Convert it to our native format.
00705          */
00706          ABCC_CbfNewReadPd( bpRdPd );
00707       }
00708    }
00709 
00710 #if( ABCC_CFG_SYNC_MEASUREMENT_OP )
00711    /*
00712    ** This is the Output Valid point (for OuputValidTime = 0). The
00713    ** applications has received data and handled it. Thus we reset the
00714    ** ABCC_CFG_SYNC_MEASUREMENT_OP measurement.
00715    */
00716    ABCC_SYS_GpioReset();
00717 #endif
00718 }
00719 
00720 void ABCC_TriggerReceiveMessage ( void )
00721 {
00722    ABCC_MsgType sRdMsg;
00723    ABCC_MemBufferStatusType eBufferStatus;
00724 
00725    sRdMsg.psMsg = ABCC_LinkReadMessage();
00726 
00727    if( sRdMsg.psMsg == NULL )
00728    {
00729       return;
00730    }
00731 
00732    ABCC_DEBUG_MSG_DATA( "Msg received", sRdMsg.psMsg );
00733 
00734    eBufferStatus = ABCC_MemGetBufferStatus( sRdMsg.psMsg );
00735 
00736    /*
00737    ** A new message is available.
00738    */
00739    if( ABCC_GetLowAddrOct( sRdMsg.psMsg16->sHeader.iCmdReserved ) & ABP_MSG_HEADER_C_BIT )
00740    {
00741       /*
00742       ** The message is a command, let the application respond.
00743       */
00744       ABCC_CbfReceiveMsg( sRdMsg.psMsg );
00745    }
00746    else
00747    {
00748       if( abcc_eMainState == ABCC_DRV_SETUP )
00749       {
00750          /*
00751          ** The message is a reponse to a setup command we have sent.
00752          */
00753          ABCC_DEBUG_MSG_EVENT( "Routing response to setup state machine",
00754                                sRdMsg.psMsg );
00755          ABCC_SetupResponses( sRdMsg.psMsg );
00756 
00757          if ( ABCC_SetupCommands() )
00758          {
00759             abcc_eMainState = ABCC_DRV_RUNNING;
00760          }
00761       }
00762       else
00763       {
00764          ABCC_MsgHandlerFuncType pnMsgHandler = 0;
00765          pnMsgHandler = ABCC_LinkGetMsgHandler( ABCC_GetLowAddrOct( sRdMsg.psMsg16->sHeader.iSourceIdDestObj ) );
00766 
00767          if( pnMsgHandler )
00768          {
00769             ABCC_DEBUG_MSG_EVENT( "Routing response to registered response handler", sRdMsg.psMsg );
00770             pnMsgHandler( sRdMsg.psMsg );
00771          }
00772          else
00773          {
00774             ABCC_DEBUG_MSG_EVENT( "No response handler found", sRdMsg.psMsg );
00775             ABCC_CbfReceiveMsg( sRdMsg.psMsg );
00776          }
00777       }
00778    }
00779 
00780    if( ABCC_MemGetBufferStatus( sRdMsg.psMsg ) == eBufferStatus )
00781    {
00782       /*
00783       ** The status has not been changed while the user processed the response
00784       ** message. Then this buffer shall be freed by the driver.
00785       */
00786       ABCC_ReturnMsgBuffer( &sRdMsg.psMsg );
00787    }
00788 }
00789 
00790 ABCC_ErrorCodeType ABCC_SendCmdMsg( ABP_MsgType*  psCmdMsg, ABCC_MsgHandlerFuncType pnMsgHandler )
00791 {
00792    ABCC_ErrorCodeType eResult;
00793    ABCC_MsgType sMsg;
00794 
00795    sMsg.psMsg = psCmdMsg;
00796 
00797    /*
00798    ** Register function to handle response.
00799    ** Must be done before sending the message to avoid race condition.
00800    */
00801    if( ABCC_LinkMapMsgHandler( ABCC_GetLowAddrOct( sMsg.psMsg16->sHeader.iSourceIdDestObj ),
00802                                pnMsgHandler ) == ABCC_EC_NO_ERROR )
00803    {
00804       eResult = ABCC_LinkWriteMessage( sMsg.psMsg );
00805       if( eResult != ABCC_EC_NO_ERROR )
00806       {
00807          /*
00808          ** Free message handler resource
00809          */
00810          (void)ABCC_LinkGetMsgHandler( ABCC_GetLowAddrOct( sMsg.psMsg16->sHeader.iSourceIdDestObj ) );
00811       }
00812    }
00813    else
00814    {
00815       eResult = ABCC_EC_NO_RESOURCES;
00816 
00817       /*
00818       ** Report error
00819       */
00820       ABCC_ASSERT( FALSE );
00821    }
00822 
00823    return( eResult );
00824 }
00825 
00826 UINT16 ABCC_GetCmdQueueSize( void )
00827 {
00828    return( ABCC_LinkGetNumCmdQueueEntries() );
00829 }
00830 
00831 
00832 ABCC_ErrorCodeType ABCC_SendRespMsg( ABP_MsgType* psMsgResp )
00833 {
00834    return( ABCC_LinkWriteMessage( psMsgResp ) );
00835 }
00836 
00837 ABP_MsgType* ABCC_GetCmdMsgBuffer( void )
00838 {
00839    if( ABCC_GetCmdQueueSize() == 0 )
00840    {
00841       return( NULL );
00842    }
00843    return( ABCC_MemAlloc() );
00844 }
00845 
00846 ABCC_ErrorCodeType ABCC_ReturnMsgBuffer( ABP_MsgType** ppsBuffer )
00847 {
00848    ABCC_LinkFree( ppsBuffer );
00849 
00850    return( ABCC_EC_NO_ERROR );
00851 }
00852 
00853 void ABCC_TakeMsgBufferOwnership( ABP_MsgType* psMsg )
00854 {
00855    ABCC_MemSetBufferStatus( psMsg, ABCC_MEM_BUFSTAT_OWNED );
00856 }
00857 
00858 void ABCC_SetPdSize( const UINT16 iReadPdSize, const UINT16 iWritePdSize )
00859 {
00860    DEBUG_EVENT( ( "New process data sizes RdPd %d WrPd %d\n", iReadPdSize, iWritePdSize ) );
00861    pnABCC_DrvSetPdSize( iReadPdSize, iWritePdSize );
00862 }
00863 
00864 
00865 void ABCC_HWReset( void )
00866 {
00867    DEBUG_EVENT( ( "HW Reset\n" ) );
00868    ABCC_ShutdownDriver();
00869    ABCC_SYS_HWReset();
00870 }
00871 
00872 
00873 void ABCC_ShutdownDriver( void )
00874 {
00875    DEBUG_EVENT( ( " Enter Shutdown state\n" ) );
00876 
00877 #if( ABCC_CFG_SYNC_ENABLE && ABCC_CFG_USE_ABCC_SYNC_SIGNAL )
00878    ABCC_SYS_SyncInterruptDisable();
00879 #endif
00880 
00881 #if( ABCC_CFG_INT_ENABLED )
00882    ABCC_SYS_AbccInterruptDisable();
00883 #endif
00884    ABCC_SYS_Close();
00885    ABCC_TimerDisable();
00886    abcc_eMainState = ABCC_DRV_SHUTDOWN;
00887 }
00888 
00889 
00890 BOOL ABCC_ModuleDetect( void )
00891 {
00892 #if( ABCC_CFG_MOD_DETECT_PINS_CONN )
00893    return( ABCC_SYS_ModuleDetect() );
00894 #else
00895    return( TRUE );
00896 #endif
00897 }
00898 
00899 UINT16 ABCC_ModCap( void )
00900 {
00901    return( pnABCC_DrvGetModCap() );
00902 }
00903 
00904 UINT16 ABCC_LedStatus()
00905 {
00906    return( pnABCC_DrvGetLedStatus() );
00907 }
00908 
00909 UINT8 ABCC_AnbState( void )
00910 {
00911    return( pnABCC_DrvGetAnybusState() );
00912 }
00913 
00914 BOOL ABCC_IsSupervised( void )
00915 {
00916    return( pnABCC_DrvIsSupervised() );
00917 }
00918 
00919 void ABCC_HWReleaseReset( void )
00920 {
00921    ABCC_SYS_HWReleaseReset();
00922 }
00923 
00924 ABP_AppStatusType ABCC_GetAppStatus( void )
00925 {
00926    return( abcc_eAppStatus );
00927 }
00928 
00929 void ABCC_SetAppStatus( ABP_AppStatusType eAppStatus )
00930 {
00931    if( abcc_eAppStatus != eAppStatus )
00932    {
00933       abcc_eAppStatus = eAppStatus;
00934       pnABCC_DrvSetAppStatus( eAppStatus );
00935    }
00936 }
00937 
00938 UINT8 ABCC_ReadModuleId( void )
00939 {
00940 #ifdef ABCC_CFG_ABCC_MODULE_ID
00941    return( ABCC_CFG_ABCC_MODULE_ID );
00942 #else
00943    return( ABCC_SYS_ReadModuleId() );
00944 #endif
00945 }
00946 
00947 void ABCC_RunTimerSystem( const INT16 iDeltaTimeMs )
00948 {
00949    ABCC_TimerTick( iDeltaTimeMs );
00950 }
00951 
00952 
00953 UINT8 ABCC_GetNewSourceId( void )
00954 {
00955    static UINT8 bSourceId = 0;
00956    UINT8 bTempSrcId;
00957    ABCC_PORT_UseCritical();
00958 
00959    do
00960    {
00961       ABCC_PORT_EnterCritical();
00962       bTempSrcId = ++bSourceId;
00963       ABCC_PORT_ExitCritical();
00964    }  while (  ABCC_LinkIsSrcIdUsed( bTempSrcId ) );
00965 
00966    return( bTempSrcId );
00967 }
00968 
00969 UINT8 ABCC_GetOpmode( void )
00970 {
00971 #if( ABCC_CFG_OP_MODE_GETTABLE )
00972    return( ABCC_SYS_GetOpmode() );
00973 #elif ( defined( ABCC_CFG_ABCC_OP_MODE_30 ) &&                                \
00974         defined( ABCC_CFG_ABCC_OP_MODE_40 ) )
00975    UINT8 bModuleId;
00976 
00977    bModuleId = ABCC_ReadModuleId();
00978 
00979    if( bModuleId == ABP_MODULE_ID_ACTIVE_ABCC30 )
00980    {
00981       return( ABCC_CFG_ABCC_OP_MODE_30 );
00982    }
00983    else
00984    {
00985       return( ABCC_CFG_ABCC_OP_MODE_40 );
00986    }
00987 #elif defined( ABCC_CFG_ABCC_OP_MODE_30 )
00988    return( ABCC_CFG_ABCC_OP_MODE_30 );
00989 #elif defined( ABCC_CFG_ABCC_OP_MODE_40 )
00990    return( ABCC_CFG_ABCC_OP_MODE_40 );
00991 #else
00992    /*
00993    ** The user has not configured any way to determine the operating mode
00994    */
00995    #error "No method to determine the operating mode is available. Either set ABCC_CFG_OP_MODE_GETTABLE to TRUE or any of ABCC_CFG_ABCC_OP_MODE_X. See descriptions in abcc_cfg.h for details."
00996 #endif /* End of #if defined( ABCC_CFG_OP_MODE_HW_CONF ) */
00997 }
00998 
00999 
01000 void ABCC_GetAttribute( ABP_MsgType* psMsg,
01001                         UINT8 bObject,
01002                         UINT16 iInstance,
01003                         UINT8 bAttribute,
01004                         UINT8 bSourceId )
01005 {
01006    ABCC_MsgType sMsg;
01007    sMsg.psMsg = psMsg;
01008 
01009    ABCC_SetLowAddrOct( sMsg.psMsg16->sHeader.iSourceIdDestObj, bSourceId ); /* SourceId */
01010    ABCC_SetHighAddrOct( sMsg.psMsg16->sHeader.iSourceIdDestObj, bObject );  /* bObject */
01011    psMsg->sHeader.iInstance = iTOiLe( iInstance );                          /* Instance */
01012    ABCC_SetLowAddrOct(  sMsg.psMsg16->sHeader.iCmdReserved,
01013                   ABP_MSG_HEADER_C_BIT | ABP_CMD_GET_ATTR );                /* Command */
01014 
01015    sMsg.psMsg16->sHeader.iDataSize = 0;                                     /* Data size           */
01016    ABCC_SetLowAddrOct( sMsg.psMsg16->sHeader.iCmdExt0CmdExt1, bAttribute ); /* CmdExt0 (Attribute) */
01017    ABCC_SetHighAddrOct( sMsg.psMsg16->sHeader.iCmdExt0CmdExt1, 0 );         /* CmdExt1 (reserved)  */
01018 }
01019 
01020 void ABCC_SetByteAttribute(ABP_MsgType* psMsg,
01021                            UINT8 bObject,
01022                            UINT16 iInstance,
01023                            UINT8 bAttribute,
01024                            UINT8 bVal,
01025                            UINT8 bSourceId )
01026 {
01027    ABCC_MsgType sMsg;
01028    sMsg.psMsg = psMsg;
01029 
01030    ABCC_SetLowAddrOct( sMsg.psMsg16->sHeader.iSourceIdDestObj, bSourceId );  /* SourceId */
01031    ABCC_SetHighAddrOct( sMsg.psMsg16->sHeader.iSourceIdDestObj, bObject );   /* bObject */
01032    psMsg->sHeader.iInstance = iTOiLe( iInstance );                           /* Instance */
01033    ABCC_SetLowAddrOct(  sMsg.psMsg16->sHeader.iCmdReserved,
01034                   ABP_MSG_HEADER_C_BIT | ABP_CMD_SET_ATTR );                 /* Command */
01035 
01036    sMsg.psMsg16->sHeader.iDataSize = iTOiLe( 1 );                            /* Data size           */
01037    ABCC_SetLowAddrOct( sMsg.psMsg16->sHeader.iCmdExt0CmdExt1, bAttribute );  /* CmdExt0 (Attribute) */
01038    ABCC_SetHighAddrOct( sMsg.psMsg16->sHeader.iCmdExt0CmdExt1, 0 );          /* CmdExt1 (reserved)  */
01039    ABCC_SetLowAddrOct( sMsg.psMsg16->aiData[ 0 ], bVal );                    /* Data                */
01040 }
01041 
01042 void ABCC_SetMsgHeader( ABP_MsgType* psMsg,
01043                         UINT8 bObject,
01044                         UINT16 iInstance,
01045                         UINT8 bAttribute,
01046                         ABP_MsgCmdType eService,
01047                         UINT16 iDataSize,
01048                         UINT8 bSourceId )
01049 {
01050    ABCC_MsgType sMsg;
01051    sMsg.psMsg = psMsg;
01052 
01053    ABCC_SetLowAddrOct( sMsg.psMsg16->sHeader.iSourceIdDestObj, bSourceId );  /* SourceId */
01054    ABCC_SetHighAddrOct( sMsg.psMsg16->sHeader.iSourceIdDestObj, bObject );   /* bObject */
01055    psMsg->sHeader.iInstance = iTOiLe( iInstance );                           /* Instance */
01056    ABCC_SetLowAddrOct(  sMsg.psMsg16->sHeader.iCmdReserved,
01057                         ABP_MSG_HEADER_C_BIT | eService );                   /* Command */
01058 
01059    sMsg.psMsg16->sHeader.iDataSize = iTOiLe( iDataSize );                    /* Data size           */
01060    ABCC_SetLowAddrOct( sMsg.psMsg16->sHeader.iCmdExt0CmdExt1, bAttribute );  /* CmdExt0 (Attribute) */
01061    ABCC_SetHighAddrOct( sMsg.psMsg16->sHeader.iCmdExt0CmdExt1, 0 );          /* CmdExt1 (reserved)  */
01062 }
01063 
01064 ABCC_ErrorCodeType ABCC_VerifyMessage( const ABP_MsgType* psMsg )
01065 {
01066    const ABP_MsgType16* psMsg16 = (const ABP_MsgType16* )psMsg;
01067    if( ABCC_GetLowAddrOct( psMsg16->sHeader.iCmdReserved ) & ABP_MSG_HEADER_E_BIT )
01068    {
01069       return( ABCC_EC_RESP_MSG_E_BIT_SET );
01070    }
01071    return( ABCC_EC_NO_ERROR );
01072 }
01073 
01074 
01075 void SetErrorReporter( ABCC_ErrorReporter nFunc )
01076 {
01077    ErrorReporter = nFunc;
01078 }
01079 
01080 
01081 /*------------------------------------------------------------------------------
01082 ** ABCC_GetDataTypeSizeInBits()
01083 **------------------------------------------------------------------------------
01084 */
01085 UINT16 ABCC_GetDataTypeSizeInBits( UINT8 bDataType )
01086 {
01087    UINT16 iSetBitSize;
01088 
01089    if( ABP_Is_PADx( bDataType ) )
01090    {
01091       iSetBitSize = bDataType - ABP_PAD0;
01092    }
01093    else if ( ABP_Is_BITx( bDataType ) )
01094    {
01095       iSetBitSize = ( ( bDataType - ABP_BIT1 ) + 1 );
01096    }
01097    else
01098    {
01099       iSetBitSize = (UINT16)ABCC_GetDataTypeSize( bDataType );
01100       iSetBitSize *= 8;
01101    }
01102 
01103    return( iSetBitSize );
01104 }
01105 
01106 
01107 
01108 /*------------------------------------------------------------------------------
01109 ** ABCC_GetDataTypeSize()
01110 **------------------------------------------------------------------------------
01111 */
01112 
01113 UINT8 ABCC_GetDataTypeSize( UINT8 bDataType )
01114 {
01115    UINT8 bSize;
01116    switch( bDataType )
01117    {
01118 
01119    case ABP_UINT8:
01120    case ABP_BOOL:
01121    case ABP_SINT8:
01122    case ABP_ENUM:
01123    case ABP_BITS8:
01124    case ABP_CHAR:
01125    case ABP_OCTET:
01126       bSize = ABP_UINT8_SIZEOF;
01127       break;
01128 
01129    case ABP_UINT16:
01130    case ABP_BITS16:
01131    case ABP_SINT16:
01132       bSize = ABP_UINT16_SIZEOF;
01133       break;
01134    case ABP_UINT32:
01135    case ABP_SINT32:
01136    case ABP_BITS32:
01137    case ABP_FLOAT:
01138       bSize = ABP_UINT32_SIZEOF;
01139       break;
01140 
01141    case ABP_SINT64:
01142    case ABP_UINT64:
01143       bSize = ABP_UINT64_SIZEOF;
01144       break;
01145 
01146    case ABP_BIT1:
01147    case ABP_BIT2:
01148    case ABP_BIT3:
01149    case ABP_BIT4:
01150    case ABP_BIT5:
01151    case ABP_BIT6:
01152    case ABP_BIT7:
01153       bSize = ABP_UINT8_SIZEOF;
01154       break;
01155 
01156 
01157    case ABP_PAD1:
01158    case ABP_PAD2:
01159    case ABP_PAD3:
01160    case ABP_PAD4:
01161    case ABP_PAD5:
01162    case ABP_PAD6:
01163    case ABP_PAD7:
01164    case ABP_PAD8:
01165       bSize = ABP_UINT8_SIZEOF;
01166       break;
01167 
01168    case ABP_PAD9:
01169    case ABP_PAD10:
01170    case ABP_PAD11:
01171    case ABP_PAD12:
01172    case ABP_PAD13:
01173    case ABP_PAD14:
01174    case ABP_PAD15:
01175    case ABP_PAD16:
01176       bSize = ABP_UINT16_SIZEOF;
01177       break;
01178    default:
01179       bSize = 0;
01180       break;
01181    }
01182 
01183    return( bSize );
01184 }
01185 
01186 void ABCC_GetMsgString( ABP_MsgType* psMsg, char* pcString, UINT16 iNumChar, UINT16 iOctetOffset )
01187 {
01188    ABCC_PORT_StrCpyToNative( pcString,
01189                              ABCC_GetMsgDataPtr( psMsg ),
01190                              iOctetOffset,
01191                              iNumChar );
01192 }
01193 
01194 void ABCC_SetMsgString( ABP_MsgType* psMsg, const char* pcString, UINT16 iNumChar, UINT16 iOctetOffset )
01195 {
01196    ABCC_PORT_StrCpyToPacked( ABCC_GetMsgDataPtr( psMsg ),
01197                              iOctetOffset,
01198                              pcString,
01199                              iNumChar );
01200 }
01201 
01202 void ABCC_GetMsgData8( ABP_MsgType* psMsg, UINT8* pbData, UINT16 iOctetOffset )
01203 {
01204 #ifdef ABCC_SYS_16_BIT_CHAR
01205    *pbData = 0;
01206 #endif
01207    ABCC_PORT_Copy8( pbData, 0, ABCC_GetMsgDataPtr( psMsg ), iOctetOffset );
01208 }
01209 
01210 void ABCC_SetMsgData8( ABP_MsgType* psMsg, UINT8 bData, UINT16 iOctetOffset )
01211 {
01212    ABCC_PORT_Copy8( ABCC_GetMsgDataPtr( psMsg ), iOctetOffset, &bData, 0 );
01213 }
01214 
01215 void ABCC_GetMsgData16( ABP_MsgType* psMsg, UINT16* piData, UINT16 iOctetOffset )
01216 {
01217    ABCC_PORT_Copy16( piData, 0, ABCC_GetMsgDataPtr( psMsg ), iOctetOffset );
01218    *piData = iLeTOi( *piData );
01219 }
01220 
01221 void ABCC_SetMsgData16( ABP_MsgType* psMsg, UINT16 iData, UINT16 iOctetOffset )
01222 {
01223    iData = iTOiLe( iData );
01224    ABCC_PORT_Copy16( ABCC_GetMsgDataPtr( psMsg ), iOctetOffset, &iData, 0 );
01225 }
01226 
01227 void ABCC_GetMsgData32( ABP_MsgType* psMsg, UINT32* plData, UINT16 iOctetOffset )
01228 {
01229    ABCC_PORT_Copy32( plData, 0, ABCC_GetMsgDataPtr( psMsg ), iOctetOffset );
01230    *plData = lLeTOl( *plData );
01231 }
01232 
01233 void ABCC_SetMsgData32( ABP_MsgType* psMsg, UINT32 lData, UINT16 iOctetOffset )
01234 {
01235    lData = lTOlLe( lData );
01236    ABCC_PORT_Copy32( ABCC_GetMsgDataPtr( psMsg ), iOctetOffset, &lData, 0 );
01237 }
01238 
01239 #if( ABCC_CFG_64BIT_ADI_SUPPORT )
01240 void ABCC_GetMsgData64( ABP_MsgType* psMsg, UINT64* plData, UINT16 iOctetOffset );
01241 {
01242    ABCC_PORT_Copy64( plData, 0, ABCC_GetMsgDataPtr( psMsg ), iOctetOffset );
01243    *plData = lLeTOl64( *plData );
01244 }
01245 
01246 void ABCC_SetMsgData64( ABP_MsgType* psMsg, UINT64 lData, UINT16 iOctetOffset );
01247 {
01248    lData = lTOlLe64( lData );
01249    ABCC_PORT_Copy64( ABCC_GetMsgDataPtr( psMsg ), iOctetOffset, &lData, 0 );
01250 }
01251 #endif