Revision d2931db9

View differences:

core/inc/aos_rtcan.h
1
#ifndef AOS_RTCAN
2
#define AOS_RTCAN
3

  
4
#endif // AOS_RTCAN
5

  
6
#include <hal.h>
7
#include <hal_can.h>
8

  
9
#include <stdint.h>
10

  
11

  
12
/* include msg_types */
13

  
14
/* include rtcanconfig */
15

  
16
typedef uint16_t rtcan_id_t;
17

  
18
typedef struct {
19
    rtcan_id_t id;
20
    uint8_t* payload;
21
    uint8_t laxity:5;
22
    uint8_t fragmentCounter:7;
23
    uint8_t payloadSize;
24

  
25
}rtcan_msg_t;
26

  
27
typedef struct {
28
    struct rtcan_msg_t *head;
29
    struct rtcan_msg_t *tail;
30
    uint8_t size;
31

  
32
}msgqueue_t;
33

  
34
typedef struct{
35
    uint8_t fragment:7;
36

  
37
}rtcan_frame_t;
38

  
39

  
40

  
41
/*===========================================================================*/
42
/* External declarations.                                                    */
43
/*===========================================================================*/
44

  
45
#ifdef __cplusplus
46
extern "C" {
47
#endif
48
  msg_t rtcan_transmit(CANDriver *canp,
49
                           canmbx_t mailbox,
50
                           const CANTxFrame *ctfp);
51
  msg_t rtcan_receive(CANDriver *canp,
52
                          canmbx_t mailbox,
53
                          CANRxFrame *crfp);
54
#ifdef __cplusplus
55
}
56
#endif
57

  
58

  
59

  
60
//TODO: public methods
core/src/aos_rtcan.c
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 <hal.h>
20
#include <hal_can.h>
21
#include <hal_can_lld.h>
22
#include <aos_rtcan.h>
23

  
24
#define True 1
25
#define False 0
26
#define NRT 1111111
27
#define HRT 0000000
28

  
29
msg_t rtcan_transmit(CANDriver *canp, canmbx_t mailbox, const CANTxFrame *ctfp){
30
    // call cantransmit, needed params driver, mailbox and tx frame
31

  
32
    msg_t transmit = canTransmitTimeout(canp,mailbox,ctfp,TIME_IMMEDIATE);
33
    return transmit;
34
}
35

  
36
msg_t rtcan_receive(CANDriver *canp, canmbx_t mailbox,CANRxFrame *crfp){
37
    // call lld cantransmit, needed params driver, mailbox and rx frame
38
    return canReceiveTimeout(canp,mailbox,crfp,TIME_IMMEDIATE);
39
}
40

  
41
/** Initialize rtcan
42
void rtcanInit(){
43
    //necessary?
44
}
45

  
46
/** Start rtcan *
47
void rtcanStart(CANDriver *canp, const CANConfig *config){
48
    can_lld_Start(canp,config);
49
}
50

  
51
/** Stop rtcan *
52
void rtcanStop(CANDriver *canp){
53
    can_lld_Stop(canp);
54
}
55

  
56
/** Stop rtcan reset param and start again *
57
void rtcanReset(){}
58
*
59

  
60
msgqueue_t msgqueueInit(rtcan_msg_t* msg){
61
    struct msgqueue_t queue;
62
    queue->head = msg;
63
    queue->tail = msg;
64
    return queue;
65
}
66

  
67
/** enqueue rtcanmsg_t  *
68
void msgqueueEnqueue(msgqueue_t* mqueue,rtcan_msg_t* msg){
69
    if(!msgqueueEmpty(mqueue)){
70
    // HRT message most imminent so enqueued at head
71
        msgqueue_t* curMsg = mqueue->tail;
72
        while(curMsg->prev != mqueue->head){
73
            if(msg->laxity < curMsg->laxity){
74
                break;
75
            }
76
            curMsg = curMsg->prev;
77
        }
78
        //what about the tail?
79
        msg->prev = curMsg->prev;
80
        curMsg->prev = msg;
81

  
82
    }else{
83
        msgqueueInit(msg);
84
    }
85
}
86

  
87

  
88
/** dequeue rtcanmsg *
89
rtcan_msg_t* msgqueueDequeue(msgqueue_t* mqueue){
90
    if(!msgqueueEmpty(mqueue)){
91
        rtcan_msg_t dq = mqueue->head;
92
        mqueue->head = dq->prev;
93
        return dq;
94
    }
95
    return NULL;
96
}
97

  
98

  
99

  
100
/** empty or clear?*/
101
int msgqueueEmpty(msgqueue_t* mqueue){
102
    if(mqueue == NULL){
103
        return True;
104
    }
105
    return False;
106
}
107
//TODO: ISR
108
//TODO: Params
modules/DiWheelDrive_1-1/module.c
807 807
  /* data           */ &_utVcnl4020Data,
