lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /******************************************************************************* |
| 2 | * °æÈ¨ËùÓÐ (C)2023, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£ |
| 3 | * |
| 4 | * ÎļþÃû³Æ: nvserver_rpc.c |
| 5 | * Îļþ±êʶ: nvserver_rpc.c |
| 6 | * ÄÚÈÝÕªÒª: nvserverת½ÓcapµÄnvserver |
| 7 | * |
| 8 | * ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ |
| 9 | * ------------------------------------------------------------------------------ |
| 10 | * 2016/06/13 V1.0 Create ÁõÑÇÄÏ ´´½¨ |
| 11 | * |
| 12 | *******************************************************************************/ |
| 13 | |
| 14 | /******************************************************************************* |
| 15 | * Í·Îļþ * |
| 16 | *******************************************************************************/ |
| 17 | #include <unistd.h> |
| 18 | #include <errno.h> |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <dirent.h> |
| 22 | #include <string.h> |
| 23 | #include <sys/file.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <sys/stat.h> |
| 26 | #include <sys/ipc.h> |
| 27 | #include <sys/msg.h> |
| 28 | |
| 29 | #include "nvserver.h" |
| 30 | #include "nv_typedef.h" |
| 31 | #include <message.h> |
| 32 | #include "sc_rpc.h" |
| 33 | |
| 34 | #ifdef FOTA_AB |
| 35 | #include "zxic_fota_ab_upgrade.h" |
| 36 | #endif |
| 37 | |
| 38 | #ifdef __cplusplus |
| 39 | extern "C" |
| 40 | { |
| 41 | #endif |
| 42 | |
| 43 | /******************************************************************************* |
| 44 | * ³£Á¿¶¨Òå * |
| 45 | *******************************************************************************/ |
| 46 | |
| 47 | /******************************************************************************* |
| 48 | * ºê¶¨Òå * |
| 49 | *******************************************************************************/ |
| 50 | #define RPC_RPMSG_DEV "/dev/rpmsg8" |
| 51 | |
| 52 | /******************************************************************************* |
| 53 | * Êý¾ÝÀàÐͶ¨Òå * |
| 54 | *******************************************************************************/ |
| 55 | |
| 56 | /******************************************************************************* |
| 57 | * ¾Ö²¿º¯ÊýÉùÃ÷ * |
| 58 | *******************************************************************************/ |
| 59 | |
| 60 | /******************************************************************************* |
| 61 | * ¾Ö²¿¾²Ì¬±äÁ¿¶¨Òå * |
| 62 | *******************************************************************************/ |
| 63 | |
| 64 | /******************************************************************************* |
| 65 | * È«¾Ö±äÁ¿¶¨Òå * |
| 66 | *******************************************************************************/ |
| 67 | static int g_rpc_fd = -1; |
| 68 | |
| 69 | /******************************************************************************* |
| 70 | * ¾Ö²¿º¯ÊýʵÏÖ * |
| 71 | *******************************************************************************/ |
| 72 | /******************************************************************************* |
| 73 | * ¹¦ÄÜÃèÊö: analyMsg |
| 74 | * ²ÎÊý˵Ã÷: |
| 75 | * (´«Èë²ÎÊý) msgrecv:½ÓÊÕÏûÏ¢ |
| 76 | * (´«³ö²ÎÊý) msgsnd:·¢ËÍÏûÏ¢ |
| 77 | * ·µ »Ø Öµ: 0±íʾ³É¹¦ |
| 78 | * ÆäËü˵Ã÷: void |
| 79 | *******************************************************************************/ |
| 80 | static void analyMsg(T_NV_MSG_INFO *msgrecv, T_NV_MSG_RESULT *msgsnd) |
| 81 | { |
| 82 | T_sc_rpc_header rpc_data = {0}; |
| 83 | |
| 84 | rpc_data.msg_type = RPC_MSG_TYPE_REQUEST; |
| 85 | rpc_data.func_id = RPC_FUNC_ID_NV; |
| 86 | rpc_data.data_len = sizeof(T_NV_MSG_INFO); |
| 87 | memcpy(rpc_data.data, msgrecv, sizeof(T_NV_MSG_INFO)); |
| 88 | |
| 89 | sc_rpc_send(g_rpc_fd, &rpc_data, 0); |
| 90 | |
| 91 | while (0 != sc_rpc_recv(g_rpc_fd, &rpc_data, 0)) // µÈ´ýCAPºË´´½¨Í¨µÀ |
| 92 | { |
| 93 | sleep(1); |
| 94 | continue; |
| 95 | } |
| 96 | |
| 97 | memcpy(msgsnd, rpc_data.data, sizeof(T_NV_MSG_RESULT)); |
| 98 | } |
| 99 | |
| 100 | /******************************************************************************* |
| 101 | * È«¾Öº¯ÊýʵÏÖ * |
| 102 | *******************************************************************************/ |
| 103 | |
| 104 | /******************************************************************************* |
| 105 | * ¹¦ÄÜÃèÊö: main |
| 106 | * ²ÎÊý˵Ã÷: |
| 107 | * (´«Èë²ÎÊý) void |
| 108 | * (´«³ö²ÎÊý) void |
| 109 | * ·µ »Ø Öµ: void |
| 110 | * ÆäËü˵Ã÷: void |
| 111 | *******************************************************************************/ |
| 112 | int nvserver_main(int argc, char *argv[]) |
| 113 | { |
| 114 | int msgId = 0; |
| 115 | T_NV_MSG_INFO rcvBuf; |
| 116 | T_NV_MSG_RESULT sndBuf; |
| 117 | struct msqid_ds msgInfo; |
| 118 | |
| 119 | prctl(PR_SET_NAME, "nvserver", 0, 0, 0); |
| 120 | |
| 121 | memset(&msgInfo, 0, sizeof(msgInfo)); |
| 122 | |
| 123 | g_rpc_fd = sc_rpc_open(RPC_RPMSG_DEV); |
| 124 | |
| 125 | msgId = msgget(MODULE_ID_NV, IPC_CREAT | 0600); |
| 126 | if (-1 == msgId) |
| 127 | { |
| 128 | printf("nvserver error: msgget msgId fail, errno = %d\n", errno); |
| 129 | return -1; |
| 130 | } |
| 131 | |
| 132 | if (-1 != msgctl(msgId, IPC_STAT, &msgInfo)) |
| 133 | { |
| 134 | msgInfo.msg_qbytes = 262144; // 256k |
| 135 | if (-1 == msgctl(msgId, IPC_SET, &msgInfo)) |
| 136 | { |
| 137 | printf("nvserver error: msgctl msgId fail, errno = %d\n", errno); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | // ÏûÏ¢½»»¥ |
| 142 | while (1) |
| 143 | { |
| 144 | memset(&rcvBuf, 0, sizeof(rcvBuf)); |
| 145 | memset(&sndBuf, 0, sizeof(sndBuf)); |
| 146 | if (-1 == msgrcv(msgId, &rcvBuf, sizeof(T_NV_MSG_INFO) - sizeof(long), MSG_TYPE_NV, 0)) |
| 147 | { |
| 148 | printf("nvserver error: nvserver msgrcv fail, errno = %d!\n", errno); |
| 149 | continue; |
| 150 | } |
| 151 | |
| 152 | analyMsg(&rcvBuf, &sndBuf); |
| 153 | |
| 154 | if (-1 == msgsnd(msgId, &sndBuf, sizeof(T_NV_MSG_RESULT) - sizeof(long), 0)) |
| 155 | { |
| 156 | printf("nvserver error: nvserver msgsnd fail, errno = %d!\n", errno); |
| 157 | continue; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | return (0); |
| 162 | } |
| 163 | |
| 164 | #ifdef __cplusplus |
| 165 | } |
| 166 | #endif |