void CMCP23017::dumpReg(const uint8_t nRegAddr)
{
	uint8_t nRegVal = readReg(nRegAddr);
	Serial.print("********** ");
	Serial.print(getRegName(nRegAddr));
	Serial.print(" = ");
	Serial.print(nRegVal, BIN);
	Serial.println(" **********");
}
Beispiel #2
0
// should be called immediately after reception in case sender wants ACK
void RFM69::sendACK(const void* buffer, uint8_t bufferSize) {
  uint8_t sender = SENDERID;
  int16_t _RSSI = RSSI; // save payload received RSSI value
  writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks
  uint32_t now = millis();
  while (!canSend() && millis() - now < RF69_CSMA_LIMIT_MS) receiveDone();
  sendFrame(sender, buffer, bufferSize, false, true);
  RSSI = _RSSI; // restore payload RSSI
}
unsigned int get_rx_queue_num_pkts_dropped_bad(nf2device* nf2, unsigned char port) {
	unsigned int retval = 0;
	switch(port) {
		case 0:
			readReg(nf2, MAC_GRP_0_RX_QUEUE_NUM_PKTS_DROPPED_BAD_REG, &retval);
			break;
		case 1:
			readReg(nf2, MAC_GRP_1_RX_QUEUE_NUM_PKTS_DROPPED_BAD_REG, &retval);
			break;
		case 2:
			readReg(nf2, MAC_GRP_2_RX_QUEUE_NUM_PKTS_DROPPED_BAD_REG, &retval);
			break;
		case 3:
			readReg(nf2, MAC_GRP_3_RX_QUEUE_NUM_PKTS_DROPPED_BAD_REG, &retval);
			break;
	}
	return retval;
}
Beispiel #4
0
int8_t RFM69OOK::readRSSI(bool forceTrigger) {
  if (forceTrigger)
  {
    // RSSI trigger not needed if DAGC is in continuous mode
    writeReg(REG_RSSICONFIG, RF_RSSI_START);
    while ((readReg(REG_RSSICONFIG) & RF_RSSI_DONE) == 0x00); // Wait for RSSI_Ready
  }
  return -(readReg(REG_RSSIVALUE) >> 1);
}
Beispiel #5
0
/*
 *  Read the version info from the board
 */
void read_info( struct nf2device *nf2  )
{
  int i;

  // Read the version and revision
  readReg(nf2, DEV_ID_DEVICE_ID, &nf2->info.nf2_device_id);
  readReg(nf2, DEV_ID_REVISION, &nf2->info.nf2_revision);

  // Read the version string
  for (i = 0; i < DEVICE_STR_NUM_REGS; i++)
  {
    readReg(nf2, DEV_ID_DEV_STR_0 + i * 4, (unsigned *)(nf2->info.nf2_device_str + i * 4));

    // Perform byte swapping if necessary
    *(unsigned *)(nf2->info.nf2_device_str + i * 4) = ntohl(*(unsigned *)(nf2->info.nf2_device_str + i * 4));
  }
  nf2->info.nf2_device_str[DEVICE_STR_LEN - 1] = '\0';
}
Beispiel #6
0
static int getPrId() {

	uint32_t data = 0;

	/* read the current status register */
	readReg(DEVICE_NAME_ADC, PR_STATUS_ADDR, &data);

	return (data & 0xFF);
}
Beispiel #7
0
bool Acceleration_Sensor::init()
{
    const unsigned char activeModeWith100Hz = (1 << 0) | (3 << 3); // Active Mode @ 100Hz

    writeReg(Ctrl_Reg1, activeModeWith100Hz);
    const char whoAmIReg = readReg(WhoAmI);

    return (mWhoAmIExpectedValue == whoAmIReg);
}
Beispiel #8
0
unsigned short readRam (unsigned char reg)
{
    //read ram space address
    unsigned char hi,lo;

    while (readReg (RAMSTAT)&0x01);//wait for indirect registers

    writeReg(RAMADDR,reg) ;


    while (readReg (RAMSTAT)&0x01);//wait for indirect registers


    hi = readReg(RAMHI);
    lo = readReg(RAMLO);

    return (SixteenBit (hi,lo));
}
void update()//中断服务函数
{ 
	uint8_t Asr_Count=0;
	if((readReg(0x2b) & 0x10) && readReg(0xb2)==0x21 && readReg(0xbf)==0x35)//如果有语音识别中断、DSP闲、ASR正常结束
	{
		writeReg(0x29,0) ;///////////关中断
		writeReg(0x02,0) ;/////////////关FIFO中断
		Asr_Count = readReg(0xba);//读中断辅助信息
		if(Asr_Count>0 && Asr_Count<4) //////如果有识别结果
		{
			readnum=readReg(0xc5);
			readflag=1;
		}	
		writeReg(0x2b,0);//////清楚中断编号
		writeReg(0x1C,0);////////貌似关麦克风啊~~为毛
	}
	readReg(0x06);  
	delay(10);
	readReg(0x06);  
	writeReg(0x89, 0x03);  
	delay(5);
	writeReg(0xcf, 0x43);  
	delay(5);
	writeReg(0xcb, 0x02);
	writeReg(0x11, PLL_11);  
	writeReg(0x1e,0x00);
	writeReg(0x19, PLL_ASR_19); 
	writeReg(0x1b, PLL_ASR_1B);	
	writeReg(0x1d, PLL_ASR_1D);
	delay(10);
	writeReg(0xcd, 0x04);
	writeReg(0x17, 0x4c); 
	delay(5);
	writeReg(0xcf, 0x4f);  
	writeReg(0xbd, 0x00);
	writeReg(0x17, 0x48);
	delay(10);
	writeReg(0x3c, 0x80);  
	writeReg(0x3e, 0x07);
	writeReg(0x38, 0xff);  
	writeReg(0x3a, 0x07);
	writeReg(0x40, 0);   
	writeReg(0x42, 8);
	writeReg(0x44, 0); 
	writeReg(0x46, 8); 
	delay(1);	
	writeReg(0x1c, 0x09);////////麦克风设置保留
	writeReg(0xbd, 0x20);/////////保留设置
	writeReg(0x08, 0x01);///////////→清除FIFO_DATA
	delay( 1);
	writeReg(0x08, 0x00);////////////清除指定FIFO后再写入一次00H
	delay( 1);
	writeReg(0xb2, 0xff);////////给0xB2写FF
	writeReg(0x37, 0x06);////////开始识别
	delay( 5 );
	writeReg(0x1c, g_Mic);////////选择麦克风
	writeReg(0x29, 0x10);////////开同步中断
	writeReg(0xbd, 0x00);/////////启动为语音识别
}	
Beispiel #10
0
/*
 * initialize CC1101
 */
