Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Help in semaphores

Hi

Can anyone Plz Help me in Semaphores in MicroC os2 .Just Give me some Working Code of two task swithched on semaphores.Whether the task print hello word .it is fine.I have Used the the Function OSSemCreate(),OSSempend() and OSSempost()...They are not working in My Case .I dont know the Stupid Reason Behind it.But Some how the output is different from the Code which i have write.

I also read the different Manuals of altera on MicroC OS2 but it cant helped me alot..

SO Urgent Help Required PLZ Plz .....

Some Simple Example......

Thanks In Advanced for The Nice Guy Who Give me SOme Soution...

regards

Hasil86

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Creating the Semaphore

       
    // create Semaphore 
       m_t_sem_access = OSSemCreate(0);
       if (m_t_sem_access == NULL) 
       {
           // just in case some error handling
       }
    
    Accessing a semaphore protected area

    
       OSSemPend(m_t_sem_access, 
                                  L_SPI_ACCESS_TIMEOUT, 
                     &proc_i_error);   
       switch (proc_i_error)
          {
    // error handling
    ....
    }
    
    Removing the Lock

    
       proc_i_error = OSSemPost(m_t_sem_access);
       if (proc_i_error != OS_NO_ERR)
          {
    ....
          }
    
    This code snippets are taken from my current project. The semaphore is used to protect access to a hardware device.

    Karsten