Exemple #1
0
static DRIVER_API_RC i2c_sync_write(struct td_device *dev, int len,
				    uint8_t *data)
{
	DRIVER_API_RC ret;
	OS_ERR_TYPE ret_os;
	struct apds9190_info *ir_dev = (struct apds9190_info *)dev->priv;
	struct sba_request *req = &ir_dev->req;

	req->request_type = SBA_TX;
	req->priv_data = ir_dev->i2c_sync_sem;
	req->callback = apds_sba_completion_callback;
	req->tx_len = len;
	req->tx_buff = data;

	if ((ret =
		     sba_exec_dev_request((struct sba_device *)dev,
					  req)) == DRV_RC_OK) {
		/* Wait for transfer to complete (timeout = 100ms) */
		if ((ret_os =
			     semaphore_take(ir_dev->i2c_sync_sem,
					    SBA_TIMEOUT)) != E_OS_OK) {
			if (ret_os == E_OS_ERR_BUSY) {
				ret = DRV_RC_TIMEOUT;
			} else {
				ret = DRV_RC_FAIL;
			}
		} else {
			ret = req->status;
		}
	}

	return ret;
}
Exemple #2
0
bool i2c_operation(I2COperation op)
{
	if (!queue_send(op_queue, &op, PORT_MAX_DELAY))
		return FALSE;

	semaphore_take(bus_lock, PORT_MAX_DELAY);

	return TRUE;
}
Exemple #3
0
void sensor_delay_ms(uint32_t msecs)
{
	if (msecs >= CONVERT_TICKS_TO_MS(1)) {
		T_SEMAPHORE sem = semaphore_create(0);
		semaphore_take(sem, (int)msecs + 1); /* details in FIRE-5618 */
		semaphore_delete(sem);
	} else {
		wait_ticks(msecs * AON_CNT_TICK_PER_MS);
	}
}
Exemple #4
0
bool i2c_stop()
{
	state = I2C_STATE_STOP;

	I2CStop(I2C1);

	if (!semaphore_take(bus_lock, PORT_MAX_DELAY))
		return FALSE;

	return TRUE;
}
Exemple #5
0
bool i2c_acknowledge(bool ack)
{
	state = I2C_STATE_ACKNOWLEDGE;

	I2CAcknowledgeByte(I2C1, ack);

	if (!semaphore_take(bus_lock, PORT_MAX_DELAY))
		return FALSE;

	return TRUE;
}
Exemple #6
0
void sensor_delay_ms(uint32_t msecs)
{
	if (msecs >= CONVERT_TICKS_TO_MS(1)) {
		T_SEMAPHORE sem = semaphore_create(0);
/* Ensure that we will wait at least 'msecs' millisecond as if semaphore_take is called
 * right before the timer tick interrupt it will be released immediately */
		semaphore_take(sem, (int)msecs + 1);
		semaphore_delete(sem);
	} else {
		wait_ticks(msecs * AON_CNT_TICK_PER_MS);
	}
}
Exemple #7
0
bool i2c_transmit(char byte)
{
	state = I2C_STATE_TRANSMIT;

	if (I2CSendByte(I2C1, byte) != I2C_SUCCESS)
		return FALSE;

	if (!semaphore_take(bus_lock, PORT_MAX_DELAY))
		return FALSE;

	return TRUE;
}
Exemple #8
0
bool i2c_receive()
{
	state = I2C_STATE_RECEIVE;

	if (I2CReceiverEnable(I2C1, TRUE) != I2C_SUCCESS)
		return FALSE;

	if (!semaphore_take(bus_lock, PORT_MAX_DELAY))
		return FALSE;

	return TRUE;
}
Exemple #9
0
/**
 * Read a message from a queue.
 *
 *     Read and dequeue a message.
 *     This service may panic if err parameter is NULL and:
 *      -# queue parameter is invalid, or
 *      -# message parameter is NULL, or
 *      -# when called from an ISR.
 *
 *     Authorized execution levels:  task, fiber.
 *
 * @param queue : handler on the queue (value returned by queue_create).
 *
 * @param message (out): pointer to read message.
 *
 * @param timeout: maximum number of milliseconds to wait for the message. Special
 *                values OS_NO_WAIT and OS_WAIT_FOREVER may be used.
 *
 * @param err (out): execution status:
 *          -# E_OS_OK : a message was read
 *          -# E_OS_ERR_TIMEOUT: no message was received
 *          -# E_OS_ERR_EMPTY: the queue is empty
 *          -# E_OS_ERR: invalid parameter
 *          -# E_OS_ERR_NOT_ALLOWED: service cannot be executed from ISR context.
 */
