2 * @copyright Copyright (c) 2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __CAN_MNG_API_H__
18 #define __CAN_MNG_API_H__
28 #define UINT8 unsigned char
31 #define UINT16 unsigned short
37 #define UINT32 unsigned int
40 /*------------------------------------------*/
42 /*------------------------------------------*/
43 #if defined(CAN_MNG_API_FORCE_DEBUG)
44 #define CAN_MNG_API_LOGT(fmt,...) fprintf(stderr, "[T][CAN_API] %s(%s)(%d):" fmt "\n", __FILE__, __func__, __LINE__, ## __VA_ARGS__)
45 #define CAN_MNG_API_LOGD(fmt,...) fprintf(stderr, "[D][CAN_API] %s(%s)(%d):" fmt "\n", __FILE__, __func__, __LINE__, ## __VA_ARGS__)
46 #define CAN_MNG_API_LOGE(fmt,...) fprintf(stderr, "[E][CAN_API] %s(%s)(%d):" fmt "\n", __FILE__, __func__, __LINE__, ## __VA_ARGS__)
48 #define CAN_MNG_API_LOGT(fmt,...)
49 #define CAN_MNG_API_LOGD(fmt,...)
50 #define CAN_MNG_API_LOGE(fmt,...)
52 /*------------------------------------------*/
53 /* API return value */
54 /*------------------------------------------*/
55 #define CAN_CTL_RET_SUCCESS 0 /* Normal end */
56 #define CAN_CTL_RET_ERR_PARAM -1 /* Parameter error */
57 #define CAN_CTL_RET_ERR_NOSVC -2 /* Service not open error */
58 #define CAN_CTL_RET_ERR_ERR -3 /* Other error */
60 /*------------------------------------------*/
61 /* Received command information */
62 /*------------------------------------------*/
63 #define CAN_CTL_CMD_LEN_MAX 255 /* Maximum data length */
64 #define CAN_DAT_LEN_MAX CAN_CTL_CMD_LEN_MAX /* Maximum data length */
65 #define CAN_CTL_CMD_ID_HI_NUM 128 /* Number of higher CAN-ID(8bit) (00 to 7F) */
67 #define CAN_CTL_MAX_RCV_CAN_SIZE 23
72 /* Object for CAN communication control API */
73 typedef struct _CanCtlApiObj {
74 /* ID assigned to the command reception notification callback */
78 /* CAN command structure */
79 typedef struct _CanCtlApiCmd {
80 UINT8 len; /* Data length */
81 UINT8 data[CAN_DAT_LEN_MAX]; /* Data */
84 /* Received ID MAP information */
85 typedef struct _CanCtlRcvId {
86 UINT16 id[CAN_CTL_CMD_ID_HI_NUM]; /* CAN ID MAP(000~7FF) */
90 /* CAN Frame structure */
95 #define LCN_SRV_MSB_FRAME_DAT_SIZE (8) /* MSB send/receive frame data size */
97 typedef struct _CanData {
98 CanId id; /* CAN Frame structure */
99 UINT8 dlc; /* Valid bytes of DATA#1~#8. DLC is 1 to 8. */
100 UINT8 Data[LCN_SRV_MSB_FRAME_DAT_SIZE]; /* Receive data */
101 /* Data of DLC size is valid, otherwise set to 0 as invalid value. */
104 /** @forward declarations
111 UINT32 CanCtlApiOpen(CanCtlApiObj* pClientObj);
112 UINT32 CanCtlApiClose(CanCtlApiObj* pClientObj);
113 UINT32 CanCtlApiSndCmd(CanCtlApiObj* pClientObj, CanCtlApiCmd* pSndCmd);
114 UINT32 CanCtlApiSetRcvId(CanCtlApiObj* pClientObj, CanCtlRcvId* pRcvId);
115 UINT32 CanCtlApiRcvCmd(CanCtlApiObj* pClientObj, CanCtlApiCmd* pRcvCmd);
116 UINT32 CanCtlApiRcvSpd(CanCtlApiObj* pClientObj, CanCtlApiCmd* pRcvCmd);
120 #endif /* __CAN_MNG_API_H__ */