William Kane / Generic

Dependents:   LaserioLib

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers abcc_handler_par.c Source File

abcc_handler_par.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 ** This file implements the ABCC_DunDriver() and ABCC_ISR() routine
00027 ** for parallel operating mode.
00028 ********************************************************************************
00029 ********************************************************************************
00030 */
00031 
00032 #include "abcc_drv_cfg.h"
00033 
00034 #if( ABCC_CFG_DRV_PARALLEL )
00035 
00036 #include "abcc_td.h"
00037 #include "../abcc_drv_if.h"
00038 #include "abp.h"
00039 #include "abcc.h"
00040 #include "../abcc_link.h"
00041 #include "abcc_sys_adapt.h"
00042 #include "../abcc_debug_err.h"
00043 #include "../abcc_handler.h"
00044 #include "../abcc_timer.h"
00045 
00046 /*******************************************************************************
00047 ** Public Globals
00048 ********************************************************************************
00049 */
00050 
00051 /*******************************************************************************
00052 ** Private Globals
00053 ********************************************************************************
00054 */
00055 
00056 #ifndef ABCC_CFG_SYNC_ENABLE
00057 #define ABCC_CFG_SYNC_ENABLE                       ( FALSE )
00058 #endif
00059 
00060 #ifndef ABCC_CFG_USE_ABCC_SYNC_SIGNAL
00061 #define ABCC_CFG_USE_ABCC_SYNC_SIGNAL              ( FALSE )
00062 #endif
00063 
00064 #if ( ABCC_CFG_INT_ENABLE_MASK_PAR & ABP_INTMASK_SYNCIEN )
00065 #error "Use ABCC_CFG_USE_ABCC_SYNC_SIGNAL define in abcc_drv_cfg.h to choose sync interrupt source. Do not use ABP_INTMASK_SYNCIEN"
00066 #endif
00067 
00068 #ifndef ABCC_CFG_HANDLE_INT_IN_ISR_MASK
00069 #define ABCC_CFG_HANDLE_INT_IN_ISR_MASK                ( 0 )
00070 #endif
00071 
00072 /*******************************************************************************
00073 ** Private Services
00074 ********************************************************************************
00075 */
00076 
00077 /*------------------------------------------------------------------------------
00078 ** Translates the ABP Interrupt status register value to the driver's ISR Event
00079 ** bit definitions (ABCC_ISR_EVENT_X).
00080 **------------------------------------------------------------------------------
00081 ** Arguments:
00082 **    iIntStatus - ABP Interrupt status register value
00083 **
00084 ** Returns:
00085 **    Bit field composed of ABCC_ISR_EVENT_X bit definitions
00086 **------------------------------------------------------------------------------
00087 */
00088 static UINT16 AbpIntStatusToAbccIsrEvent( UINT16 iIntStatus )
00089 {
00090    UINT16 iAbccIsrEvents;
00091 
00092    iAbccIsrEvents = 0;
00093 
00094    if( iIntStatus & ABP_INTSTATUS_RDPDI )
00095    {
00096       iAbccIsrEvents |= ABCC_ISR_EVENT_RDPD;
00097    }
00098 
00099    if( iIntStatus & ABP_INTSTATUS_RDMSGI )
00100    {
00101       iAbccIsrEvents |= ABCC_ISR_EVENT_RDMSG;
00102    }
00103 
00104    if( ( iIntStatus & ABP_INTSTATUS_WRMSGI ) ||
00105        ( iIntStatus & ABP_INTSTATUS_ANBRI ) )
00106    {
00107       iAbccIsrEvents |= ABCC_ISR_EVENT_WRMSG;
00108    }
00109 
00110    if( iIntStatus & ABP_INTSTATUS_STATUSI )
00111    {
00112       iAbccIsrEvents |= ABCC_ISR_EVENT_STATUS;
00113    }
00114 
00115    return( iAbccIsrEvents );
00116 }
00117 
00118 /*******************************************************************************
00119 ** Public Services
00120 ********************************************************************************
00121 */
00122 
00123 /*------------------------------------------------------------------------------
00124 ** ABCC_RunDriver()
00125 **------------------------------------------------------------------------------
00126 */
00127 ABCC_ErrorCodeType ABCC_ParRunDriver( void )
00128 {
00129    ABCC_MainStateType eMainState = ABCC_GetMainState();
00130 
00131    if( eMainState < ABCC_DRV_SETUP )
00132    {
00133       if( eMainState != ABCC_DRV_ERROR )
00134       {
00135          ABCC_ERROR( ABCC_SEV_WARNING, ABCC_EC_INCORRECT_STATE, 0 );
00136          ABCC_SetMainStateError();
00137       }
00138 
00139       return( ABCC_EC_INCORRECT_STATE );
00140    }
00141 
00142    if( ( ABCC_iInterruptEnableMask & ( ABP_INTMASK_WRMSGIEN | ABP_INTMASK_ANBRIEN ) ) == 0 )
00143    {
00144       ABCC_LinkCheckSendMessage();
00145    }
00146 
00147    if( ( ABCC_iInterruptEnableMask & ABP_INTMASK_RDPDIEN ) == 0 )
00148    {
00149       ABCC_TriggerRdPdUpdate();
00150    }
00151 
00152    if( ( ABCC_iInterruptEnableMask & ABP_INTMASK_STATUSIEN ) == 0 )
00153    {
00154       ABCC_TriggerAnbStatusUpdate();
00155    }
00156 
00157    if( ( ABCC_iInterruptEnableMask & ABP_INTMASK_RDMSGIEN ) == 0 )
00158    {
00159       ABCC_TriggerReceiveMessage();
00160    }
00161 
00162    return( ABCC_EC_NO_ERROR );
00163 }
00164 #if( ABCC_CFG_INT_ENABLED )
00165 void ABCC_ParISR( void )
00166 {
00167    UINT16 iIntStatus;
00168    UINT16 iIntToHandleInISR;
00169    UINT16 iEventToHandleInCbf;
00170    ABCC_MainStateType eMainState;
00171 
00172    eMainState = ABCC_GetMainState();
00173 
00174    /*
00175    ** Let the driver handle the interrupt and clear the interrupt register.
00176    */
00177    iIntStatus = pnABCC_DrvISR();
00178 
00179    if( eMainState < ABCC_DRV_WAIT_COMMUNICATION_RDY )
00180    {
00181       return;
00182    }
00183 
00184    if( eMainState == ABCC_DRV_WAIT_COMMUNICATION_RDY )
00185    {
00186       ABCC_SetReadyForCommunication();
00187       return;
00188    }
00189 
00190    /*
00191    ** Only handle event defined in ABCC_CFG_HANDLE_INT_IN_ISR_MASK
00192    ** Special case for sync. If sync is supported and the sync signal
00193    ** is not used.
00194    */
00195 #if( ABCC_CFG_SYNC_ENABLE && !ABCC_CFG_USE_ABCC_SYNC_SIGNAL )
00196    iIntToHandleInISR = iIntStatus & ( ABCC_CFG_HANDLE_INT_IN_ISR_MASK | ABP_INTSTATUS_SYNCI );
00197 
00198    if( iIntToHandleInISR & ABP_INTSTATUS_SYNCI )
00199    {
00200       ABCC_CbfSyncIsr();
00201    }
00202 #else
00203    iIntToHandleInISR = iIntStatus & ABCC_CFG_HANDLE_INT_IN_ISR_MASK;
00204 #endif
00205 
00206 
00207    if( iIntToHandleInISR & ABP_INTSTATUS_RDPDI )
00208    {
00209       ABCC_TriggerRdPdUpdate();
00210    }
00211 
00212    if( iIntToHandleInISR & ABP_INTSTATUS_STATUSI )
00213    {
00214       ABCC_TriggerAnbStatusUpdate();
00215    }
00216 
00217    if( iIntToHandleInISR & ABP_INTSTATUS_RDMSGI )
00218    {
00219       ABCC_TriggerReceiveMessage();
00220    }
00221 
00222    if( ( iIntToHandleInISR & ABP_INTSTATUS_WRMSGI ) ||
00223        ( iIntToHandleInISR & ABP_INTSTATUS_ANBRI ) )
00224    {
00225       /*
00226       ** Check if there is something in the queue to be sent.
00227       */
00228       ABCC_LinkCheckSendMessage();
00229    }
00230 
00231    if( ( iIntStatus & ~ABCC_CFG_HANDLE_INT_IN_ISR_MASK ) != 0 )
00232    {
00233       iEventToHandleInCbf = AbpIntStatusToAbccIsrEvent( iIntStatus & ~ABCC_CFG_HANDLE_INT_IN_ISR_MASK );
00234 
00235       if( iEventToHandleInCbf != 0 )
00236       {
00237          ABCC_CbfEvent( iEventToHandleInCbf );
00238       }
00239    }
00240 }
00241 #else
00242 void ABCC_ParISR( void )
00243 {
00244    ABCC_ERROR( ABCC_SEV_WARNING, ABCC_EC_INTERNAL_ERROR, 0);
00245 }
00246 #endif
00247 
00248 #endif /* ABCC_CFG_DRV_PARALLEL */
00249 
00250 /*******************************************************************************
00251 ** Public Services
00252 ********************************************************************************
00253 */
00254 
00255 /*******************************************************************************
00256 ** Tasks
00257 ********************************************************************************
00258 */