#166430 - cyril_sy - Sun Feb 08, 2009 1:29 am
Hi!
I am developing an application which only uses audio features. So decided to use only the arm7 for the moment. However I want to print messages on the screen, for debugging.
I first succeed in sending strings from the arm7 to the arm9, and printing them :
Code: |
/* ARM7 code */
void arm7Printf(const char * s)
{
fifoSendDatamsg(FIFO_USER_01, sizeof(s), (u8*)&s);
}
/* ARM9 code */
void arm7PrintfFifoHandler(int bytes, void* user_data)
{
char * data;
fifoGetDatamsg(FIFO_USER_01, bytes, (u8*)&data);
iprintf(data);
}
|
It works fine, so I tried this in the arm7 code :
Code: |
void arm7Printf(const char * format, ...)
{
static char* tmp = NULL;
va_list ap;
if (tmp == NULL) {
tmp = malloc(100);
}
va_start(ap, format);
vsnprintf(tmp, 100, format, ap);
va_end(ap);
fifoSendDatamsg(FIFO_USER_01, sizeof(tmp), (u8*)&tmp);
}
|
Unfortunately it doesn't works...
It seems that sprintf and other functions like that doesn't work on the arm7...
Is it something wrong in my code ?
Thanks ;)
#166431 - Lazy1 - Sun Feb 08, 2009 1:41 am
From a quick look, unless something changed the arm9 cannot access memory allocated on the arm7.
Also, you are trying to get the string length with sizeof()?
You should be using strlen instead.
#166432 - Pete_Lockwood - Sun Feb 08, 2009 2:24 am
Strlen is one issue. You're also taking the address of the pointer unnecessarily.
Try
Code: |
void arm7Printf(const char * format, ...)
{
static char* tmp = NULL;
va_list ap;
if (tmp == NULL) {
tmp = malloc(100);
}
va_start(ap, format);
vsnprintf(tmp, 100, format, ap);
va_end(ap);
fifoSendDatamsg(FIFO_USER_01, strlen(tmp), (u8*)tmp);
}
|
_________________
It's not an illusion, it just looks like one.
#166433 - Lazy1 - Sun Feb 08, 2009 3:30 am
Also, why not just have an array instead of allocating memory like that?
It would be make your code much neater, simpler and easier to follow.
#166452 - Pete_Lockwood - Sun Feb 08, 2009 12:36 pm
Certainly.
_________________
It's not an illusion, it just looks like one.
#166455 - cyril_sy - Sun Feb 08, 2009 12:47 pm
Thanks for replies :)
Lazy1 wrote: |
Also, why not just have an array instead of allocating memory like that?
It would be make your code much neater, simpler and easier to follow.
|
Before the malloc, I tried with an array, I got this error in No$gba : No$gba wrote: |
Undefined opcode - with no debug vector defined |
So I tried with a malloc, just to see... I stops the error.
Pete_Lockwood wrote: |
Strlen is one issue. You're also taking the address of the pointer unnecessarily. |
I don't know how does FIFO works, I wanted to send the pointer, not the entire string. I tried with strlen, it doesn't solve the problem...
#166457 - Pete_Lockwood - Sun Feb 08, 2009 1:08 pm
The fifo function's definition says it takes a pointer to the data to send. Try without taking the address.
EDIT: looks like there's a fifoSendAddress function for if you just want to send the pointer.
_________________
It's not an illusion, it just looks like one.
#166480 - wintermute - Sun Feb 08, 2009 7:38 pm
The arm9 does not have access to the arm7 internal ram so sending a pointer won't work.
Attempting to write an application that runs only on the arm7 is a bad idea. Does your audio application require functionality that isn't provided by maxmod?
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog
#166504 - Lazy1 - Mon Feb 09, 2009 5:48 am
Found this as well:
Code: |
// Handlers are called when new data arrives - they're called from interrupt level, but well secured so not too much caution is necessary.
// Except that you shouldn't alloc/free or printf from within them, just to be safe.
|
So you'll need to find a way around that.
#166557 - cyril_sy - Mon Feb 09, 2009 6:48 pm
wintermute wrote: |
The arm9 does not have access to the arm7 internal ram so sending a pointer won't work. |
Thanks :), instead of sending the pointer, I send the chars, one by one :
Code: |
/* ARM7 side */
void arm7Printf(const char * format, ...)
{
char tmp[100];
va_list ap;
va_start(ap, format);
vsnprintf(tmp, 100, format, ap);
va_end(ap);
char * p;
for (p = tmp; *p != '\0'; p++) {
fifoSendValue32(FIFO_USER_01, *p);
}
}
/* ARM9 side */
void arm7PrintfFifoHandler(u32 value32, void * userdata)
{
putchar(value32);
}
|
It works nice, but should it always work ? can I check if the fifo is full ?
wintermute wrote: |
Attempting to write an application that runs only on the arm7 is a bad idea. Does your audio application require functionality that isn't provided by maxmod? |
I don't plan to use only the arm7, I want to do an ocarina (when you blow on the mic, a note is played). For the moment I am trying the digital processing part only, I suppose it should be on the ARM7 side ?