amiro-os / core / src / aos_rtcan.c @ e7131d09
History | View | Annotate | Download (2.675 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 | #define NRT 1111111 |
||
29 | #define HRT 0000000 |
||
30 | |||
31 | e7131d09 | Julian Leichert | /*
|
32 | * @brief transmit Message over CAN
|
||
33 | */
|
||
34 | d2931db9 | Julian L | msg_t rtcan_transmit(CANDriver *canp, canmbx_t mailbox, const CANTxFrame *ctfp){
|
35 | // call cantransmit, needed params driver, mailbox and tx frame
|
||
36 | |||
37 | msg_t transmit = canTransmitTimeout(canp,mailbox,ctfp,TIME_IMMEDIATE); |
||
38 | return transmit;
|
||
39 | } |
||
40 | |||
41 | e7131d09 | Julian Leichert | /*
|
42 | * @brief receive Message over CAN
|
||
43 | */
|
||
44 | d2931db9 | Julian L | msg_t rtcan_receive(CANDriver *canp, canmbx_t mailbox,CANRxFrame *crfp){ |
45 | // call lld cantransmit, needed params driver, mailbox and rx frame
|
||
46 | return canReceiveTimeout(canp,mailbox,crfp,TIME_IMMEDIATE);
|
||
47 | } |
||
48 | |||
49 | e7131d09 | Julian Leichert | // Handling Message Queues
|
50 | d2931db9 | Julian L | |
51 | e7131d09 | Julian Leichert | bool enqueueMsg(uint8_t *payload, uint8_t msgType, systime_t deadline){
|
52 | return false; |
||
53 | d2931db9 | Julian L | } |
54 | |||
55 | e7131d09 | Julian Leichert | bool pushRTCanMsgSorted(rtcan_msg_t *msg,msgqueue_t* msgqueue){
|
56 | return false; |
||
57 | d2931db9 | Julian L | } |
58 | |||
59 | e7131d09 | Julian Leichert | /*
|
60 | * @brief push Message to its Queue, based on type of Message
|
||
61 | */
|
||
62 | void pushRTCanMsg(rtcan_msg_t *msg,msgqueue_t* msgqueue){
|
||
63 | if(msg != NULL){ |
||
64 | if(msgqueueEmpty(msgqueue)){
|
||
65 | msgqueue->head = msg; |
||
66 | msgqueue->tail= msg; |
||
67 | msg->next = msg; |
||
68 | return;
|
||
69 | } |
||
70 | //todo special case handling
|
||
71 | if(msgqueue->tail != NULL){ |
||
72 | if(msg->msgType == 10){ |
||
73 | if(pushRTCanMsgSorted(msg,msgqueue) == true){ |
||
74 | return;
|
||
75 | }; |
||
76 | } |
||
77 | msgqueue->tail->next = msg; |
||
78 | msg->next = msg; |
||
79 | msgqueue->tail = msg; |
||
80 | msgqueue->size++; |
||
81 | d2931db9 | Julian L | } |
82 | e7131d09 | Julian Leichert | } |
83 | d2931db9 | Julian L | } |
84 | |||
85 | e7131d09 | Julian Leichert | /*
|
86 | * @brief dequeue Message from Queue
|
||
87 | */
|
||
88 | rtcan_msg_t* popRTCanMsg(msgqueue_t* msgqueue){ |
||
89 | if(!msgqueueEmpty(msgqueue)){
|
||
90 | return msgqueue->head;
|
||
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 |