Revision e7131d09
| core/inc/aos_rtcan.h | ||
|---|---|---|
| 5 | 5 |
|
| 6 | 6 |
#include <hal.h> |
| 7 | 7 |
#include <hal_can.h> |
| 8 |
#include <hal_can_lld.h> |
|
| 8 | 9 |
|
| 9 | 10 |
#include <stdint.h> |
| 10 | 11 |
|
| ... | ... | |
| 15 | 16 |
|
| 16 | 17 |
typedef uint16_t rtcan_id_t; |
| 17 | 18 |
|
| 18 |
typedef struct {
|
|
| 19 |
typedef struct rtcan_msg_t{
|
|
| 19 | 20 |
rtcan_id_t id; |
| 20 | 21 |
uint8_t* payload; |
| 21 | 22 |
uint8_t laxity:5; |
| 22 | 23 |
uint8_t fragmentCounter:7; |
| 23 | 24 |
uint8_t payloadSize; |
| 25 |
uint8_t msgType:2; |
|
| 26 |
systime_t deadline; |
|
| 27 |
struct rtcan_msg_t *next; |
|
| 28 |
|
|
| 24 | 29 |
|
| 25 | 30 |
}rtcan_msg_t; |
| 26 | 31 |
|
| 27 | 32 |
typedef struct {
|
| 28 |
struct rtcan_msg_t *head;
|
|
| 29 |
struct rtcan_msg_t *tail;
|
|
| 33 |
rtcan_msg_t *head; |
|
| 34 |
rtcan_msg_t *tail; |
|
| 30 | 35 |
uint8_t size; |
| 31 | 36 |
|
| 32 | 37 |
}msgqueue_t; |
| ... | ... | |
| 51 | 56 |
msg_t rtcan_receive(CANDriver *canp, |
| 52 | 57 |
canmbx_t mailbox, |
| 53 | 58 |
CANRxFrame *crfp); |
| 59 |
bool enqueueMsg(uint8_t *payload,uint8_t msgType,systime_t deadline); |
|
| 54 | 60 |
#ifdef __cplusplus |
| 55 | 61 |
} |
| 56 | 62 |
#endif |
| core/src/aos_rtcan.c | ||
|---|---|---|
| 20 | 20 |
#include <hal_can.h> |
| 21 | 21 |
#include <hal_can_lld.h> |
| 22 | 22 |
#include <aos_rtcan.h> |
| 23 |
#include <aos_thread.h> |
|
| 24 |
#include <chthreads.h> |
|
| 23 | 25 |
|
| 24 | 26 |
#define True 1 |
| 25 | 27 |
#define False 0 |
| 26 | 28 |
#define NRT 1111111 |
| 27 | 29 |
#define HRT 0000000 |
| 28 | 30 |
|
| 31 |
/* |
|
| 32 |
* @brief transmit Message over CAN |
|
| 33 |
*/ |
|
| 29 | 34 |
msg_t rtcan_transmit(CANDriver *canp, canmbx_t mailbox, const CANTxFrame *ctfp){
|
| 30 | 35 |
// call cantransmit, needed params driver, mailbox and tx frame |
| 31 | 36 |
|
| ... | ... | |
| 33 | 38 |
return transmit; |
| 34 | 39 |
} |
| 35 | 40 |
|
| 41 |
/* |
|
| 42 |
* @brief receive Message over CAN |
|
| 43 |
*/ |
|
| 36 | 44 |
msg_t rtcan_receive(CANDriver *canp, canmbx_t mailbox,CANRxFrame *crfp){
|
| 37 | 45 |
// call lld cantransmit, needed params driver, mailbox and rx frame |
| 38 | 46 |
return canReceiveTimeout(canp,mailbox,crfp,TIME_IMMEDIATE); |
| 39 | 47 |
} |
| 40 | 48 |
|
| 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 |
} |
|
| 49 |
// Handling Message Queues |
|
| 50 | 50 |
|
| 51 |
/** Stop rtcan * |
|
| 52 |
void rtcanStop(CANDriver *canp){
|
|
| 53 |
can_lld_Stop(canp); |
|
| 51 |
bool enqueueMsg(uint8_t *payload, uint8_t msgType, systime_t deadline){
|
|
| 52 |
return false; |
|
| 54 | 53 |
} |
| 55 | 54 |
|
| 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; |
|
| 55 |
bool pushRTCanMsgSorted(rtcan_msg_t *msg,msgqueue_t* msgqueue){
|
|
| 56 |
return false; |
|
| 65 | 57 |
} |
| 66 | 58 |
|
| 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); |
|
| 59 |
/* |
|
| 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++; |
|
| 84 | 81 |
} |
| 82 |
} |
|
| 85 | 83 |
} |
| 86 | 84 |
|
| 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; |
|
| 85 |
/* |
|
| 86 |
* @brief dequeue Message from Queue |
|
| 87 |
*/ |
|
| 88 |
rtcan_msg_t* popRTCanMsg(msgqueue_t* msgqueue){
|
|
| 89 |
if(!msgqueueEmpty(msgqueue)){
|
|
| 90 |
return msgqueue->head; |
|
| 94 | 91 |
} |
| 95 | 92 |
return NULL; |
| 96 | 93 |
} |
| 97 | 94 |
|
| 95 |
/** |
|
| 96 |
* @brief schedule rtcan messages into mailboxes |
|
| 97 |
*/ |
|
| 98 |
void schedule(){
|
|
| 98 | 99 |
|
| 100 |
} |
|
| 99 | 101 |
|
| 100 | 102 |
/** empty or clear?*/ |
| 101 | 103 |
int msgqueueEmpty(msgqueue_t* mqueue){
|
| modules/STM32F407G-DISC1/module.h | ||
|---|---|---|
| 82 | 82 |
*/ |
| 83 | 83 |
extern SerialConfig moduleHalProgIfConfig; |
| 84 | 84 |
|
| 85 |
|
|
| 85 | 86 |
/** |
| 86 | 87 |
* @brief Real-Time Clock driver. |
| 87 | 88 |
*/ |
| unittests/lld/inc/ut_lld_rtcan.h | ||
|---|---|---|
| 2 | 2 |
#define UT_LLD_RTCAN_H |
| 3 | 3 |
|
| 4 | 4 |
|
| 5 |
#include "hal_can.h"
|
|
| 5 |
#include <hal_can.h>
|
|
| 6 | 6 |
#include <aos_unittest.h> |
| 7 | 7 |
#include <amiro-lld.h> |
| 8 | 8 |
#include <stdint.h> |
| unittests/lld/src/ut_lld_rtcan.c | ||
|---|---|---|
| 16 | 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 |
#include <stdio.h> |
|
| 20 |
#include <string.h> |
|
| 19 | 21 |
#include <stdint.h> |
| 20 | 22 |
#include <hal.h> |
| 21 | 23 |
#include <module.h> |
Also available in: Unified diff