On Fri, Mar 20, 2015 at 7:08 AM, James Smith <jsm...@ska.ac.za> wrote:
> Hello all, > > I've given some thought to the topic of writing (and reading) registers on > the ROACH using the python corr module. Often in a design a single register > may be sliced into many bits to control various things. The way I've > normally seen such a register written in python looks something like this: > > fpga.write_int('control',1<<9|1<<10|0<<25|1<<2|1<<3) > > My feeling is that this approach is difficult to maintain - inheriting > code from someone else (or even from one's self 6 months down the line) is > likely to bring about some confusion in this case, and lead to a fair > amount of spelunking through the Simulink model in order to figure out what > bit 9 and bit 10 etc. do. On top of this, it places limitations on changing > one of the bits later without modifying the other ones - bitwise or > functions work well enough when you're over-writing zeros, but if there's > something there already it might not work so well. > So it turns out that it is possible to define registers which aren't full word sizes long in tcpborphserver itself - and then the powerpc will do the shifts for you - this is particularly useful, for writes as that then cuts out a network operation (which would be needed to fetch the adjacent bits so that they aren't clobbered by the write). In the fpg file (or on the telnet connection), use optional [:bits] after an offset or a length to define the register - it is fine if such a register overlaps with something else, as long as the name is unique. The downside of all this: It isn't tested at all, as nobody is using it yet. And the code to make it work is a bit tricky - search for the read/write functions in https://github.com/ska-sa/katcp_devel/blob/master/tcpborphserver3/raw.c, for example write_cmd regards marc