This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

semaphore bug??



I have written an application that blocks on a semaphore.  When an interrupt is generated, the
semaphore is released, and the program **should** continue.  Here is a snippit:

/* synchronization semaphore */
static  cyg_sem_t dma_store_done_sem;

// I then initialize the semaphore to 0 and register the isr ...

static cyg_uint32 dma_store_done_isr(cyg_vector_t vector, cyg_addrword_t data, cyg_addrword_t *regs)
{
  CYG_WORD32 dspctl;

  //diag_printf("Entered dma_store_done_isr.  vector = %d Releasing semaphore.\n", vector);
  cyg_interrupt_acknowledge(vector);
  /* put the DMA into reset  */
  HAL_READ_UINT32_MCB(DSPCTL, dspctl);
  dspctl |= ResetDMA;
  HAL_WRITE_UINT32_MCB(DSPCTL, dspctl);
  cyg_semaphore_post(&dma_store_done_sem);
  return CYG_ISR_HANDLED;
}

void StoreCoreData( CYG_WORD32 coreAddr, CYG_WORD32 *addr, int nWords )
{
  cyg_count32 value;
  CYG_WORD32 dspctl;
  cyg_mutex_lock(&dma_store_imem_block);

 ... do stuff ...

  if (!cyg_semaphore_timed_wait(&dma_store_done_sem, cyg_current_time() + 10) ) {
    printf("StoreCoreData: semaphore dma_store_done_sem timed out.\n");
    cyg_semaphore_peek(&dma_store_done_sem, &value);
    printf("StoreCoreData: semaphore value = %d\n", value);
  }
  cyg_mutex_unlock(&dma_store_imem_block);
  return;
}

I have checked, and the interrupt is being sent,  and   cyg_semaphore_post() is
being called.  On the second time I try this, I get:

(gdb) c
Continuing.
StoreCoreData: semaphore dma_store_done_sem timed out.
StoreCoreData: semaphore value = 1

How is it possible that the semaphore is blocked when the value is 1?
If I don't put use cyg_semaphore_timed_wait, it blocks forever.  I have checked
and the value of the semaphore just after    cyg_semaphore_post() in the isr
is one.

Any suggestions?

	-- Warren

Warren J. Jasper
wjasper@tx.ncsu.edu


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]