[QUOTE=SarasMuthu;1267973]I am working with Vivado HLS for function "Pseudo Random Bit Sequence Generator". I need C code for PRBS using buffer concept.
Can anyone help in writing and executing this program using storage concept.
I tried this code, But Not working
Code:
bool pseudo_random() {
static ap_uint<3> lfsr=5;
//x^3 + x^2 + 1
bool b_3 = lfsr.get_bit(3-3);
bool b_2 = lfsr.get_bit(3-2);
bool new_bit = b_3 ^ b_2 ;
lfsr = lfsr >> 1;
lfsr.set_bit(2, new_bit);
return lfsr.get_bit(0);
}
2.
Code:
int16_t prbs(int16_t);
int main(void)
{
xil_printf("%c[2J",27);
uint16_t start_state = 0x7D0; /* Any nonzero start state will work. */
uint16_t lfsr = start_state;
uint16_t count = 0;
do
{
lfsr = prbs(lfsr) ;
//printf("value= 0x%02X\n", lfsr);
count++;
} while (count < 50);
return 0;
}
int16_t prbs(int16_t lfsr)
{
bool 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);
bit = ((lfsr >> 0) ^ (lfsr >> 2) ) & 1;
lfsr = (lfsr >> 1) | (bit << 10);
printf("%d",bit);
return lfsr;
}
I want to execute PRBS using buffer concept. Through basic knowledge i have written the Codes for Pseudo_random binary sequence using buffer concept but showing error.
Code:
int main() {
{
uint32 buff[];
static unsigned lfsr = 0xCD;
int bit, i, count;
for ( i = 0; i > 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 4) ) & 1;
lfsr = (lfsr >> 1) | (bit << 7);
buff[] =bit;
}
memcpy(buff+i, bit, bit* sizeof(int));
buff[0] +=1;
for (i = 0; i < 50; i++) {
buff[i+1]= buff[i]+ 1;
}
printf("%d", &buff);
}
}