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" |
| 34 | #include <assert.h> |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 35 | #include <stdlib.h> |
| 36 | #include <string.h> |
| 37 | #include <sstream> |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 38 | #include <stdarg.h> |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 39 | |
| 40 | CSubsystemObject::CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement) |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 41 | : _pInstanceConfigurableElement(pInstanceConfigurableElement), |
| 42 | _uiDataSize(pInstanceConfigurableElement->getFootPrint()), |
| 43 | _pucBlackboardLocation(NULL), |
| 44 | _uiAccessedIndex(0) |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 45 | { |
| 46 | // Syncer |
| 47 | _pInstanceConfigurableElement->setSyncer(this); |
| 48 | } |
| 49 | |
| 50 | CSubsystemObject::~CSubsystemObject() |
| 51 | { |
| 52 | _pInstanceConfigurableElement->unsetSyncer(); |
| 53 | } |
| 54 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 55 | // Blackboard data location |
| 56 | uint8_t* CSubsystemObject::getBlackboardLocation() const |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 57 | { |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 58 | return _pucBlackboardLocation; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | // Size |
| 62 | uint32_t CSubsystemObject::getSize() const |
| 63 | { |
| 64 | return _uiDataSize; |
| 65 | } |
| 66 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 67 | // Conversion utility |
| 68 | uint32_t CSubsystemObject::asInteger(const string& strValue) |
| 69 | { |
| 70 | return strtoul(strValue.c_str(), NULL, 0); |
| 71 | } |
| 72 | |
| 73 | string CSubsystemObject::asString(uint32_t uiValue) |
| 74 | { |
| 75 | ostringstream ostr; |
| 76 | |
| 77 | ostr << uiValue; |
| 78 | |
| 79 | return ostr.str(); |
| 80 | } |
| 81 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 82 | // Synchronization |
| 83 | bool CSubsystemObject::sync(CParameterBlackboard& parameterBlackboard, bool bBack, string& strError) |
| 84 | { |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 85 | // Get blackboard location |
| 86 | _pucBlackboardLocation = parameterBlackboard.getLocation(_pInstanceConfigurableElement->getOffset()); |
| 87 | // Access index init |
| 88 | _uiAccessedIndex = 0; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 89 | |
| 90 | #ifdef SIMULATION |
| 91 | return true; |
| 92 | #endif |
| 93 | |
| 94 | // Synchronize to/from HW |
| 95 | if (bBack) { |
| 96 | |
| 97 | // Read from HW |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 98 | if (!accessHW(true, strError)) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 99 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 100 | strError = "Unable to back synchronize configurable element " + _pInstanceConfigurableElement->getPath() + ": " + strError; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 101 | |
| 102 | return false; |
| 103 | } |
| 104 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 105 | } else { |
| 106 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 107 | // Send to HW |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 108 | if (!accessHW(false, strError)) { |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 109 | |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 110 | strError = "Unable to synchronize configurable element " + _pInstanceConfigurableElement->getPath() + ": " + strError; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 111 | |
| 112 | return false; |
| 113 | } |
| 114 | } |
| 115 | return true; |
| 116 | } |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 117 | |
| 118 | // Sync to/from HW |
| 119 | bool CSubsystemObject::sendToHW(string& strError) |
| 120 | { |
| 121 | strError = "Send to HW interface not implemented at subsystsem level!"; |
| 122 | |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | bool CSubsystemObject::receiveFromHW(string& strError) |
| 127 | { |
| 128 | strError = "Receive from HW interface not implemented at subsystsem level!"; |
| 129 | |
| 130 | return false; |
| 131 | } |
| 132 | |
| 133 | // Fall back HW access |
| 134 | bool CSubsystemObject::accessHW(bool bReceive, string& strError) |
| 135 | { |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 136 | // Default access fall back |
Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 137 | if (bReceive) { |
| 138 | |
| 139 | return receiveFromHW(strError); |
| 140 | } else { |
| 141 | |
| 142 | return sendToHW(strError); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // Blackboard access from subsystems |
| 147 | void CSubsystemObject::blackboardRead(void* pvData, uint32_t uiSize) |
| 148 | { |
| 149 | assert(_uiAccessedIndex + uiSize <= _uiDataSize); |
| 150 | |
| 151 | memcpy(pvData, _pucBlackboardLocation + _uiAccessedIndex, uiSize); |
| 152 | |
| 153 | _uiAccessedIndex += uiSize; |
| 154 | } |
| 155 | |
| 156 | void CSubsystemObject::blackboardWrite(const void* pvData, uint32_t uiSize) |
| 157 | { |
| 158 | assert(_uiAccessedIndex + uiSize <= _uiDataSize); |
| 159 | |
| 160 | memcpy(_pucBlackboardLocation + _uiAccessedIndex, pvData, uiSize); |
| 161 | |
| 162 | _uiAccessedIndex += uiSize; |
| 163 | } |
Patrick Benavoli | 63499d4 | 2011-10-24 18:50:03 +0200 | [diff] [blame] | 164 | |
| 165 | // Logging |
| 166 | void CSubsystemObject::log(const string& strMessage, ...) const |
| 167 | { |
| 168 | char acBuffer[512]; |
| 169 | va_list listPointer; |
| 170 | |
| 171 | va_start(listPointer, strMessage); |
| 172 | |
| 173 | vsnprintf(acBuffer, sizeof(acBuffer), strMessage.c_str(), listPointer); |
| 174 | |
| 175 | va_end(listPointer); |
| 176 | |
| 177 | _pInstanceConfigurableElement->log(acBuffer); |
| 178 | } |