This is my code, however alt_getchar() is returning a wrong value, not what i typed
int noia = 0;
/* 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 );
alt_printf("%x\n", IORD_32DIRECT(SHARED_MEM_BASE, 0x00));
noia = alt_getchar();
if (noia == 1)
altera_avalon_mutex_unlock( mutex );
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.
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 :)
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.
--- 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.