- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No problem to get result with hello_world_small. But I am very unhappy with uart character input. Documentation sweeps me thru a lot of mystic solutions. How can I do a simple character input in the small footprint version whitout losing the integration with the IDE-Quartus? I am running a EP2C8.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I realize that this post is old and you probably already found a solution but here you go anyway:
# include "altera_avalon_uart_regs.h" char ch; ch = IORD_ALTERA_AVALON_UART_RXDATA(UART1_BASE);- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- originally posted by jakobjones@Feb 15 2007, 10:00 PM i realize that this post is old and you probably already found a solution but here you go anyway:
# include "altera_avalon_uart_regs.h"
char ch;
ch = iord_altera_avalon_uart_rxdata(uart1_base);
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=21653)
--- quote end ---
--- Quote End --- -- What if you are polling for a UART character? That command will just dump whatever's in the register, regardless of whether there's something there. I tried using this before reading the post, and I just get into a massive loop because there is no event that the code waits for. I believe that you need to look at RRDY in the _STATUS register (bit mask 0x0080) to see if there's a byte there. I have been trying this, but I'm getting "blank" data back. I believe that it's because I'm also using printf() HAL functions, which the datasheet refers to there being a problem running both register access and HAL at the same time. I'm having issues with a "small" build, and the getchar() and file i/o methods seem to work fine, but don't compile properly when targeting a device that does not have enough room to cram a "full" C library (EP2S15). Does anyone have a solution for polling for a UART character w/out getchar() or getc()? I suspect that I could stop using fprint() - HAL, and do all of the character I/O using IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE, data) commands, but rewriting fprint() is not too appealing, since I'm a hardware/FPGA guy that's dabbling in C. Any thoughts/comments on this would be appreciated. Thanks, Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
with fprintf:
fprintf(FILE, "%d\r\n", var); instead do this: char buffer[1000]; int count; sprintf(buffer, "%d\r\n", var); for(count = 0; buffer[count]; ++count) { IOWR_ALTERA_AVALON_UART_TXDATA(UART_0_BASE, buffer[count]); } This is quick and dirty. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/unsure.gif Missing is buffer overrun check but it will basicly work. Karsten- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In case this helps anyone else out, I did end up getting my project to fit inside of a 10kB block, as opposed to the 52kB or so that it was bloating into previously. Here are a few of the steps that I followed:
1. I ended up building a new Nios project using the "memory test" template (instead of the "blank" template). This was per a suggestion by an Altera FAE that maybe the blank template would instantiate (and compile) all possible code that could be used (as opposed to just what would be needed for a UART-based memory test program), thus increasing the size. I can't say w/ any certainty whether or not this actually effected the size or not. 2. I replaced all references to printf() and getchar() with alt_printf() and alt_getchar(). The catch here being that these are light-weight versions of the bona-fide C function calls, and I had to make modifications to my code to account for this. The alt_printf() only has a few variable substitutions that can be made (most of my changes had to do with this), while I did not have to make any modifications to alt_getchar(). So those where the two major changes that I made, which then allowed me to check "lightweight device driver API", and giving me the small footprint. Now that I look back at the project settings, it did not require me to select "small C library" in order to get the reduced size. The SOPC project used the following peripherals: cpu_0 (Nios II/e w/ level 1 debug) onchip_memory (16k) uart_0 various parallel I/O (pio) Hope this helps anyone else that might be having the same problem. Jeff
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page