1 /*
2 * Copyright (c) 2011-2014, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 #include <fstream>
31 #include <string>
32 #include <sstream>
33 #include <cstdlib>
34 #include <cassert>
35 #include <iostream>
36 #include "ParameterType.h"
37 #include "MappingContext.h"
38 #include "SkeletonMappingKeys.h"
39 #include "InstanceConfigurableElement.h"
40 #include "SkeletonSubsystemObject.h"
41
42 #define STR_FORMAT_LENGTH 32
43
44 #define base CFormattedSubsystemObject
45
46 using std::string;
47
CSkeletonSubsystemObject(const string & strMappingValue,CInstanceConfigurableElement * pInstanceConfigurableElement,const CMappingContext & context)48 CSkeletonSubsystemObject::CSkeletonSubsystemObject(
49 const string& strMappingValue,
50 CInstanceConfigurableElement* pInstanceConfigurableElement,
51 const CMappingContext& context
52 ) :
53 base(pInstanceConfigurableElement,
54 strMappingValue,
55 EAmend1,
56 EAmendEnd - EAmend1 + 1,
57 context),
58 _bWrongElementTypeError(false)
59 {
60 // Get actual element type
61 const CParameterType* pParameterType = static_cast<const CParameterType*>(pInstanceConfigurableElement->getTypeElement());
62
63 // Retrieve sizes
64 _uiScalarSize = pParameterType->getSize();
65 _uiArraySize = pInstanceConfigurableElement->getFootPrint() / _uiScalarSize;
66
67 // Construct message
68 _strMessage = context.getItem(ESkeletonOwner) + ":" + strMappingValue ;
69
70 // Handle types
71 // Check we are able to handle elements (no exception support, defer the error)
72 switch(pInstanceConfigurableElement->getType()) {
73
74 case CInstanceConfigurableElement::EParameter:
75 break;
76 default:
77 _bWrongElementTypeError = true;
78 break;
79 }
80
81 }
82 // Sync to/from HW
accessHW(bool bReceive,string & strError)83 bool CSkeletonSubsystemObject::accessHW(bool bReceive, string& strError)
84 {
85 // Check parameter type is ok (deferred error, no exceptions available :-()
86 if (_bWrongElementTypeError) {
87
88 strError = "Unsupported parameter type";
89
90 return false;
91 }
92
93 return base::accessHW(bReceive, strError);
94 }
95
sendToHW(string & strError)96 bool CSkeletonSubsystemObject::sendToHW(string& strError)
97 {
98 (void) strError;
99
100 uint32_t uiIndex;
101
102 void* pvValue = alloca(_uiScalarSize);
103
104 for (uiIndex = 0 ; uiIndex < _uiArraySize ; uiIndex++) {
105
106 // Read Value in BlackBoard
107 blackboardRead(pvValue, _uiScalarSize);
108
109 // Send here the value
110 std::cout << "Sending to HW: " << _strMessage << std::endl;
111 }
112
113 return true;
114 }
115
receiveFromHW(string & strError)116 bool CSkeletonSubsystemObject::receiveFromHW(string& strError)
117 {
118 (void) strError;
119
120 uint32_t uiIndex;
121
122 void* pvValue = alloca(_uiScalarSize);
123
124 for (uiIndex = 0 ; uiIndex < _uiArraySize ; uiIndex++) {
125
126 // Retreive here the value
127 std::cout << "Retreive from HW: " << _strMessage << std::endl;
128
129 // Write Value in Blackboard
130 blackboardWrite(pvValue, _uiScalarSize);
131 }
132
133 return true;
134 }
135