Пример #1
0
/***	putEeprom
**
**	Parameters:
**		eeprom	- pointer to a flash memory page acting as emulated EEPROM
**		address	- location to be written
**		data	- data to be written
**
**	Return Value:
**		Returns true if the operation was successful, false otherwise
**
**	Errors:
**		none
**
**	Description:
**		Searches through emulated EEPROM page for valid address then
**		invalidates that location and writes the address and data
**		to a new unused location.
*/
BOOL putEeprom(eeSeg * eeprom, uint32_t address, uint8_t data)
{
	eeSeg tempSeg;

	int i;

	uint32_t nextAvalible;

	//Check if address exists 
	for(i=0; i < _EEPROM_PAGE_SIZE; i++) {
		
		//Check if eeSeg is valid and address matches
		if(getValid(eeprom[i]) && !getTaken(eeprom[i]) && 
		   getAddress(eeprom[i]) == address) {
			
			   //If data is same do nothing
			   if(data == getData(eeprom[i])) {
				   return fTrue;
			   }
			   //If data is different invalidate eeSeg
			   else {
				   tempSeg = eeprom[i];
				   tempSeg.temp.valid = 0;
				   writeFlashWord((void*)&eeprom[i],tempSeg.data);

				   // If data is 0xFF return
				//if(data == 0xFF) {
				//	printf(" and data is 0xFF so done.\n\r");
				//	return fTrue;
				//}
			   }
		}
		//If empty eeSeg found save location and break
		else if(getValid(eeprom[i]) && getTaken(eeprom[i])) {
			nextAvalible = i;
			break;
		}
	}

	//If I == max size no valid segments exist
	if(i == _EEPROM_PAGE_SIZE) {
		return fFalse;
	}

	//Pack address with data and write to flash
	tempSeg = pack(address,data);
	writeFlashWord((void*)&eeprom[i],tempSeg.data);

	return fTrue;
}
Пример #2
0
/***	getEeprom
**
**	Parameters:
**		eeprom	- pointer to flash memory acting as emulated eeprom
**		address	- location to be read
**		data	- data to be read
**
**	Return Value:
**		Returns true or false wether the operation was successful
**		or not.
**
**	Errors:
**		none
**
**	Description:
**		Searches through emulated eeprom for valid address and
**		returns data. If no address can be found the funtion
**		will return false and set data pointer to 0xFF
*/
BOOL getEeprom(eeSeg * eeprom, uint32_t address,uint8_t * data)
{
	int i;

	//Check if address exists
	for(i=0; i < _EEPROM_PAGE_SIZE; i++) {
		//Check if eeSeg is valid and address matches
		if(getValid(eeprom[i]) && !getTaken(eeprom[i]) &&
		   getAddress(eeprom[i]) == address) {
			//Set data to pointer and return
			*data = getData(eeprom[i]);
			return fTrue;
		}
		else if(getValid(eeprom[i]) && getTaken(eeprom[i])) {
			break;
		}
	}

	//If address not found return 0xFF
	*data = 0xFF;
	return fFalse;
}
Пример #3
0
/***	putBuffer
**
**	Parameters:
**		eeprom	- pointer to flash memory acting as emulated eeprom
**		buffer	- pointer to buffer
**
**	Return Value:
**		Returns true or false wether the operation was successful
**		or not.
**
**	Errors:
**		none
**
**	Description:
**		Searches through emulated eeprom for valid addresses
**		then writes data to buffer using address as the index
*/
uint32_t putBuffer(eeSeg * eeprom, uint8_t * buffer)
{
	uint16_t tempAddress;

	int i;

	//Initialize each byte in buffer to 0xFF
	for(i=0; i < _EEPROM_PAGE_SIZE; i++) {
		buffer[i] = 0xFF;
	}
	
	//Find all valid addresses and load them to buffer
	for(i=0; i < _EEPROM_PAGE_SIZE; i++) {
		if(getValid(eeprom[i]) && !getTaken(eeprom[i])) {
			tempAddress = getAddress(eeprom[i]);
			buffer[tempAddress] = getData(eeprom[i]);
		}
	}
}
Пример #4
0
/***	putBuffer
**
**	Parameters:
**		eeprom	- pointer to flash memory acting as emulated EEPROM
**		buffer	- pointer to buffer
**
**	Return Value:
**		Returns true if the operation was successful, false otherwise
**
**	Errors:
**		none
**
**	Description:
**		Searches through emulated EEPROM for valid addresses
**		then writes data to buffer using address as the index
**		buffer must be big enough to hold all addresses (even
**		those that aren't used) i.e. MAX_ADDRESS_DEFAULT big.
*/
uint32_t putBuffer(uint8_t * buffer)
{
	uint16_t tempAddress;

	int i, j;

	//Initialize each byte in buffer to 0xFF
	for(i=0; i < max_address; i++) {
		buffer[i] = 0xFF;
	}
	
	//Find all valid addresses and load them to buffer
	for(j=0; j < _EEPROM_PAGE_COUNT; j++) {
	for(i=0; i < _EEPROM_PAGE_SIZE; i++) {
			if(getValid((eeSeg)eedata_addr[j][i]) && !getTaken((eeSeg)eedata_addr[j][i])) {
				tempAddress = getAddress((eeSeg)eedata_addr[j][i]);
				buffer[tempAddress] = getData((eeSeg)eedata_addr[j][i]);
			}
		}
	}
}
Пример #5
0
void BCPattern::matchAnchored(const Expr& pattern,
                              PC start, PC end, Result& result) {
  auto pos = pattern.begin();

  for (auto inst = start; inst != end; ) {
    // Detect a match.
    if (pos == pattern.end()) {
      result.m_start = start;
      result.m_end = inst;
      return;
    }

    auto const op = peek_op(inst);

    // Skip pattern-globally ignored opcodes.
    if (m_ignores.count(op)) {
      inst = next(inst);
      continue;
    }

    // Check for alternations whenever we fail to match.
    auto nomatch = [&] {
      if (!pos->hasAlt()) return result.erase();

      // Pop the capture if we made one.
      if (pos->shouldCapture()) {
        result.m_captures.pop_back();
      }

      for (auto const& atom : pos->getAlt()) {
        // Construct the full alternate pattern.
        auto alt = Expr { atom };
        alt.insert(alt.end(), std::next(pos), pattern.end());
        auto res = result;

        // Match on the alternate.
        matchAnchored(alt, inst, end, res);

        if (res.found()) {
          result = res;
          result.m_start = start;
          return;
        }
      }
      return result.erase();
    };

    // Capture the atom if desired.
    if (pos->shouldCapture()) {
      result.m_captures.push_back(inst);
    }

    // Check for shallow match.
    if (pos->op() != op) {
      return nomatch();
    }

    auto filter = pos->getFilter();

    // Check for deep match if desired.
    if (filter && !filter(inst, result.m_captures)) {
      return nomatch();
    }

    if ((pos->op() == Op::JmpZ || pos->op() == Op::JmpNZ)) {
      // Match the taken block, if there is one.
      auto off = instrJumpOffset(inst);
      assert(off);

      auto res = result;
      matchAnchored(pos->getTaken(), inst + *off, end, res);

      if (!res.found()) {
        return nomatch();
      }

      // Grab the captures.
      result.m_captures = res.m_captures;
    }

    if (pos->hasSeq()) {
      // Match the subsequence if we have one.
      auto res = result;
      matchAnchored(pos->getSeq(), next(inst), end, res);

      if (!res.found()) {
        return nomatch();
      }

      // Set the PC.
      result.m_captures = res.m_captures;
      inst = res.m_end;
    } else {
      // Step the PC.
      inst = next(inst);
    }

    // Step the pattern.
    ++pos;
  }

  // Detect a terminal match.
  if (pos == pattern.end()) {
    result.m_start = start;
    result.m_end = end;
  }
}