⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 canoperrors.h

📁 开放源码的CanOpen源码(C)
💻 H
字号:
/*******************************************************************************

    Errors.h - Header for error handling
    
    Copyright (C) 2004  Janez Paternoster, Slovenia

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


    Author: janez.paternoster@siol.net

    History:
    2004/06/25 [JP]  File Created
    2004/08/09 [JP]  Added ERROR_isr_timer_overflow and changed ERROR_REGISTER_BIT0_CONDITION

********************************************************************************
      
      Principle of error handling

      Description of error handling:
         If somewhere in program occures error, ErrorReport() function has to be
         called with error flag bit and Error code. If that error is being 
         repaired, call ErrorReset(). Functions sets(resets) appropriate bit
         in ODE_ErrorStatusBits array and (if free) writes to EmergencyErrorCode.
         Every emergency message is sent only first time, when bit is set.
         Functions are fast, so other error code executes from main():
            - if CheckErrors is set:
               - calculate error register (OD 0x1001);
            - if EmergencyToSend is set:
               - send emergency message;
               - write to history (OD 0x1003);
         
         Emergency message has 5 bytes of manufacturer specific error field.
         This field can be used for send information from ODE_ErrorStatusBits array.
         
         If Error register is non-zero, node can be set to pre-operational state.
         
         Error handling can also be used with other user program code.

****** standards ***************************************************************

   Error register 0x1001 (ds-301):
   bit      mandatory/opt      description
   -----------------------------------------------------------------------------
   0        M                  generic error
   1        O                  current
   2        O                  voltage
   3        O                  temperature
   4        O                  communication error (overrun, error state)
   5        O                  device profile specific
   6        O                  Reserved (always 0)
   7        O                  manufacturer specific
   
   
   Emergency error codes (ds-301):
   error code       description
   -----------------------------------------------------------------------------
   00xx             Error Reset or No Error
   10xx             Generic Error
   20xx             Current
   21xx             Current, device input side
   22xx             Current inside the device
   23xx             Current, device output side
   30xx             Voltage
   31xx             Mains Voltage
   32xx             Voltage inside the device
   33xx             Output Voltage
   40xx             Temperature
   41xx             Ambient Temperature
   42xx             Device Temperature
   50xx             Device Hardware
   60xx             Device Software
   61xx             Internal Software
   62xx             User Software
   63xx             Data Set
   70xx             Additional Modules
   80xx             Monitoring
   81xx             Communication
   8110             CAN Overrun (Objects lost)
   8120             CAN in Error Passive Mode
   8130             Life Guard Error or Heartbeat Error
   8140             recovered from bus off
   8150             Transmit COB-ID collision
   82xx             Protocol Error
   8210             PDO not processed due to length error
   8220             PDO length exceeded
   90xx             External Error
   F0xx             Additional Functions
   FFxx             Device specific
   
   
   Emergency error codes (ds-401):
   error code       description
   -----------------------------------------------------------------------------
   2310             Current at outputs too high (overload)
   2320             Short circuit at outputs
   2330             Load dump at outputs
   3110             Input voltage too high
   3120             Input voltage too low
   3210             Internal voltage too high
   3220             Internal voltage too low
   3310             Output voltage too high
   3320             Output voltage too low

*******************************************************************************/

#ifndef _ERRORS_H
#define _ERRORS_H

/***** Table of standard error codes (DS 301) *********************************/
//Each error code value corresponds one error bit
   #define ERROR_CODES {                                                   \
         0x0000, 0x6100, 0x6110, 0x6120, 0x6000, 0x6300, 0     , 0x8100,   \
         0x8110, 0x8140, 0x8120, 0x8120, 0x8110, 0x8110, 0x8130, 0x8100,   \
         0     , 0     , 0     , 0     , 0     , 0     , 0     , 0     ,   \
         0     , 0     , 0     , 0     , 0     , 0     , 0     , 0     ,   \
         0x8200, 0x8200, 0x8200, 0x8200, 0x8200, 0x8210, 0x0000, 0         }
         
         
/***** definitions of specific error bits *************************************/
//byte 0, important generic and communication errors for CANopen
   #define ERROR_NO_ERROR                             0x00
   #define ERROR_ErrorReport_ParametersNotSupp        0x01
   #define ERROR_isr_low_WrongInterrupt               0x02
   #define ERROR_wrong_PDO_mapping                    0x03
   #define ERROR_isr_timer_overflow                   0x04
   #define ERROR_WrongNodeIDorBitRate                 0x05

   #define ERROR_TPDO_OUTSIDE_WINDOW                  0x07
//byte 1, important communication errors
   #define ERROR_CAN_RXB_OVERFLOW                     0x08
   #define ERROR_CAN_TX_BUS_OFF                       0x09
   #define ERROR_CAN_TX_BUS_PASSIVE                   0x0A
   #define ERROR_CAN_RX_BUS_PASSIVE                   0x0B
   #define ERROR_CanSendPDO_Overflow                  0x0C
   #define ERROR_CanSendOther_Overflow                0x0D
   #define ERROR_HEARTBEAT_CONSUMER                   0x0E
   #define ERROR_SYNC_TIME_OUT                        0x0F
//byte 2 important user defined errors

//byte 3 user defined errors, not important

//byte 4, protocol errors, not important
   #define ERROR_CO_RXMSG_NMTlength                   0x20
   #define ERROR_CO_RXMSG_NMTcmd                      0x21
   #define ERROR_CO_RXMSG_HeartBeatLength             0x22
   #define ERROR_CO_RXMSG_SyncLength                  0x23
   #define ERROR_CO_RXMSG_SDOlength                   0x24
   #define ERROR_CO_RXMSG_PDOlength                   0x25
   #define ERROR_CAN_BUS_WARNING                      0x26



/***** other defines **********************************************************/
   #define ERROR_BIT_READ(error_bit)   (ODE_ErrorStatusBits[error_bit>>3] & (1<<(error_bit & 0x07)))

//calculation of Error register 0x1001:
   //generic error
   #define ERROR_REGISTER_BIT0_CONDITION (ODE_ErrorStatusBits[0] & 0x3E)
   //communication error
   #define ERROR_REGISTER_BIT4_CONDITION (ODE_ErrorStatusBits[1] || (ODE_ErrorStatusBits[0]&0x80))
   //device profile specific
   #define ERROR_REGISTER_BIT5_CONDITION (ODE_ErrorStatusBits[0] & 0x00)
   //manufacturer specific
   #define ERROR_REGISTER_BIT7_CONDITION (ODE_ErrorStatusBits[2])
   
//Defines for bytes 5...8 in emergency message
   #define ERROR_EMERGENCY_BYTE5    ODE_ErrorStatusBits[0]
   #define ERROR_EMERGENCY_BYTE6    ODE_ErrorStatusBits[1]
   #define ERROR_EMERGENCY_BYTE7    ODE_ErrorStatusBits[2]
   #define ERROR_EMERGENCY_BYTE8    ODE_ErrorStatusBits[3]

/***** Functions **************************************************************/
   //Code is optional value, send as 4-th byte in Emergency message
   //if error occures, call this function with appropriate bit
   void ErrorReport(unsigned char ErrorBit, unsigned char Code);
   //if error is solved, call this function
   void ErrorReset(unsigned char ErrorBit, unsigned char Code);

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -