Click here to Skip to main content
14,545,399 members

ATL / WTL / STL

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder16-Jul-09 3:09
cofounderChris Maunder16-Jul-09 3:09 
PinnedHow to get an answer to your question PinPopular
Chris Maunder16-Jul-09 3:05
cofounderChris Maunder16-Jul-09 3:05 
QuestionKeypad locks Pin
Member 79891227-Mar-20 13:23
MemberMember 79891227-Mar-20 13:23 
QuestionTo insert a node at the back of a XOR doubly linked list Pin
Tarun Jha17-Oct-19 9:38
MemberTarun Jha17-Oct-19 9:38 
AnswerRe: To insert a node at the back of a XOR doubly linked list Pin
ZurdoDev10-Jan-20 1:02
mveZurdoDev10-Jan-20 1:02 
QuestionWhy non-template function does not compile where as template function compiles? Pin
PBMBJoshi2-May-19 23:23
MemberPBMBJoshi2-May-19 23:23 
AnswerRe: Why non-template function does not compile where as template function compiles? Pin
Richard MacCutchan2-May-19 23:29
mveRichard MacCutchan2-May-19 23:29 
AnswerRe: Why non-template function does not compile where as template function compiles? Pin
k505410-Oct-19 8:53
mvek505410-Oct-19 8:53 
QuestionAdvice on interdependent asynchronous functions and task queuing? Pin
arnold_w7-Feb-19 23:07
Memberarnold_w7-Feb-19 23:07 
I am working with embedded programming in standard C and there are 2 microcontrollers communicating with each other using a home-made SPI-protocol. In addition, microcontroller 2 has a CAN-bus that should also (indirectly) be fully accessible from microcontroller 1. The scheduler and task queues are also home-made so no realtime operating system is used. My tasks look like this:
void (*task_t)(uint8_t* taskData, uint16_t sizeOfTaskDataInBytes);
My functions to add 1 or 2 tasks look like this:
typedef enum {
    TASK_IN_WAIT_PHASE      = 0,
    TASK_FINISHED           = 1
} taskStatus_e;

typedef taskStatus_e (*getTaskStatusCallback_t)(uint8_t* data, uint16_t dataSizeBytes);

Bool_t queueTask(taskQueueSelector_e, task_t, uint8_t* data, uint16_t dataSizeBytes, getTaskStatusCallback_t);
Bool_t queue2Tasks(taskQueueSelector_e, task_t task1, uint8_t* data1, uint16_t data1SizeBytes, getTaskStatusCallback_t getTaskStatusCallback1, task_t task2, uint8_t* data2, uint16_t data2SizeBytes, getTaskStatusCallback_t getTaskStatusCallback2);
When microcontroller 1 wants to read from microcontroller 2 over SPI, the following code is used:
struct SPI_secretData_s {
    volatile Bool_t                    accessInProgress;
    volatile int8_t                    numRetriesLeft;
};

#define PLEASE_SEE_NUM_REGS_TO_ACCESS_PARAMETER     (1)

struct SPI_readRegsTaskParams_s {
    struct SPI_secretData_s            secretData;
    volatile uint32_t                  startAddr;
    volatile uint16_t                  numRegsToAccess;
    volatile SPI_readStatus_e          readStatus;
    volatile uint16_t                  readBuffer[PLEASE_SEE_NUM_REGS_TO_ACCESS_PARAMETER];
};

queue2Tasks(SPI_QUEUE_SELECTOR, SPI_readRegs, (uint8_t*)&SPI_readRegsTaskParams, sizeof(SPI_readRegsTaskParams), SPI_getTaskStatusCallback, SPI_handleReadIsFinished, NULL, 0, NULL);

taskStatus_e SPI_getTaskStatusCallback(uint8_t* data, uint16_t dataSizeBytes) {
    struct SPI_readRegsTaskParams_s* SPI_readRegsTaskParams = (struct SPI_readRegsTaskParams_s*)data;
    return (SPI_readRegsTaskParams->secretData.accessInProgress) ? TASK_IN_WAIT_PHASE : TASK_FINISHED;
}

uint32_t SPI_handleReadIsFinished(uint8_t* notUsed, uint16_t sizeOfNotUsedInBytes) {
    struct SPI_readRegsTaskParams_s* SPI_readRegsTaskParams = (struct SPI_readRegsTaskParams_s*)getPreviousTaskData();
    //... Do what you need to do with the read data...
}
When microcontroller 2 wants to read from the CAN-bus, the following code is used:
struct CAN_secretData_s {
    volatile Bool_t                         accessInProgress;
};