void queue_get_message (T_QUEUE queue, T_QUEUE_MESSAGE* message, int timeout, OS_ERR_TYPE* err)
{
    OS_ERR_TYPE _err;
    T_EXEC_LEVEL execLvl = _getExecLevel();
    queue_impl_t * q = (queue_impl_t*) queue;

    /* check input parameters */
    if( (message == NULL) || (!queue_used(q)) || (q->sema==NULL) || (timeout<OS_WAIT_FOREVER) )
    {
        error_management (err, E_OS_ERR);
        return;
    }

    /* check execution level */
    if ((E_EXEC_LVL_FIBER == execLvl) || (E_EXEC_LVL_TASK == execLvl))
    {
        _err = semaphore_take(q->sema, timeout);
        switch(_err){

        case E_OS_OK:
        {
            uint32_t it_mask = interrupt_lock();
            _err = remove_data(q, message);
            interrupt_unlock(it_mask);
            error_management (err, E_OS_OK);
        }
            break;
        case E_OS_ERR_TIMEOUT:
            error_management (err, E_OS_ERR_TIMEOUT);
            break;
        case E_OS_ERR_BUSY:
            if(err){
                //QUEUE EMPTY, is a common use case, do not panic even if err == NULL
                *err = E_OS_ERR_EMPTY;
            }
            break;
        default:
            //unknown error
            panic(E_OS_ERR_UNKNOWN);
        }
    }
    else
    {
        error_management (err, E_OS_ERR_NOT_ALLOWED);
    }

    return;
}
Exemple #10
0
bool i2c_start(bool restart)
{
	if (restart) {
		state = I2C_STATE_REPEATED_START;

		if (I2CRepeatStart(I2C1) != I2C_SUCCESS)
			return FALSE;
	} else {
		state = I2C_STATE_START;

		if (I2CStart(I2C1) != I2C_SUCCESS)
			return FALSE;
	}

	if (!semaphore_take(bus_lock, PORT_MAX_DELAY))
		return FALSE;

	return TRUE;
}
Exemple #11
0
uint8_t i2c_read_reg8(struct td_device *dev, uint8_t reg)
{
	DRIVER_API_RC ret;
	OS_ERR_TYPE ret_os;
	struct apds9190_info *ir_dev = (struct apds9190_info *)dev->priv;
	struct sba_request *req = &ir_dev->req;
	uint8_t rsp;
	uint8_t cmd = COMMAND_ENABLE | reg;

	req->request_type = SBA_TRANSFER;
	req->tx_buff = &cmd;
	req->tx_len = 1;
	req->rx_buff = &rsp;
	req->rx_len = 1;
	req->priv_data = ir_dev->i2c_sync_sem;
	req->callback = apds_sba_completion_callback;
	req->full_duplex = 1;

	if ((ret =
		     sba_exec_dev_request((struct sba_device *)dev,
					  req)) == DRV_RC_OK) {
		/* Wait for transfer to complete (timeout = 100ms) */
		if ((ret_os =
			     semaphore_take(ir_dev->i2c_sync_sem,
					    SBA_TIMEOUT)) != E_OS_OK) {
			if (ret_os == E_OS_ERR_BUSY) {
				ret = DRV_RC_TIMEOUT;
			} else {
				ret = DRV_RC_FAIL;
			}
		} else {
			ret = req->status;
		}
	}

	if (ret < 0)
		return ret;
	else
		return rsp;
}
Exemple #12
0
DRIVER_API_RC sensor_bus_access(struct sensor_sba_info *info,
				uint8_t *tx_buffer, uint32_t tx_len,
				uint8_t *rx_buffer,
				uint32_t rx_len, bool req_read,
				int slave_addr)
{
	int i;
	sba_request_t *req;
	DRIVER_API_RC ret = DRV_RC_OK;
	OS_ERR_TYPE err;

	if ((i = get_sba_req(&info->bitmap, info->req_cnt)) >= info->req_cnt) {
		pr_debug(LOG_MODULE_DRV, "%s:DEV[%d] No req left", __func__,
			 info->dev_id);
		return DRV_RC_FAIL;
	}

	req = &info->reqs[i].req;

	if (0 <= slave_addr)
		req->addr.cs = slave_addr;

	if (req_read)
		config_req_read(tx_buffer, tx_len, rx_buffer, rx_len, req);
	else
		config_req_write(tx_buffer, tx_len, req);

	if (sba_exec_request(req)) {
		pr_debug(LOG_MODULE_DRV, "%s:DEV[%d] request exec error",
			 __func__,
			 info->dev_id);
		release_sba_req(&info->bitmap, i);
		return DRV_RC_FAIL;
	}

	if (info->block_type == SLEEP) {
		if ((err =
			     semaphore_take(info->reqs[i].sem,
					    SENSOR_BUS_TIMEOUT))) {
			pr_debug(LOG_MODULE_DRV,
				 "%s:DEV[%d] take semaphore err#%d", __func__,
				 info->dev_id,
				 err);
			release_sba_req(&info->bitmap, i);
			return DRV_RC_FAIL;
		}
	} else {
		struct sensor_sba_req *sensor_req =
			(struct sensor_sba_req *)req;
		while (1) {
			if (sensor_req->complete_flag != 0) {
				sensor_req->complete_flag = 0;
				break;
			}
		}
	}

	if (req->status) {
		pr_error(LOG_MODULE_DRV, "%s:DEV[%d] state error", __func__,
			 info->dev_id);
		ret = DRV_RC_FAIL;
	}
	release_sba_req(&info->bitmap, i);

	return ret;
}