Advice on custom NIOS packet, and allocating NIOS memory

Discussions related to embedded firmware, driver, and user mode application software development

Advice on custom NIOS packet, and allocating NIOS memory

Postby ifrasch » Tue Mar 07, 2017 7:25 pm

I'm working on a project to scan the entire spectrum 0.3 - 3.8 GHz and detect spectrum holes. This project performs all processing inside the FPGA and involves 125 frequency retune operations. The NIOS II processor will be used to tune to each frequency and instruct the FPGA datapath to process X samples before tuning to the next frequency.

To kick off an iteration of this scanner, I want send a custom packet from the host PC to the NIOS (through UART) which contains a big list of precalculated frequencies to tune to along with some other information (DC offset, gain, etc. for each frequency). This packet will be around 1250 bytes long. The NIOS will store the list in memory somewhere. Then, a special START packet will be sent to tell the NIOS to do the scan.

Now, after digging through bladeRF codebase, I realized that the packets which are sent between the host PC and the NIOS are fixed at 16 bytes. Even if you change the software, the packet size is fixed to 16 bytes in the HDL in command_uart.vhd as well as the NIOS system in general. It seems like it would be a bit of a pain to make the changes to allow for a 1250-byte packet to be sent.

So instead I can split my 1250-byte packet into a bunch of 16-byte custom packets which I send over to the NIOS one-by-one. I'll need to allocate a 1250-byte chunk of memory in the NIOS - and write to this memory as the packets come in. A question I have here is, how should I go about declaring this 1250-byte chunk of memory in the NIOS? Can I just declare a stack memory buffer in the code? Or would a heap buffer be better? Or would I need to add separate RAM/register memory to the NIOS system which connects to the processor through the Avalon interface?

TL;DR: Need to send 1250 bytes from PC to NIOS and store them in NIOS memory.

Any advice on how I should do this?

Ian
ifrasch
 
Posts: 11
Joined: Mon Apr 11, 2016 12:41 pm

Re: Advice on custom NIOS packet, and allocating NIOS memory

Postby bglod » Wed Mar 08, 2017 9:44 am

I would first try to use stack or heap memory. I'm not sure it matters much which one you choose. You could try both ways and compare! Stack is faster and you're allocating a known, fixed size at compile-time, so you could argue that's enough to use it. However, I'm sort of leaning toward heap just due to the size of the packet and maybe you'll want to change the size dynamically later on. You have 125 retunes now, but what if you want to use a header packet that tells the Nios the number of retunes?

There is 16 KB of memory on the Nios, but you can increase this if you need to.

It sounds like it would be too much of a hassle to add and access a dedicated block RAM as a memory-mapped device, but I'm not 100% sure off hand.
bglod
 
Posts: 32
Joined: Thu Jun 18, 2015 6:10 pm

Re: Advice on custom NIOS packet, and allocating NIOS memory

Postby ifrasch » Wed Mar 08, 2017 4:47 pm

OK, I'll try stack/heap memory first. I was worried about a stack/heap overflow since the Nios is basically a microcontroller. But 16KB should be enough, and it's good to know that I can increase this with a few clicks.

Do you happen to know if/where I can find how much of the 16KB is allocated for the stack vs heap vs instructions?
ifrasch
 
Posts: 11
Joined: Mon Apr 11, 2016 12:41 pm

Re: Advice on custom NIOS packet, and allocating NIOS memory

Postby bglod » Thu Mar 09, 2017 5:12 am

I don't think there is a set limit for the stack size, but you could limit the heap. According to the NiosII Software manual (page 6-39, "Placement of the Heap and Stack", it looks like the two could collide as there is no stack checking. However, you can limit the heap if you needed to prevent this.
bglod
 
Posts: 32
Joined: Thu Jun 18, 2015 6:10 pm

Re: Advice on custom NIOS packet, and allocating NIOS memory

Postby ifrasch » Thu Mar 09, 2017 9:56 am

Ah, ok. Thanks!
ifrasch
 
Posts: 11
Joined: Mon Apr 11, 2016 12:41 pm

Re: Advice on custom NIOS packet, and allocating NIOS memory

Postby ifrasch » Fri Mar 10, 2017 9:28 pm

Update for anyone else reading this:

I discovered that when building the bladeRF FPGA image with build_bladerf.sh, the following message is printed regarding RAM usage:
Code: Select all
Info: (bladeRF_nios.elf) 12 KBytes program size (code + initialized data).
Info:                    3232 Bytes free for stack + heap.

I added some custom Nios code and tried declaring a fixed-size stack memory buffer of 1125 bytes, like this:
Code: Select all
uint8_t mem[1125];

After recompiling with build_bladerf.sh, the RAM usage is as follows:
Code: Select all
Info: (bladeRF_nios.elf) 15 KBytes program size (code + initialized data).
Info:                    976 Bytes free for stack + heap.

At first I thought I was going to have to increase the RAM size since only 976 bytes were free. However, upon further testing I discovered that the fixed 1125-byte stack memory buffer is part of the 15KB program size (it must technically be "initialized data"). My test consisted of reducing the size of the mem buffer to 9 bytes and rerunning the build script. When I did that, it showed 13KB program size and 2092 bytes free for stack+heap. So clearly a fixed stack memory buffer is part of the program size.

I'm assuming now that the 976 free bytes for stack+heap will be enough for the Nios code to run properly. I'll report back if I find out that isn't enough.
ifrasch
 
Posts: 11
Joined: Mon Apr 11, 2016 12:41 pm


Return to Software development

Who is online

Users browsing this forum: No registered users and 10 guests