cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Explorer
Explorer
4,486 Views
Registered: ‎03-29-2017

How to get random bit sequence in XSDK from HLS IP

Jump to solution

Hi,

Currently I'm working with Kintex 7, for random bit sequence function. I have created HLS IP for the function, integrated IP with vivado and exported it to SDK.

 

But in SDK, i am getting only "Single bit" value instead of sequence of random bits. I think its showing last bit of sequence in Hardware. Please anyone guide me. What`s wrong in my coding? Need help from anyone.

 

Hls Source code

 

#include <stdint.h>
#include <stdio.h>
#include "ap_cint.h"

int PRBS_prj()
{
#pragma HLS INTERFACE s_axilite port=return bundle=a
   int start_state = 0xCD;
   int lfsr = start_state;
   bool bit;
    unsigned period = 0;

do
    {
    /* taps:  3, 2 and 1 ; feedback polynomial:  x^3 + x^2 + 1 */
    bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 4) ) & 1;
    printf("%d", bit);
    lfsr = (lfsr >> 1) | (bit << 7);
            ++period;
        } while (lfsr != start_state);
return bit;
}


Test Bench

 

#include <stdint.h>
#include <stdio.h>
#include "ap_cint.h"

int main()
{
   int start_state = 0xCD;
   int lfsr = start_state;
   bool bit;
    unsigned period = 0;
    PRBS_prj();
    do
        {

        bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 4) ) & 1;
        printf("%d", bit);

         lfsr = (lfsr >> 1) | (bit << 7);
                ++period;
            } while (lfsr != start_state);
return 0;
    }

 

SDK Source Code

 

#include "xprbs_prj.h"



int main()
{
    init_platform();
     bool Resulth;
 
  xil_printf("%c[2J",27);
  XPrbs_prj PRBS;
  XPrbs_prj  *PRBSPTR=&PRBS;
  XPrbs_prj_Initialize(PRBSPTR,XPAR_PRBS_PRJ_0_DEVICE_ID);
  XPrbs_prj_Start(PRBSPTR);
   while (!XPrbs_prj_IsDone(PRBSPTR));
   Resulth=XPrbs_prj_Get_return(PRBSPTR);
   xil_printf("[hw] Resulth = %d \r\n", Resulth);
   cleanup_platform();
  return 0;
}

 

************************** Function Prototypes *****************************/
#ifndef __linux__
int XPrbs_prj_Initialize(XPrbs_prj *InstancePtr, u16 DeviceId);
XPrbs_prj_Config* XPrbs_prj_LookupConfig(u16 DeviceId);
int XPrbs_prj_CfgInitialize(XPrbs_prj *InstancePtr, XPrbs_prj_Config *ConfigPtr);
#else
int XPrbs_prj_Initialize(XPrbs_prj *InstancePtr, const char* InstanceName);
int XPrbs_prj_Release(XPrbs_prj *InstancePtr);
#endif

void XPrbs_prj_Start(XPrbs_prj *InstancePtr);
u32 XPrbs_prj_IsDone(XPrbs_prj *InstancePtr);
u32 XPrbs_prj_IsIdle(XPrbs_prj *InstancePtr);
u32 XPrbs_prj_IsReady(XPrbs_prj *InstancePtr);
void XPrbs_prj_EnableAutoRestart(XPrbs_prj *InstancePtr);
void XPrbs_prj_DisableAutoRestart(XPrbs_prj *InstancePtr);
u32 XPrbs_prj_Get_return(XPrbs_prj *InstancePtr);


void XPrbs_prj_InterruptGlobalEnable(XPrbs_prj *InstancePtr);
void XPrbs_prj_InterruptGlobalDisable(XPrbs_prj *InstancePtr);
void XPrbs_prj_InterruptEnable(XPrbs_prj *InstancePtr, u32 Mask);
void XPrbs_prj_InterruptDisable(XPrbs_prj *InstancePtr, u32 Mask);
void XPrbs_prj_InterruptClear(XPrbs_prj *InstancePtr, u32 Mask);
u32 XPrbs_prj_InterruptGetEnabled(XPrbs_prj *InstancePtr);
u32 XPrbs_prj_InterruptGetStatus(XPrbs_prj *InstancePtr);

#ifdef __cplusplus
}
#endif

Tags (2)
VIVDOIP.PNG
Tera.PNG
Hls_Csim.PNG
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Explorer
Explorer
7,345 Views
Registered: ‎03-29-2017

Re: How to get random bit sequence in XSDK from HLS IP

Jump to solution

Oops, finally i have got random bit sequences in XSDK from HLS IP. Just, i have used register concept for writing program for PRBS function in HLS.

 

View solution in original post

0 Kudos
10 Replies
Highlighted
Teacher
Teacher
4,454 Views
Registered: ‎03-31-2012

Re: How to get random bit sequence in XSDK from HLS IP

Jump to solution

@thaus_015 the problem is that your hls accelerated block always runs the whole sequence (because of the do while loop) and it returns the last "bit". If you want to be able to call it repeatedly and get a different bit of the lfsr sequence, you need to define the "lfsr" variable as static and do only one step of the lfsr update each time it's called. So get rid of the do while loop in PRBS_prj, declare lfsr as static and update lfsr just once per call of the accelerated function. 

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Highlighted
Explorer
Explorer
4,421 Views
Registered: ‎03-29-2017

Re: How to get random bit sequence in XSDK from HLS IP

Jump to solution

To muzaffer, Still, my problem is not solved. Still i am facing same problem. Please help me out in completing this task. Did some modification in source code of HLS but still getting last bit in TERA TERAMINAL.

 

Suggest me :)

 

Source code:

 

int PRBS_prj()
{
#pragma HLS INTERFACE s_axilite port=return bundle=a
    static unsigned lfsr  = 0xCD;
       int bit, i;
       for ( i = 0; i < 50; i++)
       {
       bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 4) ) & 1;
      lfsr = (lfsr >> 1) | (bit << 7);
     printf("%d", bit);
       }
       return bit;
           }

 

 

Test Beach

 

int main()
{
   static unsigned lfsr  = 0xCD;
   int bit, i;

    PRBS_prj();

    for ( i = 0; i < 50; i++)
          {
          bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 4) ) & 1;
  printf("%d", bit);
          lfsr = (lfsr >> 1) | (bit << 7);

          }
return 0;
    }

HLS_Csim.PNG
0 Kudos
Highlighted
Teacher
Teacher
4,414 Views
Registered: ‎03-31-2012

Re: How to get random bit sequence in XSDK from HLS IP

Jump to solution

@thaus_015 you still have a loop in PRBS_prj where you have replaced the do, while with a for loop. You should get rid of the loop, have it execute only one stage of the lfsr update each time it's called. I am assuming this is what you want to accomplish. 

Also in the main, you are not checking the return of the function at all. You should put the PRBS_prj and the local calculation in a loop and compare the results for every bit output from the main lfsr & also from the PRBS_prj function. 

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Highlighted
Explorer
Explorer
4,371 Views
Registered: ‎03-29-2017

Re: How to get random bit sequence in XSDK from HLS IP

Jump to solution
 
@muzaffer, I have changed my programming codes without loop. But, eventhough i am not getting random Sequence in XSDK. I am struggling with this task. Please tell me the way, how to getting random sequences in XSDK through HLS IP.
 
 
HLS Source code:
int main(void)
{
    static int lfsr = 0x3425u;
    unsigned int mask = 0xF0;
    int bit;                    /* Must be 16bit to allow bit<<15 later in the code */
        //taps: 16 14 13 11; feedback polynomial: x^16 + x^14 + x^13 + x^11 + 1 
        bit  = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1;
        lfsr =  (lfsr >> 1) | (bit << 15);
      
        for (mask = 0xF0; mask; mask >>= 1)
        putchar('0' + !!(lfsr & mask));
 
    return lfsr;
}
0 Kudos
Highlighted
Teacher
Teacher
4,355 Views
Registered: ‎03-31-2012

Re: How to get random bit sequence in XSDK from HLS IP

Jump to solution

@thaus_015 main is your testbench (right?)  and the PRBS_prj is the HLS accelerated function. In main,  you need the loop which calls the local test lfsr and you need to include PRBS_prj in this loop. PRBS_prj should generate one bit output at a time and in the main loop, you need to compare PRBS_prj output to the local lfsr. PRBS_prj should not have a loop in it. It should have static on lfsr and shift once and produce one bit of output everytime it is called (assuming this is what you are trying to accomplish)

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
Highlighted
Explorer
Explorer
4,310 Views
Registered: ‎03-29-2017

Re: How to get random bit sequence in XSDK from HLS IP

Jump to solution

@muzaffer. I have tried but i am not getting sequences of bit from HLS IP.

 

I think that to get non-stop stream of random bits out of the IP, then one way is using FIFO for connecting the IP to PS and hls::stream at the output of the HLS code. For steam data communication between an IP and SDK, i am right ?

0 Kudos
Highlighted
Explorer
Explorer
7,346 Views
Registered: ‎03-29-2017

Re: How to get random bit sequence in XSDK from HLS IP

Jump to solution

Oops, finally i have got random bit sequences in XSDK from HLS IP. Just, i have used register concept for writing program for PRBS function in HLS.

 

View solution in original post

0 Kudos
Highlighted
Newbie
Newbie
2,673 Views
Registered: ‎02-04-2018

Re: How to get random bit sequence in XSDK from HLS IP

Jump to solution

I am also facing the same problem from several days..Can you explain me what is register concept in HLS..so that we will get continuous values in SDK.

0 Kudos
Highlighted
Explorer
Explorer
2,668 Views
Registered: ‎03-29-2017

Re: How to get random bit sequence in XSDK from HLS IP

Jump to solution

Hi,

 

Can you explain your concept. Actually, what you need as output.

0 Kudos
Highlighted
Moderator
Moderator
1,907 Views
Registered: ‎11-09-2015

Re: How to get random bit sequence in XSDK from HLS IP

Jump to solution

HI @manoj_king,

 

Please create a new topic on the Vivado HLS board a this topic is quite old and close. You can tag thaus_15 if needed using the @ + username.

 

Thanks,

 

Regards


Florent
Product Application Engineer - Xilinx Technical Support EMEA
**~ Don't forget to reply, give kudos, and accept as solution.~**
0 Kudos