Beispiel #1
0
/////////////////////////////////////////////////////////////////////////////
// Checks the transfer status or waits for status == 0 (no ongoing transfer)
// IN: blocking = 1: waits for the ongoing transfer to finish; 
//                0: returns the current transfer status
// OUT: transfer status (1: ongoing; 0: no transfer; < 0: error during last
//      transfer. clears the transfer-status on errors.
//      (see README for error codes)
/////////////////////////////////////////////////////////////////////////////
s32 FRAM_TransferWaitCheck(u8 blocking){
  s32 res;
  if(transfer_status == 1){
    // ongoing transfer: poll IIC transfer status
    transfer_status = blocking ? 
      MIOS32_IIC_TransferWait(FRAM_IIC_PORT) : 
      MIOS32_IIC_TransferCheck(FRAM_IIC_PORT);
    }
  res = transfer_status;
  // clear error status
  if(transfer_status < 0)
    transfer_status = 0;
  // return last transfer status
  return res;
  }
Beispiel #2
0
/////////////////////////////////////////////////////////////////////////////
//! Waits until transfer is finished
//! \param[in] iic_port the IIC port (0..MIOS32_IIC_NUM-1)
//! \return 0 if no ongoing transfer
//! \return < 0 if error during transfer
//! \note Note that the semaphore will be released automatically after an error
//! (MIOS32_IIC_TransferBegin() has to be called again)
/////////////////////////////////////////////////////////////////////////////
s32 MIOS32_IIC_TransferWait(u8 iic_port)
{
  iic_rec_t *iicx = &iic_rec[iic_port];// simplify addressing of record
  u32 repeat_ctr = MIOS32_IIC_TIMEOUT_VALUE;
  u16 last_buffer_ix = iicx->buffer_ix;

  if( iic_port >= MIOS32_IIC_NUM )
    return MIOS32_IIC_ERROR_INVALID_PORT;

  while( --repeat_ctr > 0 ) {
    // check if buffer index has changed - if so, reload repeat counter
    if( iicx->buffer_ix != last_buffer_ix ) {
      repeat_ctr = MIOS32_IIC_TIMEOUT_VALUE;
      last_buffer_ix = iicx->buffer_ix;
    }

    // get transfer state
    s32 check_state = MIOS32_IIC_TransferCheck(iic_port);

    // exit if transfer finished or error detected
    if( check_state <= 0 ) {
      if( check_state < 0 )
	iicx->iic_semaphore = 0; // release semaphore for easier programming at user level
      return check_state;
    }
  }

  // timeout error - something is stalling...

  // re-initialize peripheral
  MIOS32_IIC_InitPeripheral(iic_port);

  // release semaphore (!)
  iicx->iic_semaphore = 0;

  return (iicx->last_transfer_error=MIOS32_IIC_ERROR_TIMEOUT);
}