Pull request #58: am64x/am243x: SDFM: Add configurable memory support

Merge in PINDSW/motor_control_sdk from a0502729_PINDSW-7016_sdfm_move_sample_output_to_tcm to next

* commit 'd010c593a9b14d1017c6236624180eea99eec28d':
  am64x/am243x: SDFM: Add configurable memory support
This commit is contained in:
Achala Ram 2023-10-26 00:10:39 -05:00 committed by Dhaval Khandla
commit b9eb2b68ae
13 changed files with 159 additions and 28 deletions

View File

@ -103,6 +103,9 @@ SECTIONS
.bss.ipc_vring_mem (NOLOAD) : {} > RTOS_NORTOS_IPC_SHM_MEM
/* General purpose non cacheable memory, used in some examples */
.bss.nocache (NOLOAD) : {} > NON_CACHE_MEM
/* TCM used by ICSS PRU to write sdfm sample output */
.gSdfmSampleOutput : {} align(4) > R5F_TCMB0
}
/*

View File

@ -103,6 +103,9 @@ SECTIONS
.bss.ipc_vring_mem (NOLOAD) : {} > RTOS_NORTOS_IPC_SHM_MEM
/* General purpose non cacheable memory, used in some examples */
.bss.nocache (NOLOAD) : {} > NON_CACHE_MEM
/* TCM used by ICSS PRU to write sdfm sample output */
.gSdfmSampleOutput : {} align(4) > R5F_TCMB0
}
/*

View File

@ -103,6 +103,9 @@ SECTIONS
.bss.ipc_vring_mem (NOLOAD) : {} > RTOS_NORTOS_IPC_SHM_MEM
/* General purpose non cacheable memory, used in some examples */
.bss.nocache (NOLOAD) : {} > NON_CACHE_MEM
/* TCM used by ICSS PRU to write sdfm sample output */
.gSdfmSampleOutput : {} align(4) > R5F_TCMB0
}
/*

View File

@ -139,6 +139,8 @@ PRUICSS_Handle gPruIcssHandle;
/* Test Sdfm handles */
sdfm_handle gHPruSdfm;
/* Sdfm output samples, written by PRU cores */
__attribute__((section(".gSdfmSampleOutput"))) uint32_t gSdfm_sampleOutput[NUM_CH_SUPPORTED];
/* Test Sdfm parameters */
SdfmPrms gTestSdfmPrms = {
@ -156,7 +158,8 @@ SdfmPrms gTestSdfmPrms = {
{0,0}},
15, /*Over current osr: The effect count is OSR + 1*/
128, /*Normal current osr */
1 /*comparator enable*/
1, /*comparator enable*/
(uint32_t)&gSdfm_sampleOutput /*Output samples base address*/
};
#define PRUICSS_G_MUX_EN ( 0x1 ) /* ICSSG_SA_MX_REG:G_MUX_EN */

View File

