コード例 #1
0
ファイル: I2CController.cpp プロジェクト: HubertD/openstella
unsigned long I2CController::nolock_write8(uint8_t addr, uint8_t data, bool sendStartCondition, bool sendStopCondition)
{
	unsigned long ret;

	I2CMasterSlaveAddrSet(_base, addr, 0);
	I2CMasterDataPut(_base, data);
	if (sendStartCondition) {
		I2CMasterControl(_base, sendStopCondition ? I2C_MASTER_CMD_SINGLE_SEND : I2C_MASTER_CMD_BURST_SEND_START);
		ret = I2CMasterErr(_base);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}

	} else {
		I2CMasterControl(_base, sendStopCondition ? I2C_MASTER_CMD_BURST_SEND_FINISH : I2C_MASTER_CMD_BURST_SEND_CONT);
		ret = I2CMasterErr(_base);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}

	}
	ret = waitFinish();
	if (ret != I2C_MASTER_ERR_NONE) {
		return ret;
	}

	return 0;
}
コード例 #2
0
ファイル: I2CController.cpp プロジェクト: HubertD/openstella
unsigned long I2CController::nolock_read(uint8_t addr, uint8_t *buf, int count, bool sendStartCondition, bool sendStopCondition)
{
	unsigned long ret;

	if (count<1) return 0;
	ret = nolock_read8(addr, buf, sendStartCondition, (sendStopCondition && count==1));
	if (ret != I2C_MASTER_ERR_NONE) {
		return ret;
	}

	for (uint8_t i=1; i<count; i++) {
		I2CMasterControl(_base, ((i==(count-1)) && sendStopCondition) ? I2C_MASTER_CMD_BURST_RECEIVE_FINISH : I2C_MASTER_CMD_BURST_RECEIVE_CONT);
		ret = I2CMasterErr(_base);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}
		ret = waitFinish();
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}
		buf[i] = I2CMasterDataGet(_base);
		ret = I2CMasterErr(_base);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}

	}

	return 0;
}
コード例 #3
0
unsigned long I2CController::write(uint8_t addr, const void *ptr, int count, bool sendStartCondition, bool sendStopCondition)
{
	const uint8_t *buf = (const uint8_t *) ptr;

	RecursiveMutexGuard guard(&_lock);
	unsigned long ret;

	if (count<1) return 0;

	ret = write8(addr, buf[0], sendStartCondition, (count==1) && sendStopCondition);
	if (ret != I2C_MASTER_ERR_NONE) { return ret; }

	ret = I2CMasterErr(_base);
	if (ret != I2C_MASTER_ERR_NONE) { return ret; }

	for(int i=1; i<count; i++) {
		I2CMasterDataPut(_base, buf[i]);
		I2CMasterControl(_base, (sendStopCondition && (i == count-1)) ? I2C_MASTER_CMD_BURST_SEND_FINISH : I2C_MASTER_CMD_BURST_SEND_CONT);
		ret = I2CMasterErr(_base);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}
		ret = waitFinish(_defaultTimeout);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}
	}
  return 0;
}
コード例 #4
0
unsigned long I2CController::read(uint8_t addr, void *ptr, int count, bool sendStartCondition, bool sendStopCondition)
{
	uint8_t *buf = (uint8_t *) ptr;

	RecursiveMutexGuard guard(&_lock);
	unsigned long ret;

	if (count<1) return 0;
	ret = read8(addr, buf, sendStartCondition, (sendStopCondition && count==1));
	if (ret != I2C_MASTER_ERR_NONE) {
		return ret;
	}

	for (uint8_t i=1; i<count; i++) {
		I2CMasterControl(_base, ((i==(count-1)) && sendStopCondition) ? I2C_MASTER_CMD_BURST_RECEIVE_FINISH : I2C_MASTER_CMD_BURST_RECEIVE_CONT);
		ret = I2CMasterErr(_base);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}
		ret = waitFinish(_defaultTimeout);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}
		buf[i] = I2CMasterDataGet(_base);
		ret = I2CMasterErr(_base);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}

	}

	return 0;
}
コード例 #5
0
unsigned long I2CController::read8(uint8_t addr, uint8_t *data, bool sendStartCondition, bool sendStopCondition)
{
	RecursiveMutexGuard guard(&_lock);
	unsigned long ret;

	I2CMasterSlaveAddrSet(_base, addr, 1);
	if (sendStartCondition) {
		I2CMasterControl(_base, sendStopCondition ? I2C_MASTER_CMD_SINGLE_SEND : I2C_MASTER_CMD_BURST_RECEIVE_START);
		ret = I2CMasterErr(_base);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}
	} else {
		I2CMasterControl(_base, sendStopCondition ? I2C_MASTER_CMD_BURST_RECEIVE_FINISH : I2C_MASTER_CMD_BURST_RECEIVE_CONT);
		ret = I2CMasterErr(_base);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}
	}
	ret = waitFinish(_defaultTimeout);
	if (ret != I2C_MASTER_ERR_NONE) {
		return ret;
	}

	*data = I2CMasterDataGet(_base);
	ret = I2CMasterErr(_base);
	if (ret != I2C_MASTER_ERR_NONE) {
		return ret;
	}
	return 0;
}
コード例 #6
0
ファイル: sdisk2.c プロジェクト: godzivan/sdisk2-firmware
void duplicateFat(void)
{
	unsigned short i, j;
	unsigned long adr = fatAddr;
	unsigned char *buf = &writeData[0][0];

	cmd(16, 512);
	for (j=0; j<sectorsPerFat; j++) {
		cmd17(adr);
		for (i=0; i<512; i++) buf[i] = readByte();
		readByte(); readByte(); // discard CRC bytes

		PORTB |= (1<<SD_CS);
		PORTB &= ~(1<<SD_CS);	
	
		cmd(24,adr+(unsigned long)sectorsPerFat*512);		
		writeByte(0xff);
		writeByte(0xfe);
		for (i=0; i<512; i++) writeByte(buf[i]);
		writeByte(0xff);
		writeByte(0xff);
		readByte();
		waitFinish();
		adr += 512;

		PORTB |= (1<<SD_CS);
		PORTB &= ~(1<<SD_CS);
	}
}
コード例 #7
0
ファイル: sdisk2.c プロジェクト: godzivan/sdisk2-firmware
void writeSD(unsigned long adr, unsigned char *data, unsigned short len)
{
	unsigned int i;
	unsigned char *buf = &writeData[0][0];

	cmd(16, 512);
	cmd17(adr&0xfffffe00);
	for (i=0; i<512; i++) buf[i] = readByte();
	readByte(); readByte(); // discard CRC bytes
	memcp(&(buf[adr&0x1ff]), data, len);
	
	PORTB |= (1<<SD_CS);
	PORTB &= ~(1<<SD_CS);
				
	cmd(24,adr&0xfffffe00);		
	writeByte(0xff);
	writeByte(0xfe);
	for (i=0; i<512; i++) writeByte(buf[i]);
	writeByte(0xff);
	writeByte(0xff);
	readByte();
	waitFinish();
	
	PORTB |= (1<<SD_CS);
	PORTB &= ~(1<<SD_CS);	
}
コード例 #8
0
ファイル: rsxutil.cpp プロジェクト: CaptainCPS/PSL1GHT
static void waitRSXIdle()
{
	rsxSetWriteBackendLabel(context,GCM_LABEL_INDEX,sLabelVal);
	rsxSetWaitLabel(context,GCM_LABEL_INDEX,sLabelVal);

	++sLabelVal;

	waitFinish();
}
コード例 #9
0
static void waitRSXIdle(gcmContextData *context){
	u32 sLabelVal = 1;

	rsxSetWriteBackendLabel(context, GCM_LABEL_INDEX, sLabelVal);
	rsxSetWaitLabel(context, GCM_LABEL_INDEX, sLabelVal);

	sLabelVal++;

	waitFinish(context, sLabelVal);
}
コード例 #10
0
void I2CController::setup(GPIOPin sda, GPIOPin scl, speed_t speed, bool doEnableInterrupts, uint32_t defaultTimeout)
{
	RecursiveMutexGuard guard(&_lock);
	_sda = sda;
	_scl = scl;
	_defaultTimeout = defaultTimeout;

	MAP_SysCtlPeripheralEnable(_periph);
	SysCtlPeripheralReset(_periph);

	_sda.enablePeripheral();
	if (_base == I2C0_MASTER_BASE) {
		_sda.mapAsI2C0SDA();
	}
	else if (_base == I2C1_MASTER_BASE) {
		_sda.mapAsI2C1SDA();
	}
	else {
		while(1) { /* we should never get here! */ }
	}
	_sda.configure(GPIOPin::I2C);

	_scl.enablePeripheral();
	if (_base == I2C0_MASTER_BASE) {
		_scl.mapAsI2C0SCL();
	}
	else if (_base == I2C1_MASTER_BASE) {
		_scl.mapAsI2C1SCL();
	}
	else {
		while(1) { /* we should never get here! */ }
	}
	_scl.configure(GPIOPin::I2CSCL);

	I2CMasterInitExpClk(_base, MAP_SysCtlClockGet(), (speed==speed_400kBit) ? 1 : 0);
	I2CMasterEnable(_base);

	if (doEnableInterrupts) enableInterrupts(true, true);

    // Do a dummy receive to make sure you don't get junk on the first receive.
    I2CMasterControl(_base, I2C_MASTER_CMD_SINGLE_RECEIVE);
    waitFinish(1);
}
コード例 #11
0
ファイル: I2CController.cpp プロジェクト: HubertD/openstella
unsigned long I2CController::nolock_write(uint8_t addr, uint8_t *buf, int count, bool sendStartCondition, bool sendStopCondition)
{
	unsigned long ret;

	if (count<1) return 0;
	nolock_write8(addr, buf[0], sendStartCondition, (count==1) && sendStopCondition);
	ret = I2CMasterErr(_base);
	if (ret != I2C_MASTER_ERR_NONE) {
		return ret;
	}
	for(int i=1; i<count; i++) {
		I2CMasterDataPut(_base, buf[i]);
		I2CMasterControl(_base, (sendStopCondition && (i == count-1)) ? I2C_MASTER_CMD_BURST_SEND_FINISH : I2C_MASTER_CMD_BURST_SEND_CONT);
		ret = I2CMasterErr(_base);
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}
		ret = waitFinish();
		if (ret != I2C_MASTER_ERR_NONE) {
			return ret;
		}
	}
  return 0;
}
コード例 #12
0
 ~JobScheduler(void)
 {
   waitFinish();
   MEMALLOC_DELETE_ARRAY(ThreadWorker,mThreads);
   LOCK_FREE_Q::releaseLockFreeQ(mPending);
 }