From 4a2bddb260b0a61510cbdeae4a330862a12eb151 Mon Sep 17 00:00:00 2001 From: maek Date: Fri, 10 Dec 2010 08:15:27 +0100 Subject: [PATCH] Initial commit of PORT driver for TMS570. --- arch/arm/arm_cr4/drivers/Port.c | 208 +++++++++++++++++++++++++++ boards/ti_tms570ls/build_config.mk | 2 +- boards/ti_tms570ls/config/Port_Cfg.c | 65 +++++++++ boards/ti_tms570ls/config/Port_Cfg.h | 77 ++++++++++ 4 files changed, 351 insertions(+), 1 deletion(-) create mode 100644 arch/arm/arm_cr4/drivers/Port.c create mode 100644 boards/ti_tms570ls/config/Port_Cfg.c create mode 100644 boards/ti_tms570ls/config/Port_Cfg.h diff --git a/arch/arm/arm_cr4/drivers/Port.c b/arch/arm/arm_cr4/drivers/Port.c new file mode 100644 index 00000000..1232fcbc --- /dev/null +++ b/arch/arm/arm_cr4/drivers/Port.c @@ -0,0 +1,208 @@ +/* -------------------------------- Arctic Core ------------------------------ + * Arctic Core - the open source AUTOSAR platform http://arccore.com + * + * Copyright (C) 2009 ArcCore AB + * + * This source code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by the + * Free Software Foundation; See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * -------------------------------- Arctic Core ------------------------------*/ + + +#include "Std_Types.h" +#include "Port.h" +#include "Det.h" +#include "Cpu.h" +#include + +#define GET_PIN_PORT(_pin) (_pin >> 8) +#define GET_PIN_PIN(_pin) (_pin & 0x1F) +#define GET_PIN_MASK(_pin) (1 << (_pin & 0x1F)) + +typedef enum +{ + PORT_UNINITIALIZED = 0, PORT_INITIALIZED, +} Port_StateType; + + +typedef volatile struct +{ + uint32 FUN; + uint32 DIR; + uint32 DIN; + uint32 DOUT; + uint32 DSET; + uint32 DCLR; + uint32 PDR; + uint32 PULDIS; + uint32 PSL; +} Port_RegisterType; + + +#define PORT_NOT_CONFIGURED 0x00000000 + +#define PORT_0_BASE ((Port_RegisterType *)0xFFF7BC30) +#define PORT_1_BASE ((Port_RegisterType *)0xFFF7BC50) +#define PORT_2_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED) +#define PORT_3_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED) +#define PORT_4_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED) +#define PORT_5_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED) +#define PORT_6_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED) +#define PORT_7_BASE ((Port_RegisterType *)PORT_NOT_CONFIGURED) +#define PORT_8_BASE ((Port_RegisterType *)0xFFF7DDE0) +#define PORT_9_BASE ((Port_RegisterType *)0xFFF7DFE0) +#define PORT_10_BASE ((Port_RegisterType *)0xFFF7E1E0) +#define PORT_NUMBER_OF_PORTS 11 + +static Port_RegisterType * const Port_Base[] = +{ + PORT_0_BASE, + PORT_1_BASE, + PORT_2_BASE, + PORT_3_BASE, + PORT_4_BASE, + PORT_5_BASE, + PORT_6_BASE, + PORT_7_BASE, + PORT_8_BASE, + PORT_9_BASE, + PORT_10_BASE, +}; + + + +static Port_StateType _portState = PORT_UNINITIALIZED; +static const Port_ConfigType * _configPtr = &PortConfigData; + +#if (PORT_DEV_ERROR_DETECT) +#define VALIDATE_PARAM_CONFIG(_ptr,_api) \ + if( (_ptr)==((void *)0) ) { \ + Det_ReportError(MODULE_ID_PORT, 0, _api, PORT_E_PARAM_CONFIG ); \ + goto cleanup; \ + } + +#define VALIDATE_STATE_INIT(_api)\ + if(PORT_INITIALIZED!=_portState){\ + Det_ReportError(MODULE_ID_PORT, 0, _api, PORT_E_UNINIT ); \ + goto cleanup; \ + } + +#define VALIDATE_PARAM_PIN(_pin, _api)\ + if(GET_PIN_PORT(_pin) >= PORT_NUMBER_OF_PORTS || Port_Base[GET_PIN_PORT(_pin)] == PORT_NOT_CONFIGURED || GET_PIN_PIN(_pin) > 7 ){\ + Det_ReportError(MODULE_ID_PORT, 0, _api, PORT_E_PARAM_PIN ); \ + goto cleanup; \ + } + +#else +#define VALIDATE_PARAM_CONFIG(_ptr,_api) +#define VALIDATE_STATE_INIT(_api) +#define VALIDATE_PARAM_PIN(_pin, _api) +#endif + +#if PORT_VERSION_INFO_API == STD_ON +static Std_VersionInfoType _Port_VersionInfo = +{ + .vendorID = (uint16)1, + .moduleID = (uint16) MODULE_ID_PORT, + .instanceID = (uint8)1, + .sw_major_version = (uint8)PORT_SW_MAJOR_VERSION, + .sw_minor_version = (uint8)PORT_SW_MINOR_VERSION, + .sw_patch_version = (uint8)PORT_SW_PATCH_VERSION, + .ar_major_version = (uint8)PORT_AR_MAJOR_VERSION, + .ar_minor_version = (uint8)PORT_AR_MINOR_VERSION, + .ar_patch_version = (uint8)PORT_AR_PATCH_VERSION, +}; +#endif + +void Port_Init(const Port_ConfigType *configType) { + VALIDATE_PARAM_CONFIG(configType, PORT_INIT_ID); + + // Bring GIO register out of reset. + gioREG->GCR0 = 1; + + for (uint16 i = 0; i < PORT_NUMBER_OF_PINS; i++) { + uint8 port = GET_PIN_PORT(configType->pins[i].pin); + uint32 mask = GET_PIN_MASK(configType->pins[i].pin); + uint16 conf = configType->pins[i].conf; + + if (conf & PORT_FUNC) { + // Don't do anything, let each driver configure??? + continue; + } + + // Set pin direction + if (conf & PORT_PIN_IN) { + Port_Base[port]->DIR &= ~mask; + + } else { + Port_Base[port]->DIR |= mask; + + // Set open drain + if (conf & PORT_ODE_ENABLE) { + Port_Base[port]->PDR |= mask; + } else { + Port_Base[port]->PDR &= ~mask; + } + } + + // Set pull up or down or nothing. + if (conf & PORT_PULL_NONE) { + Port_Base[port]->PULDIS |= mask; + + } else { + Port_Base[port]->PULDIS &= ~mask; + if (conf & PORT_PULL_UP) { + Port_Base[port]->PSL |= mask; + + } else { + Port_Base[port]->PSL &= ~mask; + } + } + } + cleanup:return; +} + +#if ( PORT_SET_PIN_DIRECTION_API == STD_ON ) +void Port_SetPinDirection( Port_PinType pin, Port_PinDirectionType direction ) +{ + VALIDATE_STATE_INIT(PORT_SET_PIN_DIRECTION_ID); + VALIDATE_PARAM_PIN(pin, PORT_SET_PIN_DIRECTION_ID); + // TODO IMPLEMENT! + +cleanup:return; +} +#endif + +void Port_RefreshPortDirection( void ) +{ + // TODO IMPLEMENT! +} + +#if PORT_VERSION_INFO_API == STD_ON +void Port_GetVersionInfo(Std_VersionInfoType* versionInfo) +{ + VALIDATE_STATE_INIT(PORT_GET_VERSION_INFO_ID); + memcpy(versionInfo, &_Port_VersionInfo, sizeof(Std_VersionInfoType)); + cleanup: return; +} +#endif + +#if (PORT_SET_PIN_MODE_API == STD_ON) +void Port_SetPinMode(Port_PinType Pin, Port_PinModeType Mode) { + uint8 port = GET_PIN_PORT(Pin); + uint8 pin = GET_PIN_PIN(Pin); + uint32 mask = GET_PIN_MASK(Pin); +/* + Port_PinType pin = Pin & 0x1F; + Port_PinType port = Pin >> 8; + Port_PinType mask = 1 << pin; +*/ + Port_Base[port]->FUN &= ~mask; + Port_Base[port]->FUN |= ((Mode & 1) << pin); +} +#endif diff --git a/boards/ti_tms570ls/build_config.mk b/boards/ti_tms570ls/build_config.mk index 0d1aa275..9c3ffd6a 100644 --- a/boards/ti_tms570ls/build_config.mk +++ b/boards/ti_tms570ls/build_config.mk @@ -27,7 +27,7 @@ CFG+=STM32_CL MOD_AVAIL+=MCU # System + Communication + Diagnostic -MOD_AVAIL+=CANIF CANTP COM DCM DEM DET ECUM IOHWAB KERNEL PDUR WDGM RTE CAN +MOD_AVAIL+=CANIF CANTP COM DCM DEM DET ECUM IOHWAB KERNEL PDUR WDGM RTE CAN PORT DIO # Additional MOD_AVAIL+=RAMLOG diff --git a/boards/ti_tms570ls/config/Port_Cfg.c b/boards/ti_tms570ls/config/Port_Cfg.c new file mode 100644 index 00000000..f0f43079 --- /dev/null +++ b/boards/ti_tms570ls/config/Port_Cfg.c @@ -0,0 +1,65 @@ +/* + * Configuration of module Port (Port_Cfg.c) + * + * Created by: + * Configured for (MCU): TMS570 + * + * Module vendor: ArcCore + * Module version: 2.0.2 + * + * + * Generated by Arctic Studio (http://arccore.com) + * on Fri Dec 10 07:52:22 CET 2010 + */ + + + +#include "Port.h" + + + +const Port_ConfigType PortConfigData = +{ + .pins = { + { + .pin = PORT_PIN_DCAN1_TX, + .conf = ( PORT_PIN_OUT | PORT_FUNC | PORT_PULL_NONE ), + }, + { + .pin = PORT_PIN_DCAN1_RX, + .conf = ( PORT_PIN_IN | PORT_FUNC | PORT_PULL_NONE ), + }, + { + .pin = PORT_PIN_DCAN2_TX, + .conf = ( PORT_PIN_OUT | PORT_FUNC | PORT_PULL_NONE ), + }, + { + .pin = PORT_PIN_DCAN2_RX, + .conf = ( PORT_PIN_IN | PORT_FUNC | PORT_PULL_NONE ), + }, + { + .pin = PORT_PIN_DCAN3_TX, + .conf = ( PORT_PIN_OUT | PORT_FUNC | PORT_PULL_NONE ), + }, + { + .pin = PORT_PIN_DCAN3_RX, + .conf = ( PORT_PIN_IN | PORT_FUNC | PORT_PULL_NONE ), + }, + { + .pin = PORT_PIN_GIOA0, + .conf = ( PORT_PIN_OUT | PORT_FUNC_NO | PORT_PULL_NONE ), + }, + { + .pin = PORT_PIN_GIOA3, + .conf = ( PORT_PIN_OUT | PORT_FUNC_NO | PORT_PULL_NONE ), + }, + { + .pin = PORT_PIN_GIOA4, + .conf = ( PORT_PIN_OUT | PORT_FUNC_NO | PORT_PULL_NONE ), + }, + { + .pin = PORT_PIN_GIOA5, + .conf = ( PORT_PIN_OUT | PORT_FUNC_NO | PORT_PULL_NONE ), + }, + } +}; diff --git a/boards/ti_tms570ls/config/Port_Cfg.h b/boards/ti_tms570ls/config/Port_Cfg.h new file mode 100644 index 00000000..57454ddd --- /dev/null +++ b/boards/ti_tms570ls/config/Port_Cfg.h @@ -0,0 +1,77 @@ +/* + * Configuration of module Port (Port_Cfg.h) + * + * Created by: + * Configured for (MCU): TMS570 + * + * Module vendor: ArcCore + * Module version: 2.0.2 + * + * + * Generated by Arctic Studio (http://arccore.com) + * on Fri Dec 10 07:52:22 CET 2010 + */ + + +#if (PORT_SW_MAJOR_VERSION != 1) +#error "Port: Configuration file version differs from BSW version." +#endif + + +#ifndef PORT_CFG_H_ +#define PORT_CFG_H_ + +#include "Std_Types.h" + + +/** Build version info API */ +#define PORT_VERSION_INFO_API STD_ON +/** Enable Development Error Trace */ +#define PORT_DEV_ERROR_DETECT STD_ON +/** Build change pin direction API */ +#define PORT_SET_PIN_DIRECTION_API STD_ON +/** Allow Pin mode changes during runtime */ +#define PORT_SET_PIN_MODE_API STD_ON + +#define PORT_NUMBER_OF_PINS 10 + +#define PORT_FUNC (1 << 1) +#define PORT_FUNC_NO (0 << 1) +#define PORT_PULL_NONE (1 << 2) +#define PORT_PULL_UP (1 << 3) +#define PORT_PULL_DOWN (0 << 3) +#define PORT_ODE_ENABLE (1 << 4) + +/** HW specific symbolic names of pins */ +/** @req PORT013 */ +typedef enum +{ + PORT_PIN_DCAN1_TX = 0x0800, + PORT_PIN_DCAN1_RX = 0x0801, + PORT_PIN_DCAN2_TX = 0x0900, + PORT_PIN_DCAN2_RX = 0x0901, + PORT_PIN_DCAN3_TX = 0x0a00, + PORT_PIN_DCAN3_RX = 0x0a01, + PORT_PIN_GIOA0 = 0x0000, + PORT_PIN_GIOA3 = 0x0003, + PORT_PIN_GIOA4 = 0x0004, + PORT_PIN_GIOA5 = 0x0005, +} Port_PinType; + +typedef struct { + Port_PinType pin; + uint8 conf; +} Port_ConfiguredPinType; + +/** Top level configuration container */ +/** @req PORT073 */ +typedef struct +{ + const Port_ConfiguredPinType pins[PORT_NUMBER_OF_PINS]; +} Port_ConfigType; + +/** Instance of the top level configuration container */ +extern const Port_ConfigType PortConfigData; + + +#endif /*PORT_CFG_H_*/ -- 2.39.2