Em 4/7/2010 05:23, solarwind escreveu: > I don't really know much about writing protocols or implementing them, > but I had the following idea. I don't really know if it's the "right" > way to go about it, so please comment on it. > > I'm trying to design a multi master protocol for RS485 networks > (specifically working on how the microcontroller will handle the data > at this point). > > The MCU will have an ISR as follows, which will be called every time a > byte is received: > > ISR() { > if buffer not full > push byte into a FIFO buffer > start(processing_thread) > } > > processing_thread() { > if frame complete (if we have a full, complete frame in the buffer) > process_frame() (process the frame, handle the message, whatever) > stop(processing_thread) > } > > Pastebin link for those who have trouble reading the above formatted > text: http://pastebin.com/Z8YRt69k > > > In this way, the ISR stays relatively free most of the time. It only > executes some short code when a byte is received. So, even if the > processing of the message data takes a long time (for whatever > reason), the ISR is free to continue pushing data into the buffer. > Meanwhile, the processing thread runs "in the background" to handle > the received data. > > I would imagine that using an interrupt (rather than consistently > polling for data) is far more efficient. Is this the way it's usually > done in the microcontroller world? Or have I totally missed something? Your idea is fine. It all depends on how you implement it. Are you still using FreeRTOS? Which MCU? With FreeRTOS, if your RX interrupt has a higher priority than the kernel you may have trouble. I implemented a system using this same approach, but because I was using two UARTs at 115200bps I had to set the RX ISRs in the high-priority interrupt (PIC18). In this situation, you cannot call any of the FreeRTOS functions from the ISR, then what I did was to set the processing task with a higher priority than all the others and to sleep for one tick if there is no data to process, so the ISR doesn't need to wake it. The processing task then wakes at the beginning of each tick, and if there is no data to process it sleeps immediately, leaving the rest of the tick for the other tasks to run. The resulting performance is very good. Best regards, Isaac __________________________________________________ Fale com seus amigos de gra=E7a com o novo Yahoo! Messenger = http://br.messenger.yahoo.com/ = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist