Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

Problem with SDK shell -while using custom logic

Hi,

The following code behaves as expected when executed from telnet terminal but fails from nios_SDK shell.

"main" creates two processes. one process reads the data from the socket and second process writes data to our custom logic and reads it back and displays the read data. Our custom logic is just an Inverter.

From both SDK shell and telnet, socket is working correctly. The second process which writes into the custom logic is not working correctly on SDK shell.

Input is: "i": 0 ----> 255. [ Incrementing by "1" for each execution]

So expected output is: 255 -----> 0 [ Decrementing by "1" for each execution]

But the output is not regularly decrementing, Instead:

Test input ------------> output

0 - 255

1 - 254

2 - 254

3 - 254

4 - 254

5 - 254

6 - 254

7 - 248

8 - 248

9 - 248

10- 248

11- 248

12- 248

13- 242

14 - 242

15 - 242

.

.

.

.

.

int

client_bit (void *a)

{

char c;

int shmid;

key_t key;

int *shm_1 = (int*)shared_mem1, *s, *shm_2;

int s_fd;

struct sockaddr_in address;

int num_read;

struct timespec nt;

nt.tv_sec = 0;

nt.tv_nsec = SLEEP_INT;

if ((s_fd = socket (AF_INET, SOCK_STREAM, 0)) < 0)

printf ("The socket was not created\n");

printf ("socket created\n");

address.sin_family = AF_INET;

address.sin_port = htons (16500);

inet_pton (AF_INET, "10.112.14.36", &address.sin_addr);

printf ("Connecting.....\n");

if (connect (s_fd, (struct sockaddr *) &address, sizeof (address)) == 0)

printf ("The connection was accepted with the server %s...\n",

inet_ntoa (address.sin_addr));

while (num_read != SIZE2)

num_read += recv (s_fd, s + num_read, SIZE2 - num_read, 0);

...............

.........

}

int

process (void *a)

{

unsigned char *p,*u;

volatile int i,k=0,k1=0,k2=0;

p = 0x00800050;

k = k+1;

u = 0x00800054;

for ( i = 0; ; i++ )

{

*p = i;

k++;k1++;k2++;

printf(" \n\t Data_out: %d ", *u);

}

}

int

main ()

{

int cid[3];

int i, ret;

shared_mem1 = (char*)malloc(sizeof(unsigned char)*SHMSZ);

printf("Shared mem1 %x Shared mem2 %x\n",shared_mem1, shared_mem2);

// Create a thread for each file

cid[0] = clone (client_bit, &stack1[STACK_SIZE-1], SIGCHLD|CLONE_VM, NULL);

usleep (1);

cid[1] = clone ( process, &stack2[STACK_SIZE-1], SIGCHLD|CLONE_VM, NULL);

usleep (1);

for (i = 0; i < 1; i++)

{

ret = waitpid (cid[i],&ret,0);

}

free(shared_mem1);

return (0);

}

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hi,

    the difference between SDK_shell and telenet terminal is that one uses jtag cable and the other uses ethernet which is more fast than jtag.

    is it a problem of latency ? so u can insert wait each time u want tio red from custom logic.

    that&#39;s what I think http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/rolleyes.gif
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    The problem was that:

    I didn&#39;t set the 31st bit of the address used to access the ports of User Logic. (which was later corrected by Hippo)

    So the uncaching of I/O was not happening in the SDK shell, Once I set that 31st bit, everything is working fine.

    Best Regards,

    K V Naresh