Tirthankar De


Discussion created by Tirthankar De on Apr 30, 2006
Latest reply on Apr 30, 2006 by Shannon Roberts

I am writing a CAN API which can be called by two or more threads. This can be achieved if the interfaces provided are re-entrant. The single interface that need to be re-entrant is CanSend() which takes in two field- pointer to CAN FRAME and priority of the CAN MESSAGE for arbitration internal to node (i.e if previously message with priority low is loaded but now another message with priority high has come, and low priority message is not yet transmitted so abort it and transmit current high priority message.). The problem is how can i make a CanSend() re-entrant as the data copy of CAN FRAME to CAN REGISTERS (arbitration field, control field, 8 bytes data etc) cannot be an atomic operation unless i disable interrupts! Blocking a thread on calling this function is not allowed, so semaphore to indicate resource been aquired is ruled out! Also if another thread(say T2) pre-empts the current thread (say T1) which has finished copying 50% of CAN FRAME to CAN REGISTERS, then the T2 copies all CAN FRAME data to h/w registers and transmits.... then gives control back to T1, T1 now assumes 50% copy is over so resumes copy from 50% which results in bad FRAME, as first half had been overwritten by T2! Also I need to take care that HIGH PRIORITY messages are transmitted first. There can be N number of threads pre-emting each other.....life becomes miserable. CAN somebody help me out on this?