void cc1101Init(uint8_t mode100k) {
	cli();

	bitSet(DDR_SPI,    PIN_SPI_SS);												// set B2(SS) as Output
	bitSet(DDR_SPI,    PIN_SPI_MOSI);											// set B3(MOSI) as Output
	bitClear(DDR_SPI,  PIN_SPI_MISO);											// set B4(MISO) as Input
	bitSet(DDR_SPI,    PIN_SPI_SCK);											// set B5(SCK) as Output

	bitClear(DDR_GDO0, PIN_GDO0);												// set B2(SS) as Input

	bitSet(PORT_SPI,   PIN_SPI_SS);												// set SS high
	bitSet(PORT_SPI,   PIN_SPI_SCK);											// set SCK high
	bitClear(PORT_SPI, PIN_SPI_MOSI);											// set MOSI high

	SPCR = _BV(SPE) | _BV(MSTR);												// SPI speed = CLK/4

	cc1101_Deselect();															// some deselect and selects to initialize the TRX868modul
	_delay_us(30);

	cc1101_Select();	
	_delay_us(30);

	cc1101_Deselect();
	_delay_us(45);

	cmdStrobe(CC1101_SRES);														// send reset
	_delay_us(100);

	for (uint8_t i=0; i<sizeof(initVal); i += 2) {								// write initialize value to cc1101
		writeReg(pgm_read_byte(&initVal[i]), pgm_read_byte(&initVal[i+1]));	
	}

	if (mode100k) {																// switch to 100k mode
		for (uint8_t i=0; i<sizeof(initValUpdate); i += 2) {					// write initialize value to cc1101
			writeReg(
				pgm_read_byte(&initValUpdate[i]),
				pgm_read_byte(&initValUpdate[i+1])
			);
		}
	}

	cmdStrobe(CC1101_SCAL);														// calibrate frequency synthesizer and turn it off
	_delay_ms(4);

	do {
		cmdStrobe(CC1101_SRX);
	} while (readReg(CC1101_MARCSTATE, CC1101_STATUS) != 0x0D);
	
	writeReg(CC1101_PATABLE, PA_MaxPower);										// configure PATABLE
	cmdStrobe(CC1101_SRX);														// flush the RX buffer
	cmdStrobe(CC1101_SWORRST);													// reset real time clock

	_delay_ms(3);

	sei();
}
Beispiel #11
0
static void startrx (u1_t rxmode) {
    ASSERT( (readReg(RegOpMode) & OPMODE_MASK) == OPMODE_SLEEP );
    if(getSf(LMIC.rps) == FSK) { // FSK modem
        rxfsk(rxmode);
    } else { // LoRa modem
        rxlora(rxmode);
    }
    // the radio will go back to STANDBY mode as soon as the RX is finished
    // or timed out, and the corresponding IRQ will inform us about completion.
}
void nRF24L01p::irqFunction(byte _mask,boolean _onoff){
	byte buf=readReg(CONFIG);
	if(_onoff==true){
		buf|=0x70;
		buf&=(~_mask | 0x0F);
	}else if(_onoff==false){
		buf|=(_mask & 0x70);
	}
	writeReg(CONFIG,buf);
}
Beispiel #13
0
// start transmitter (buf=LMIC.frame, len=LMIC.dataLen)
static void starttx () {
    ASSERT( (readReg(RegOpMode) & OPMODE_MASK) == OPMODE_SLEEP );
    if(getSf(LMIC.rps) == FSK) { // FSK modem
        txfsk();
    } else { // LoRa modem
        txlora();
    }
    // the radio will go back to STANDBY mode as soon as the TX is finished
    // the corresponding IRQ will inform us about completion.
}
Beispiel #14
0
uint8_t EM2874Device::readReg (const uint8_t idx)
{
	uint8_t val;
	if(!readReg (idx, &val)) {
#ifdef DEBUG
	*log << "readReg(" << (unsigned)idx << ") failed.";
#endif
	}
	return val;
}
/**
 * Determine the size of a standard SD flash memory card
 * \return The number of 512 byte data blocks in the card
 */ 
