include/emcy.h
author mwildbolz
Mon, 01 Oct 2012 17:04:34 +0200
changeset 751 d005211221c7
parent 529 c171e11707c5
permissions -rw-r--r--
Changed call to sleep function because it gets redefined when using RTAI_LXRT
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     1
/*
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     3
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     5
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     6
See COPYING file for copyrights details.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     7
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    12
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    16
Lesser General Public License for more details.
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    17
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    21
*/
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    22
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    23
/*!
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    24
** @file   emcy.h
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    25
** @author Luis Jimenez
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    26
** @date   Wed Sep 26 2007
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    27
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    28
** @brief Declarations of the functions that manage EMCY (emergency) messages
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    29
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    30
**
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    31
*/
528
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    32
 
529
c171e11707c5 Second time, Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 528
diff changeset
    33
/** @defgroup emcyo Emergency Object
c171e11707c5 Second time, Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 528
diff changeset
    34
 *  Emergency Object is used to communicate device and application failures.
c171e11707c5 Second time, Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 528
diff changeset
    35
 *  @ingroup comobj
c171e11707c5 Second time, Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 528
diff changeset
    36
 */
c171e11707c5 Second time, Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 528
diff changeset
    37
					 
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    38
#ifndef __emcy_h__
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    39
#define __emcy_h__
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    40
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    41
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    42
#include <applicfg.h>
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    43
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    44
/* The error states 
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    45
 * ----------------- */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    46
typedef enum enum_errorState {
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    47
  Error_free		= 0x00, 
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    48
  Error_occurred	= 0x01
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    49
} e_errorState;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    50
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    51
typedef struct {
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    52
	UNS16 errCode;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    53
	UNS8 errRegMask;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    54
	UNS8 active;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    55
} s_errors;
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    56
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    57
#include "data.h"
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    58
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    59
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 296
diff changeset
    60
typedef void (*post_emcy_t)(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg);
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 296
diff changeset
    61
void _post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg);
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    62
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    63
/*************************************************************************
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    64
 * Functions
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    65
 *************************************************************************/
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    66
528
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    67
/** 
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    68
 * @ingroup emcy
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    69
 * @brief Sets a new error with code errCode. Also sets corresponding bits in Error register (1001h)
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    70
 * @param *d Pointer on a CAN object data structure
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    71
 * @param errCode The error code
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    72
 * @param errRegMask
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    73
 * @param addInfo
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    74
 * @return
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    75
 */
296
03f2b8b8cb0b Solved a small bug in emcy.c (errRegMask was always '1' in EMCY_setError.
luis
parents: 284
diff changeset
    76
UNS8 EMCY_setError(CO_Data* d, UNS16 errCode, UNS8 errRegMask, UNS16 addInfo);
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    77
528
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    78
/**
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    79
 * @ingroup emcy 
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    80
 * @brief Indicates it has recovered from error errCode. Also clears corresponding bits in Error register (1001h)
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    81
 * @param *d Pointer on a CAN object data structure
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    82
 * @param errCode The error code
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    83
 */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    84
void EMCY_errorRecovered(CO_Data* d, UNS16 errCode);
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    85
528
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    86
/**
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    87
 * @ingroup emcy 
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    88
 * @brief Start EMCY consumer and producer
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    89
 * @param *d Pointer on a CAN object data structure
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    90
 */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    91
void emergencyInit(CO_Data* d);
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    92
528
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    93
/** 
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    94
 * @ingroup emcy
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    95
 * @brief Stop EMCY producer and consumer
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
    96
 * @param *d Pointer on a CAN object data structure 
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    97
 */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    98
void emergencyStop(CO_Data* d);
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
    99
528
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
   100
/** 
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
   101
 * @ingroup emcy
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
   102
 * @brief This function is responsible to process an EMCY canopen-message
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
   103
 * @param *d Pointer on a CAN object data structure 
0a30e161d63c Re-write doxygen tags in headers files to generate User API documentation
greg
parents: 378
diff changeset
   104
 * @param *m Pointer on the CAN-message which has to be analysed.
284
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   105
 */
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   106
void proceedEMCY(CO_Data* d, Message* m);
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   107
24bf3d692993 Implemented EMCY objects.
luis
parents:
diff changeset
   108
#endif /*__emcy_h__ */