Statistics
| Branch: | Tag: | Revision:

amiro-os / core / src / aos_rtcan.c @ 5766017b

History | View | Annotate | Download (2.706 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 <hal.h>
20
#include <hal_can.h>
21
#include <hal_can_lld.h>
22
#include <aos_rtcan.h>
23
#include <aos_thread.h>
24
#include <chthreads.h>
25

    
26
#define True 1
27
#define False 0
28

    
29
/*
30
 * @brief transmit Message over CAN
31
 */
32
msg_t rtcan_transmit(CANDriver *canp, canmbx_t mailbox, const CANTxFrame *ctfp){
33
    // call cantransmit, needed params driver, mailbox and tx frame
34

    
35
    msg_t transmit = canTransmitTimeout(canp,mailbox,ctfp,TIME_IMMEDIATE);
36
    return transmit;
37
}
38

    
39
/*
40
 * @brief receive Message over CAN
41
 */
42
msg_t rtcan_receive(CANDriver *canp, canmbx_t mailbox,CANRxFrame *crfp){
43
    // call lld cantransmit, needed params driver, mailbox and rx frame
44
    return canReceiveTimeout(canp,mailbox,crfp,TIME_IMMEDIATE);
45
}
46

    
47
// Handling Message Queues
48

    
49
bool enqueueMsg(uint8_t *payload, uint8_t msgType, systime_t deadline){
50
    return false;
51
}
52

    
53
bool pushRTCanMsgSorted(rtcan_msg_t *msg,msgqueue_t* msgqueue){
54
    return false;
55
}
56

    
57
/*
58
 * @brief push Message to its Queue, based on type of Message
59
 */
60
void pushRTCanMsg(rtcan_msg_t *msg,msgqueue_t* msgqueue){
61
  if(msg != NULL){
62
    if(msgqueueEmpty(msgqueue)){
63
        msgqueue->head = msg;
64
        msgqueue->tail= msg;
65
        msg->next = NULL;
66
        return;
67
    }
68
    //todo special case handling
69
    if(msgqueue->tail != NULL){
70
      if(msg->msgType == 10){
71
          if(pushRTCanMsgSorted(msg,msgqueue) == true){
72
              return;
73
          };
74
      }
75
      msgqueue->tail->next = msg;
76
      msg->next = NULL;
77
      msgqueue->tail = msg;
78
      msgqueue->size++;
79
    }
80
  }
81
}
82

    
83
/*
84
 * @brief dequeue Message from Queue
85
 */
86
rtcan_msg_t* popRTCanMsg(msgqueue_t* msgqueue){
87
    if(!msgqueueEmpty(msgqueue)){
88
        rtcan_msg_t elem = msgqueue->head;
89
        msgqueue->head = elem->next;
90
        return elem;
91
    }
92
    return NULL;
93
}
94

    
95
/**
96
 * @brief schedule rtcan messages into mailboxes
97
 */
98
void schedule(){
99

    
100
}
101

    
102
/** empty or clear?*/
103
int msgqueueEmpty(msgqueue_t* mqueue){
104
    if(mqueue == NULL){
105
        return True;
106
    }
107
    return False;
108
}
109
//TODO: ISR
110
//TODO: Params