uint32_t SdCard::cardSize(void)
{
  uint16_t c_size;
  csd_t csd;
  if (!readReg(CMD9, (uint8_t *)&csd)) return 0;
  uint8_t read_bl_len = csd.read_bl_len;
  c_size = (csd.c_size_high << 10) | (csd.c_size_mid << 2) | csd.c_size_low;
  uint8_t c_size_mult = (csd.c_size_mult_high << 1) | csd.c_size_mult_low;
  return (uint32_t)(c_size+1) << (c_size_mult + read_bl_len - 7);
}
void CMCP23017::setOutput(const uint8_t nPin)
{
	// Get value from MCP23017 port A if nPin is between 8 and 15 or from port B if nPin is between 0 and 7
	uint8_t nPort = getPort(nPin, IODIRA, IODIRB),
			nPortVal = readReg(nPort);

	// Preserve all the bits except for the one corresponding to the pin that we are changing to input mode (1)
	nPortVal &= ~getPinMask(nPin);
	writeReg(nPort, nPortVal);
}
Beispiel #17
0
// should be called immediately after reception in case sender wants ACK
void RFM69::sendACK(const void* buffer, uint8_t bufferSize) {
  ACK_REQUESTED = 0;   // TWS added to make sure we don't end up in a timing race and infinite loop sending Acks
  uint8_t sender = SENDERID;
  int16_t _RSSI = RSSI; // save payload received RSSI value
  writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks
  uint32_t now = millis();
  while (!canSend() && millis() - now < RF69_CSMA_LIMIT_MS) {    delayMicroseconds(MICROSLEEP_LENGTH); /* printf(".");*/ receiveDone();}
  sendFrame(sender, buffer, bufferSize, false, true);
  RSSI = _RSSI; // restore payload RSSI
}
void CMCP23017::setAutoIncrement(const bool bEnable)
{
	// Save the contents of the IOCON register.
	uint8_t nIOCONVal = readReg(IOCONA);

	if (bEnable)
		writeReg(IOCONA, nIOCONVal | 0b00100000);
	else
		writeReg(IOCONA, nIOCONVal & 0b11011111);
}
Beispiel #19
0
void Player_AD::writeReg(int r, int v) {
	if (r >= 0 && r < ARRAYSIZE(_registerBackUpTable)) {
		_registerBackUpTable[r] = v;
	}

	// Handle volume scaling depending on the sound type.
	if (r >= 0x40 && r <= 0x55) {
		const int operatorOffset = r - 0x40;
		const int channel = _operatorOffsetToChannel[operatorOffset];
		if (channel != -1) {
			const bool twoOPOutput = (readReg(0xC0 + channel) & 0x01) != 0;

			int scale = Audio::Mixer::kMaxChannelVolume;
			// We only scale the volume of operator 2 unless both operators
			// are set to directly produce sound.
			if (twoOPOutput || operatorOffset == _operatorOffsetTable[channel * 2 + 1]) {
				if (_hwChannels[channel].sfxOwner) {
					scale = _sfxVolume;
				} else {
					scale = _musicVolume;
				}
			}

			int vol = 0x3F - (v & 0x3F);
			vol = vol * scale / Audio::Mixer::kMaxChannelVolume;
			v &= 0xC0;
			v |= (0x3F - vol);
		}
	}

	// Since AdLib's lowest volume level does not imply that the sound is
	// completely silent we ignore key on in such a case.
	// We also ignore key on for music whenever we do seeking.
	if (r >= 0xB0 && r <= 0xB8) {
		const int channel = r - 0xB0;
		bool mute = false;
		if (_hwChannels[channel].sfxOwner) {
			if (!_sfxVolume) {
				mute = true;
			}
		} else {
			if (!_musicVolume) {
				mute = true;
			} else {
				mute = _isSeeking;
			}
		}

		if (mute) {
			v &= ~0x20;
		}
	}

	_opl2->writeReg(r, v);
}
/**
* \brief begin function - must be called before using other functions
*
* This function enables the magnetometer.
* The magnetometer is an I2C device so we initialise the I2C communications,
* make contact with the magnetometer, and check that it's what we think it is.
*
* We set the sampling rate to 10Hz, but where the values are from a heavily
* oversampled set of values 
*/
void EngduinoMagnetometerClass::begin() 
{	uint8_t reg;

	// Join I2C bus as master
	//
	Wire.begin();
	
	// Check to see that the device is there
	//
	Wire.beginTransmission(FXMS3110_IIC_ADDRESS);
	int error = Wire.endTransmission();  
	if (error != 0) {
		Serial.println("Error: I2C device not found");
		return;
	}
	
	// Check that it's the device we think it is
	//
	readReg(FXMS3110_WHO_AM_I, &reg);
	if (reg != FXMS3110)  {
		Serial.println("Error: Not an FXMS3110");
		return;
	}

	// Set this to raw mode - no user correction
	// and automatically enable reset to deal with big magnetic
	// fields
	readReg(FXMS3110_CTRL_REG2,  &reg);
	reg |= AUTO_MRST_EN_MASK | RAW_MASK;
	writeReg(FXMS3110_CTRL_REG2, &reg);


	standby();		// Stop the magnetometer

	// Set 10Hz data rate = 1280 Hz ADC with 128 times oversampling
	readReg(FXMS3110_CTRL_REG1, &reg);
	reg &= ~(DR_MASK | OS_MASK);
	reg |= DATA_RATE_1280_128;
	writeReg(FXMS3110_CTRL_REG1, &reg);
	
	activate();		// And start it again
}
Beispiel #21
0
/*
 * Audio engine interrupt service routine
 * To wake up ae wait queue
 */
