Using Semaphore - to create sequential code


#1

I am trying to figure the best way to create a “sequential” solution which sends and receives messages on UART:

// Simple view of Upload Code – which uploads code to the uC connected to UART

UploadCode()
{
   for(i=0; i < Sectors; i++){
      for(j=0; j < BlocksPerSector; j++) {
           for(k=0; k <LinesPerBlock> 0){
                    ProcessMessage();
                 }
           }
      }
   }
}

bool handlerDataReceive(u16 DataSize, u8 * Data )
{
    AddDataToBuffer();
    // Wake up code interested in this data
    adl_semProduce(MsgSemaphore);
}

I was expecting that adl_semConsume will block and give back control to the OS and when data on UART is received handlerDataReceive will be invoked which will produce a semaphore and unblock the Upload code.

However the Upload code gets blocked and handlerDataReceive is not invoked.

Any ideas on a good way to solve this issue?


#2

Hi,

I think the semaphore service can only be used for high level interruption handlers. And as far as I know, the UART handling does not fall into this category!

Why don’t you call the code interested in the data right after you have received the data?

Best Regards,
Jan


#3

A State Machine?