/* * Copyright (c) 2020 NVIDIA Corporation. All Rights Reserved. * * NVIDIA Corporation and its licensors retain all intellectual property and * proprietary rights in and to this software and related documentation. Any * use, reproduction, disclosure or distribution of this software and related * documentation without an express license agreement from NVIDIA Corporation * is strictly prohibited. */ #include "rawstream.h" NvSciSyncModule syncModule = NULL; NvSciBufModule bufModule = NULL; NvSciSyncAttrList producerSignalAttrs = NULL; NvSciSyncAttrList consumerSignalAttrs = NULL; NvSciSyncAttrList producerWaitAttrs = NULL; NvSciSyncAttrList consumerWaitAttrs = NULL; NvSciSyncAttrList prodToConsAttrs = NULL; NvSciSyncAttrList consToProdAttrs = NULL; NvSciSyncObj consumerSignalObj = NULL; NvSciSyncObj producerSignalObj = NULL; NvSciSyncObj consumerWaitObj = NULL; NvSciSyncObj producerWaitObj = NULL; NvSciBufAttrList producerWriteAttrs = NULL; NvSciBufAttrList consumerReadAttrs = NULL; NvSciBufAttrList combinedBufAttrs = NULL; Buffer buffers[totalBuffers]; IpcWrapper ipcWrapper; int main(int argc, char *argv[]) { NvSciError err; int producer; const char* endpoint; int ret = 0; if ((argc == 2) && (strcmp(argv[1], "-p") == 0)){ producer = 1; endpoint = "Producer"; } else if ((argc == 2) && (strcmp(argv[1], "-c") == 0)) { producer = 0; endpoint = "Consumer"; } else { fprintf(stderr, "The usage of the app is ./rawstream followed by -p or -c\n"); fprintf(stderr, " -p denotes producer and -c denotes consumer\n"); return 1; } fprintf(stderr, "%p application starting\n", endpoint); // Open sync module (shared by both all threads) err = NvSciSyncModuleOpen(&syncModule); if (NvSciError_Success != err) { fprintf(stderr, "%s unable to open sync module (%x)\n", endpoint, err); return 1; } // Open buf module (shared by both all threads) err = NvSciBufModuleOpen(&bufModule); if (NvSciError_Success != err) { fprintf(stderr, "%s unable to open buf module (%x)\n", endpoint, err); ret = 1; goto close_sync_module; } // Initialize IPC library err = NvSciIpcInit(); if (NvSciError_Success != err) { fprintf(stderr, "%s unable to init ipc library (%x)\n", endpoint, err); ret = 1; goto close_buf_module; } // Establish IPC communications based on endpoint // TODO: Settle on final IPC channel names if (producer == 1) { err = ipcInit("nvscisync_a_0", &ipcWrapper); } else { err = ipcInit("nvscisync_a_1", &ipcWrapper); } if (NvSciError_Success != err) { fprintf(stderr, "%s unable to initialize communication (%x)\n", endpoint, err); ret = 1; goto deinit_IPC; } // Test communication by exchanging a simple handshake message const int send_handshake = 12345; err = ipcSend(&ipcWrapper, &send_handshake, sizeof(send_handshake)); if (NvSciError_Success != err) { fprintf(stderr, "%s failed to send handshake (%x)\n", endpoint, err); ret = 1; goto deinit_IPC; } int recv_handshake = 0; ipcRecvFill(&ipcWrapper, &recv_handshake, sizeof(recv_handshake)); if (NvSciError_Success != err) { fprintf(stderr, "%s failed to receive handshake (%x)\n", endpoint, err); ret = 1; goto deinit_IPC; } if (send_handshake != recv_handshake) { fprintf(stderr, "%s handshake did not match (%x)\n", endpoint, err); ret = 1; goto deinit_IPC; } // Initialize buffer list for (uint32_t i=0; i 0; j--) { if (tmp & 1) { tmp = (tmp >> 1) ^ CRC32_POLYNOMIAL; } else { tmp >>= 1; } } crcTable[i] = tmp; } initialized = 1; } //Calculate CRC for the data for (y = 0U; y < height; y++) { for (x = 0U; x < width; x++) { tmp = (crc >> 8) & 0x00FFFFFFL; crc = tmp ^ crcTable[((uint32_t) crc ^ *(data_ptr + x)) & 0xFF]; } data_ptr += pitch; } return crc; }