コード例 #1
0
ファイル: i2c_T.cpp プロジェクト: gotoco/lowPowerFreeRtos
enum Error i2cWriteToSlaveT(uint16_t addr, const char *string, uint8_t lenght, portTickType ticks_to_wait)
{
	struct _i2cMessage message;

	message.length = lenght;
	message.addr=addr;
	message.rxFlag=TX_FLAG;
	message.sendMessTaskHandle=xTaskGetCurrentTaskHandle();

	if (message.length == 0)
		return ERROR_NONE;

	if (string >= __ram_start)				// is the string in RAM?
			{
		message.string = (char*) pvPortMalloc(message.length);
		if (message.string == NULL)
			return ERROR_FreeRTOS_errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;

		memcpy(message.string, string, message.length);
	} else
		message.string = (char*) string;// no, string in ROM - just use the address

	enum Error error;

	if(message.sendMessTaskHandle != NULL){
		portBASE_TYPE ret = xQueueSend(_rxTxQueue, &message, ticks_to_wait);
		error = errorConvert_portBASE_TYPE(ret);
	}
	else{
		_i2cWrite(&message);
	}

	return error;
}
コード例 #2
0
ファイル: i2c_T.cpp プロジェクト: gotoco/lowPowerFreeRtos
static void _i2cTask(void *parameters)
{

	while(1){

		struct _i2cMessage message;
		xQueueReceive(_rxTxQueue, &message, portMAX_DELAY);	// get data to send

		xSemaphoreTake(_i2cHrdSemaphore, portMAX_DELAY);	// wait for DMA to be free, useful think for a future

		if(message.rxFlag){
			_i2cRead(&message);
		}else{
			_i2cWrite(&message);
		}


		xSemaphoreGive(_i2cHrdSemaphore);
		vTaskDelay(1/portTICK_RATE_MS);	//Then go sleep
	}
}
コード例 #3
0
ファイル: i2c.c プロジェクト: gustavors88/augreality
// i2cWrite - Writes the specified number of data bytes to the specified address
bool i2cWrite(uint8_t addr, uint8_t *data, uint16_t count) {
	i2cState.status &= ~I2C_STATUS_NOSTOP;
	return _i2cWrite(addr, data, count);
}
コード例 #4
0
ファイル: i2c.c プロジェクト: gustavors88/augreality
// i2cReadRegister - Reads the specified amount of data from the given register address on
// the specified I2C address
bool i2cReadRegister(uint8_t addr, uint8_t reg, uint8_t *value, uint16_t count) {
	i2cState.status |= I2C_STATUS_NOSTOP;
	// Write out the location we want and read in data
	return _i2cWrite(addr, &reg, 1) && _i2cRead(addr, value, count);
}