commit d2931db9faf52d0104a4f3813c1989647dc22db9
Author: Julian L <diki1aap@gmail.com>
Date:   Mon Jan 28 10:50:02 2019 +0100

    Rtcan send/receive and unittest, refs #1188

diff --git a/core/inc/aos_rtcan.h b/core/inc/aos_rtcan.h
new file mode 100644
index 0000000..0ef5c1c
--- /dev/null
+++ b/core/inc/aos_rtcan.h
@@ -0,0 +1,60 @@
+#ifndef AOS_RTCAN
+#define AOS_RTCAN
+
+#endif // AOS_RTCAN
+
+#include <hal.h>
+#include <hal_can.h>
+
+#include <stdint.h>
+
+
+/* include msg_types */
+
+/* include rtcanconfig */
+
+typedef uint16_t rtcan_id_t;
+
+typedef struct {
+    rtcan_id_t id;
+    uint8_t* payload;
+    uint8_t laxity:5;
+    uint8_t fragmentCounter:7;
+    uint8_t payloadSize;
+
+}rtcan_msg_t;
+
+typedef struct {
+    struct rtcan_msg_t *head;
+    struct rtcan_msg_t *tail;
+    uint8_t size;
+
+}msgqueue_t;
+
+typedef struct{
+    uint8_t fragment:7;
+
+}rtcan_frame_t;
+
+
+
+/*===========================================================================*/
+/* External declarations.                                                    */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+  msg_t rtcan_transmit(CANDriver *canp,
+                           canmbx_t mailbox,
+                           const CANTxFrame *ctfp);
+  msg_t rtcan_receive(CANDriver *canp,
+                          canmbx_t mailbox,
+                          CANRxFrame *crfp);
+#ifdef __cplusplus
+}
+#endif
+
+
+
+//TODO: public methods
diff --git a/core/src/aos_rtcan.c b/core/src/aos_rtcan.c
new file mode 100644
index 0000000..d0db976
--- /dev/null
+++ b/core/src/aos_rtcan.c
@@ -0,0 +1,108 @@
+/*
+AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
+Copyright (C) 2016..2018  Thomas Schöpping et al.
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <hal.h>
+#include <hal_can.h>
+#include <hal_can_lld.h>
+#include <aos_rtcan.h>
+
+#define True 1
+#define False 0
+#define NRT 1111111
+#define HRT 0000000
+
+msg_t rtcan_transmit(CANDriver *canp, canmbx_t mailbox, const CANTxFrame *ctfp){
+    // call cantransmit, needed params driver, mailbox and tx frame
+
+    msg_t transmit = canTransmitTimeout(canp,mailbox,ctfp,TIME_IMMEDIATE);
+    return transmit;
+}
+
+msg_t rtcan_receive(CANDriver *canp, canmbx_t mailbox,CANRxFrame *crfp){
+    // call lld cantransmit, needed params driver, mailbox and rx frame
+    return canReceiveTimeout(canp,mailbox,crfp,TIME_IMMEDIATE);
+}
+
+/** Initialize rtcan
+void rtcanInit(){
+    //necessary?
+}
+
+/** Start rtcan *
+void rtcanStart(CANDriver *canp, const CANConfig *config){
+    can_lld_Start(canp,config);
+}
+
+/** Stop rtcan *
+void rtcanStop(CANDriver *canp){
+    can_lld_Stop(canp);
+}
+
+/** Stop rtcan reset param and start again *
+void rtcanReset(){}
+*
+
+msgqueue_t msgqueueInit(rtcan_msg_t* msg){
+    struct msgqueue_t queue;
+    queue->head = msg;
+    queue->tail = msg;
+    return queue;
+}
+
+/** enqueue rtcanmsg_t  *
+void msgqueueEnqueue(msgqueue_t* mqueue,rtcan_msg_t* msg){
+    if(!msgqueueEmpty(mqueue)){
+    // HRT message most imminent so enqueued at head
+        msgqueue_t* curMsg = mqueue->tail;
+        while(curMsg->prev != mqueue->head){
+            if(msg->laxity < curMsg->laxity){
+                break;
+            }
+            curMsg = curMsg->prev;
+        }
+        //what about the tail?
+        msg->prev = curMsg->prev;
+        curMsg->prev = msg;
+
+    }else{
+        msgqueueInit(msg);
+    }
+}
+
+
+/** dequeue rtcanmsg *
+rtcan_msg_t* msgqueueDequeue(msgqueue_t* mqueue){
+    if(!msgqueueEmpty(mqueue)){
+        rtcan_msg_t dq = mqueue->head;
+        mqueue->head = dq->prev;
+        return dq;
+    }
+    return NULL;
+}
+
+
+
+/** empty or clear?*/
+int msgqueueEmpty(msgqueue_t* mqueue){
+    if(mqueue == NULL){
+        return True;
+    }
+    return False;
+}
+//TODO: ISR
+//TODO: Params
diff --git a/modules/DiWheelDrive_1-1/module.c b/modules/DiWheelDrive_1-1/module.c
index c1b8e14..31da92f 100644
--- a/modules/DiWheelDrive_1-1/module.c
+++ b/modules/DiWheelDrive_1-1/module.c
@@ -807,6 +807,25 @@ aos_unittest_t moduleUtAlldVcnl4020 = {
   /* data           */ &_utVcnl4020Data,
 };
 