static irqreturn_t ace_interrupt(int irq, void *dev)
{
	volatile int ae_out_mode_reg = 0;
	
	//status 0x24
	ae_out_mode_reg = readReg(AE_STATUS_REG);
	ae_interrupt_value = ae_out_mode_reg;
	if(ae_out_mode_reg & 0x04){
	  writeReg(AE_INT_EN_REG,readReg(AE_INT_EN_REG)&(~0x0f));
	}

	ae_out_mode_reg &= 0x0f;
	writeReg(AE_STATUS_REG,ae_out_mode_reg);	
	ae_interrupt_sta = 1;

	ae_out_mode_reg = readReg(AE_STATUS_REG);//ûÓà  ²âÊÔÊÇ·ñ¿ÉÒÔdel
	wake_up_interruptible(&wait_ae);
	
    return IRQ_HANDLED;
}
Beispiel #22
0
// TODO: finish this
ULONG Ez80::readRegister(const char *tname)
{
  const char *name=aDefaultStringHelper.removeSpaces2(aDefaultStringHelper.toLower(tname));
  if(!strcmp(name,"a")) { return a; }
  if(!strcmp(name,"s")) { return sp; }
  if(!strcmp(name,"sp")) { return sp; }
  if(!strcmp(name,"f")) { return f; }
  if(!strcmp(name,"ix")) { return ix; }
  if(!strcmp(name,"iy")) { return iy; }
  if(!strcmp(name,"b")) { return b; }
  if(!strcmp(name,"c")) { return c; }
  if(!strcmp(name,"d")) { return d; }
  if(!strcmp(name,"e")) { return e; }
  if(!strcmp(name,"h")) { return h; }
  if(!strcmp(name,"l")) { return l; }
  if(!strcmp(name,"bc")) { return readReg(Ez80_REG_BC,Ez80_SIZE_WORD); }
  if(!strcmp(name,"de")) { return readReg(Ez80_REG_DE,Ez80_SIZE_WORD); }
  if(!strcmp(name,"hl")) { return readReg(Ez80_REG_HL,Ez80_SIZE_WORD); }
  return 0;
}
Beispiel #23
0
bool waitPoll(uint8_t regname, uint8_t waitflag) {
  /* Wait for the command to finish */
	uint8_t temp;
	while (1)
	{
		temp = readReg(regname);
		if (!(temp & waitflag))
			return true;
	}
	return false; // MEMEFIX: yeah i know, unreached! - add timeout?
}
Beispiel #24
0
void L3GD20::setOutputDataRate(uint8_t DataRate)
{
	uint8_t RegisterValue;

	RegisterValue = readReg(L3GD20_CTRL_REG1);

	RegisterValue &= ~(0xC0);
	RegisterValue |= ((DataRate & 0x03) << 6);

	writeReg(L3GD20_CTRL_REG1, RegisterValue);
}
Beispiel #25
0
void L3GD20::setFullScaleRange(uint8_t FullScaleRange)
{
	uint8_t RegisterValue;

	RegisterValue = readReg(L3GD20_CTRL_REG4);

	RegisterValue &= ~(0x30);
	RegisterValue |= ((FullScaleRange & 0x03) << 4);

	writeReg(L3GD20_CTRL_REG4, RegisterValue);
}
Beispiel #26
0
void broadcastRAM (int reg,unsigned short data)
{
    //write ram space address BROADCAST MODE

    while (readReg (RAMSTAT)&0x01);//wait for indirect registers
    byteToSpi ((unsigned char)(Cid|0x80));
    byteToSpi ((unsigned char)(reg));
    byteToSpi (high8bit(data));
    byteToSpi (low8bit(data));

}
Beispiel #27
0
void L3GD20::setBandwidth(uint8_t Bandwidth)
{
	uint8_t RegisterValue;

	RegisterValue = readReg(L3GD20_CTRL_REG1);

	RegisterValue &= ~(0x30);
	RegisterValue |= ((Bandwidth & 0x03) << 4);

	writeReg(L3GD20_CTRL_REG1, RegisterValue);
}
Beispiel #28
0
// To enable encryption: radio.encrypt("ABCDEFGHIJKLMNOP");
// To disable encryption: radio.encrypt(null) or radio.encrypt(0)
// KEY HAS TO BE 16 bytes !!!
void RFM69::encrypt(const char* key) {
  setMode(RF69_MODE_STANDBY);
  if (key!=0)
  {
    select();
    SPI.transfer(REG_AESKEY1 | 0x80);
    for (byte i = 0; i<16; i++)
      SPI.transfer(key[i]);
    unselect();
  }
  writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFE) | (key ? 1 : 0));
}
Beispiel #29
0
//=============================================================================
// sendAck() - updated to call new sendFrame with additional parameters
//=============================================================================
// should be called immediately after reception in case sender wants ACK
void RFM69_ATC::sendACK(const void* buffer, uint8_t bufferSize) {
  ACK_REQUESTED = 0;   // TomWS1 added to make sure we don't end up in a timing race and infinite loop sending Acks
  uint8_t sender = SENDERID;
  int16_t _RSSI = RSSI; // save payload received RSSI value
  bool sendRSSI = ACK_RSSI_REQUESTED;  
  writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks
  uint32_t now = millis();
  while (!canSend() && millis() - now < RF69_CSMA_LIMIT_MS) receiveDone();
  SENDERID = sender;    // TomWS1: Restore SenderID after it gets wiped out by receiveDone()
  sendFrame(sender, buffer, bufferSize, false, true, sendRSSI, _RSSI);   // TomWS1: Special override on sendFrame with extra params
  RSSI = _RSSI; // restore payload RSSI
}
void nRF24L01p::dataRate(byte _RFdr){
	testLow();
	byte buf_RF=readReg(RF_SETUP);
	switch (_RFdr){
		case 1		: _RFdr=0x00; break;
		case 2		: _RFdr=0x08; break;
		case 250	: _RFdr=0x20; break;
		default		: _RFdr=buf_RF; break;
	}
	writeReg(RF_SETUP, _RFdr | (buf_RF & 0x07));
	testHigh();
}