|
@@ -12,17 +12,18 @@ int active = 1;
|
|
|
|
|
|
void mailbox_irq_handler(int val)
|
|
|
{
|
|
|
- printf("mailbox msg recv %d\n",val);
|
|
|
- msg_done = 1;
|
|
|
+ printf("mailbox msg recv %d\n",val);
|
|
|
+ msg_done = 1;
|
|
|
}
|
|
|
|
|
|
void init_signal(int fd)
|
|
|
{
|
|
|
- int flags,ret;
|
|
|
-
|
|
|
- signal(SIGIO, mailbox_irq_handler);
|
|
|
+ int flags = 0, ret = 0;
|
|
|
+
|
|
|
+ signal(SIGIO, mailbox_irq_handler);
|
|
|
|
|
|
ret = fcntl(fd, F_SETOWN, getpid());
|
|
|
+ printf("mailbox fcntl F_SETOWN ret: %d\n",ret);
|
|
|
|
|
|
flags = fcntl(fd, F_GETFL);
|
|
|
|
|
@@ -31,46 +32,46 @@ void init_signal(int fd)
|
|
|
|
|
|
void * mailbox_user_read(void *arg)
|
|
|
{
|
|
|
- char buf[8];
|
|
|
- int fp = open("/sys/kernel/debug/soc:mailbox_client@0/message",O_RDWR);
|
|
|
-
|
|
|
- while(active)
|
|
|
- {
|
|
|
- read(fp,buf,sizeof(char));
|
|
|
- printf("user recv:%c\n",buf[0]);
|
|
|
- }
|
|
|
- close(fp);
|
|
|
+ char buf[8] = {0};
|
|
|
+ int fp = open("/sys/kernel/debug/soc:mailbox_client@0/message", O_RDWR);
|
|
|
+
|
|
|
+ while(active) {
|
|
|
+ read(fp, buf, sizeof(char));
|
|
|
+ printf("user recv:%c\n", buf[0]);
|
|
|
+ }
|
|
|
+ close(fp);
|
|
|
+ return NULL;
|
|
|
}
|
|
|
|
|
|
int main(int argv,char **argc)
|
|
|
{
|
|
|
- int fd,i=0,ret;
|
|
|
- char buf_tx[8],buf_rx[8];
|
|
|
+ int fd = 0, i = 0;
|
|
|
+ char buf_tx[8];
|
|
|
|
|
|
- fd = open("/sys/kernel/debug/soc:mailbox_client@0/message",O_RDWR);
|
|
|
- if(fd < 0)
|
|
|
+ fd = open("/sys/kernel/debug/soc:mailbox_client@0/message", O_RDWR);
|
|
|
+ if (fd < 0) {
|
|
|
printf("open device error\n");
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
|
|
|
- pthread_t thread_read;
|
|
|
+ pthread_t thread_read;
|
|
|
+ if (pthread_create(&thread_read, NULL, mailbox_user_read, NULL) != 0) {
|
|
|
+ printf("pthread_create error\n");
|
|
|
+ close(fd);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
- if(pthread_create(&thread_read,NULL,mailbox_user_read,NULL) != 0)
|
|
|
- {
|
|
|
- printf("pthread_create error\n");
|
|
|
- close(fd);
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- buf_tx[0] = 'a';
|
|
|
- do{
|
|
|
- write(fd,buf_tx,sizeof(char));
|
|
|
- printf("user send:%c\n",buf_tx[0]);
|
|
|
- sleep(1);
|
|
|
+ buf_tx[0] = 'a';
|
|
|
+ do {
|
|
|
+ write(fd, buf_tx, sizeof(char));
|
|
|
+ printf("user send:%c\n", buf_tx[0]);
|
|
|
+ sleep(1);
|
|
|
|
|
|
- buf_tx[0]++;
|
|
|
- i++;
|
|
|
- }while(i<2);
|
|
|
- active = 0;
|
|
|
+ buf_tx[0]++;
|
|
|
+ i++;
|
|
|
+ } while (i < 2);
|
|
|
+ active = 0;
|
|
|
close(fd);
|
|
|
|
|
|
- return 1;
|
|
|
+ return 0;
|
|
|
}
|