Beispiel #1
0
void BitSet::clearTrailingBits() 
{
    U_32 mk = getBitMask(setSize) - 1;
    for (U_32 i = getWordIndex(setSize); i < wordsCapacity; ++i) {
        words[i] &= mk;
        mk = 0;
    }
}
Beispiel #2
0
    void generateVirtualPort(std::ostream & stream, const VirtualPort * p, const uc::AvrUC * controller)
    {
        assert(p && controller);
        stream << "\t\tstruct\t\t// vport " << p->identifier << "\n\t\t{\n";

        {
            // Generate vport entries (non-function)
            stream << "\t\t\tunion\n\t\t\t{\n";
            for(std::list<PinBlock *>::const_iterator it = p->pinBlocks.begin(); it != p->pinBlocks.end(); it++)
            generatePinBlock(stream, *it, controller, "\t\t\t\t");
            stream << "\t\t\t};\n";
        }

        {
            // Generate vport access functions
            // Count total number of bits
            int bitCount = 0;
            for(std::list<PinBlock *>::const_iterator it = p->pinBlocks.begin(); it != p->pinBlocks.end(); it++)
                bitCount += (*it)->getPinCount();
            if(bitCount > 32)
                bitCount = 32;

            // generate code
            uc::PinType pt = uc::PIN;
            for(int i = 0; i < 3; i++)
            {
                if (i == 1) pt = uc::PORT; else if (i == 2) pt = uc::DDR;

                std::string capPinTypeString = capitalize(uc::getPinTypeString(pt));
                std::string lowPinTypeString = tolower(uc::getPinTypeString(pt));
                std::string dataTypeString   = getDataType(bitCount == 1 ? 8 : bitCount);

                // get ? function
                {
                    stream << "\t\t\t" << dataTypeString << " get" << capPinTypeString
                        << "()\n\t\t\t{\n\t\t\t\tSyncPortmap(*this);\n\t\t\t\treturn ";
                    int bit = 0;
                    std::list<PinBlock *>::const_iterator it = p->pinBlocks.begin();
                    for(; it != p->pinBlocks.end() || bit > bitCount; it++)
                    {
                        const int pinCount = (*it)->getPinCount();
                        if (bit != 0)
                            stream << " || ";
                        stream << "(" << (*it)->identifier << "." << lowPinTypeString;
                        if (bit > 0)
                            stream << " << " << bit;
                        stream << ")";
                        bit += pinCount;
                    }
                    stream << ";\n\t\t\t}\n";
                }
                // set function
                {
                    stream << "\t\t\t" << "void set" << capPinTypeString << "(" << dataTypeString << " i)\n\t\t\t{\n";
                    int bit = 0;
                    std::list<PinBlock *>::const_iterator it = p->pinBlocks.begin();
                    for(; it != p->pinBlocks.end() || bit > bitCount; it++)
                    {
                        const int pinCount = (*it)->getPinCount();
                        stream << "\t\t\t\t" << (*it)->identifier << "." << lowPinTypeString
                             << " = (i & " << getBitMask(bit, pinCount) << ")";
                        if (bit > 0 && pinCount != 1)
                            stream << " >> " << bit;
                        stream << ";\n";
                        bit += pinCount;
                    }
                    stream << "\t\t\t}\n";
                }
            }
        }

        stream << "\t\t} " << p->identifier << ";\n";
    }
Beispiel #3
0
unsigned getWaitcntBitMask(IsaVersion Version) {
  unsigned Vmcnt = getBitMask(getVmcntBitShift(), getVmcntBitWidth());
  unsigned Expcnt = getBitMask(getExpcntBitShift(), getExpcntBitWidth());
  unsigned Lgkmcnt = getBitMask(getLgkmcntBitShift(), getLgkmcntBitWidth());
  return Vmcnt | Expcnt | Lgkmcnt;
}
constexpr T setBitField(T so, T hi, T lo) {
	return (so << lo) & getBitMask(hi, lo);
}
constexpr T getBitField(T so, T hi, T lo) {
	return (so & getBitMask(hi, lo)) >> lo;
}