| /******************************************************************************* |
| * °æÈ¨ËùÓÐ (C)2023, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£ |
| * |
| * ÎļþÃû³Æ: nvserver_rpc.c |
| * Îļþ±êʶ: nvserver_rpc.c |
| * ÄÚÈÝÕªÒª: nvserverת½ÓcapµÄnvserver |
| * |
| * ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ |
| * ------------------------------------------------------------------------------ |
| * 2016/06/13 V1.0 Create ÁõÑÇÄÏ ´´½¨ |
| * |
| *******************************************************************************/ |
| |
| /******************************************************************************* |
| * Í·Îļþ * |
| *******************************************************************************/ |
| #include <unistd.h> |
| #include <errno.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <dirent.h> |
| #include <string.h> |
| #include <sys/file.h> |
| #include <sys/types.h> |
| #include <sys/stat.h> |
| #include <sys/ipc.h> |
| #include <sys/msg.h> |
| |
| #include "nvserver.h" |
| #include "nv_typedef.h" |
| #include <message.h> |
| #include "sc_rpc.h" |
| |
| #ifdef FOTA_AB |
| #include "zxic_fota_ab_upgrade.h" |
| #endif |
| |
| #ifdef __cplusplus |
| extern "C" |
| { |
| #endif |
| |
| /******************************************************************************* |
| * ³£Á¿¶¨Òå * |
| *******************************************************************************/ |
| |
| /******************************************************************************* |
| * ºê¶¨Òå * |
| *******************************************************************************/ |
| #define RPC_RPMSG_DEV "/dev/rpmsg8" |
| |
| /******************************************************************************* |
| * Êý¾ÝÀàÐͶ¨Òå * |
| *******************************************************************************/ |
| |
| /******************************************************************************* |
| * ¾Ö²¿º¯ÊýÉùÃ÷ * |
| *******************************************************************************/ |
| |
| /******************************************************************************* |
| * ¾Ö²¿¾²Ì¬±äÁ¿¶¨Òå * |
| *******************************************************************************/ |
| |
| /******************************************************************************* |
| * È«¾Ö±äÁ¿¶¨Òå * |
| *******************************************************************************/ |
| static int g_rpc_fd = -1; |
| |
| /******************************************************************************* |
| * ¾Ö²¿º¯ÊýʵÏÖ * |
| *******************************************************************************/ |
| /******************************************************************************* |
| * ¹¦ÄÜÃèÊö: analyMsg |
| * ²ÎÊý˵Ã÷: |
| * (´«Èë²ÎÊý) msgrecv:½ÓÊÕÏûÏ¢ |
| * (´«³ö²ÎÊý) msgsnd:·¢ËÍÏûÏ¢ |
| * ·µ »Ø Öµ: 0±íʾ³É¹¦ |
| * ÆäËü˵Ã÷: void |
| *******************************************************************************/ |
| static void analyMsg(T_NV_MSG_INFO *msgrecv, T_NV_MSG_RESULT *msgsnd, T_sc_rpc_header *rpc_data, T_sc_rpc_header *rpc_data2) |
| { |
| unsigned int timeout = 10; |
| int try_cnt = 0; |
| |
| memset(rpc_data, 0, sizeof(T_sc_rpc_header)); |
| memset(rpc_data2, 0, sizeof(T_sc_rpc_header)); |
| |
| rpc_data->msg_type = RPC_MSG_TYPE_REQUEST; |
| rpc_data->func_id = RPC_FUNC_ID_NV; |
| rpc_data->data_len = sizeof(T_NV_MSG_INFO); |
| memcpy(rpc_data->data, msgrecv, sizeof(T_NV_MSG_INFO)); |
| |
| do |
| { |
| if (try_cnt > 0) |
| { |
| sc_rpc_clear(g_rpc_fd); |
| } |
| sc_rpc_send(g_rpc_fd, rpc_data, 0); |
| try_cnt++; |
| //sleep(1); |
| //continue; |
| } while (0 != sc_rpc_recv(g_rpc_fd, rpc_data2, timeout)); // µÈ´ýCAPºË´´½¨Í¨µÀ |
| |
| memcpy(msgsnd, rpc_data2->data, sizeof(T_NV_MSG_RESULT)); |
| } |
| |
| /******************************************************************************* |
| * È«¾Öº¯ÊýʵÏÖ * |
| *******************************************************************************/ |
| |
| /******************************************************************************* |
| * ¹¦ÄÜÃèÊö: main |
| * ²ÎÊý˵Ã÷: |
| * (´«Èë²ÎÊý) void |
| * (´«³ö²ÎÊý) void |
| * ·µ »Ø Öµ: void |
| * ÆäËü˵Ã÷: void |
| *******************************************************************************/ |
| int nvserver_main(int argc, char *argv[]) |
| { |
| int msgId = 0; |
| T_NV_MSG_INFO rcvBuf; |
| T_NV_MSG_RESULT sndBuf; |
| struct msqid_ds msgInfo; |
| T_sc_rpc_header *rpc_data; |
| T_sc_rpc_header *rpc_data2; |
| |
| prctl(PR_SET_NAME, "nvserver", 0, 0, 0); |
| |
| memset(&msgInfo, 0, sizeof(msgInfo)); |
| |
| g_rpc_fd = sc_rpc_open(RPC_RPMSG_DEV); |
| |
| msgId = msgget(MODULE_ID_NV, IPC_CREAT | 0600); |
| if (-1 == msgId) |
| { |
| printf("nvserver error: msgget msgId fail, errno = %d\n", errno); |
| return -1; |
| } |
| |
| if (-1 != msgctl(msgId, IPC_STAT, &msgInfo)) |
| { |
| msgInfo.msg_qbytes = 262144; // 256k |
| if (-1 == msgctl(msgId, IPC_SET, &msgInfo)) |
| { |
| printf("nvserver error: msgctl msgId fail, errno = %d\n", errno); |
| } |
| } |
| |
| rpc_data = malloc(sizeof(T_sc_rpc_header)); |
| if (rpc_data == NULL) |
| { |
| perror("[error]nvrpc malloc error\n"); |
| return -2; |
| } |
| rpc_data2 = malloc(sizeof(T_sc_rpc_header)); |
| if (rpc_data2 == NULL) |
| { |
| perror("[error]nvrpc malloc2 error\n"); |
| free(rpc_data); |
| return -3; |
| } |
| |
| // ÏûÏ¢½»»¥ |
| while (1) |
| { |
| memset(&rcvBuf, 0, sizeof(rcvBuf)); |
| memset(&sndBuf, 0, sizeof(sndBuf)); |
| if (-1 == msgrcv(msgId, &rcvBuf, sizeof(T_NV_MSG_INFO) - sizeof(long), MSG_TYPE_NV, 0)) |
| { |
| printf("nvserver error: nvserver msgrcv fail, errno = %d!\n", errno); |
| continue; |
| } |
| |
| analyMsg(&rcvBuf, &sndBuf, rpc_data, rpc_data2); |
| |
| if (-1 == msgsnd(msgId, &sndBuf, sizeof(T_NV_MSG_RESULT) - sizeof(long), 0)) |
| { |
| printf("nvserver error: nvserver msgsnd fail, errno = %d!\n", errno); |
| continue; |
| } |
| } |
| |
| free(rpc_data); |
| free(rpc_data2); |
| return (0); |
| } |
| |
| #ifdef __cplusplus |
| } |
| #endif |