amiro-os / core / src / aos_rtcan.c @ 8d756b18
History | View | Annotate | Download (2.682 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 |
|
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
|