Question

I'm programming a board from TI, and I'd like to somehow be able to have two different ISR's post to a task's message queue. That part works fine. However, on the receiving end, is there any intelligent way for the task to pend on its queue and perform a different operation on the data based on which ISR posted?

Basically, I have an LCD update task that displays information from my motors. However, if I have a motor sensor ISR and a button press ISR that send different information to be updated, can this be done on one queue?

Était-ce utile?

La solution

Sure. When each ISR sends a message to the queue, put something in the message that identifies the ISR that sent it. Then, when the receiver reads the queue, it can decide which action to take based on the identifier.

ISR1() {
  char msg[4];
  msg[0] = '1';                 // Identify the queue
  get_3_ISR1_data_bytes(msg+1); // Get the data
  q_send(msg);
}

ISR2() {
  char msg[4];
  msg[0] = '2';                 // Identify the queue
  get_3_ISR2_data_bytes(msg+1); // Get the data
  q_send(msg);
}

handler() {
  char *msg;
  q_rcv(msg);
  switch (msg[0]) {
  case '1':
    // Do ISR1 stuff
    break;
  case '2':
    // Do ISR2 stuff
    break;
  default:
    // Something unpleasant has happened
  }
}

If an entire char is too expensive, you can set just one bit (to 0 or 1) to identify the ISR.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top