Wiki

This version (12 Jul 2023 08:52) was approved by Sakthivel Perumal.The Previously approved version (12 Jul 2023 08:51) is available.Diff

Click here to go back

Target and Communication Libraries Integration

This section briefs about the implementation and configuration details of different components of the SigmaStudio+ for SHARCa

Integrating target and communication libraries into custom real-time application
In order to create an Application (SHARC in this case), running the communication library and target libraries, users must do the following:

1. In CrossCore Embedded Studio, start a new CrossCore Project. Enter the name of the project, type of project, processor etc. when requested, and proceed by pressing ‘Next’.

2. Add the SigmaStudio+ for SHARC communication library and target library to the project from the installed Add-ins for the project using system.svc setting.



3. Pin Multiplexing to be enable in system properties for enabling the SPI1 as mentions below:


4. Include the following header files in the main Application code.

  a. adi_ss_smap.h
  b. adi_ss_ipc.h
  c. adi_ss_connection.h
  d. adi_ss_communication.h
  e. adi_ss_ssn.h

5. Copy the adi_ss_gmap.asm and adi_ss_app.ldf files from example lib Integration application (Example: C:\Analog Devices\SigmaStudioPlus-Relx.x.x\Target\Examples\LibraryIntegration\ADSP-21569\LibIntegrationExample_Core1\src) into your project source folder.

6. Refer the app.ldf available in the respective processor library Integration example project in the below path: “C:\Analog Devices\SigmaStudioPlus-Relx.x.x\Target\Examples\LibraryIntegration”, and update the memory sections, stack and heap allocation and inclusion of “adi_ss_app.ldf” file in the app.ldf. The app.ldf will be present in the CCES project's “system-->startup_ldf” folder.
Also note that if your system does not have L3 memory, you need to make a change to the following section in your app.ldf as follows, which is needed for the SigmaStudio GMAP memory allocation.

 mem_L2_bw               { TYPE(BW RAM) START(0x20000000) END(0x200b9fff) WIDTH(8) }
 #if !defined(MY_SDRAM_SWCODE_MEM)
 /* 96 kB reserverd for SS4G code  */
 mem_L2_bw_SS4G_Code    { TYPE(BW RAM) START(0x200C0000) END(0x200D7fff) WIDTH(8) }   
 #endif  
 #if !defined(MY_SDRAM_DATA1_MEM)   
 /* 160 kB reserverd for SS4G data  */   
 mem_L2_bw_SS4G_Data    { TYPE(BW RAM) START(0x200D8000) END(0x200f9fff) WIDTH(8) }   
 #endif


7. Allocate instance memory for connection and communication component within the main application code, as shown below.

 /* Connection and Communication Instance Mem */
 ALIGN(4)
 SECTION("ss_app_data0_fast")
 uint8_t adi_ss_commn_mem[ADI_SS_COMM_MEMSIZE];
 ALIGN(4)
 SECTION("ss_app_data0_fast")
 uint8_t adi_ss_connection_mem[ADI_SS_CONNECTION_MEMSIZE];


8.Declare the SSnconfig, Backchannel info variables and the functions needed for SSncofig, in the global space of the main application as shown below:

   volatile uint32_t nSMAPReceived=0;
   /* SMAP */
   ADI_SS_MEM_SMAP oSMAPSharc0;
   ADI_SS_MEM_MAP oSSnMemMap;
   /* SSn Config structure */
   ADI_SS_CONFIG  *pSSnConfig,oSSnConfig;
   /* SSnProperties structure */
   ADI_SS_SSNPROPERTIES *pSSnProperties,oSSnProperties;
   /* Defining SSn Handle */
   ADI_SS_SSN_HANDLE hSSnHandle;
   /* Backchannel info */
   ADI_SS_BACKCH_INFO 	oBkChannelInfoSharc0;
   /* I/O buffer and pointers for SSn instance */
   float32_t aSSInOutBuff[BLOCK_SIZE*NUM_CHANNELS];
   float32_t *pSSInBuff[NUM_CHANNELS];
   float32_t *pSSOutBuff[NUM_CHANNELS];
   void adi_ss_comm_callback_cmd4(uint32_t  *pCommPayloadBuff,
                             int32_t   nPayloadCount,
                             ADI_SS_SSN_HANDLE hSSn);
   void adi_SMAP_Application_Callback(ADI_SS_PROC_ID eCoreID);
   /* Convert the audio samples generated by ADC into float format */
   void    CopyFix2Float( volatile        uint32_t  *pInBuffer,
                                      uint32_t nInStride,
                     volatile        float    *pOutBuffer,
                                      uint32_t nOutStride,
                                      uint32_t nBlockSize,
                                      uint32_t nShiftFlag);
   /* Convert the audio samples from float to fixed point (which can be consumed by DAC) */
   uint32_t CopyFloat2Fix(volatile   float *pInBuffer,
                                      uint32_t nInStride,
                             volatile uint32_t *pOutBuffer,
                                      uint32_t nOutStride,
                                      uint32_t nBlockSize,
                                      uint32_t nShiftFlag);

