blob: f0f1985f8c8dcda3d02bf3a037c7367dd14b9a0c [file] [log] [blame]
Patrick Benavoli68a91282011-08-31 11:23:23 +02001/* <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 Benavoli6ba361d2011-08-31 11:23:24 +020035#include <stdlib.h>
36#include <string.h>
37#include <sstream>
Patrick Benavoli68a91282011-08-31 11:23:23 +020038
39CSubsystemObject::CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020040 : _pInstanceConfigurableElement(pInstanceConfigurableElement),
41 _uiDataSize(pInstanceConfigurableElement->getFootPrint()),
42 _pucBlackboardLocation(NULL),
43 _uiAccessedIndex(0)
Patrick Benavoli68a91282011-08-31 11:23:23 +020044{
45 // Syncer
46 _pInstanceConfigurableElement->setSyncer(this);
47}
48
49CSubsystemObject::~CSubsystemObject()
50{
51 _pInstanceConfigurableElement->unsetSyncer();
52}
53
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020054// Blackboard data location
55uint8_t* CSubsystemObject::getBlackboardLocation() const
Patrick Benavoli68a91282011-08-31 11:23:23 +020056{
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020057 return _pucBlackboardLocation;
Patrick Benavoli68a91282011-08-31 11:23:23 +020058}
59
60// Size
61uint32_t CSubsystemObject::getSize() const
62{
63 return _uiDataSize;
64}
65
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020066// Conversion utility
67uint32_t CSubsystemObject::asInteger(const string& strValue)
68{
69 return strtoul(strValue.c_str(), NULL, 0);
70}
71
72string CSubsystemObject::asString(uint32_t uiValue)
73{
74 ostringstream ostr;
75
76 ostr << uiValue;
77
78 return ostr.str();
79}
80
Patrick Benavoli68a91282011-08-31 11:23:23 +020081// Synchronization
82bool CSubsystemObject::sync(CParameterBlackboard& parameterBlackboard, bool bBack, string& strError)
83{
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020084 // Get blackboard location
85 _pucBlackboardLocation = parameterBlackboard.getLocation(_pInstanceConfigurableElement->getOffset());
86 // Access index init
87 _uiAccessedIndex = 0;
Patrick Benavoli68a91282011-08-31 11:23:23 +020088
89#ifdef SIMULATION
90 return true;
91#endif
92
93 // Synchronize to/from HW
94 if (bBack) {
95
96 // Read from HW
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020097 if (!accessHW(true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020098
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020099 strError = "Unable to back synchronize configurable element " + _pInstanceConfigurableElement->getPath() + ": " + strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200100
101 return false;
102 }
103
Patrick Benavoli68a91282011-08-31 11:23:23 +0200104 } else {
105
Patrick Benavoli68a91282011-08-31 11:23:23 +0200106 // Send to HW
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200107 if (!accessHW(false, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200108
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200109 strError = "Unable to synchronize configurable element " + _pInstanceConfigurableElement->getPath() + ": " + strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200110
111 return false;
112 }
113 }
114 return true;
115}
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200116
117// Sync to/from HW
118bool CSubsystemObject::sendToHW(string& strError)
119{
120 strError = "Send to HW interface not implemented at subsystsem level!";
121
122 return false;
123}
124
125bool CSubsystemObject::receiveFromHW(string& strError)
126{
127 strError = "Receive from HW interface not implemented at subsystsem level!";
128
129 return false;
130}
131
132// Fall back HW access
133bool CSubsystemObject::accessHW(bool bReceive, string& strError)
134{
135 // Default access falls back
136 if (bReceive) {
137
138 return receiveFromHW(strError);
139 } else {
140
141 return sendToHW(strError);
142 }
143}
144
145// Blackboard access from subsystems
146void CSubsystemObject::blackboardRead(void* pvData, uint32_t uiSize)
147{
148 assert(_uiAccessedIndex + uiSize <= _uiDataSize);
149
150 memcpy(pvData, _pucBlackboardLocation + _uiAccessedIndex, uiSize);
151
152 _uiAccessedIndex += uiSize;
153}
154
155void CSubsystemObject::blackboardWrite(const void* pvData, uint32_t uiSize)
156{
157 assert(_uiAccessedIndex + uiSize <= _uiDataSize);
158
159 memcpy(_pucBlackboardLocation + _uiAccessedIndex, pvData, uiSize);
160
161 _uiAccessedIndex += uiSize;
162}