+static int _utShellCmdCb_LldRtCan(BaseSequentialStream* stream, int argc, char* argv[])
+{
+  (void)argc;
+  (void)argv;
+  aosUtRun(stream, &moduleUtLldRtCan, NULL);
+  return AOS_OK;
+}
+aos_unittest_t moduleUtLldRtCan = {
+  /* name           */ "RTCAN",
+  /* info           */ NULL,
+  /* test function  */ utLldRtCanFunc,
+  /* shell command  */ {
+    /* name     */ "unittest:rtcan",
+    /* callback */ _utShellCmdCb_LldRtCan,
+    /* next     */ NULL,
+  },
+  /* data           */ NULL,
+};
+
 #endif /* AMIROOS_CFG_TESTS_ENABLE == true */
 
 /** @} */
diff --git a/modules/DiWheelDrive_1-1/module.h b/modules/DiWheelDrive_1-1/module.h
index 943e731..b8ad56e 100644
--- a/modules/DiWheelDrive_1-1/module.h
+++ b/modules/DiWheelDrive_1-1/module.h
@@ -347,6 +347,7 @@ extern ROMCONST char* moduleShellPrompt;
   aosShellAddCommand(&aos.shell, &moduleUtAlldPca9544a.shellcmd);             \
   aosShellAddCommand(&aos.shell, &moduleUtAlldTps62113.shellcmd);             \
   aosShellAddCommand(&aos.shell, &moduleUtAlldVcnl4020.shellcmd);             \
+  aosShellAddCommand(&aos.shell, &moduleUtLldRtCan.shellcmd);                 \
 }
 
 /**
@@ -450,6 +451,7 @@ extern ROMCONST char* moduleShellPrompt;
 #include <alld_pca9544a.h>
 #include <alld_tps62113.h>
 #include <alld_vcnl4020.h>
+#include <ut_lld_rtcan.h>
 
 /**
  * @brief   Motor driver.
@@ -581,6 +583,11 @@ extern aos_unittest_t moduleUtAlldTps62113;
  * @brief   VCNL4020 (proximity sensor) unit test object.
  */
 extern aos_unittest_t moduleUtAlldVcnl4020;
+/**
+ * @brief RtCan unit test object.
+*/
+extern aos_unittest_t moduleUtLldRtCan;
+
 
 #endif /* AMIROOS_CFG_TESTS_ENABLE == true */
 
diff --git a/unittests/lld/inc/ut_lld_rtcan.h b/unittests/lld/inc/ut_lld_rtcan.h
new file mode 100644
index 0000000..6828e95
--- /dev/null
+++ b/unittests/lld/inc/ut_lld_rtcan.h
@@ -0,0 +1,28 @@
+#ifndef UT_LLD_RTCAN_H
+#define UT_LLD_RTCAN_H
+
+
+#include "hal_can.h"
+#include <aos_unittest.h>
+#include <amiro-lld.h>
+#include <stdint.h>
+
+typedef struct{
+    /**
+     * Type of Operation to be tested
+     * send or receive
+     * @brief operation
+     */
+    char* operation;
+}ut_rtcandata_t;
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+  aos_utresult_t utLldRtCanFunc(BaseSequentialStream* stream, aos_unittest_t* ut);
+#ifdef __cplusplus
+}
+#endif
+
+#endif // UT_LLD_RTCAN_H
diff --git a/unittests/lld/src/ut_lld_rtcan.c b/unittests/lld/src/ut_lld_rtcan.c
new file mode 100644
index 0000000..19ef726
--- /dev/null
+++ b/unittests/lld/src/ut_lld_rtcan.c
@@ -0,0 +1,78 @@
+/*
+AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
+Copyright (C) 2016..2018  Thomas Schöpping et al.
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdint.h>
+#include <hal.h>
+#include <module.h>
+#include <hal_can.h>
+#include <aos_rtcan.h>
+#include <ut_lld_rtcan.h>
+
+
+#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
+#include <aos_debug.h>
+#include <chprintf.h>
+#include <aos_thread.h>
+
+/**
+ * @brief   RTCAN unit test function.
+ *
+ * @param[in] stream  Stream for input/output.
+ * @param[in] ut      Unit test object.
+ *
+ * @return            Unit test result value.
+ */
+aos_utresult_t utLldRtCanFunc(BaseSequentialStream* stream, aos_unittest_t* ut)
+{
+
+  aosDbgCheck(ut->data != NULL && ((ut_rtcandata_t*)ut->data)->operation!= NULL);
+  // local variables
+  // rtcanTransmit and reveive Test necessary
+  aos_utresult_t result = {0, 0};
+  //aos_getTime irgendwas
+  msg_t msg = MSG_TIMEOUT;
+  char* operation = ((ut_rtcandata_t*)ut->data)->operation;
+
+  if(strcmp(operation, "send")==0){
+        CANTxFrame ctfp;
+        ctfp.RTR = CAN_RTR_DATA;
+        ctfp.IDE = CAN_IDE_STD;
+        ctfp.DLC = 0;
+        ctfp.SID = 0x003;
+        msg = rtcan_transmit(&MODULE_HAL_CAN,CAN_ANY_MAILBOX,&ctfp);
+  }else if (strcmp(operation, "receive")==0){
+        CANRxFrame crfp;
+        crfp.RTR = CAN_RTR_DATA;
+        crfp.IDE = CAN_IDE_STD;
+        crfp.DLC = 0;
+        crfp.SID = 0x003;
+        msg = rtcan_receive(&MODULE_HAL_CAN,CAN_ANY_MAILBOX,&crfp);
+  }
+
+  if(msg == MSG_OK){
+      aosUtPassedMsg(stream,&result,"Message transmitted");
+  }else{
+      aosUtFailedMsg(stream,&result,"Timeout");
+  }
+
+  return result;
+}
+
+#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_LED) */
+
+
