amiro-os / unittests / lld / src / ut_lld_rtcan.c @ 8d756b18
History | View | Annotate | Download (3.6 KB)
1 | d2931db9 | Julian L | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | Copyright (C) 2016..2018 Thomas Schöpping et al.
|
||
4 | |||
5 | This program is free software: you can redistribute it and/or modify
|
||
6 | it under the terms of the GNU General Public License as published by
|
||
7 | the Free Software Foundation, either version 3 of the License, or
|
||
8 | (at your option) any later version.
|
||
9 | |||
10 | This program is distributed in the hope that it will be useful,
|
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | GNU General Public License for more details.
|
||
14 | |||
15 | You should have received a copy of the GNU General Public License
|
||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
17 | */
|
||
18 | |||
19 | #include <stdint.h> |
||
20 | #include <hal.h> |
||
21 | #include <module.h> |
||
22 | #include <hal_can.h> |
||
23 | #include <aos_rtcan.h> |
||
24 | #include <ut_lld_rtcan.h> |
||
25 | |||
26 | |||
27 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
28 | #include <aos_debug.h> |
||
29 | #include <chprintf.h> |
||
30 | #include <aos_thread.h> |
||
31 | |||
32 | /**
|
||
33 | 8d756b18 | Julian L | * @brief Helper function to serialize data.
|
34 | *
|
||
35 | * @param[out] dst Pointer to the output buffer.
|
||
36 | * @param[in] src Data to be serialized.
|
||
37 | * @param[in] n Number of bytes to serialize.
|
||
38 | */
|
||
39 | inline void _serialize(uint8_t* dst, const uint64_t src, const uint8_t n) |
||
40 | { |
||
41 | aosDbgCheck(dst != NULL);
|
||
42 | aosDbgCheck(n > 0 && n <= 8); |
||
43 | |||
44 | for (uint8_t byte = 0; byte < n; ++byte) { |
||
45 | dst[byte] = (uint8_t)((src >> (byte * 8)) & 0xFF); |
||
46 | } |
||
47 | |||
48 | return;
|
||
49 | } |
||
50 | |||
51 | /**
|
||
52 | * @brief Helper function to deserialize data.
|
||
53 | *
|
||
54 | * @param[in] src Pointer to the buffer of data to be deserialzed.
|
||
55 | * @param[in] n Number of bytes to deserialize.
|
||
56 | *
|
||
57 | * @return The deserialized 32 bit data.
|
||
58 | */
|
||
59 | inline uint64_t _deserialize(uint8_t* src, const uint8_t n) |
||
60 | { |
||
61 | aosDbgCheck(src != NULL);
|
||
62 | aosDbgCheck(n > 0 && n <= 8); |
||
63 | |||
64 | uint64_t result = 0;
|
||
65 | for (uint8_t byte = 0; byte < n; ++byte) { |
||
66 | result |= ((uint64_t)src[byte]) << (byte * 8);
|
||
67 | } |
||
68 | |||
69 | return result;
|
||
70 | } |
||
71 | /**
|
||
72 | d2931db9 | Julian L | * @brief RTCAN unit test function.
|
73 | *
|
||
74 | * @param[in] stream Stream for input/output.
|
||
75 | * @param[in] ut Unit test object.
|
||
76 | *
|
||
77 | * @return Unit test result value.
|
||
78 | */
|
||
79 | aos_utresult_t utLldRtCanFunc(BaseSequentialStream* stream, aos_unittest_t* ut) |
||
80 | { |
||
81 | |||
82 | aosDbgCheck(ut->data != NULL && ((ut_rtcandata_t*)ut->data)->operation!= NULL); |
||
83 | // local variables
|
||
84 | // rtcanTransmit and reveive Test necessary
|
||
85 | aos_utresult_t result = {0, 0}; |
||
86 | //aos_getTime irgendwas
|
||
87 | msg_t msg = MSG_TIMEOUT; |
||
88 | char* operation = ((ut_rtcandata_t*)ut->data)->operation;
|
||
89 | |||
90 | if(strcmp(operation, "send")==0){ |
||
91 | 8d756b18 | Julian L | CANTxFrame ctfp; |
92 | ctfp.RTR = CAN_RTR_DATA; |
||
93 | ctfp.IDE = CAN_IDE_STD; |
||
94 | ctfp.DLC = 0;
|
||
95 | ctfp.SID = 0x003;
|
||
96 | aos_timestamp_t stamp; |
||
97 | aosSysGetUptime(&stamp); |
||
98 | _serialize(ctfp.data8,stamp,4);
|
||
99 | msg = rtcan_transmit(&MODULE_HAL_CAN,CAN_ANY_MAILBOX,&ctfp); |
||
100 | d2931db9 | Julian L | }else if (strcmp(operation, "receive")==0){ |
101 | 8d756b18 | Julian L | aosUtInfoMsg(stream,"trying to receive msg");
|
102 | CANRxFrame crfp; |
||
103 | crfp.RTR = CAN_RTR_DATA; |
||
104 | crfp.IDE = CAN_IDE_STD; |
||
105 | crfp.DLC = 0;
|
||
106 | crfp.SID = 0x003;
|
||
107 | int empty = can_lld_is_rx_nonempty(&MODULE_HAL_CAN,CAN_ANY_MAILBOX);
|
||
108 | if (empty){
|
||
109 | aosUtInfoMsg(stream,"RX is Empty");
|
||
110 | } |
||
111 | msg = rtcan_receive(&MODULE_HAL_CAN,CAN_ANY_MAILBOX,&crfp); |
||
112 | uint64_t recv = _deserialize(crfp.data8,4);
|
||
113 | aosUtInfoMsg(stream,"Received Message has the payload: %d",recv);
|
||
114 | d2931db9 | Julian L | } |
115 | |||
116 | if(msg == MSG_OK){
|
||
117 | 8d756b18 | Julian L | aosUtPassedMsg(stream,&result,"Message sucessfull transmitted");
|
118 | d2931db9 | Julian L | }else{
|
119 | 8d756b18 | Julian L | aosUtFailedMsg(stream,&result,"Timeout while waiting for message transmission");
|
120 | d2931db9 | Julian L | } |
121 | return result;
|
||
122 | } |
||
123 | |||
124 | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_LED) */ |
||
125 |