blob: 1f1b3b775cc7f8e9d082dd2b6672a105b716b12d [file] [log] [blame]
Kevin Rocard93250d12012-07-19 17:48:30 +02001/*
Patrick Benavoli68a91282011-08-31 11:23:23 +02002 * INTEL CONFIDENTIAL
3 * Copyright © 2011 Intel
4 * Corporation All Rights Reserved.
5 *
6 * The source code contained or described herein and all documents related to
7 * the source code ("Material") are owned by Intel Corporation or its suppliers
8 * or licensors. Title to the Material remains with Intel Corporation or its
9 * suppliers and licensors. The Material contains trade secrets and proprietary
10 * and confidential information of Intel or its suppliers and licensors. The
11 * Material is protected by worldwide copyright and trade secret laws and
12 * treaty provisions. No part of the Material may be used, copied, reproduced,
13 * modified, published, uploaded, posted, transmitted, distributed, or
14 * disclosed in any way without Intel’s prior express written permission.
15 *
16 * No license under any patent, copyright, trade secret or other intellectual
17 * property right is granted to or conferred upon you by disclosure or delivery
18 * of the Materials, either expressly, by implication, inducement, estoppel or
19 * otherwise. Any license under such intellectual property rights must be
20 * express and approved by Intel in writing.
21 *
Patrick Benavoli68a91282011-08-31 11:23:23 +020022 * CREATED: 2011-06-01
23 * UPDATED: 2011-07-27
Patrick Benavoli68a91282011-08-31 11:23:23 +020024 */
25#include "BitParameter.h"
26#include "BitParameterType.h"
27#include "ParameterAccessContext.h"
28#include "ConfigurationAccessContext.h"
29#include "ParameterBlackboard.h"
30#include "BitParameterBlock.h"
Frédéric Boisnard9620e442012-05-30 16:15:02 +020031#include "BitwiseAreaConfiguration.h"
Patrick Benavoli68a91282011-08-31 11:23:23 +020032
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020033#define base CBaseParameter
Patrick Benavoli68a91282011-08-31 11:23:23 +020034
35CBitParameter::CBitParameter(const string& strName, const CTypeElement* pTypeElement) : base(strName, pTypeElement)
36{
37}
38
39// Type
40CInstanceConfigurableElement::Type CBitParameter::getType() const
41{
42 return EBitParameter;
43}
44
45// Size
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020046uint32_t CBitParameter::getBelongingBlockSize() const
Patrick Benavoli68a91282011-08-31 11:23:23 +020047{
48 return static_cast<const CBitParameterBlock*>(getParent())->getSize();
49}
50
Patrick Benavoli2ecf9002011-08-31 11:23:24 +020051// Instantiation, allocation
Patrick Benavoli68a91282011-08-31 11:23:23 +020052uint32_t CBitParameter::getFootPrint() const
53{
Frédéric Boisnard9620e442012-05-30 16:15:02 +020054 // Allocation done at parent level
Patrick Benavoli68a91282011-08-31 11:23:23 +020055 return 0;
56}
57
Patrick Benavoli065264a2011-11-20 15:46:41 +010058// Actual parameter access (tuning)
Patrick Benavoli68a91282011-08-31 11:23:23 +020059bool CBitParameter::doSetValue(const string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const
60{
Patrick Benavoli065264a2011-11-20 15:46:41 +010061 return doSet(strValue, uiOffset, parameterAccessContext);
62}
63
64void CBitParameter::doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const
65{
66 doGet(strValue, uiOffset, parameterAccessContext);
67}
68
69/// Value access
70// Boolean access
71bool CBitParameter::accessAsBoolean(bool& bValue, bool bSet, CParameterAccessContext& parameterAccessContext) const
72{
73 // Check boolean access validity here
74 if (static_cast<const CBitParameterType*>(getTypeElement())->getBitSize() != 1) {
75
76 parameterAccessContext.setError("Type mismatch");
77 // Append parameter path to error
78 parameterAccessContext.appendToError(" " + getPath());
79
80 return false;
81 }
82
83 // Rely on integer access
Guillaume Denneulin95331562012-09-27 15:13:10 +020084 uint64_t uiValue;
Patrick Benavoli065264a2011-11-20 15:46:41 +010085
86 if (bSet) {
87
88 uiValue = bValue;
89 }
90
91 if (!accessAsInteger(uiValue, bSet, parameterAccessContext)) {
92
93 return false;
94 }
95
96 if (!bSet) {
97
98 bValue = uiValue != 0;
99 }
100
101 return true;
102}
103
104// Integer Access
Guillaume Denneulin95331562012-09-27 15:13:10 +0200105bool CBitParameter::accessAsInteger(uint64_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const
Patrick Benavoli065264a2011-11-20 15:46:41 +0100106{
107 uint32_t uiOffset = getOffset();
108
109 if (bSet) {
110
111 // Set and sync
112 if (!doSet(uiValue, uiOffset, parameterAccessContext) || !sync(parameterAccessContext)) {
113
114 // Append parameter path to error
115 parameterAccessContext.appendToError(" " + getPath());
116
117 return false;
118 }
119 } else {
120
121 // Convert
122 doGet(uiValue, uiOffset, parameterAccessContext);
123 }
124 return true;
125}
126
127template <typename type>
128bool CBitParameter::doSet(type value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const
129{
Guillaume Denneulin95331562012-09-27 15:13:10 +0200130 uint64_t uiData = 0;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200131
132 // Read/modify/write
133 CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard();
134
135 // Beware this code works on little endian architectures only!
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200136 pBlackboard->readInteger(&uiData, getBelongingBlockSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200137
138 // Convert
Patrick Benavoli065264a2011-11-20 15:46:41 +0100139 if (!static_cast<const CBitParameterType*>(getTypeElement())->toBlackboard(value, uiData, parameterAccessContext)) {
Patrick Benavoli68a91282011-08-31 11:23:23 +0200140
141 return false;
142 }
143 // Write blackboard
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200144 pBlackboard->writeInteger(&uiData, getBelongingBlockSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200145
146 return true;
147}
148
Patrick Benavoli065264a2011-11-20 15:46:41 +0100149template <typename type>
150void CBitParameter::doGet(type& value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const
Patrick Benavoli68a91282011-08-31 11:23:23 +0200151{
Guillaume Denneulin95331562012-09-27 15:13:10 +0200152 uint64_t uiData = 0;
Patrick Benavoli68a91282011-08-31 11:23:23 +0200153
154 // Read blackboard
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200155 const CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard();
Patrick Benavoli68a91282011-08-31 11:23:23 +0200156
157 // Beware this code works on little endian architectures only!
Patrick Benavoli1352ae52011-10-21 16:48:04 +0200158 pBlackboard->readInteger(&uiData, getBelongingBlockSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem());
Patrick Benavoli68a91282011-08-31 11:23:23 +0200159
160 // Convert
Patrick Benavoli065264a2011-11-20 15:46:41 +0100161 static_cast<const CBitParameterType*>(getTypeElement())->fromBlackboard(value, uiData, parameterAccessContext);
Patrick Benavoli68a91282011-08-31 11:23:23 +0200162}
Frédéric Boisnard9620e442012-05-30 16:15:02 +0200163
164// AreaConfiguration creation
165CAreaConfiguration* CBitParameter::createAreaConfiguration(const CSyncerSet* pSyncerSet) const
166{
167 return new CBitwiseAreaConfiguration(this, pSyncerSet);
168}
169
170// Access from area configuration
Guillaume Denneulin95331562012-09-27 15:13:10 +0200171uint64_t CBitParameter::merge(uint64_t uiOriginData, uint64_t uiNewData) const
Frédéric Boisnard9620e442012-05-30 16:15:02 +0200172{
173 // Convert
174 return static_cast<const CBitParameterType*>(getTypeElement())->merge(uiOriginData, uiNewData);
175}