Revision 8d756b18 unittests/lld/src/ut_lld_rtcan.c
| unittests/lld/src/ut_lld_rtcan.c | ||
|---|---|---|
| 30 | 30 |
#include <aos_thread.h> |
| 31 | 31 |
|
| 32 | 32 |
/** |
| 33 |
* @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 |
/** |
|
| 33 | 72 |
* @brief RTCAN unit test function. |
| 34 | 73 |
* |
| 35 | 74 |
* @param[in] stream Stream for input/output. |
| ... | ... | |
| 49 | 88 |
char* operation = ((ut_rtcandata_t*)ut->data)->operation; |
| 50 | 89 |
|
| 51 | 90 |
if(strcmp(operation, "send")==0){
|
| 52 |
CANTxFrame ctfp; |
|
| 53 |
ctfp.RTR = CAN_RTR_DATA; |
|
| 54 |
ctfp.IDE = CAN_IDE_STD; |
|
| 55 |
ctfp.DLC = 0; |
|
| 56 |
ctfp.SID = 0x003; |
|
| 57 |
msg = rtcan_transmit(&MODULE_HAL_CAN,CAN_ANY_MAILBOX,&ctfp); |
|
| 91 |
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); |
|
| 58 | 100 |
}else if (strcmp(operation, "receive")==0){
|
| 59 |
aosUtInfoMsg(stream,"trying to receive msg"); |
|
| 60 |
CANRxFrame crfp; |
|
| 61 |
crfp.RTR = CAN_RTR_DATA; |
|
| 62 |
crfp.IDE = CAN_IDE_STD; |
|
| 63 |
crfp.DLC = 0; |
|
| 64 |
crfp.SID = 0x003; |
|
| 65 |
int empty = can_lld_is_rx_nonempty(&MODULE_HAL_CAN,CAN_ANY_MAILBOX); |
|
| 66 |
aosUtInfoMsg(stream,"%d",empty); |
|
| 67 |
msg = rtcan_receive(&MODULE_HAL_CAN,CAN_ANY_MAILBOX,&crfp); |
|
| 101 |
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); |
|
| 68 | 114 |
} |
| 69 | 115 |
|
| 70 | 116 |
if(msg == MSG_OK){
|
| 71 |
aosUtPassedMsg(stream,&result,"Message transmitted");
|
|
| 117 |
aosUtPassedMsg(stream,&result,"Message sucessfull transmitted");
|
|
| 72 | 118 |
}else{
|
| 73 |
aosUtFailedMsg(stream,&result,"Timeout");
|
|
| 119 |
aosUtFailedMsg(stream,&result,"Timeout while waiting for message transmission");
|
|
| 74 | 120 |
} |
| 75 |
|
|
| 76 | 121 |
return result; |
| 77 | 122 |
} |
| 78 | 123 |
|
Also available in: Unified diff