Esempio n. 1
0
static void i2cCallback(void *cookie, size_t tx, size_t rx, int err)
{
    if (err == 0)
        osEnqueuePrivateEvt(EVT_SENSOR_I2C, cookie, NULL, data.tid);
    else
        osLog(LOG_INFO, "ROHM: i2c error (%d)\n", err);
}
Esempio n. 2
0
static bool sensorRateProx(uint32_t rate, uint64_t latency, void *cookie)
{
    osLog(LOG_INFO, "ROHM: sensorRateProx: rate=%ld Hz latency=%lld ns\n",
          rate / 1024, latency);

    if (data.proxTimerHandle)
        timTimerCancel(data.proxTimerHandle);
    data.proxTimerHandle = timTimerSet(sensorTimerLookupCommon(supportedRates, rateTimerVals, rate), 0, 50, proxTimerCallback, NULL, false);
    data.proxState = PROX_STATE_INIT;
    osEnqueuePrivateEvt(EVT_SENSOR_PROX_TIMER, NULL, NULL, data.tid);
    sensorSignalInternalEvt(data.proxHandle, SENSOR_INTERNAL_EVT_RATE_CHG, rate, latency);

    return true;
}
Esempio n. 3
0
static bool sensorRateAls(uint32_t rate, uint64_t latency, void *cookie)
{
    osLog(LOG_INFO, "ROHM: sensorRateAls: rate=%ld Hz latency=%lld ns\n",
          rate / 1024, latency);

    if (data.alsTimerHandle)
        timTimerCancel(data.alsTimerHandle);
    data.alsTimerHandle = timTimerSet(sensorTimerLookupCommon(supportedRates, rateTimerVals, rate), 0, 50, alsTimerCallback, NULL, false);
    data.lastAlsSample.fdata = -FLT_MAX;
    osEnqueuePrivateEvt(EVT_SENSOR_ALS_TIMER, NULL, NULL, data.tid);
    sensorSignalInternalEvt(data.alsHandle, SENSOR_INTERNAL_EVT_RATE_CHG, rate, latency);

    return true;
}
Esempio n. 4
0
static bool sensorPowerProx(bool on, void *cookie)
{
    osLog(LOG_INFO, "ROHM: sensorPowerProx: %d\n", on);

    if (data.proxTimerHandle) {
        timTimerCancel(data.proxTimerHandle);
        data.proxTimerHandle = 0;
        data.proxReading = false;
    }

    data.proxOn = on;
    setMode(data.alsOn, on, (void *)(on ? SENSOR_STATE_ENABLING_PROX : SENSOR_STATE_DISABLING_PROX));

    return true;
}
Esempio n. 5
0
void spiSlaveCsInactive(struct SpiDevice *dev)
{
    struct SpiDeviceState *state = SPI_DEVICE_TO_STATE(dev);

    dev->ops->slaveSetCsInterrupt(dev, false);

    if (!state->finishCallback) {
        osLog(LOG_WARN, "%s called without callback\n", __func__);
        return;
    }

    SpiCbkF callback = state->finishCallback;
    void *cookie = state->finishCookie;
    state->finishCallback = NULL;
    state->finishCookie = NULL;

    callback(cookie, 0);
}
Esempio n. 6
0
void osHwiEnable(os_hwi_status prev_status)
{
    os_hwi_status cur_status;

#ifdef HWI_PRIORITY_LOGGING
    osLog(LOG_HWI_ENABLE, prev_status);
#endif // HWI_LOGGING

    /* SCpriority = SR_PRIORITIES_NUMBER - OSpriority
       => OSpriority = SR_PRIORITIES_NUMBER - SCpriority */
    prev_status = SR_PRIORITIES_NUMBER - prev_status;
    prev_status <<= 21;

    osHwiSwiftDisable();
    cur_status = (os_hwi_status)readSR();
    writeSR((int)((cur_status & (~SR_PRIORITY_MASK)) | prev_status));
    osHwiSwiftEnable();
 
}
Esempio n. 7
0
static bool init_app(uint32_t myTid)
{
    osLog(LOG_INFO, "ROHM: task starting\n");

    /* Set up driver private data */
    data.tid = myTid;
    data.alsOn = false;
    data.alsReading = false;
    data.proxOn = false;
    data.proxReading = false;

    /* Register sensors */
    data.alsHandle = sensorRegister(&sensorInfoAls, &sensorOpsAls, NULL, false);
    data.proxHandle = sensorRegister(&sensorInfoProx, &sensorOpsProx, NULL, false);

    osEventSubscribe(myTid, EVT_APP_START);

    return true;
}
Esempio n. 8
0
os_hwi_status osHwiDisable()
{
    os_hwi_status int_status = 0;


    osHwiSwiftDisable();
    int_status = (os_hwi_status)readSR();
    writeSR((int)(int_status | SR_PRIORITY_MASK));
    osHwiSwiftEnable();
 
#ifdef HWI_PRIORITY_LOGGING
    osLog(LOG_HWI_DISABLE, 0);
#endif // HWI_LOGGING

    /* SCpriority = SR_PRIORITIES_NUMBER - OSpriority
       => OSpriority = SR_PRIORITIES_NUMBER - SCpriority */
    int_status = (int_status & SR_PRIORITY_MASK) >> 21;
    int_status = SR_PRIORITIES_NUMBER - int_status;

    return int_status;
}
os_status osHwiCreate(os_hwi_handle     hwi_num,
                      os_hwi_priority   priority,
                      os_hwi_mode       mode,
                      os_hwi_function   handler,
                      os_hwi_arg        argument)
{
    uint16_t        index;
    uint32_t        mode_bit;
    uint32_t        *trigger_reg_ptr;
    uint32_t        trigger_reg;

    /* handle the mode register ELRx */
    index = (uint16_t)((hwi_num - 18) >> 5);          
    trigger_reg_ptr = (uint32_t *)((g_dsp_plat_map->epic).p_elr);
    trigger_reg_ptr += index;

    mode_bit = (uint32_t)(0x00000001 << ((hwi_num - 18) & 0x001F));
    if (mode == LEVEL_MODE)
    {
        READ_UINT32(trigger_reg, *trigger_reg_ptr);
        trigger_reg &= ~mode_bit;
        WRITE_UINT32(*trigger_reg_ptr, trigger_reg);
    }
    else if(mode == EDGE_MODE)
    {
        READ_UINT32(trigger_reg, *trigger_reg_ptr);
        trigger_reg |= mode_bit;
        WRITE_UINT32(*trigger_reg_ptr, trigger_reg);
    }

    /* create hwi task using phoenix API */
    (void)os_create_task(PHOENIX_TSK_INTTASK,
					   (PHOENIX_TSKFUNC)handler,
					   0,
					   hwi_num,
					   0,
					   priority,
					   (PHOENIX_INTVECTOR)(hwi_num - 18));

    /* Store handler into table */
    interrupt_pointer[hwi_num] = handler;
    if (hwi_num == OS_INT_ORED_GENERAL)
        interrupt_argument[hwi_num] = (os_hwi_arg)general_ored_interrupt;
    else if (hwi_num == OS_INT_ORED_DEBUG)
        interrupt_argument[hwi_num] = (os_hwi_arg)debug_ored_interrupt;
    else if (hwi_num == OS_INT_ORED_MAPLE)
        interrupt_argument[hwi_num] = (os_hwi_arg)maple_ored_interrupt;
    else
        interrupt_argument[hwi_num] = argument;

    return OS_SUCCESS; 
   
#if 0
    os_status       status = OS_SUCCESS;
    os_hwi_status   int_status;
    uint16_t        index;
    uint32_t        pending_bit, mode_bit;
    uint32_t        *pending_reg_ptr, *trigger_reg_ptr;
    uint32_t        trigger_reg;
    os_hwi_handle   epic_hwi_num = 0;
 
#ifdef HWI_ERROR_CHECKING
    if ( (priority > OS_HWI_LAST_PRIORITY) && (priority != OS_HWI_PRIORITY_NMI) )
    {
#ifdef HWI_ERROR_ASSERT
        OS_ASSERT;
#endif /* HWI_ERROR_ASSERT */
        RETURN_ERROR(OS_ERR_HWI_PRIORITY_INVALID);
    }
    if (handler == NULL)
    {
#ifdef HWI_ERROR_ASSERT
        OS_ASSERT;
#endif /* HWI_ERROR_ASSERT */
        RETURN_ERROR(OS_ERR_HWI_FUNCTION_INVALID);
    }
    if (HWI_INVALID_MODE(mode))
    {
#ifdef HWI_ERROR_ASSERT
        OS_ASSERT;
#endif /* HWI_ERROR_ASSERT */
        if(priority != 0) //meaning disable only
        {
            RETURN_ERROR(OS_ERR_HWI_MODE_INVALID);
        }
    }
#endif /* HWI_ERROR_CHECKING */

    if (hwi_num > OS_INT_LAST)
    {
        if(hwi_num > OS_INT_GEN_LAST)
        {
#ifdef HWI_ERROR_ASSERT
            OS_ASSERT;
#endif /* HWI_ERROR_ASSERT */
            RETURN_ERROR(OS_ERR_HWI_INVALID);
        }
        else
        {
            return osHwiCreateGeneral(hwi_num,handler,argument);
        }
    }

    if ( (priority > 0) && (priority != OS_HWI_PRIORITY_NMI) )
        priority = (os_hwi_priority)((OS_HWI_LAST_PRIORITY + 1) - priority);

    int_status = osHwiDisable();

#ifdef HWI_LOGGING
    if (priority != OS_HWI_PRIORITY_NMI)
        osLog(LOG_HWI_CREATE, (uint32_t)(((OS_HWI_LAST_PRIORITY - priority)<<16) | (hwi_num)));
    else
        osLog(LOG_HWI_CREATE, (uint32_t)(((0xFFFF)<<16) | (hwi_num))); /* for NMI interrupts */
#endif

    /* Store handler into table */
    interrupt_pointer[hwi_num] = handler;
    if (hwi_num == OS_INT_ORED_GENERAL)
        interrupt_argument[hwi_num] = (os_hwi_arg)general_ored_interrupt;
    else if (hwi_num == OS_INT_ORED_DEBUG)
        interrupt_argument[hwi_num] = (os_hwi_arg)debug_ored_interrupt;
    else if (hwi_num == OS_INT_ORED_MAPLE)
        interrupt_argument[hwi_num] = (os_hwi_arg)maple_ored_interrupt;
    else
        interrupt_argument[hwi_num] = argument;
 
    /* Non-EPIC interrupts don't require any more handling */
    if (hwi_num < EPIC_INTERRUPTS_OFFSET)
    {
        osHwiEnable(int_status);
        return status;
    }
    else /* get the EPIC interrupt zero-based index */
        epic_hwi_num = (os_hwi_handle)(hwi_num - EPIC_INTERRUPTS_OFFSET);

    prioritySet(epic_hwi_num, priority);

    /* handle the mode register ELRx */
    index = (uint16_t)(epic_hwi_num >> 5);           /* /32 */
    trigger_reg_ptr = (uint32_t *)((g_dsp_plat_map->epic).p_elr);
    trigger_reg_ptr += index;

    mode_bit = (uint32_t)(0x00000001 << (epic_hwi_num & 0x001F));
    if (mode == LEVEL_MODE)
    {
        READ_UINT32(trigger_reg, *trigger_reg_ptr);
        trigger_reg &= ~mode_bit;
        WRITE_UINT32(*trigger_reg_ptr, trigger_reg);
    }
    else // mode == EDGE_MODE
    {
        READ_UINT32(trigger_reg, *trigger_reg_ptr);
        trigger_reg |= mode_bit;
        WRITE_UINT32(*trigger_reg_ptr, trigger_reg);
    }
 
    /* handle the pending interrupt register */
    index = (uint16_t)(epic_hwi_num >> 5);               /* /32 */
    pending_reg_ptr = (uint32_t *)((g_dsp_plat_map->epic).p_ipr);
    pending_reg_ptr += index;

    /* Figure out what the pending mask looks like */
    pending_bit = (uint32_t)(0x00000001 << (epic_hwi_num & 0x001F));

    /* Clear any pending interrupts */
    WRITE_UINT32(*pending_reg_ptr,pending_bit);

    /* enable the interrupt in the ENDIS register */
    setInterruptEnable(hwi_num, TRUE);
 
    osHwiEnable(int_status);

    return status;

#endif
}
Esempio n. 10
0
static void handle_i2c_event(int state)
{
    union EmbeddedDataPoint sample;
    bool sendData;

    switch (state) {
    case SENSOR_STATE_RESET:
        data.txrxBuf.bytes[0] = ROHM_RPR0521_REG_ID;
        i2cMasterTxRx(I2C_BUS_ID, I2C_ADDR, data.txrxBuf.bytes, 1,
                        data.txrxBuf.bytes, 1, &i2cCallback,
                        (void *)SENSOR_STATE_VERIFY_ID);
        break;
    case SENSOR_STATE_VERIFY_ID:
        /* Check the sensor ID */
        if (data.txrxBuf.bytes[0] != ROHM_RPR0521_ID) {
            osLog(LOG_INFO, "ROHM: not detected\n");
            sensorUnregister(data.alsHandle);
            sensorUnregister(data.proxHandle);
            break;
        }

        /* ALS gain and LED current */
        data.txrxBuf.bytes[0] = (ROHM_RPR0521_GAIN_ALS0 << 4) |
                          (ROHM_RPR0521_GAIN_ALS1 << 2) |
                          ROHM_RPR0521_LED_CURRENT_100MA;
        /* PS gain */
        data.txrxBuf.bytes[1] = (ROHM_RPR0521_GAIN_PS << 4) | 0x1;

        i2cMasterTx(I2C_BUS_ID, I2C_ADDR, data.txrxBuf.bytes, 2,
                          &i2cCallback, (void *)SENSOR_STATE_INIT);
        break;

    case SENSOR_STATE_INIT:
        /* Start register */
        data.txrxBuf.bytes[0] = ROHM_RPR0521_REG_PS_OFFSET_LSB;
        data.txrxBuf.bytes[1] = ROHM_RPR0521_CAL_DEFAULT_OFFSET & 0xff;
        data.txrxBuf.bytes[2] = (ROHM_RPR0521_CAL_DEFAULT_OFFSET >> 8) & 0x3;
        i2cMasterTx(I2C_BUS_ID, I2C_ADDR, data.txrxBuf.bytes, 3,
                          &i2cCallback, (void *)SENSOR_STATE_IDLE);
        break;

    case SENSOR_STATE_IDLE:
        sensorRegisterInitComplete(data.alsHandle);
        sensorRegisterInitComplete(data.proxHandle);
        break;

    case SENSOR_STATE_ENABLING_ALS:
        sensorSignalInternalEvt(data.alsHandle, SENSOR_INTERNAL_EVT_POWER_STATE_CHG, true, 0);
        break;

    case SENSOR_STATE_ENABLING_PROX:
        sensorSignalInternalEvt(data.proxHandle, SENSOR_INTERNAL_EVT_POWER_STATE_CHG, true, 0);
        break;

    case SENSOR_STATE_DISABLING_ALS:
        sensorSignalInternalEvt(data.alsHandle, SENSOR_INTERNAL_EVT_POWER_STATE_CHG, false, 0);
        break;

    case SENSOR_STATE_DISABLING_PROX:
        sensorSignalInternalEvt(data.proxHandle, SENSOR_INTERNAL_EVT_POWER_STATE_CHG, false, 0);
        break;

    case SENSOR_STATE_SAMPLING:
        /* TEST: log collected data
        osLog(LOG_INFO, "ROHM: sample ready: prox=%u als0=%u als1=%u\n",
              data.txrxBuf.sample.prox, data.txrxBuf.sample.als[0], data.txrxBuf.sample.als[1]);
        */

        if (data.alsOn && data.alsReading) {
            /* Create event */
            sample.fdata = getLuxFromAlsData(data.txrxBuf.sample.als[0],
                                             data.txrxBuf.sample.als[1]);
            if (data.lastAlsSample.idata != sample.idata) {
                osEnqueueEvt(sensorGetMyEventType(SENS_TYPE_ALS), sample.vptr, NULL);
                data.lastAlsSample.fdata = sample.fdata;
            }
        }

        if (data.proxOn && data.proxReading) {
            /* Create event */
            sendData = true;
            if (data.proxState == PROX_STATE_INIT) {
                if (data.txrxBuf.sample.prox > ROHM_RPR0521_THRESHOLD_ASSERT_NEAR) {
                    sample.fdata = ROHM_RPR0521_REPORT_NEAR_VALUE;
                    data.proxState = PROX_STATE_NEAR;
                } else {
                    sample.fdata = ROHM_RPR0521_REPORT_FAR_VALUE;
                    data.proxState = PROX_STATE_FAR;
                }
            } else {
                if (data.proxState == PROX_STATE_NEAR &&
                    data.txrxBuf.sample.prox < ROHM_RPR0521_THRESHOLD_DEASSERT_NEAR) {
                    sample.fdata = ROHM_RPR0521_REPORT_FAR_VALUE;
                    data.proxState = PROX_STATE_FAR;
                } else if (data.proxState == PROX_STATE_FAR &&
                    data.txrxBuf.sample.prox > ROHM_RPR0521_THRESHOLD_ASSERT_NEAR) {
                    sample.fdata = ROHM_RPR0521_REPORT_NEAR_VALUE;
                    data.proxState = PROX_STATE_NEAR;
                } else {
                    sendData = false;
                }
            }

            if (sendData)
                osEnqueueEvt(sensorGetMyEventType(SENS_TYPE_PROX), sample.vptr, NULL);
        }

        data.alsReading = false;
        data.proxReading = false;
        break;
    }
}