9.Declare the variables required for the connection and communication configuration as shown below within the main:

   ADI_SS_MEM_BLOCK oConnectionMemBlk, *pConnectionMemBlk;
   ADI_SS_CONNECTION_CONFIG oConnConfig, *pConnConfig;
   ADI_SS_CONNECTION_RESULT eConnRet = ADI_SS_CONNECTION_FAILED;
   ADI_SS_CONNECTION_HANDLE hConnHandle;
   ADI_SS_MEM_BLOCK oCommMemBlk, *pCommMemBlk;
   ADI_SS_COMM_CONFIG oCommnConfig, *pCommnConfig;
   ADI_SS_COMM_RESULT eCommRet = ADI_SS_COMM_FAILED;
   ADI_SS_COMM_HANDLE hCommHandle;

10.Make the connection and communication configuration initialization as follows:

   /* Connection component Initialization */
   pConnConfig = &oConnConfig;
   pConnConfig->eConnectionType = ADI_SS_CONNECTION_SPI;
   pConnConfig->nDevId = 1;
   pConnConfig->eProcID = PROCESSOR_SH0;
   pConnectionMemBlk = &oConnectionMemBlk;
   pConnectionMemBlk->nSize = ADI_SS_CONNECTION_MEMSIZE;
   pConnectionMemBlk->pMem = adi_ss_connection_mem;
   eConnRet = adi_ss_connection_Init(pConnectionMemBlk, pConnConfig, &hConnHandle);
   if(eConnRet != ADI_SS_CONNECTION_SUCCESS)
   {
     printf("\nConnection component initialization failed");
     exit(-1);
   }
   /* Communication component initialization*/
   pCommnConfig = &oCommnConfig;
   pCommnConfig->bCRCBypass = false;
   pCommnConfig->bFullPacketCRC = true;
   pCommnConfig->pfCommCmd4CallBack = (ADI_SS_COMM_CMD4_CB) adi_ss_comm_callback_cmd4;
   pCommnConfig->pfCommSMAPCallBack = (ADI_SS_COMM_SMAP_CB) adi_SMAP_Application_Callback;
   pCommnConfig->hConnectionHandle = hConnHandle;
   pCommnConfig->pMemSMap[PROCESSOR_SH0] = &oSMAPSharc0;
   pCommnConfig->pBkChnlInfo[0] = &oBkChannelInfoSharc0;
   pCommMemBlk = &oCommMemBlk;
   pCommMemBlk->nSize = ADI_SS_COMM_MEMSIZE;
   pCommMemBlk->pMem = adi_ss_commn_mem;
   eCommRet = adi_ss_comm_Init(pCommMemBlk, pCommnConfig, &hCommHandle);
   if(eCommRet != ADI_SS_COMM_SUCCESS)
   {
     printf("\nCommunication component initialization failed");
     exit(-1);
   }

11.The adi_ss_comm_callback_cmd4 and adi_SMAP_Application_Callback function callbacks need to be defined in the main application file as shown below:

   void adi_SMAP_Application_Callback(ADI_SS_PROC_ID eCoreID)
   { 
    if(eCoreID==PROCESSOR_SH0)  // Corresponding SHARC core ID
     {
    	nSMAPReceived = 1;
     }
    }
   void adi_ss_comm_callback_cmd4(uint32_t *pCommPayloadBuff, int32_t  nPayloadCount, ADI_SS_SSN_HANDLE hSSn)
   {
    ;
   }

