Пример #1
0
/** 
  Read the value of an analog input.
  @return The value as an integer (0 - 1023).

  \par Example
  \code
  AnalogIn ain0(0);
  if( ain0.value() > 500 )
  {
// then do this
}
else
{
// then do that
}
\endcode
*/
int AnalogIn_value(AnalogIn *analogin)
{
    int value;
    //if ( !Semaphore_take(analogin_manager.semaphore, 1000 ) )
    if ( xSemaphoreTake(analogin_manager.semaphore, 1000 / portTICK_RATE_MS) != pdTRUE)
        return -1;

    // disable other channels, and enable the one we want
    int mask = 1 << analogin->index; 
    AT91C_BASE_ADC->ADC_CHDR = ~mask;
    AT91C_BASE_ADC->ADC_CHER = mask;
    AT91C_BASE_ADC->ADC_CR = AT91C_ADC_START; // Start the conversion

    pm_lock();
    //if ( !Semaphore_take(analogin_manager.doneSemaphore, 1000 ) ) // wait for the ISR
    if ( xSemaphoreTake(analogin_manager.doneSemaphore, 1000 / portTICK_RATE_MS) != pdTRUE) {
        pm_unlock();
        return -1;
    }
    pm_unlock();

    value = AT91C_BASE_ADC->ADC_LCDR & 0xFFFF; // grab the last converted value

    //Semaphore_give(analogin_manager.semaphore);
    xSemaphoreGive(analogin_manager.semaphore);

    return value;
}
Пример #2
0
int i2cMasterRead(uint8_t i2c_addr, uint8_t intaddr_size, uint32_t int_addr, uint8_t *data) {
    MUTEX_TAKE(i2c_mutex, -1); 
    pm_lock();
    i2cMasterConf(i2c_addr, intaddr_size, int_addr, I2CMASTER_READ);
    int rc = i2cReadByte(data);
    pm_unlock();
    MUTEX_GIVE(i2c_mutex); 
    return rc;
}
Пример #3
0
int i2cMasterWrite(uint8_t i2c_addr, uint8_t intaddr_size, uint32_t int_addr, uint8_t data) {
    MUTEX_TAKE(i2c_mutex, -1); 
    pm_lock();
    i2cMasterConf(i2c_addr, intaddr_size, int_addr, I2CMASTER_WRITE);
    int rc = i2cWriteByte(data);
    pm_unlock();
    MUTEX_GIVE(i2c_mutex); 
    return rc;
}
Пример #4
0
int pm_register(FAR struct pm_callback_s *callbacks)
{
  int ret;

  DEBUGASSERT(callbacks);

  /* Add the new entry to the end of the list of registered callbacks */

  ret = pm_lock();
  if (ret == OK)
    {
      sq_addlast(&callbacks->entry, &g_pmglobals.registry);
      pm_unlock();
    }
  return ret;
}