Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1 | /* <auto_header> |
| 2 | * <FILENAME> |
| 3 | * |
| 4 | * INTEL CONFIDENTIAL |
| 5 | * Copyright © 2011 Intel |
| 6 | * Corporation All Rights Reserved. |
| 7 | * |
| 8 | * The source code contained or described herein and all documents related to |
| 9 | * the source code ("Material") are owned by Intel Corporation or its suppliers |
| 10 | * or licensors. Title to the Material remains with Intel Corporation or its |
| 11 | * suppliers and licensors. The Material contains trade secrets and proprietary |
| 12 | * and confidential information of Intel or its suppliers and licensors. The |
| 13 | * Material is protected by worldwide copyright and trade secret laws and |
| 14 | * treaty provisions. No part of the Material may be used, copied, reproduced, |
| 15 | * modified, published, uploaded, posted, transmitted, distributed, or |
| 16 | * disclosed in any way without Intel’s prior express written permission. |
| 17 | * |
| 18 | * No license under any patent, copyright, trade secret or other intellectual |
| 19 | * property right is granted to or conferred upon you by disclosure or delivery |
| 20 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 21 | * otherwise. Any license under such intellectual property rights must be |
| 22 | * express and approved by Intel in writing. |
| 23 | * |
| 24 | * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com) |
| 25 | * CREATED: 2011-06-01 |
| 26 | * UPDATED: 2011-07-27 |
| 27 | * |
| 28 | * |
| 29 | * </auto_header> |
| 30 | */ |
| 31 | #include "SubsystemObject.h" |
| 32 | #include "InstanceConfigurableElement.h" |
| 33 | #include "ParameterBlackboard.h" |
Guillaume Denneulin | 7fce1e3 | 2012-02-17 17:34:47 +0100 | [diff] [blame^] | 34 | #include "MappingContext.h" |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 35 | #include <assert.h> |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 36 | #include <stdlib.h> |
| 37 | #include <string.h> |
| 38 | #include <sstream> |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 39 | #include <stdarg.h> |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 40 | |
| 41 | CSubsystemObject::CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement) |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 42 | : _pInstanceConfigurableElement(pInstanceConfigurableElement), |
| 43 | _uiDataSize(pInstanceConfigurableElement->getFootPrint()), |
| 44 | _pucBlackboardLocation(NULL), |
| 45 | _uiAccessedIndex(0) |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 46 | { |
| 47 | // Syncer |
| 48 | _pInstanceConfigurableElement->setSyncer(this); |
| 49 | } |
| 50 | |
| 51 | CSubsystemObject::~CSubsystemObject() |
| 52 | { |
| 53 | _pInstanceConfigurableElement->unsetSyncer(); |
| 54 | } |
| 55 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 56 | // Blackboard data location |
| 57 | uint8_t* CSubsystemObject::getBlackboardLocation() const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 58 | { |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 59 | return _pucBlackboardLocation; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | // Size |
| 63 | uint32_t CSubsystemObject::getSize() const |
| 64 | { |
| 65 | return _uiDataSize; |
| 66 | } |
| 67 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 68 | // Conversion utility |
| 69 | uint32_t CSubsystemObject::asInteger(const string& strValue) |
| 70 | { |
| 71 | return strtoul(strValue.c_str(), NULL, 0); |
| 72 | } |
| 73 | |
| 74 | string CSubsystemObject::asString(uint32_t uiValue) |
| 75 | { |
| 76 | ostringstream ostr; |
| 77 | |
| 78 | ostr << uiValue; |
| 79 | |
| 80 | return ostr.str(); |
| 81 | } |
| 82 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 83 | // Synchronization |
| 84 | bool CSubsystemObject::sync(CParameterBlackboard& parameterBlackboard, bool bBack, string& strError) |
| 85 | { |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 86 | // Get blackboard location |
| 87 | _pucBlackboardLocation = parameterBlackboard.getLocation(_pInstanceConfigurableElement->getOffset()); |
| 88 | // Access index init |
| 89 | _uiAccessedIndex = 0; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 90 | |
| 91 | #ifdef SIMULATION |
| 92 | return true; |
| 93 | #endif |
| 94 | |
| 95 | // Synchronize to/from HW |
| 96 | if (bBack) { |
| 97 | |
| 98 | // Read from HW |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 99 | if (!accessHW(true, strError)) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 100 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 101 | strError = "Unable to back synchronize configurable element " + _pInstanceConfigurableElement->getPath() + ": " + strError; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 102 | |
| 103 | return false; |
| 104 | } |
| 105 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 106 | } else { |
| 107 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 108 | // Send to HW |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 109 | if (!accessHW(false, strError)) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 110 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 111 | strError = "Unable to synchronize configurable element " + _pInstanceConfigurableElement->getPath() + ": " + strError; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 112 | |
| 113 | return false; |
| 114 | } |
| 115 | } |
| 116 | return true; |
| 117 | } |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 118 | |
| 119 | // Sync to/from HW |
| 120 | bool CSubsystemObject::sendToHW(string& strError) |
| 121 | { |
| 122 | strError = "Send to HW interface not implemented at subsystsem level!"; |
| 123 | |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | bool CSubsystemObject::receiveFromHW(string& strError) |
| 128 | { |
| 129 | strError = "Receive from HW interface not implemented at subsystsem level!"; |
| 130 | |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | // Fall back HW access |
| 135 | bool CSubsystemObject::accessHW(bool bReceive, string& strError) |
| 136 | { |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 137 | // Default access fall back |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 138 | if (bReceive) { |
| 139 | |
| 140 | return receiveFromHW(strError); |
| 141 | } else { |
| 142 | |
| 143 | return sendToHW(strError); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // Blackboard access from subsystems |
| 148 | void CSubsystemObject::blackboardRead(void* pvData, uint32_t uiSize) |
| 149 | { |
| 150 | assert(_uiAccessedIndex + uiSize <= _uiDataSize); |
| 151 | |
| 152 | memcpy(pvData, _pucBlackboardLocation + _uiAccessedIndex, uiSize); |
| 153 | |
| 154 | _uiAccessedIndex += uiSize; |
| 155 | } |
| 156 | |
| 157 | void CSubsystemObject::blackboardWrite(const void* pvData, uint32_t uiSize) |
| 158 | { |
| 159 | assert(_uiAccessedIndex + uiSize <= _uiDataSize); |
| 160 | |
| 161 | memcpy(_pucBlackboardLocation + _uiAccessedIndex, pvData, uiSize); |
| 162 | |
| 163 | _uiAccessedIndex += uiSize; |
| 164 | } |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 165 | |
| 166 | // Logging |
| 167 | void CSubsystemObject::log(const string& strMessage, ...) const |
| 168 | { |
| 169 | char acBuffer[512]; |
| 170 | va_list listPointer; |
| 171 | |
| 172 | va_start(listPointer, strMessage); |
| 173 | |
| 174 | vsnprintf(acBuffer, sizeof(acBuffer), strMessage.c_str(), listPointer); |
| 175 | |
| 176 | va_end(listPointer); |
| 177 | |
| 178 | _pInstanceConfigurableElement->log(acBuffer); |
| 179 | } |
Guillaume Denneulin | 7fce1e3 | 2012-02-17 17:34:47 +0100 | [diff] [blame^] | 180 | |
| 181 | // Amendment |
| 182 | string CSubsystemObject::formatMappingValue(const string& strMappingValue, uint32_t uiFirstAmendKey, uint32_t uiNbAmendKeys, const CMappingContext& context) |
| 183 | { |
| 184 | string strFormattedValue = strMappingValue; |
| 185 | // Search for amendment (only one supported for now) |
| 186 | size_t uiPercentPos = strFormattedValue.find('%', 0); |
| 187 | |
| 188 | // Amendment limited to one digit (values from 1 to 9) |
| 189 | assert((uiNbAmendKeys > 0) && (uiNbAmendKeys <= 9)); |
| 190 | |
| 191 | // Check we found one and that there's room for value |
| 192 | if (uiPercentPos != string::npos && uiPercentPos < strFormattedValue.size() - 1) { |
| 193 | |
| 194 | // Get Amend number |
| 195 | uint32_t uiAmendNumber = strFormattedValue[uiPercentPos + 1] - '0'; |
| 196 | |
| 197 | // Valid? |
| 198 | if (uiAmendNumber && uiAmendNumber <= uiNbAmendKeys) { |
| 199 | |
| 200 | uint32_t uiAmendType = uiFirstAmendKey + uiAmendNumber - 1; |
| 201 | |
| 202 | // Set? |
| 203 | if (context.iSet(uiAmendType)) { |
| 204 | |
| 205 | // Get Amend value |
| 206 | string strAmendValue = context.getItem(uiAmendType); |
| 207 | |
| 208 | // Make the amendment |
| 209 | strFormattedValue = strFormattedValue.substr(0, uiPercentPos) + strAmendValue + strFormattedValue.substr(uiPercentPos + 2, strFormattedValue.size() - uiPercentPos - 2); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | return strFormattedValue; |
| 214 | } |