From e510854116e9976d6863182f68bd8b3a71b93a7f Mon Sep 17 00:00:00 2001 From: Vineet Roy Date: Fri, 3 Jul 2020 22:14:51 +0530 Subject: [PATCH 1/2] Changes to add Main UART 3 for gateway --- Rules.make | 2 +- can_eth_gateway/makefile | 2 +- can_eth_gateway/src/gateway_board_pinmux.c | 108 +++++++++++++++++++++++++++ can_eth_gateway/src/main_tirtos.c | 114 ++++++++++++++++++++++++++++- makefile | 2 +- 5 files changed, 223 insertions(+), 5 deletions(-) create mode 100644 can_eth_gateway/src/gateway_board_pinmux.c diff --git a/Rules.make b/Rules.make index b1e53cc..5eaaebb 100644 --- a/Rules.make +++ b/Rules.make @@ -89,7 +89,7 @@ export TOOLCHAIN_PATH_A72 ?= $(TOOLCHAIN_PATH_GCC_ARCH64) # GATEWAY Configurations (Edit Below) ################################################################################ # Enable GATEWAY to log messages in console (UART) or CCS console -export GATEWAY_UART_ENABLE ?= FALSE +export GATEWAY_UART_ENABLE ?= TRUE ################################################################################ # Other advanced configurable variables diff --git a/can_eth_gateway/makefile b/can_eth_gateway/makefile index 5c64f76..77293da 100644 --- a/can_eth_gateway/makefile +++ b/can_eth_gateway/makefile @@ -75,7 +75,7 @@ EXT_LIB_LIST_COMMON += ${ETHFW_PATH}/out/J721E/R5F/SYSBIOS/$(BUILD_PROFILE_$(CO # Common source files and CFLAGS across all platforms and cores PACKAGE_SRCS_COMMON = . SRCS_COMMON = main_tirtos.c eth_process.c -SRCS_COMMON += can_process.c gateway_demo.c EthUtils.c utils_prf.c +SRCS_COMMON += can_process.c gateway_demo.c gateway_board_pinmux.c EthUtils.c utils_prf.c # Common source files and CFLAGS across all platforms and cores SRCS_COMMON += Can_Cfg.c Eth_Cfg.c EthTrcv_Cfg.c Can_PBcfg.c Dio_Lcfg.c Cdd_IpcCfg.c SRCS_COMMON += app_utils_can.c app_utils_eth.c diff --git a/can_eth_gateway/src/gateway_board_pinmux.c b/can_eth_gateway/src/gateway_board_pinmux.c new file mode 100644 index 0000000..e7adbca --- /dev/null +++ b/can_eth_gateway/src/gateway_board_pinmux.c @@ -0,0 +1,108 @@ +/* + * Copyright (c) Texas Instruments Incorporated 2019 + * + * 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. + */ + +/*! + * \file gateway_board_pinmux.c + * + * \brief This file contains the Gateway specific pinmux functions for J721E EVM + */ + +/* ========================================================================== */ +/* Include Files */ +/* ========================================================================== */ + +#include +#include +#include + +/* ========================================================================== */ +/* Macros & Typedefs */ +/* ========================================================================== */ + +/* None */ + +/* ========================================================================== */ +/* Structures and Enums */ +/* ========================================================================== */ + +/* None */ + +/* ========================================================================== */ +/* Internal Function Declarations */ +/* ========================================================================== */ + +/* ========================================================================== */ +/* Global Variables */ +/* ========================================================================== */ + +/* None */ + +/* ========================================================================== */ +/* Function Definitions */ +/* ========================================================================== */ + +/** Peripheral Pin Configurations */ + +static pinmuxPerCfg_t gUart4PinCfg[] = +{ + /* MyUART1 -> UART4_RXD -> W23 */ + { + PIN_RGMII6_TD3, PIN_MODE(1) | \ + ((PIN_PULL_DISABLE | PIN_INPUT_ENABLE) & (~PIN_PULL_DIRECTION)) + }, + /* MyUART1 -> UART4_TXD -> W28 */ + { + PIN_RGMII6_TD2, PIN_MODE(1) | \ + ((PIN_PULL_DISABLE) & (~PIN_PULL_DIRECTION & ~PIN_INPUT_ENABLE)) + }, + {PINMUX_END} +}; + +static pinmuxModuleCfg_t gUartPinCfg[] = +{ + {4, TRUE, gUart4PinCfg}, + {PINMUX_END} +}; + + +pinmuxBoardCfg_t gateway_MainPinmuxData[] = +{ + {0, gUartPinCfg}, + {PINMUX_END} +}; + +pinmuxBoardCfg_t gateway_WkupPinmuxData[] = +{ + {PINMUX_END} +}; + + diff --git a/can_eth_gateway/src/main_tirtos.c b/can_eth_gateway/src/main_tirtos.c index 870b8a4..d284ea8 100644 --- a/can_eth_gateway/src/main_tirtos.c +++ b/can_eth_gateway/src/main_tirtos.c @@ -121,6 +121,13 @@ #include "Cdd_IpcIrq.h" #include +#include +#include +#include +#include +#include +#include + /* ========================================================================== */ /* Macros & Typedefs */ /* ========================================================================== */ @@ -170,6 +177,10 @@ static void GatewayApp_TaskFxn(UArg a0, UArg a1); static void CanApp_TaskFxn(UArg a0, UArg a1); static void EthApp_TaskFxn(UArg a0, UArg a1); +static void GatewayApp_enableUART(void); +static void GatewayApp_setDeviceState(uint32_t moduleId, + uint32_t requiredState, + uint32_t appFlags); static void GatewayApp_TimerCb(void); @@ -286,6 +297,9 @@ static uint32_t gNumRemoteProc = sizeof(gRemoteProc) / sizeof(uint32_t); extern uint32 CanIf_DrvStatus; /**< CAN IF Driver Status, defined in CanIf.c */ extern EthApp_State gEthApp; + +/*Pinmux for UART3*/ +extern pinmuxBoardCfg_t gateway_MainPinmuxData[]; /* ========================================================================== */ /* Function Definitions */ /* ========================================================================== */ @@ -296,12 +310,15 @@ int main(void) Task_Params taskParams; - Types_FreqHz bios_freq; + Types_FreqHz bios_freq; + + /*Setup Main Domain UART 3*/ + GatewayApp_enableUART(); /* Run Startup for CAN and Ethernet and Gateway*/ CanApp_Startup(); - EthApp_Startup(); + EthApp_Startup(); if ((CANIF_DRV_INITIALIZED == CanIf_DrvStatus)) { @@ -1100,5 +1117,98 @@ int32_t Ipc_sciclientIrqTranslate(uint16_t coreId, uint32_t eventId, procIrq); } +static void GatewayApp_enableUART(void) +{ + Board_initCfg boardCfg; + Board_initParams_t initParams; + Board_STATUS status; + uint32_t i, moduleCnt, appFlags; + uint32_t clkModuleId[] = {TISCI_DEV_UART4, }; + + appFlags = 0U; + moduleCnt = UTILS_ARRAYSIZE(clkModuleId); + for(i = 0; i < moduleCnt; i++) + { + GatewayApp_setDeviceState(clkModuleId[i], + TISCI_MSG_VALUE_DEVICE_SW_STATE_ON, + appFlags); + } + + /*Setup Pinmux for Main Domain UART3*/ + Board_pinmuxUpdate(gateway_MainPinmuxData, + BOARD_SOC_DOMAIN_MAIN); + + boardCfg = BOARD_INIT_PINMUX_CONFIG| + BOARD_INIT_UART_STDIO; + + Board_getInitParams(&initParams); + /* On Jacinto 7, EthFw running on mcu2_0 uses UART instance 2 */ + initParams.uartInst = 4; + initParams.uartSocDomain = BOARD_SOC_DOMAIN_MAIN; + /* Use non-exclusive mode in board lib when accessing the module for clock enable + * to let Linux also access the module */ + initParams.pscMode = BOARD_PSC_DEVICE_MODE_NONEXCLUSIVE; + Board_setInitParams(&initParams); + + status = Board_init(boardCfg); + assert(status == BOARD_SOK); + + AppUtils_Printf(GATEWAYAPP_MSG_NORMAL, GATEWAYAPP_MSG_APP_NAME + " UART Init complete\n"); + +} + +static void GatewayApp_setDeviceState(uint32_t moduleId, + uint32_t requiredState, + uint32_t appFlags) +{ + int32_t status; + uint32_t moduleState = 0U; + uint32_t resetState = 0U; + uint32_t contextLossState = 0U; + bool turnOn; + bool turnOff; + + /* Get the module state */ + status = Sciclient_pmGetModuleState(moduleId, + &moduleState, + &resetState, + &contextLossState, + SCICLIENT_SERVICE_WAIT_FOREVER); + assert(status == CSL_PASS); + + /* No need to change if already in the requested state. Note that + * getter (HW_STATE_*) and setter (SW_STATE_*) can't be directly compared */ + turnOn = (moduleState == TISCI_MSG_VALUE_DEVICE_HW_STATE_OFF) && + (requiredState == TISCI_MSG_VALUE_DEVICE_SW_STATE_ON); + turnOff = (moduleState == TISCI_MSG_VALUE_DEVICE_HW_STATE_ON) && + (requiredState == TISCI_MSG_VALUE_DEVICE_SW_STATE_AUTO_OFF); + + /* We assert in this function upon failure as this is first function called + * from the app to enable clocks and app can't recover from this failure */ + if (turnOn || turnOff) + { + status = Sciclient_pmSetModuleState(moduleId, + requiredState, + (appFlags | + TISCI_MSG_FLAG_AOP | + TISCI_MSG_FLAG_DEVICE_RESET_ISO), + SCICLIENT_SERVICE_WAIT_FOREVER); + assert(status == CSL_PASS); + + if (requiredState == TISCI_MSG_VALUE_DEVICE_SW_STATE_ON) + { + /* Reset if changed state to enabled */ + status = Sciclient_pmSetModuleRst(moduleId, + 0x0U /*resetBit*/, + SCICLIENT_SERVICE_WAIT_FOREVER); + assert(status == CSL_PASS); + } + } + + /* Dummy assignment to avoid -Werror=unused-but-set-variable error. The GCC compiler + * doesn't consider usage of variable in assert */ + status = status; +} diff --git a/makefile b/makefile index bb60eb8..9103204 100644 --- a/makefile +++ b/makefile @@ -16,7 +16,7 @@ gateway_PKG_LIST_PACKAGE = $(addsuffix _package, $(gateway_PKG_LIST_ALL)) .PHONY : all testall gateway_libs gateway_libs_clean gateway_app_libs gateway_app_libs_clean examples examples_clean clean package $(gateway_PKG_LIST_ALL) $(gateway_DUP_EXAMPLE_LIST) depend depend_clean $(gateway_mcusw_LIB_LIST) $(gateway_mcusw_demo_LIB_LIST) $(gateway_pdk_LIB_LIST) sbl sbl_mmcsd_img sbl_ospi_img sbl_cust_img sbl_clean cesdemo depend: pdk - $(MAKE) mcusw AUTOSAR_VERSION:=431 CORE:=mcu2_1 MCUSW_UART_ENABLE:=FALSE + $(MAKE) mcusw AUTOSAR_VERSION:=431 CORE:=mcu2_1 MCUSW_UART_ENABLE:=TRUE depend_clean: pdk_clean mcusw_clean all_libs: depend gateway_libs gateway_app_libs -- 2.7.4 From bc8ee7825d90bcdbf7b74ffbaa66fbd86efd7167 Mon Sep 17 00:00:00 2001 From: Vineet Roy Date: Mon, 6 Jul 2020 13:04:22 +0530 Subject: [PATCH 2/2] Incorporating review comments --- can_eth_gateway/src/gateway_board_pinmux.c | 1 + can_eth_gateway/src/main_tirtos.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/can_eth_gateway/src/gateway_board_pinmux.c b/can_eth_gateway/src/gateway_board_pinmux.c index e7adbca..af156a0 100644 --- a/can_eth_gateway/src/gateway_board_pinmux.c +++ b/can_eth_gateway/src/gateway_board_pinmux.c @@ -71,6 +71,7 @@ /* ========================================================================== */ /** Peripheral Pin Configurations */ +/*UART4 corresponds to Main UART3 on EVM*/ static pinmuxPerCfg_t gUart4PinCfg[] = { diff --git a/can_eth_gateway/src/main_tirtos.c b/can_eth_gateway/src/main_tirtos.c index d284ea8..2d3def6 100644 --- a/can_eth_gateway/src/main_tirtos.c +++ b/can_eth_gateway/src/main_tirtos.c @@ -166,6 +166,8 @@ #define GATEWAYAPP_IPC_TASK_STACKSIZE ((IPC_TASK_STACKSIZE) * 4U) +#define MAIN_UART3_ID (4) + /* ========================================================================== */ /* Structure Declarations */ /* ========================================================================== */ @@ -1123,7 +1125,7 @@ static void GatewayApp_enableUART(void) Board_initParams_t initParams; Board_STATUS status; uint32_t i, moduleCnt, appFlags; - uint32_t clkModuleId[] = {TISCI_DEV_UART4, }; + uint32_t clkModuleId[] = {TISCI_DEV_UART4, }; /*UART4 corresponds to Main UART3 on EVM*/ appFlags = 0U; moduleCnt = UTILS_ARRAYSIZE(clkModuleId); @@ -1142,8 +1144,15 @@ static void GatewayApp_enableUART(void) BOARD_INIT_UART_STDIO; Board_getInitParams(&initParams); - /* On Jacinto 7, EthFw running on mcu2_0 uses UART instance 2 */ - initParams.uartInst = 4; + /* + On Jacinto 7, J7ES EVM exposes 4 UART's. For gateway the following assignment applies + UART0 : Linux (root) + UART1 : SysFW + UART2 : EthFW + UART3 : Gateway + */ + + initParams.uartInst = MAIN_UART3_ID; initParams.uartSocDomain = BOARD_SOC_DOMAIN_MAIN; /* Use non-exclusive mode in board lib when accessing the module for clock enable * to let Linux also access the module */ @@ -1153,6 +1162,7 @@ static void GatewayApp_enableUART(void) status = Board_init(boardCfg); assert(status == BOARD_SOK); + UART_printf("%s","hello world\n"); AppUtils_Printf(GATEWAYAPP_MSG_NORMAL, GATEWAYAPP_MSG_APP_NAME " UART Init complete\n"); -- 2.7.4