Official support library for using mbed as a programmable coprocessor in the Innomatix DAP-III+ telematics platform

Committer:
root@developer-sjc-cyan-compiler.local.mbed.org
Date:
Wed Sep 06 19:19:37 2017 +0000
Revision:
12:3d37c8a7be2b
Parent:
11:b28c0d6773bf
Added tag v1.0.7 for changeset b28c0d6773bf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Innomatix 11:b28c0d6773bf 1 /*******************************************************************
Innomatix 11:b28c0d6773bf 2 *
Innomatix 11:b28c0d6773bf 3 * File: InnomatixCanAPI.h
Innomatix 11:b28c0d6773bf 4 *
Innomatix 11:b28c0d6773bf 5 * Description: Simple CAN API for Innomatix Coprocessor applications
Innomatix 11:b28c0d6773bf 6 *
Innomatix 11:b28c0d6773bf 7 * Copyright 2015 Innomatix, LLC., All Rights Reserved
Innomatix 11:b28c0d6773bf 8 *
Innomatix 11:b28c0d6773bf 9 * THIS DOCUMENT AND ITS CONTENTS ARE INTELLECTUAL PROPERTY
Innomatix 11:b28c0d6773bf 10 * OF INNOMATIX, LLC. ANY DUPLICATION IN PART OR WHOLE
Innomatix 11:b28c0d6773bf 11 * WITHOUT PRIOR WRITTEN CONSENT IS STRICTLY PROHIBITED.
Innomatix 11:b28c0d6773bf 12 *
Innomatix 11:b28c0d6773bf 13 *******************************************************************/
Innomatix 11:b28c0d6773bf 14
Innomatix 11:b28c0d6773bf 15 #ifndef _INNOMATIX_CAN_API_H
Innomatix 11:b28c0d6773bf 16 #define _INNOMATIX_CAN_API_H
Innomatix 11:b28c0d6773bf 17
Innomatix 11:b28c0d6773bf 18 #ifdef __cplusplus
Innomatix 11:b28c0d6773bf 19 extern "C"
Innomatix 11:b28c0d6773bf 20 {
Innomatix 11:b28c0d6773bf 21 #endif
Innomatix 11:b28c0d6773bf 22 /*************************************************/
Innomatix 11:b28c0d6773bf 23
Innomatix 11:b28c0d6773bf 24 typedef enum
Innomatix 11:b28c0d6773bf 25 {
Innomatix 11:b28c0d6773bf 26 canSuccess, // 0
Innomatix 11:b28c0d6773bf 27 canInvalidChannel, // 1
Innomatix 11:b28c0d6773bf 28 canInvalidSpeed, // 2
Innomatix 11:b28c0d6773bf 29 canInvalidIdentifier, // 3
Innomatix 11:b28c0d6773bf 30 canInvalidLength, // 4
Innomatix 11:b28c0d6773bf 31 canNoData, // 5
Innomatix 11:b28c0d6773bf 32 canNotInitialized, // 6
Innomatix 11:b28c0d6773bf 33 canGeneralError // N
Innomatix 11:b28c0d6773bf 34 }CanResults_e;
Innomatix 11:b28c0d6773bf 35
Innomatix 11:b28c0d6773bf 36 typedef enum
Innomatix 11:b28c0d6773bf 37 {
Innomatix 11:b28c0d6773bf 38 canChDAP3, // CAN 3 interface on the DAP connector or wiring harness
Innomatix 11:b28c0d6773bf 39 canChDAP4 // CAN 4 interface on the DAP connector or wiring harness
Innomatix 11:b28c0d6773bf 40 }CanChannel_e;
Innomatix 11:b28c0d6773bf 41 static const char *CanChannelName[] = {"CanChDAP3", "CanChDAP4"};
Innomatix 11:b28c0d6773bf 42
Innomatix 11:b28c0d6773bf 43
Innomatix 11:b28c0d6773bf 44 typedef enum
Innomatix 11:b28c0d6773bf 45 {
Innomatix 11:b28c0d6773bf 46 canFormatStandard, // A standard, 11-bit identifier
Innomatix 11:b28c0d6773bf 47 canFormatExtended, // An extended, 29-bit identifier
Innomatix 11:b28c0d6773bf 48 }CanFormat_e;
Innomatix 11:b28c0d6773bf 49
Innomatix 11:b28c0d6773bf 50 typedef struct
Innomatix 11:b28c0d6773bf 51 {
Innomatix 11:b28c0d6773bf 52 int TxMessageCount;
Innomatix 11:b28c0d6773bf 53 int RxMessageCount;
Innomatix 11:b28c0d6773bf 54
Innomatix 11:b28c0d6773bf 55 // Increments when the internal message receive buffer is full and another message is received
Innomatix 11:b28c0d6773bf 56 int OverflowCount;
Innomatix 11:b28c0d6773bf 57 }StatisticsStruct_t, *StatisticsStruct_p;
Innomatix 11:b28c0d6773bf 58
Innomatix 11:b28c0d6773bf 59
Innomatix 11:b28c0d6773bf 60 typedef struct
Innomatix 11:b28c0d6773bf 61 {
Innomatix 11:b28c0d6773bf 62 int Id;
Innomatix 11:b28c0d6773bf 63 int DataLen;
Innomatix 11:b28c0d6773bf 64 int Timestamp;
Innomatix 11:b28c0d6773bf 65 CanFormat_e Format;
Innomatix 11:b28c0d6773bf 66 unsigned char Data[ 8 ];
Innomatix 11:b28c0d6773bf 67 }CanMessage_t, *CanMessage_p;
Innomatix 11:b28c0d6773bf 68
Innomatix 11:b28c0d6773bf 69
Innomatix 11:b28c0d6773bf 70 /**
Innomatix 11:b28c0d6773bf 71 * These functions are the event handlers for incoming CAN messages.
Innomatix 11:b28c0d6773bf 72 * They buffer the messages so they can be retrieved (by the application) later
Innomatix 11:b28c0d6773bf 73 *
Innomatix 11:b28c0d6773bf 74 * The mechanics of the API require that the application assign the event
Innomatix 11:b28c0d6773bf 75 * handler rather than take care of it internally.
Innomatix 11:b28c0d6773bf 76 * Example:
Innomatix 11:b28c0d6773bf 77 * CAN can0( p9, p10 );
Innomatix 11:b28c0d6773bf 78 * CAN can1( p30, p29 );
Innomatix 11:b28c0d6773bf 79 *
Innomatix 11:b28c0d6773bf 80 * CanInit( &can0, &can1 );
Innomatix 11:b28c0d6773bf 81 * can0.attach( OnReceiveCanZero );
Innomatix 11:b28c0d6773bf 82 * Can1.attach( OnReceiveCanOne );
Innomatix 11:b28c0d6773bf 83 *
Innomatix 11:b28c0d6773bf 84 * while( something )
Innomatix 11:b28c0d6773bf 85 * result = CanReceive( canChDAP3, ... )
Innomatix 11:b28c0d6773bf 86 *
Innomatix 11:b28c0d6773bf 87 ************************************************************************/
Innomatix 11:b28c0d6773bf 88 void OnReceiveCanZero( void );
Innomatix 11:b28c0d6773bf 89 void OnReceiveCanOne( void );
Innomatix 11:b28c0d6773bf 90
Innomatix 11:b28c0d6773bf 91
Innomatix 11:b28c0d6773bf 92 /**
Innomatix 11:b28c0d6773bf 93 * This function initializes the API and the designated CAN interface.
Innomatix 11:b28c0d6773bf 94 * Return Values:
Innomatix 11:b28c0d6773bf 95 * Success - the API was initialized and the channel is ready to use.
Innomatix 11:b28c0d6773bf 96 * InvalidChannel - the specified channel is not supported
Innomatix 11:b28c0d6773bf 97 * InvalidSpeed - the specified network speed is not supported
Innomatix 11:b28c0d6773bf 98 * GeneralError - an unknown or unspecified error has occurred
Innomatix 11:b28c0d6773bf 99 *************************************************************************/
Innomatix 11:b28c0d6773bf 100 CanResults_e CanInit( CAN *Can0, CAN *Can1 );
Innomatix 11:b28c0d6773bf 101
Innomatix 11:b28c0d6773bf 102 /**
Innomatix 11:b28c0d6773bf 103 * This function opens the CAN channel at the specified baud rate and
Innomatix 11:b28c0d6773bf 104 * begins receiving messages.
Innomatix 11:b28c0d6773bf 105 * Return Values:
Innomatix 11:b28c0d6773bf 106 * Success - the API was initialized and the channel is ready to use.
Innomatix 11:b28c0d6773bf 107 * InvalidChannel - the specified channel is not supported
Innomatix 11:b28c0d6773bf 108 * InvalidSpeed - the specified network speed is not supported
Innomatix 11:b28c0d6773bf 109 * GeneralError - an unknown or unspecified error has occurred
Innomatix 11:b28c0d6773bf 110 *************************************************************************/
Innomatix 11:b28c0d6773bf 111 CanResults_e CanOpen( CanChannel_e Channel, int Speed );
Innomatix 11:b28c0d6773bf 112
Innomatix 11:b28c0d6773bf 113
Innomatix 11:b28c0d6773bf 114 /**
Innomatix 11:b28c0d6773bf 115 * This function disables the designated CAN interface.
Innomatix 11:b28c0d6773bf 116 *************************************************************************/
Innomatix 11:b28c0d6773bf 117 void CanClose( CanChannel_e Channel );
Innomatix 11:b28c0d6773bf 118
Innomatix 11:b28c0d6773bf 119
Innomatix 11:b28c0d6773bf 120 /**
Innomatix 11:b28c0d6773bf 121 * Allow the client to send a message on the CAN bus.
Innomatix 11:b28c0d6773bf 122 * Return Values:
Innomatix 11:b28c0d6773bf 123 * Success - the message was sent
Innomatix 11:b28c0d6773bf 124 * InvalidChannel - the specified channel is not supported
Innomatix 11:b28c0d6773bf 125 * InvalidIdentifier - the provided message id is not a valid for the specified format
Innomatix 11:b28c0d6773bf 126 * InvalidLength - more than 8 bytes of data were indicated
Innomatix 11:b28c0d6773bf 127 * GeneralError - an unknown or unspecified error has occurred
Innomatix 11:b28c0d6773bf 128 *************************************************************************/
Innomatix 11:b28c0d6773bf 129 CanResults_e CanSend( CanChannel_e Channel, unsigned long Id, CanFormat_e Format, const unsigned char *Data, char DLen );
Innomatix 11:b28c0d6773bf 130
Innomatix 11:b28c0d6773bf 131
Innomatix 11:b28c0d6773bf 132 /**
Innomatix 11:b28c0d6773bf 133 * Allow the client to get a message from the CAN bus.
Innomatix 11:b28c0d6773bf 134 * Return Values:
Innomatix 11:b28c0d6773bf 135 * Success - a message was retrieved, the parameters hold the message values.
Innomatix 11:b28c0d6773bf 136 * InvalidChannel - the specified channel is not supported
Innomatix 11:b28c0d6773bf 137 * NoData - no message is available on the requested channel
Innomatix 11:b28c0d6773bf 138 * GeneralError - an unknown or unspecified error has occurred
Innomatix 11:b28c0d6773bf 139 *************************************************************************/
Innomatix 11:b28c0d6773bf 140 CanResults_e CanReceive( CanChannel_e Channel, unsigned long *Timestamp, unsigned long *Id, CanFormat_e *Format, unsigned char *Data, char *DLen );
Innomatix 11:b28c0d6773bf 141
Innomatix 11:b28c0d6773bf 142
Innomatix 11:b28c0d6773bf 143 /**
Innomatix 11:b28c0d6773bf 144 * Allow the client to retrieve statistics about the CAN interface.
Innomatix 11:b28c0d6773bf 145 *
Innomatix 11:b28c0d6773bf 146 * Return Values:
Innomatix 11:b28c0d6773bf 147 * Success - statistics were retrieved
Innomatix 11:b28c0d6773bf 148 * InvalidChannel - the specified channel is not supported
Innomatix 11:b28c0d6773bf 149 * GeneralError - an unknown or unspecified error has occurred
Innomatix 11:b28c0d6773bf 150 *************************************************************************/
Innomatix 11:b28c0d6773bf 151 CanResults_e CanStatistics( CanChannel_e Channel, StatisticsStruct_t *Stats );
Innomatix 11:b28c0d6773bf 152
Innomatix 11:b28c0d6773bf 153
Innomatix 11:b28c0d6773bf 154 /**
Innomatix 11:b28c0d6773bf 155 * Flush the Rx buffer - all messages are discarded, Rx and Overflow stats are cleared
Innomatix 11:b28c0d6773bf 156 *
Innomatix 11:b28c0d6773bf 157 * Return Values:
Innomatix 11:b28c0d6773bf 158 * Success - statistics were retrieved
Innomatix 11:b28c0d6773bf 159 * InvalidChannel - the specified channel is not supported
Innomatix 11:b28c0d6773bf 160 * GeneralError - an unknown or unspecified error has occurred
Innomatix 11:b28c0d6773bf 161 *************************************************************************/
Innomatix 11:b28c0d6773bf 162 CanResults_e CanFlush( CanChannel_e Channel );
Innomatix 11:b28c0d6773bf 163
Innomatix 11:b28c0d6773bf 164
Innomatix 11:b28c0d6773bf 165 /*************************************************/
Innomatix 11:b28c0d6773bf 166 #ifdef __cplusplus
Innomatix 11:b28c0d6773bf 167 }
Innomatix 11:b28c0d6773bf 168 #endif
Innomatix 11:b28c0d6773bf 169
Innomatix 11:b28c0d6773bf 170 #endif /* _INNOMATIX_CAN_API_H */