struct CAN_readRegsTaskParams_s {
             struct CAN_secretData_s        secretData;
    volatile uint32_t                       startAddr;
    volatile uint8_t                        numRegsToReadMax4;
    volatile uint16_t                       readRegsBuffer[4];
    volatile CAN_readStatus_e               readStatus;
};

queue2Tasks(CAN_QUEUE_SELECTOR, CAN_readRegs, (uint8_t*)&CAN_readRegsTaskParams, sizeof(CAN_readRegsTaskParams), CAN_getTaskStatusCallback, CAN_handleReadIsFinished, NULL, 0, NULL);

taskStatus_e CAN_getTaskStatusCallback(uint8_t* data, uint16_t dataSizeBytes) {
    struct CAN_readRegsTaskParams_s* CAN_readRegsTaskParams = (struct CAN_readRegsTaskParams_s*)data;
    return (CAN_readRegsTaskParams->secretData.accessInProgress) ? TASK_IN_WAIT_PHASE : TASK_FINISHED;

uint32_t CAN_handleReadIsFinished(uint8_t* notUsed, uint16_t sizeOfNotUsedInBytes) {
    struct CAN_readRegsTaskParams_s* CAN_readRegsTaskParams = (struct CAN_readRegsTaskParams_s*)getPreviousTaskData();
    //... Do what you need to do with the read data...
}

Could someone please suggest how I should handle the case when microcontroller 1 wants to read from the CAN-bus, via microcontroller 2?

modified 8-Feb-19 5:20am.

AnswerRe: Advice on interdependent asynchronous functions and task queuing? Pin
arnold_w7-Feb-19 23:34
Memberarnold_w7-Feb-19 23:34 
QuestionRecommended way to deal with queues and pointers to buffers Pin
arnold_w3-Feb-19 9:09
Memberarnold_w3-Feb-19 9:09 
AnswerRe: Recommended way to deal with queues and pointers to buffers Pin
Richard MacCutchan3-Feb-19 22:19
mveRichard MacCutchan3-Feb-19 22:19 
GeneralRe: Recommended way to deal with queues and pointers to buffers Pin
arnold_w3-Feb-19 23:40
Memberarnold_w3-Feb-19 23:40 
GeneralRe: Recommended way to deal with queues and pointers to buffers Pin
Richard MacCutchan3-Feb-19 23:48
mveRichard MacCutchan3-Feb-19 23:48 
GeneralRe: Recommended way to deal with queues and pointers to buffers Pin
arnold_w4-Feb-19 3:15
Memberarnold_w4-Feb-19 3:15 
GeneralRe: Recommended way to deal with queues and pointers to buffers Pin
Richard MacCutchan4-Feb-19 3:46
mveRichard MacCutchan4-Feb-19 3:46 
GeneralRe: Recommended way to deal with queues and pointers to buffers Pin
arnold_w4-Feb-19 3:55
Memberarnold_w4-Feb-19 3:55 
GeneralRe: Recommended way to deal with queues and pointers to buffers Pin
Richard MacCutchan4-Feb-19 4:04
mveRichard MacCutchan4-Feb-19 4:04 
GeneralRe: Recommended way to deal with queues and pointers to buffers Pin
Business2sell18-Feb-19 18:08
professionalBusiness2sell18-Feb-19 18:08 
QuestionCan a union in standard C "skip" members? Pin
arnold_w31-Jan-19 22:46
Memberarnold_w31-Jan-19 22:46 
AnswerRe: Can a union in standard C "skip" members? Pin
Richard MacCutchan31-Jan-19 23:18
mveRichard MacCutchan31-Jan-19 23:18 
GeneralRe: Can a union in standard C "skip" members? Pin
arnold_w31-Jan-19 23:47
Memberarnold_w31-Jan-19 23:47 
GeneralRe: Can a union in standard C "skip" members? Pin
Richard MacCutchan31-Jan-19 23:52
mveRichard MacCutchan31-Jan-19 23:52 
GeneralRe: Can a union in standard C "skip" members? Pin
arnold_w1-Feb-19 0:13
Memberarnold_w1-Feb-19 0:13 
GeneralRe: Can a union in standard C "skip" members? Pin
Richard MacCutchan1-Feb-19 1:42
mveRichard MacCutchan1-Feb-19 1:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.