This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPc2294+TCP

Hallo,

I have a question to the topic ethernet.
I have look at the exmaple LEDswitch Client and I don't understand why I need the following code:
..
U8 p2val, cnt, lshf;
..
p2val = 1; cnt = 0; lshf = 1;
...
send_data(p2val);
p2val = lshf ? (p2val << 1) : (p2val >> 1);
if (p2val == 0x80) lshf = 0;
if (p2val == 0x01) lshf = 1;

I don't find anything in the help from keil for what p2val stand and why I to hand this on my funktion send_data? Can something explain it.

Parents
  • Sorry for the formatting. It slipped my mind
    but I'll definitely forget it again ;-)

    I send data from a PC over a socket to the LPC in order to start something on the LPC. So I want to listen to the socket if I become the instructions from the PC.
    The function tcp_get_buf is only for sending data I have to skip it.
    Give it any buffer for the function tcp_listen or something else so that I can with e.g. the function memcpy() to copy it ?

Reply
  • Sorry for the formatting. It slipped my mind
    but I'll definitely forget it again ;-)

    I send data from a PC over a socket to the LPC in order to start something on the LPC. So I want to listen to the socket if I become the instructions from the PC.
    The function tcp_get_buf is only for sending data I have to skip it.
    Give it any buffer for the function tcp_listen or something else so that I can with e.g. the function memcpy() to copy it ?

Children
  • I gave you a hint at your usage of the tcp_get_buf(), but you didn't take the time to check in the manual, and compare with your code.

    The function allocates a block of memory for use as send buffer.

    But if the function returns a block to an allocated memory block, why are you then using a for loop to copy the unknown data from the newly allocated block into another array? To send data, you must _set_ the contents of this buffer before you write it.

    If you should use memcpy() or not when sending data depends on the situation. If the memory is available somewhere else, then memcpy() is an efficient method to move data from one buffer to another. If you are going to send data that you generate on-the-fly, then you do not need an extra buffer and buffer copy - you can build your packet directly into the allocated buffer you got from tcp_get_buf().
    the The tcp_get_buf function allocates memory for the TCP send buffer into which your application can write the outgoing data packet.

    Another thing - why do your for loop step two bytes at a time, and then perform two one-byte assigns? An attempt at loop unrolling? Only do loop unrolling if speed is critical. But if speed is critical, then memcpy() can copy the data in 32-bit chunks intead of picking up individual bytes. And memcpy() is often written in hand-optimized assembler.