Feat: gura!!!
This commit is contained in:
@@ -25,6 +25,11 @@
|
||||
|
||||
#include <gpio.h>
|
||||
#include <mbox.h>
|
||||
#include <string.h>
|
||||
#include <kmalloc.h>
|
||||
#include <thread.h>
|
||||
#include <logger.h>
|
||||
#include <utils.h>
|
||||
|
||||
/* mailbox message buffer */
|
||||
// volatile unsigned int __attribute__((aligned(16))) mbox[36];
|
||||
@@ -49,21 +54,30 @@
|
||||
/**
|
||||
* Make a mailbox call. Returns 0 on failure, non-zero on success
|
||||
*/
|
||||
int mbox_call(unsigned char ch, unsigned int *mbox)
|
||||
int mbox_call(unsigned char ch, unsigned int *input)
|
||||
{
|
||||
unsigned int r = (((unsigned int)((unsigned long)&mbox)&~0xF) | (ch&0xF));
|
||||
unsigned int *_mbox = kmalloc((size_t)input[0] + 0xf), *mbox = ALIGN16(_mbox);
|
||||
LOG(_mbox); LOG(mbox); DEBUG((size_t)input[0]);
|
||||
memcpy(mbox, input, (size_t)input[0]);
|
||||
unsigned int r = (unsigned long)mbox | (unsigned int)(ch&0xf);
|
||||
/* wait until we can write to the mailbox */
|
||||
do{asm volatile("nop");}while(*MBOX_STATUS & MBOX_FULL);
|
||||
do yield();
|
||||
while(*MBOX_STATUS & MBOX_FULL);
|
||||
/* write the address of our message to the mailbox with channel identifier */
|
||||
*MBOX_WRITE = r;
|
||||
/* now wait for the response */
|
||||
for (;;) {
|
||||
/* is there a response? */
|
||||
do{asm volatile("nop");}while(*MBOX_STATUS & MBOX_EMPTY);
|
||||
do yield();
|
||||
while(*MBOX_STATUS & MBOX_EMPTY);
|
||||
/* is it a response to our message? */
|
||||
if(r == *MBOX_READ)
|
||||
if(r == *MBOX_READ) {
|
||||
/* is it a valid successful response? */
|
||||
return mbox[1]==MBOX_RESPONSE;
|
||||
if (mbox[1] == MBOX_RESPONSE)
|
||||
memcpy(input, mbox, (size_t)input[0]);
|
||||
kfree(_mbox);
|
||||
return mbox[1] == MBOX_RESPONSE;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user