- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
int main()
{
int noia = 0;
alt_putstr("Proc 2!\n");
/* get the mutex device handle */
alt_mutex_dev* mutex = altera_avalon_mutex_open( "/dev/mutex" );
/* acquire the mutex, setting the value to one */
altera_avalon_mutex_lock( mutex, 1 );
if(altera_avalon_mutex_is_mine(mutex))
{
alt_printf("%x\n", IORD_32DIRECT(SHARED_MEM_BASE, 0x00));
noia = alt_getchar();
alt_printf("%x\n", noia);
if (noia == 1)
altera_avalon_mutex_unlock( mutex );
}
return 0;
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Are you new to C programs ?
Your printf will print hexadecimal value. because of "%x" try
noia = alt_getchar();
alt_printf("%c\n", noia);
But later in your code I see if (noia == 1)
! If you type with keyboard, alt_getchar may return between 40 and 124 (decimal values). So if you want you condition to be true you have to Press Alt with 0 then 0 then 1. If you want your condition to be true when you type '1' with keyboard, try if (noia == '1')
noia should be declared as char (not "int"). Or this is an other problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's another problem, seems like my buffer has already some info on it. I don't type anything and some value appear in the alt_getchar, like 1a, 2b etc.
Thanks for your info thought :)- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Be aware that alt_getchar() uses a "direct" driver. See Documents.
Have you tried with C usual getchar() ?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd guess that the result range of alt_getchar() is -1 (no char available) and 0..255 for a received byte (it could also return indications of abort and framing errors) - so the return value could well be 'int' not 'char'.
getchar() will pull in a lot of libc code, and may also (by default at least) require that you type <enter> before making any data available.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- It's another problem, seems like my buffer has already some info on it. I don't type anything and some value appear in the alt_getchar, like 1a, 2b etc. Thanks for your info thought :) --- Quote End --- If your problem is simply with chars already stored in buffer, what you commonly do in C is putting a while (getchar() != EOF); loop before starting. EOF is usually the portable version of the -1 result value suggested by dsl.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page