Re: How to efficiently convert the 32-bit data into 8-bit da
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef bit BOOL;
typedef union {
DWORD long_var;
BYTE char_var[4];
} MyUnion;
unsigned char ahb_sg_wr(MyUnion ahb_addr, MyUnion ahb_data)
{
unsigned char op_ready;
op_ready = 0;
//op_start_address_reg = ahb_addr;
//op_start_address_reg0 = (BYTE) (0x000000ff & ahb_addr);
//op_start_address_reg1 = (BYTE) ((0x0000ff00 & ahb_addr)>>8);
//op_start_address_reg2 = (BYTE) ((0x00ff0000 & ahb_addr)>>16);
//op_start_address_reg3 = (BYTE) ((0xff000000 & ahb_addr)>>24);
op_start_address_reg0 = ahb_addr.char_var[3];
op_start_address_reg1 = ahb_addr.char_var[2];
op_start_address_reg2 = ahb_addr.char_var[1];
op_start_address_reg3 = ahb_addr.char_var[0];
//op_data_count_reg = 4; //4 bytes are read
//op_type_reg = 2;
//op_data_fifo_reg2 = ahb_data[0]; //just append
//op_data_fifo_reg2 = ahb_data[1]; //just append
//op_data_fifo_reg2 = ahb_data[2]; //just append
//op_data_fifo_reg2 = ahb_data[3]; //just append
// op_data_fifo_reg2 = (BYTE)(0x000000ff & ahb_data) ;
//op_data_fifo_reg2 = (BYTE)((0x0000ff00 & ahb_data)>>8) ;
//op_data_fifo_reg2 = (BYTE)((0x00ff0000 & ahb_data)>>16) ;
//op_data_fifo_reg2 = (BYTE)((0xff000000 & ahb_data)>>24) ;
op_data_fifo_reg2 = ahb_data.char_var[3];
op_data_fifo_reg2 = ahb_data.char_var[2];
op_data_fifo_reg2 = ahb_data.char_var[1];
op_data_fifo_reg2 = ahb_data.char_var[0];
op_cs_reg = 6;
while (!op_ready)
op_ready = op_cs_reg & 1;
op_data_fifo_cs_reg2 = 4;
op_data_fifo_cs_reg2 = 0;
return TRUE;
}
ahb_addr.long_var = 0x01020304;
ahb_data.long_var = 0x10203040;
ahb_sg_wr(ahb_addr,ahb_data);
The following code snippets are portion of my application used for 8051 MCU!
Unfortunately, this approache also generates too big corresponding assembly codes and the low simulation speed (for the ahb_sg_wr task).
And this schema also relates the byte allocation with the actual C Compliler as well. In fact ,how does the complier alignes the corresponding byte with the specific location of the long word(32-bit here)?
However, this method does have advantage speed over the correspoding method mentioned by above shifting operations. This is a big improvement in fact!
Currently, i've utilized one method of passing 4-byte parameters isolatedly and directly instead of a 32-bit one just as below:
ahb_sg_wr(a1,a2,a3,a4,d1,d2,d3,d4); to reduce the convertions.
Virtually, this way will have better code size and speed for my Keil Compiler. Nevertheless, the speed is still an issue since task calling will cost quite a lot of cycles (or assembly codes as well).
Currently, i'm wondering whether a 32-bit MCU shall be used to replace the 8-bit MCU to alleviate the timing pressure, but if some better methods can be used to realize this objective, then it's much better since i realy don't like to replace this 8-bit MCU!
Here thanks for all of your help a lot!
Thomson