![]() |
|
ADSP 21xx
Have you found this site useful? Did we save you time? Did we cure your head-ache? Is your hair growing back now? Please make a donation to help with maintenance. |
Objective Real-Time Software on the ADSP21XXInput/Output Objects on the ADSP 218XGeneralThe 218X series introduced a third address field, Input/Output (I/O). However, a major hurdle in using I/O objects on the 218X, is the severely limited I/O addressing modes. There is only one, namely the immediate mode. This is a very good reason to avoid using I/O mapping altogether and memory map all I/O ports. H.Acker did not have the opportunity to provide design input into the multi channel data recorder. The first time he saw the device, was when the designer handed him one of the first working models. As you may remember, this device has four identical A/D channels, which can allow one to write compact, object oriented control code. The only problem is the I/O mapped ports. H.Acker handled the problem by creating separate program threads for each port, which made the code four times larger than it needed to be. His successor S.Ucker, was faced with the problem of porting the four channel code to a new 32 channel device. Clearly, replicating the code to make 32 threads would not be practical at all. I/O Addressing ModesAs indicated above, there is only one mode, where the address has to be an immediate value, which is assembled directly into the instruction:
This limitation presents a real problem. In order to process the multiple data recorder ports, it would be prudent to create a single control process and run it in a loop, with incrementing port addresses. That way, one only need to debug the code once to make it handle all 32 channels. Clearly a huge saving in code space and debugging effort.
If the ports were memory mapped, S.Ucker would have had no problem at all and could use the DAG registers to address the I/O in the same way as one would address a data table and the auto incrementing features of the DAG registers would make handling the 32 ports a simple matter. Clearly, what S.Ucker needs, is an indirect I/O instruction, where the I/O address can be supplied in a register, but there is none. So, how now brown cow? Self Modifying CodeThe only solution, is self modifying code. The ADSP 218X normally executes from internal PM, which is RAM. This memory is writeable. Therefore, we can create special functions, that will accept the port address as a parameter and create the relevant I/O instruction on the fly.
While self modifying code is usually an absolute no-no, this case presents a very good excuse to use it. If we encapsulate it in a set of procedures, it would be robust and S.Ucker would be eternally grateful for this solution.
The IO instruction is a type 29 instruction, which looks like this:
Each instruction is 24 bits in size. The bottom 4 bits is the register number, which is 0000H for ar. The immediate address is 14 bits, followed by a direction bit, to indicate read or write and finally the type 29 opcode, which is 00001H. The difficulty is that the path between the PM and the ALU is only 16 bits wide. When we read a 24 bit PM word into ar, we only get the upper 16 bits. The lower 8 bits move into the px register. The same thing happens when we write to PM. The lower 8 bits are supplied by the px register and the upper 16 bits by ar. Therefore, we have to create the I/O instruction in stages.
First, we take the I/O address in ar and shift it left by 4, then we add in the code for the ar register. The lower 8 bits of sr0 is moved to the px register. Secondly, we take the address in ar, shift it right by 4 and add in the type 29 opcode and the direction bit. Our I/O instruction is now ready and can be written to PM. We use the DAG register set i4 for this purpose and write our synthesized instruction into a NOP instruction, which was inserted as a place holder. Note that the px register is automatically written to PM, together with the contents of sr0, during a full 24 bit wide move. The code for an I/O write operation is very similar to the above and the only difference is the direction bit:
While self modifying code in general is best avoided, this is clearly a case where its use is justified and S.Ucker went whistling home... |
|
Copyright © 1996-2008, Aerospace Software Ltd., GPL. |