def parseRegister(register, baseAddress, prefix, ext): noActionIfZeroBits = 0xFFFFFFFF noActionIfOneBits = 0x00000000 fieldOut = "" for field in register.fields: msb = field.bit_offset + field.bit_width - 1 lsb = field.bit_offset fieldType = "unsigned" fieldName = Ft.formatVariable(field.name) fieldOut += " ///%s\n" % Ft.formatComment(field.description) cValuesOut = "" if Ft.useEnumeratedValues(field.enumerated_values, field.bit_width): fieldType = "%sVal" % (fieldName.capitalize()) fieldOut += " enum class %s {\n" % fieldType cValuesOut = " namespace %sC{\n" % fieldType for v in field.enumerated_values: if v.value is not None and v.is_default is None: #some value are defaults, we ignore them valName = Ft.getKey( ext, ['field', field.name, 'enum', v.name, '.rename' ]) or Ft.formatEnumValue(v.name) if valName != 'reserved': fieldOut += " %s=0x%08x, ///<%s\n" % ( valName, v.value, Ft.formatComment(v.description)) cValuesOut += " constexpr Register::FieldValue<decltype(%s)::Type,%sVal::%s> %s{};\n" % ( fieldName, fieldName.capitalize(), valName, valName) fieldOut += " };\n" cValuesOut += " }\n" access = Ft.getAccess(field, Ft.getKey(ext, ['field', field.name])) fieldOut += " constexpr Register::FieldLocation<Addr,Register::maskFromRange(%d,%d),Register::%s,%s> %s{}; \n%s" % ( msb, lsb, access, fieldType, fieldName, cValuesOut) if "oneTo" not in access: #only remove bits from reserved field if a write of zero actually changes something noActionIfZeroBits = Ft.clearBitsFromRange(msb, lsb, noActionIfZeroBits) if "zeroTo" in access: #if zeroToSet or zeroToClear then writing a 1 is a no action noActionIfOneBits = Ft.setBitsFromRange(msb, lsb, noActionIfOneBits) regType = "std::uint32_t" if register.size is not None: if register.size is 8: regType = "std::uint8_t" elif register.size is 16: regType = "std::uint16_t" out = " namespace %s{ ///<%s\n" % (Ft.formatNamespace( "%s_%s" % (prefix, register.name)), Ft.formatComment(register.description)) out += " using Addr = Register::Address<0x%08x,0x%08x,0x%08x,%s>;\n" % ( baseAddress + register.address_offset, noActionIfZeroBits, noActionIfOneBits, regType) out += fieldOut out += " }\n" return out
def parseRegister(register, baseAddress, prefix, ext): reservedBits = 0xFFFFFFFF fieldOut = "" for field in register.fields: msb = field.bit_offset+field.bit_width-1 lsb = field.bit_offset fieldType = "unsigned" fieldName = Ft.formatVariable(field.name) fieldOut += " ///%s\n" % field.description if Ft.useEnumeratedValues(field.enumerated_values,field.bit_width): fieldType = "%sVal" % (fieldName) fieldOut += " enum class %s {\n" % fieldType cValuesOut = "" for v in field.enumerated_values: if v.value is not None and v.is_default is None: #some value are defaults, we ignore them valName = Ft.getKey(ext,['field',field.name,'enum',v.name,'.rename']) or Ft.formatEnumValue(v.name) if valName != 'reserved': fieldOut+=" %s=0x%08x, ///<%s\n" % (valName,v.value,v.description) cValuesOut+=" constexpr MPL::Value<%sVal,%sVal::%s> %s{};\n" % (fieldName,fieldName,valName,valName) fieldOut += " };\n namespace %sValC{\n%s }\n" % (fieldName,cValuesOut) fieldOut += " constexpr Register::BitLocation<Addr,Register::maskFromRange(%d,%d),Register::%s,%s> %s{}; \n" % (msb,lsb,Ft.getAccess(register,field),fieldType,fieldName) reservedBits = Ft.clearBitsFromRange(msb,lsb,reservedBits) regType = "unsigned" if register.size is not None and register.size is 8: regType = "unsigned char" out = " namespace %s{ ///<%s\n" % (Ft.formatNamespace("%s%s" % (prefix, register.name)),register.description) out += " using Addr = Register::Address<0x%08x,0x%08x,0,%s>;\n" % (baseAddress + register.address_offset,reservedBits,regType) out += fieldOut out += " }\n" return out
def parseRegister(register, baseAddress, prefix, ext): noActionIfZeroBits = 0xFFFFFFFF noActionIfOneBits = 0x00000000 fieldOut = "" for field in register.fields: msb = field.bit_offset + field.bit_width - 1 lsb = field.bit_offset fieldType = "unsigned" fieldName = Ft.formatVariable(field.name) fieldOut += " ///%s\n" % Ft.formatComment( Ft.getKey(ext, ["field", field.name, "description"]) or field.description ) cValuesOut = "" if Ft.useEnumeratedValues(field.enumerated_values, field.bit_width): fieldType = "%sVal" % (fieldName.capitalize()) fieldOut += " enum class %s {\n" % fieldType cValuesOut = " namespace %sC{\n" % fieldType for v in field.enumerated_values: if v.value is not None and v.is_default is None: # some value are defaults, we ignore them valName = Ft.getKey(ext, ["field", field.name, "enum", v.name, ".rename"]) or Ft.formatEnumValue( v.name ) if valName != "reserved": fieldOut += " %s=0x%08x, ///<%s\n" % ( valName, v.value, Ft.formatComment(v.description), ) cValuesOut += ( " constexpr Register::FieldValue<decltype(%s)::Type,%sVal::%s> %s{};\n" % (fieldName, fieldName.capitalize(), valName, valName) ) fieldOut += " };\n" cValuesOut += " }\n" access = Ft.getAccess(field, Ft.getKey(ext, ["field", field.name])) fieldOut += ( " constexpr Register::FieldLocation<Addr,Register::maskFromRange(%d,%d),Register::%s,%s> %s{}; \n%s" % (msb, lsb, access, fieldType, fieldName, cValuesOut) ) if "oneTo" not in access: # only remove bits from reserved field if a write of zero actually changes something noActionIfZeroBits = Ft.clearBitsFromRange(msb, lsb, noActionIfZeroBits) if "zeroTo" in access: # if zeroToSet or zeroToClear then writing a 1 is a no action noActionIfOneBits = Ft.setBitsFromRange(msb, lsb, noActionIfOneBits) size = Ft.getKey(ext, ["size"]) if size is not None: register.size = size elif register.size is None: register.size = 32 if register.size is 8: regType = "unsigned char" if register.size is 16: regType = "unsigned short" if register.size is 32: regType = "unsigned" out = " namespace %s{ ///<%s\n" % ( Ft.formatNamespace("%s_%s" % (prefix, register.name)), Ft.formatComment(register.description), ) out += " using Addr = Register::Address<0x%08x,0x%08x,0x%08x,%s>;\n" % ( baseAddress + register.address_offset, noActionIfZeroBits, noActionIfOneBits, regType, ) out += fieldOut out += " }\n" return out