"Greg London" <[email protected]> writes:

> This is really convoluted, so feel free to reply to me offlist.
>
> I'm trying to model a register map for a voltage regulator chip.
>
> Our chips used to have an extremely simple register map.
> There was an I2C interface, and the designers created a
> list of register names, defined what address they were
> at, how many bits wide they were, masks, etc, and we
> were done. It was easy because every register name
> was completely unique.
>
> So I just modeled it as a simple perl hash.
>
> Our latest regulator chip has multiple voltage outputs
> and the old register map approach fell apart. We now have
> the same register names occuring at multiple addresses
> and each version of a register might behave a little
> differently.
>
> i.e. the "output_voltage" register might be ten
> bits wide for the first voltage output core
> and another "output_voltage" register might be 12 bits wide
> for the second core.  And of course,
> each "output_voltage" has to have a different address
> depending on which output its controlling.
>
> I don't even know how to model this.

Would it work for you to keep your hash but make the values instead be
references to arrays of references to objects with the attributes you
mention above: address, width, masks, etc.?  Are the values in your
current hash objects with such attributes? Is it only that before you
had one value per name and now you have many or is there more to it than
that?

I guess what I'm thinking is maybe where in the part of your email I've
removed, what you are thinking of as container classes could be regular
Perl arrays (and above maybe I missed a level since you mention
containers of containers, but still that could be a hash of arrays of
references to arrays of references to structs). Maybe you'd want to
abstract over it and hide away in a module with subs that know the data
structure. 

I probably don't fully understand your requirements, but I'm not seeing
the case for subclassing or polymorphism. Is it that some hash elements
you want the old way as simple values and others in collections? So
either have a rigid 2 (or 3?) level structure that you walk down and
when you only have one you have an array of one, or else use ref to see
whether you have an array or scalar in each hash value and in each array
element as you walk down the tree.

-- 
Mike Small
[email protected]

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to