blob: ce6275b2d8fcf35472a65c96c5ab33c03ecf9b15 [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 Benavoli63499d42011-10-24 18:50:03 +020038#include <stdarg.h>
Patrick Benavoli68a91282011-08-31 11:23:23 +020039
40CSubsystemObject::CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement)
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020041 : _pInstanceConfigurableElement(pInstanceConfigurableElement),
42 _uiDataSize(pInstanceConfigurableElement->getFootPrint()),
43 _pucBlackboardLocation(NULL),
44 _uiAccessedIndex(0)
Patrick Benavoli68a91282011-08-31 11:23:23 +020045{
46 // Syncer
47 _pInstanceConfigurableElement->setSyncer(this);
48}
49
50CSubsystemObject::~CSubsystemObject()
51{
52 _pInstanceConfigurableElement->unsetSyncer();
53}
54
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020055// Blackboard data location
56uint8_t* CSubsystemObject::getBlackboardLocation() const
Patrick Benavoli68a91282011-08-31 11:23:23 +020057{
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020058 return _pucBlackboardLocation;
Patrick Benavoli68a91282011-08-31 11:23:23 +020059}
60
61// Size
62uint32_t CSubsystemObject::getSize() const
63{
64 return _uiDataSize;
65}
66
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020067// Conversion utility
68uint32_t CSubsystemObject::asInteger(const string& strValue)
69{
70 return strtoul(strValue.c_str(), NULL, 0);
71}
72
73string CSubsystemObject::asString(uint32_t uiValue)
74{
75 ostringstream ostr;
76
77 ostr << uiValue;
78
79 return ostr.str();
80}
81
Patrick Benavoli68a91282011-08-31 11:23:23 +020082// Synchronization
83bool CSubsystemObject::sync(CParameterBlackboard& parameterBlackboard, bool bBack, string& strError)
84{
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020085 // Get blackboard location
86 _pucBlackboardLocation = parameterBlackboard.getLocation(_pInstanceConfigurableElement->getOffset());
87 // Access index init
88 _uiAccessedIndex = 0;
Patrick Benavoli68a91282011-08-31 11:23:23 +020089
90#ifdef SIMULATION
91 return true;
92#endif
93
94 // Synchronize to/from HW
95 if (bBack) {
96
97 // Read from HW
Patrick Benavoli6ba361d2011-08-31 11:23:24 +020098 if (!accessHW(true, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +020099
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200100 strError = "Unable to back synchronize configurable element " + _pInstanceConfigurableElement->getPath() + ": " + strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200101
102 return false;
103 }
104
Patrick Benavoli68a91282011-08-31 11:23:23 +0200105 } else {
106
Patrick Benavoli68a91282011-08-31 11:23:23 +0200107 // Send to HW
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200108 if (!accessHW(false, strError)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200109
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200110 strError = "Unable to synchronize configurable element " + _pInstanceConfigurableElement->getPath() + ": " + strError;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200111
112 return false;
113 }
114 }
115 return true;
116}
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200117
118// Sync to/from HW
119bool CSubsystemObject::sendToHW(string& strError)
120{
121 strError = "Send to HW interface not implemented at subsystsem level!";
122
123 return false;
124}
125
126bool 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
134bool CSubsystemObject::accessHW(bool bReceive, string& strError)
135{
Patrick Benavoli63499d42011-10-24 18:50:03 +0200136 // Default access fall back
Patrick Benavoli6ba361d2011-08-31 11:23:24 +0200137 if (bReceive) {
138
139 return receiveFromHW(strError);
140 } else {
141
142 return sendToHW(strError);
143 }
144}
145
146// Blackboard access from subsystems
147void 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
156void 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 Benavoli63499d42011-10-24 18:50:03 +0200164
165// Logging
166void 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}