amiro-os / unittests / lld / src / ut_lld_rtcan.c @ ece66d59
History | View | Annotate | Download (3.638 KB)
1 |
/*
|
---|---|
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 <stdio.h> |
20 |
#include <string.h> |
21 |
#include <stdint.h> |
22 |
#include <hal.h> |
23 |
#include <module.h> |
24 |
#include <hal_can.h> |
25 |
#include <aos_rtcan.h> |
26 |
#include <ut_lld_rtcan.h> |
27 |
|
28 |
|
29 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
30 |
#include <aos_debug.h> |
31 |
#include <chprintf.h> |
32 |
#include <aos_thread.h> |
33 |
|
34 |
/**
|
35 |
* @brief Helper function to serialize data.
|
36 |
*
|
37 |
* @param[out] dst Pointer to the output buffer.
|
38 |
* @param[in] src Data to be serialized.
|
39 |
* @param[in] n Number of bytes to serialize.
|
40 |
*/
|
41 |
inline void _serialize(uint8_t* dst, const uint64_t src, const uint8_t n) |
42 |
{ |
43 |
aosDbgCheck(dst != NULL);
|
44 |
aosDbgCheck(n > 0 && n <= 8); |
45 |
|
46 |
for (uint8_t byte = 0; byte < n; ++byte) { |
47 |
dst[byte] = (uint8_t)((src >> (byte * 8)) & 0xFF); |
48 |
} |
49 |
|
50 |
return;
|
51 |
} |
52 |
|
53 |
/**
|
54 |
* @brief Helper function to deserialize data.
|
55 |
*
|
56 |
* @param[in] src Pointer to the buffer of data to be deserialzed.
|
57 |
* @param[in] n Number of bytes to deserialize.
|
58 |
*
|
59 |
* @return The deserialized 32 bit data.
|
60 |
*/
|
61 |
inline uint64_t _deserialize(uint8_t* src, const uint8_t n) |
62 |
{ |
63 |
aosDbgCheck(src != NULL);
|
64 |
aosDbgCheck(n > 0 && n <= 8); |
65 |
|
66 |
uint64_t result = 0;
|
67 |
for (uint8_t byte = 0; byte < n; ++byte) { |
68 |
result |= ((uint64_t)src[byte]) << (byte * 8);
|
69 |
} |
70 |
|
71 |
return result;
|
72 |
} |
73 |
/**
|
74 |
* @brief RTCAN unit test function.
|
75 |
*
|
76 |
* @param[in] stream Stream for input/output.
|
77 |
* @param[in] ut Unit test object.
|
78 |
*
|
79 |
* @return Unit test result value.
|
80 |
*/
|
81 |
aos_utresult_t utLldRtCanFunc(BaseSequentialStream* stream, aos_unittest_t* ut) |
82 |
{ |
83 |
|
84 |
aosDbgCheck(ut->data != NULL && ((ut_rtcandata_t*)ut->data)->operation!= NULL); |
85 |
// local variables
|
86 |
// rtcanTransmit and reveive Test necessary
|
87 |
aos_utresult_t result = {0, 0}; |
88 |
//aos_getTime irgendwas
|
89 |
msg_t msg = MSG_TIMEOUT; |
90 |
char* operation = ((ut_rtcandata_t*)ut->data)->operation;
|
91 |
|
92 |
if(strcmp(operation, "send")==0){ |
93 |
CANTxFrame ctfp; |
94 |
ctfp.RTR = CAN_RTR_DATA; |
95 |
ctfp.IDE = CAN_IDE_STD; |
96 |
ctfp.DLC = 0;
|
97 |
ctfp.SID = 0x003;
|
98 |
aos_timestamp_t stamp; |
99 |
aosSysGetUptime(&stamp); |
100 |
_serialize(ctfp.data8,stamp,4);
|
101 |
msg = rtcan_transmit(&MODULE_HAL_CAN,CAN_ANY_MAILBOX,&ctfp); |
102 |
}else if (strcmp(operation, "receive")==0){ |
103 |
aosUtInfoMsg(stream,"trying to receive msg");
|
104 |
CANRxFrame crfp; |
105 |
crfp.RTR = CAN_RTR_DATA; |
106 |
crfp.IDE = CAN_IDE_STD; |
107 |
crfp.DLC = 0;
|
108 |
crfp.SID = 0x003;
|
109 |
int empty = can_lld_is_rx_nonempty(&MODULE_HAL_CAN,CAN_ANY_MAILBOX);
|
110 |
if (empty){
|
111 |
aosUtInfoMsg(stream,"RX is Empty");
|
112 |
} |
113 |
msg = rtcan_receive(&MODULE_HAL_CAN,CAN_ANY_MAILBOX,&crfp); |
114 |
uint64_t recv = _deserialize(crfp.data8,4);
|
115 |
aosUtInfoMsg(stream,"Received Message has the payload: %d",recv);
|
116 |
} |
117 |
|
118 |
if(msg == MSG_OK){
|
119 |
aosUtPassedMsg(stream,&result,"Message sucessfull transmitted");
|
120 |
}else{
|
121 |
aosUtFailedMsg(stream,&result,"Timeout while waiting for message transmission");
|
122 |
} |
123 |
return result;
|
124 |
} |
125 |
|
126 |
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_LED) */ |
127 |
|
128 |
|