[Feature][ZXW-65]merged P49 base code
Change-Id: I3e09c0c3d47483bc645f02310380ecb7fc6f4041
diff --git a/ap/app/msg_test/Makefile b/ap/app/msg_test/Makefile
new file mode 100755
index 0000000..20fbee9
--- /dev/null
+++ b/ap/app/msg_test/Makefile
@@ -0,0 +1,42 @@
+#*******************************************************************************
+#*******************************************************************************
+include $(COMMON_MK)
+
+##############USER COMIZE BEGIN################
+EXEC1 = msgsnd
+EXEC2 = msgrcv
+
+OBJS1 = msgsnd.o
+OBJS2 = msgrcv.o
+
+CFLAGS += -I.
+CFLAGS += -I$(APP_DIR)/include
+CFLAGS += -I./../inc
+
+CFLAGS += -g -Werror=implicit-function-declaration
+
+
+LDLIBS +=
+
+##############USER COMIZE END##################
+
+#*******************************************************************************
+# targets
+#*******************************************************************************
+all: $(EXEC1) $(EXEC2)
+
+$(EXEC1): $(OBJS1)
+ $(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) $(LDLIBS_$@) -Wl,--end-group
+ @cp $@ $@.elf
+
+$(EXEC2): $(OBJS2)
+ $(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) $(LDLIBS_$@) -Wl,--end-group
+ @cp $@ $@.elf
+
+romfs:
+ $(ROMFSINST) $(EXEC1) /bin/$(EXEC1)
+ $(ROMFSINST) $(EXEC2) /bin/$(EXEC2)
+
+clean:
+ -@rm -f $(EXEC1) $(EXEC2) *.elf *.gdb *.o
+
diff --git a/ap/app/msg_test/msgrcv.c b/ap/app/msg_test/msgrcv.c
new file mode 100755
index 0000000..e3e69aa
--- /dev/null
+++ b/ap/app/msg_test/msgrcv.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+// Define message queue structure
+struct msg_buffer {
+ long msg_type;
+ char msg[100];
+} message;
+main(int argc,char *argv[]) {
+ key_t my_key;
+ int msg_id;
+ int ret;
+ my_key = atoi(argv[1]); //create unique key
+ msg_id = msgget(my_key, 0666 | IPC_CREAT); //create message queue and return id
+ printf("Message id: %d\n", msg_id);
+ ret = msgrcv(msg_id, &message, sizeof(message), 1, 0); //used to receive message
+ // display the message
+ printf("Received Message len is %d, message is : %s \n", ret, message.msg);
+ //msgctl(msg_id, IPC_RMID, NULL); //destroy the message queue
+ return 0;
+}
diff --git a/ap/app/msg_test/msgsnd.c b/ap/app/msg_test/msgsnd.c
new file mode 100755
index 0000000..6c5a5f0
--- /dev/null
+++ b/ap/app/msg_test/msgsnd.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+// structure for message queue
+struct msg_buffer {
+ long msg_type;
+ char msg[100];
+} message;
+main(int argc,char *argv[]) {
+ key_t my_key;
+ int msg_id;
+ int ret;
+ my_key = atoi(argv[1]); //create unique key
+ msg_id = msgget(my_key, 0666 | IPC_CREAT); //create message queue and return id
+ printf("Message id: %d\n", msg_id);
+ message.msg_type = 1;
+ printf("Write Message : ");
+ fgets(message.msg, 100, stdin);
+ ret = msgsnd(msg_id, &message, sizeof(message), 0); //send message
+ printf("Sent message ret is %d message is : %s \n", ret, message.msg);
+}
diff --git a/ap/app/msg_test/readme b/ap/app/msg_test/readme
new file mode 100644
index 0000000..d847e08
--- /dev/null
+++ b/ap/app/msg_test/readme
@@ -0,0 +1,53 @@
+1、目录结构:
+├── Makefile makefile
+├── msgrcv.c 消息队列接收测试程序
+├── msgsnd.c 消息队列发送测试程序
+└── readme 本文件
+
+
+2、说明
+2.1、针对msgget/msgrcv/msgsnd接口
+2.2、msgget依靠key创建消息队列,约定:0x0~0xFFFEFFFF为本核消息区间,0xFFFF0000~0xFFFFFFFF为车载双核跨核消息(针对非跨核工程,依然是本核消息)。
+
+3、使用说明
+3.0、只针对车载版本的测试程序,测试程序名为 msgsnd/msgrcv。
+3.1、AP侧跨核发送测试:msgsnd key (key为int型整数,这里选取0xFFFF0000~0xFFFFFFFF范围,例如-200)
+ CAP侧运行msgrcv key,使用相同的key进行接收,会获取AP侧发送的消息内容并进行打印。
+3.2、AP侧跨核接收测试:msgrcv key (这里同样选择-200),CAP核运行msgsnd -200进行发送。
+3.3、AP侧本核发送测试:key取值范围0x0~0xFFFEFFFF即为本核消息。
+3.4、AP侧本核接收测试:同上。
+
+4、示例:
+4.1、跨核AP->CAP
+ AP:
+ # msgsnd -200
+ Message id: 10
+ Write Message : helloworld
+ Sent message ret is 0 message is : helloworld
+ CAP:
+
+ # msgrcv -200
+ Message id: 10
+ Received Message len is 104, message is : helloworld
+
+4.2、跨核CAP->AP
+ CAP:
+ # msgsnd -200
+ Message id: 11
+ Write Message : nihaoshijie
+ Sent message ret is 0 message is : nihaoshijie
+ AP:
+ # msgrcv -200
+ Message id: 11
+ Received Message len is 104, message is : nihaoshijie
+
+4.3、本核消息队列
+ AP:
+ # msgsnd 100
+ Message id: 12
+ Write Message : huanying
+ Sent message ret is 0 message is : huanying
+ AP:
+ # msgrcv 100
+ Message id: 12
+ Received Message len is 104, message is : huanying
\ No newline at end of file