1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "can_if.h"
10 #include "can/can_client.h"
11 #include "can/can_core.h"
12
CanBusOpen(int32_t number,DevHandle * handle)13 int32_t CanBusOpen(int32_t number, DevHandle *handle)
14 {
15 int32_t ret;
16 struct CanClient *client = NULL;
17
18 ret = CanClientCreateByNumber(number, &client);
19 if (ret == HDF_SUCCESS) {
20 *handle = (DevHandle)client;
21 }
22 return ret;
23 }
24
CanBusClose(DevHandle handle)25 void CanBusClose(DevHandle handle)
26 {
27 CanClientDestroy((struct CanClient *)handle);
28 }
29
CanBusSendMsg(DevHandle handle,const struct CanMsg * msg)30 int32_t CanBusSendMsg(DevHandle handle, const struct CanMsg *msg)
31 {
32 return CanClientWriteMsg((struct CanClient *)handle, msg);
33 }
34
CanBusReadMsg(DevHandle handle,struct CanMsg * msg,uint32_t tms)35 int32_t CanBusReadMsg(DevHandle handle, struct CanMsg *msg, uint32_t tms)
36 {
37 return CanClientReadMsg((struct CanClient *)handle, msg, tms);
38 }
39
CanBusAddFilter(DevHandle handle,const struct CanFilter * filter)40 int32_t CanBusAddFilter(DevHandle handle, const struct CanFilter *filter)
41 {
42 return CanClientAddFilter((struct CanClient *)handle, filter);
43 }
44
CanBusDelFilter(DevHandle handle,const struct CanFilter * filter)45 int32_t CanBusDelFilter(DevHandle handle, const struct CanFilter *filter)
46 {
47 return CanClientDelFilter((struct CanClient *)handle, filter);
48 }
49
CanBusSetCfg(DevHandle handle,const struct CanConfig * cfg)50 int32_t CanBusSetCfg(DevHandle handle, const struct CanConfig *cfg)
51 {
52 return CanClientSetCfg((struct CanClient *)handle, cfg);
53 }
54
CanBusGetCfg(DevHandle handle,struct CanConfig * cfg)55 int32_t CanBusGetCfg(DevHandle handle, struct CanConfig *cfg)
56 {
57 return CanClientGetCfg((struct CanClient *)handle, cfg);
58 }
59
CanBusGetState(DevHandle handle)60 int32_t CanBusGetState(DevHandle handle)
61 {
62 return CanClientGetState((struct CanClient *)handle);
63 }
64