808 808
};
809 809

  
810
static int _utShellCmdCb_LldRtCan(BaseSequentialStream* stream, int argc, char* argv[])
811
{
812
  (void)argc;
813
  (void)argv;
814
  aosUtRun(stream, &moduleUtLldRtCan, NULL);
815
  return AOS_OK;
816
}
817
aos_unittest_t moduleUtLldRtCan = {
818
  /* name           */ "RTCAN",
819
  /* info           */ NULL,
820
  /* test function  */ utLldRtCanFunc,
821
  /* shell command  */ {
822
    /* name     */ "unittest:rtcan",
823
    /* callback */ _utShellCmdCb_LldRtCan,
824
    /* next     */ NULL,
825
  },
826
  /* data           */ NULL,
827
};
828

  
810 829
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
811 830

  
812 831
/** @} */
modules/DiWheelDrive_1-1/module.h
347 347
  aosShellAddCommand(&aos.shell, &moduleUtAlldPca9544a.shellcmd);             \
348 348
  aosShellAddCommand(&aos.shell, &moduleUtAlldTps62113.shellcmd);             \
349 349
  aosShellAddCommand(&aos.shell, &moduleUtAlldVcnl4020.shellcmd);             \
350
  aosShellAddCommand(&aos.shell, &moduleUtLldRtCan.shellcmd);                 \
350 351
}
351 352

  
352 353
/**
......
450 451
#include <alld_pca9544a.h>
451 452
#include <alld_tps62113.h>
452 453
#include <alld_vcnl4020.h>
454
#include <ut_lld_rtcan.h>
453 455

  
454 456
/**
455 457
 * @brief   Motor driver.
......
581 583
 * @brief   VCNL4020 (proximity sensor) unit test object.
582 584
 */
583 585
extern aos_unittest_t moduleUtAlldVcnl4020;
586
/**
587
 * @brief RtCan unit test object.
588
*/
589
extern aos_unittest_t moduleUtLldRtCan;
590

  
584 591

  
585 592
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */
586 593

  
unittests/lld/inc/ut_lld_rtcan.h
1
#ifndef UT_LLD_RTCAN_H
2
#define UT_LLD_RTCAN_H
3

  
4

  
5
#include "hal_can.h"
6
#include <aos_unittest.h>
7
#include <amiro-lld.h>
8
#include <stdint.h>
9

  
10
typedef struct{
11
    /**
12
     * Type of Operation to be tested
13
     * send or receive
14
     * @brief operation
15
     */
16
    char* operation;
17
}ut_rtcandata_t;
18

  
19

  
20
#ifdef __cplusplus
21
extern "C" {
22
#endif
23
  aos_utresult_t utLldRtCanFunc(BaseSequentialStream* stream, aos_unittest_t* ut);
24
#ifdef __cplusplus
25
}
26
#endif
27

  
28
#endif // UT_LLD_RTCAN_H
unittests/lld/src/ut_lld_rtcan.c
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 <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
 * @brief   RTCAN unit test function.
34
 *
35
 * @param[in] stream  Stream for input/output.
36
 * @param[in] ut      Unit test object.
37
 *
38
 * @return            Unit test result value.
39
 */
40
aos_utresult_t utLldRtCanFunc(BaseSequentialStream* stream, aos_unittest_t* ut)
41
{
42

  
43
  aosDbgCheck(ut->data != NULL && ((ut_rtcandata_t*)ut->data)->operation!= NULL);
44
  // local variables
45
  // rtcanTransmit and reveive Test necessary
46
  aos_utresult_t result = {0, 0};
47
  //aos_getTime irgendwas
48
  msg_t msg = MSG_TIMEOUT;
49
  char* operation = ((ut_rtcandata_t*)ut->data)->operation;
50

  
51
  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);
58
  }else if (strcmp(operation, "receive")==0){
59
        CANRxFrame crfp;
60
        crfp.RTR = CAN_RTR_DATA;
61
        crfp.IDE = CAN_IDE_STD;
62
        crfp.DLC = 0;
63
        crfp.SID = 0x003;
64
        msg = rtcan_receive(&MODULE_HAL_CAN,CAN_ANY_MAILBOX,&crfp);
65
  }
66

  
67
  if(msg == MSG_OK){
68
      aosUtPassedMsg(stream,&result,"Message transmitted");
69
  }else{
70
      aosUtFailedMsg(stream,&result,"Timeout");
71
  }
72

  
73
  return result;
74
}
75

  
76
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_USE_LED) */
77

  
78

  

Also available in: Unified diff