12.The SSnconfig needs to be done after waiting for SMAP to be downloaded from SigmaStudio Host as shown below:

    /* Wait for SMAP to be received from host */
    while(!nSMAPReceived)
    {
    }
   /* Populating Memory addresses of different blocks from SMAP */
   oSSnMemMap.nMemBlocks = 11;
   pSSnInfo = &oSMAPSharc0.oSSnInfo[0];
   for(i=0; i<oSSnMemMap.nMemBlocks; i++)
   {
oSSnMemMap.pMemBlocks[i] = &pSSnInfo->oSSnBuff[i];
   }
   /* Create an instance of SSn */
   adi_ss_create( &hSSnHandle, &oSSnMemMap);
   if(hSSnHandle == NULL)
   {
   printf("\n SSn instance creation failed");
   exit(-1);
   }
   /* Provide SSn handle to communication component using the adi_ss_comm_SetProperties() API */
   pCommProp.haSSnHandle[PROCESSOR_SH0][0] = hSSnHandle;
   pCommProp.nNumProcBlocks = 1;
   pCommProp.nProcId = PROCESSOR_SH0;
   eCommRet = adi_ss_comm_SetProperties(hCommHandle,ADI_COMM_PROP_SSN_HANDLE,&pCommProp);
   if(eCommRet != ADI_SS_COMM_SUCCESS)
   {
     printf("\nError in Communication component");
     exit(-1);
   }
   /* Initialize the SSn instance */
   pSSnConfig = &oSSnConfig;
   pSSnConfig->hSSComm = hCommHandle;
   pSSnConfig->nBlockSize = BLOCK_SIZE ;
   pSSnConfig->nInChannels = 8;
   pSSnConfig->nOutChannels = 8;
   pSSnConfig->bSkipProcessOnCRCError = 0;
   pSSnConfig->bSkipInitialDownload = 0U;
   pSSnConfig->nInitNoWait = 0;
   pSSnConfig->eProcID = PROCESSOR_SH0;
   pSSnConfig->bClearUnusedOutput = 1;
   eSSRes =  adi_ss_init(hSSnHandle, pSSnConfig);
   if(eSSRes != ADI_SS_SUCCESS)
   {
    printf("\nSSn instance initialization failed");
    exit(-1);
   }
   pSSnProperties = &oSSnProperties;
   /* Initialize SigmaStudio I/O pointers */
   for(i=0; i<NUM_CHANNELS; i++)
   {
    pSSInBuff[i] = &aSSInOutBuff[i*BLOCK_SIZE];
    pSSOutBuff[i] = pSSInBuff[i];
   }

13.The schematic process function can be called within the main process loop as shown below. The copyfix2float() will convert the fixed point input samples to floating point data that can be processed in the schematic_process function. Also the copyfloat2fix() will convert the processed data to fixed point to be sent to the Sport buffers.

   /* Fixed to float conversion and copy to SS input buffer */
   for(i=0; i<NUM_CHANNELS; i++)
   {
     CopyFix2Float((volatile uint32_t*)&nTempBuff[i], NUM_CHANNELS, pSSInBuff[i], 1, BLOCK_SIZE, 2u);
   }
   /* Call to the Schematic processing  */
   adi_ss_schematic_process(hSSnHandle,BLOCK_SIZE,(adi_ss_sample_t **)pSSInBuff,(adi_ss_sample_t **)pSSOutBuff,pSSnProperties);
   /* Float to fix conversion and copy back to SPORT buffer */
   for(i=0; i<NUM_CHANNELS; i++)
   {
     CopyFloat2Fix(pSSOutBuff[i], 1, (volatile uint32_t * )&pSportOut[i], NUM_CHANNELS, BLOCK_SIZE, 0u);
   }
   

14. Please include the “src” path for including the “adi_ss_app.ldf” file as shown below.

Note:

   •   This document explains about the Sigma Studio library integration. The I/O source configurations like 
       ADC/DAC, SPORT configurations for receiving I/O data, SRU configurations for signal routing and I/O Buffer 
       allocations should be taken care by the developer.
   •   We have the different lib-Integration examples for different target processors which is available in the 
       below path, please refer the same for any integration issues.
       C:\Analog Devices\SigmaStudioPlus-Rex.x.x\Target\Examples\LibraryIntegration
resources/tools-software/sigmastudiov2/targetintegration/integratecommlibrary.txt · Last modified: 12 Jul 2023 08:52 by Sakthivel Perumal