Exemplo n.º 1
0
/**
 * @brief Lock SPI bus for exclusive access
 *
 * On SPI buses where there are multiple devices, it will be necessary to lock
 * SPI to have exclusive access to the buses for a sequence of transfers.
 * The bus should be locked before the chip is selected. After locking the SPI
 * bus, the caller should then also call the setfrequency(), setbpw(), and
 * setmode() methods to make sure that the SPI is properly configured for the
 * device. If the SPI bus is being shared, then it may have been left in an
 * incompatible state.
 *
 * @param dev pointer to structure of device data
 * @return 0 on success, negative errno on error
 */
static int tsb_spi_lock(struct device *dev)
{
    struct tsb_spi_dev_info *info = NULL;
    int ret = 0, loop = 0;

    /* check input parameters */
    if (!dev || !device_get_private(dev)) {
        return -EINVAL;
    }

    info = device_get_private(dev);

    if (info->spi_pmstate == PM_SLEEP) {
        pm_activity(TSB_SPI_ACTIVITY);

        /* SPI not powered, fail any accessing */;
        while (info->spi_pmstate == PM_SLEEP) {
            usleep(1000);
            if (++loop > 10) {
                return -EIO;
            }
        }
    }

    /* Take the semaphore (perhaps waiting) */
    ret = sem_wait(&info->bus);
    if (ret != OK) {
        /* The sem_wait() call should fail only if we are awakened by
         * a signal.
         */
        return -get_errno();
    }
    info->state = TSB_SPI_STATE_LOCKED;
    return 0;
}
Exemplo n.º 2
0
static int gpio_pad_detect_isr(int irq, void *context)
{
    pm_activity(PM_ACTIVITY);

    if (work_available(&g_info->work))
        work_queue(HPWORK, &g_info->work, gpio_pad_detect_worker, NULL, 0);

    return OK;
}
Exemplo n.º 3
0
static void button_handler(int id, int irq)
{
  /* At this point the MCU should have already awakened.  The state
   * change will be handled in the IDLE loop when the system is re-awakened
   * The button interrupt handler should be totally ignorant of the PM
   * activities and should report button activity as if nothing
   * special happened.
   */

  pm_activity(CONFIG_PM_BUTTON_ACTIVITY);
}