@ -176,6 +176,12 @@ int32_t init_sdfm_pru_fw(uint8_t pruId, SdfmPrms *pSdfmPrms, sdfm_handle *pHSdfm
/* Initialize SDFM instance */
hSdfm = SDFM_init(pruId);
uint32_t i;
i = SDFM_getFirmwareVersion(hSdfm);
DebugP_log("\n\n\n");
DebugP_log("SDFM firmware version \t: %x.%x.%x (%s)\n\n", (i >> 24) & 0x7F,
(i >> 16) & 0xFF, i & 0xFFFF, i & (1 << 31) ? "internal" : "release");
if (hSdfm == NULL)
{
return SDFM_ERR_INIT_SDFM;
@ -184,6 +190,9 @@ int32_t init_sdfm_pru_fw(uint8_t pruId, SdfmPrms *pSdfmPrms, sdfm_handle *pHSdfm
uint8_t SDFM_CH;
hSdfm->iep_clock = pSdfmPrms->iep_clock;
hSdfm->sdfm_clock = pSdfmPrms->sd_clock;
hSdfm->sampleOutputInterface = (SDFM_SampleOutInterface *)(pSdfmPrms->samplesBaseAddress);
uint32_t sampleOutputInterfaceGlobalAddr = CPU0_BTCM_SOCVIEW(pSdfmPrms->samplesBaseAddress);
hSdfm->p_sdfm_interface->sampleBufferBaseAdd = sampleOutputInterfaceGlobalAddr;
hSdfm->iep_inc = 1; /* Default IEP increment 1 */
@ -199,6 +208,7 @@ int32_t init_sdfm_pru_fw(uint8_t pruId, SdfmPrms *pSdfmPrms, sdfm_handle *pHSdfm
/*set Noraml current OSR */
SDFM_setFilterOverSamplingRatio(hSdfm, pSdfmPrms->FilterOsr);
/*below configuration for all three channel*/
for(SDFM_CH = 0; SDFM_CH < NUM_CH_SUPPORTED; SDFM_CH++)
{
@ -247,7 +257,6 @@ int32_t init_sdfm_pru_fw(uint8_t pruId, SdfmPrms *pSdfmPrms, sdfm_handle *pHSdfm
return SDFM_ERR_NERR;
}
/*
* ======== initPruSdfm ========
*/

View File

@ -145,6 +145,8 @@ typedef struct SdfmPrms_s {
uint16_t FilterOsr;
/**< over current enable field */
uint8_t en_com;
/**< output samples base address*/
uint32_t samplesBaseAddress;
} SdfmPrms;

View File

@ -41,6 +41,7 @@
#include <drivers/gpio.h>
#include <kernel/dpl/AddrTranslateP.h>
//*****************************************************************************
//
// Defines for the API.
@ -286,7 +287,7 @@ void SDFM_configComparatorGpioPins(sdfm_handle h_sdfm, uint8_t ch,uint32_t gpio_
/* Get current (or latest) sample for the specified channel */
uint32_t SDFM_getFilterData(sdfm_handle h_sdfm, uint8_t ch)
{
return h_sdfm->p_sdfm_interface->curr_out_samp_buf[ch];
return h_sdfm->sampleOutputInterface->sampleOutput[ch];
}
/*Configure normal current OSR for data filter*/
@ -300,6 +301,11 @@ void SDFM_setFilterOverSamplingRatio(sdfm_handle h_sdfm, uint16_t nc_osr)
count = (int)((float)nc_osr*((float)iep_freq/(float)sd_clock));
h_sdfm->p_sdfm_interface->sdfm_cfg_trigger.nc_prd_iep_cnt = count;
}
/*return firmware version */
uint64_t SDFM_getFirmwareVersion(sdfm_handle h_sdfm)
{
return h_sdfm->p_sdfm_interface->firmwareVersion;
}
/* SDFM global enable */
void SDFM_enable(sdfm_handle h_sdfm)
{

View File

@ -0,0 +1,70 @@
;
; Copyright (C) 2023 Texas Instruments Incorporated
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
;
; Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
;
; Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the
; distribution.
;
; Neither the name of Texas Instruments Incorporated nor the names of
; its contributors may be used to endorse or promote products derived
; from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
.if !$isdefed("__firmware_version_h")
__firmware_version_h .set 1
; ICSS_FIRMWARE_RELEASE_1:
; bit 31..16 reserved
; bit15..8 device number
FIRMWARE_DEVICE_AM335x .set 0 ; AM335x
FIRMWARE_DEVICE_AM437x .set 1 ; AM437x
FIRMWARE_DEVICE_AM64x_AM243x .set 2 ; AM64x_AM243x
; bit7..0 protocol type
FIRMWARE_PROTOCOL_TYPE_PROFIBUS_SLAVE .set 0x00
FIRMWARE_PROTOCOL_TYPE_ETHERCAT_SLAVE .set 0x01
FIRMWARE_PROTOCOL_TYPE_PROFINET_DEVICE .set 0x02
FIRMWARE_PROTOCOL_TYPE_SERCOS_SLAVE .set 0x03
FIRMWARE_PROTOCOL_TYPE_OPENMAC_SLAVE .set 0x04
FIRMWARE_PROTOCOL_TYPE_ETHERNET .set 0x05
FIRMWARE_PROTOCOL_TYPE_ENETIP_SLAVE .set 0x06
FIRMWARE_PROTOCOL_TYPE_ENDAT_MASTER .set 0x07
FIRMWARE_PROTOCOL_TYPE_TAMAGAWA .set 0x08
FIRMWARE_PROTOCOL_TYPE_SDFM .set 0x09
; ICSS_FIRMWARE_RELEASE_2:
; bit31 release or internal version
FIRMWARE_VERSION_RELEASE .set 0
FIRMWARE_VERSION_INTERNAL .set 1
; bit30..24 version number
FIRMWARE_VERSION_REVISION .set 0x01
; bit23..16 major number
FIRMWARE_VERSION_MAJOR .set 0x00
; bit15..0 minor number
FIRMWARE_VERSION_MINOR .set 0x0000
ICSS_FIRMWARE_RELEASE_1 .set ((FIRMWARE_DEVICE_AM64x_AM243x << 8) | (FIRMWARE_PROTOCOL_TYPE_SDFM << 0))
ICSS_FIRMWARE_RELEASE_2 .set ((FIRMWARE_VERSION_RELEASE << 31) | (FIRMWARE_VERSION_REVISION << 24) | (FIRMWARE_VERSION_MAJOR << 16) | (FIRMWARE_VERSION_MINOR << 0))
.endif

View File

@ -198,12 +198,17 @@
#define FW_REG_SDFM_CFG_SECOND_TRIG_SAMPLE_TIME ( 0xF0 )
#define SDFM_CFG_NC_PRD_IEP_CNT_OFFSET ( 0xF4)
/*Sample output offset*/
#define SDFM_CFG_OUT_SAMP_BUF_OFFSET ( 0xF8 )
/* output sample buffer base address offset*/
#define SDFM_CFG_OUT_SAMP_BUF_BASE_ADD_OFFSET ( 0xF8 )
/*Firmware version offset*/
#define SDFM_FIRMWARE_VERSION_OFFSET (0xFC)
/*Debug */
#define SDFM_DUBUG_OFFSET ( 0x104 )
/*output sample offset*/
#define SDFM_CFG_OUT_SAMP_BUF_OFFSET (0x00)
/*
Firmware register bit fields
*/

View File

@ -36,6 +36,7 @@
%}
.include "sdfm.h"
.include "sdfm_macros.h"
.include "firmware_version.h"
@ -82,7 +83,9 @@ OUT_SAMP_BUF: .usect ".outSamps", ICSSG_NUM_SD_CH_FW*4, 4
SDFM_ENTRY:
; Clear registers R0-R30
ZERO &R0, 124
LDI32 TEMP_REG0, ICSS_FIRMWARE_RELEASE_1
LDI32 TEMP_REG1, ICSS_FIRMWARE_RELEASE_2
SBCO &TEMP_REG0, CT_PRU_ICSSG_LOC_DMEM, SDFM_FIRMWARE_VERSION_OFFSET, 8
; Disable Task Manager
;.word 0x32000000
M_PRU_TM_DISABLE
@ -490,7 +493,8 @@ comp_ch2_end:
.if $isdefed("DEBUG_CODE")
; Write local interleaved output samples to Host buffer address
LBBO &TEMP_REG3, OUT_SAMP_BUF_REG, 0, ICSSG_NUM_SD_CH_FW*4
SBCO &TEMP_REG3, CT_PRU_ICSSG_LOC_DMEM, SDFM_CFG_OUT_SAMP_BUF_OFFSET, ICSSG_NUM_SD_CH_FW*4
LBCO &TEMP_REG0, CT_PRU_ICSSG_LOC_DMEM, SDFM_CFG_OUT_SAMP_BUF_BASE_ADD_OFFSET,4
SBBO &TEMP_REG3, TEMP_REG0, SDFM_CFG_OUT_SAMP_BUF_OFFSET, ICSSG_NUM_SD_CH_FW*4
; Trigger interrupt
LDI R31.w0, TRIGGER_HOST_SDFM_IRQ
.endif
@ -623,7 +627,8 @@ END_RESET_NC_FRAME:
LDI SAMP_CNT_REG, 0 ; reset NC sample count
; Write local interleaved output samples to Host buffer address
LBBO &TEMP_REG3, OUT_SAMP_BUF_REG, 0, ICSSG_NUM_SD_CH_FW*4
SBCO &TEMP_REG3, CT_PRU_ICSSG_LOC_DMEM, SDFM_CFG_OUT_SAMP_BUF_OFFSET, ICSSG_NUM_SD_CH_FW*4
LBCO &TEMP_REG0, CT_PRU_ICSSG_LOC_DMEM, SDFM_CFG_OUT_SAMP_BUF_BASE_ADD_OFFSET,4
SBBO &TEMP_REG3, TEMP_REG0, SDFM_CFG_OUT_SAMP_BUF_OFFSET, ICSSG_NUM_SD_CH_FW*4
;Trigger interrupt
LDI R31.w0, TRIGGER_HOST_SDFM_IRQ
;;SBCO &NC_OUTPUT_SAMP, CT_PRU_ICSSG_LOC_DMEM, SDFM_DUBUG_OFFSET, 4

View File

@ -1,5 +1,10 @@
const uint32_t pru_SDFM_PRU0_image_0[] = {
0x2effbd80,
0x240000c1,
0x24020981,
0x240100c2,
0x24000082,
0x81fc7881,
0x32000000,
0x240fff81,
0x81000a81,
@ -16,9 +21,9 @@ const uint32_t pru_SDFM_PRU0_image_0[] = {
0x91340401,
0x1f01e1e1,
0x81340401,
0x2300fd99,
0x23010399,
0x32800000,
0x23010499,
0x23010a99,
0x240c00c2,
0x24000082,
0x91021801,
@ -42,11 +47,11 @@ const uint32_t pru_SDFM_PRU0_image_0[] = {
0x0b04e1e1,
0x110fe1e2,
0x10020256,
0x23011e99,
0x23016e99,
0x23012299,
0x23013399,
0x23016599,
0x23012499,
0x23017499,
0x23012899,
0x23013999,
0x23016b99,
0x1f19fefe,
0x240fffd5,
0x24ffff95,
@ -60,7 +65,7 @@ const uint32_t pru_SDFM_PRU0_image_0[] = {
0x81001a01,
0x9114189a,
0xd1009a02,
0x21003d00,
0x21004200,
0xc9019a26,
0x10161602,
0x09020202,
@ -230,7 +235,7 @@ const uint32_t pru_SDFM_PRU0_image_0[] = {
0x00e1e2e1,
0x81983a81,
0x01011c1c,
0x79000010,
0x79000011,
0xd1003c07,
0xc9007c06,
0x91f03881,
@ -244,7 +249,8 @@ const uint32_t pru_SDFM_PRU0_image_0[] = {
0x2400003c,
0x2400001c,
0xf100b484,
0x81f8b884,
0x91f83881,
0xe100a184,
0x2400229f,
0x24000000,
0x2f852381,
@ -254,7 +260,7 @@ const uint32_t pru_SDFM_PRU0_image_0[] = {
0x10000000,
0x24000b01,
0x81000a01,
0x2400b181,
0x2400b681,
0x810c0a81,
0x24140081,
0x81380a81,
@ -295,10 +301,10 @@ const uint32_t pru_SDFM_PRU0_image_0[] = {
0x110f0203,
0x68160303,
0x911e1801,
0x21012e00,
0x21013400,
0x68360303,
0x91621801,
0x21012e00,
0x21013400,
0x68560302,
0x91a61801,
0x0903e3e3,
@ -323,7 +329,7 @@ const uint32_t pru_SDFM_PRU0_image_0[] = {
0x09044141,
0x11304141,
0x12410101,
0x21016000,
0x21016600,
0x6836030e,
0x24000081,
0x917c1841,
@ -337,7 +343,7 @@ const uint32_t pru_SDFM_PRU0_image_0[] = {
0x09044141,
0x11304141,
0x12410101,
0x21016000,
0x21016600,
0x6856030d,
0x24000081,
0x91c01841,

View File

@ -286,8 +286,16 @@ uint32_t SDFM_getFilterData(sdfm_handle h_sdfm,uint8_t ch);
*
*/
void SDFM_setFilterOverSamplingRatio(sdfm_handle h_sdfm, uint16_t nc_osr);
/**
*
* \brief Return Firmware version
*
* \param[in] h_sdfm SDFM handle
*
* \retval firmwareVersion release vesrion of firmware
*
*/
uint64_t SDFM_getFirmwareVersion(sdfm_handle h_sdfm);
/** @} */
#ifdef __cplusplus

View File

@ -113,6 +113,7 @@ extern "C" {
#define IEP_DEFAULT_INC 0x1
/* SDFM output buffer size in 32-bit words */
@ -293,10 +294,16 @@ typedef struct SDFM_Interface_s{
SDFM_Cfg sdfm_cfg_ptr[NUM_CH_SUPPORTED];
/*<sdfm time sampling interface pointer */
SDFM_CfgTrigger sdfm_cfg_trigger;
/**< host output sample buffer */
volatile uint32_t curr_out_samp_buf[NUM_CH_SUPPORTED];
/**< host output sample buffer base address */
volatile uint32_t sampleBufferBaseAdd;
/**<firmware version */
volatile uint64_t firmwareVersion;
}SDFM_Interface;
typedef struct SDFM_SampleOutInterface_s
{
uint32_t sampleOutput[NUM_CH_SUPPORTED];
}SDFM_SampleOutInterface;
/**
* \brief Structure defining SDFM interface
*
@ -310,6 +317,7 @@ typedef struct SDFM_s {
uint32_t iep_clock;
uint8_t iep_inc;
SDFM_Interface * p_sdfm_interface;
SDFM_SampleOutInterface *sampleOutputInterface;
} SDFM;