Statistics
| Branch: | Tag: | Revision:

amiro-os / core / src / aos_rtcan.c @ 5034a2a5

History | View | Annotate | Download (2.71 KB)

1 d2931db9 Julian L
/*
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 e7131d09 Julian Leichert
#include <aos_thread.h>
24
#include <chthreads.h>
25 d2931db9 Julian L
26
#define True 1
27
#define False 0
28
29 e7131d09 Julian Leichert
/*
30
 * @brief transmit Message over CAN
31
 */
32 d2931db9 Julian L
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 e7131d09 Julian Leichert
/*
40
 * @brief receive Message over CAN
41
 */
42 d2931db9 Julian L
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 e7131d09 Julian Leichert
// Handling Message Queues
48 d2931db9 Julian L
49 e7131d09 Julian Leichert
bool enqueueMsg(uint8_t *payload, uint8_t msgType, systime_t deadline){
50
    return false;
51 d2931db9 Julian L
}
52
53 e7131d09 Julian Leichert
bool pushRTCanMsgSorted(rtcan_msg_t *msg,msgqueue_t* msgqueue){
54
    return false;
55 d2931db9 Julian L
}
56
57 e7131d09 Julian Leichert
/*
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 5766017b Julian Leichert
        msg->next = NULL;
66 e7131d09 Julian Leichert
        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 5766017b Julian Leichert
      msg->next = NULL;
77 e7131d09 Julian Leichert
      msgqueue->tail = msg;
78
      msgqueue->size++;
79 d2931db9 Julian L
    }
80 e7131d09 Julian Leichert
  }
81 d2931db9 Julian L
}
82
83 e7131d09 Julian Leichert
/*
84
 * @brief dequeue Message from Queue
85
 */
86
rtcan_msg_t* popRTCanMsg(msgqueue_t* msgqueue){
87
    if(!msgqueueEmpty(msgqueue)){
88 5034a2a5 Julian Leichert
        rtcan_msg_t *elem = msgqueue->head;
89 5766017b Julian Leichert
        msgqueue->head = elem->next;
90
        return elem;
91 d2931db9 Julian L
    }
92
    return NULL;
93
}
94
95 e7131d09 Julian Leichert
/**
96
 * @brief schedule rtcan messages into mailboxes
97
 */
98
void schedule(){
99 d2931db9 Julian L
100 e7131d09 Julian Leichert
}
101 d2931db9 Julian L
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