Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
DIOT WIC Gateware
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
DIOT WIC Gateware
Commits
8c42bc5f
Commit
8c42bc5f
authored
Aug 15, 2018
by
Projects
Committed by
Grzegorz Daniluk
Aug 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support to handle input errors in DIOT_Crate
parent
44a9a1f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
39 deletions
+73
-39
diot_crate.cpp
sw/diot-sw/gui_demo/diot_crate.cpp
+19
-35
diot_crate.h
sw/diot-sw/gui_demo/diot_crate.h
+54
-4
No files found.
sw/diot-sw/gui_demo/diot_crate.cpp
View file @
8c42bc5f
...
...
@@ -21,11 +21,7 @@
void
DIOT_Crate
::
SetOutput
(
int
slot
,
int
idx
,
bool
state
)
{
if
(
slot
>
card_count
)
{
throw
std
::
runtime_error
(
"DIOT_Crate::GetIO(): Too high slot number"
);
}
const
int
var_offset
=
getVarOffset
(
slot
,
idx
);
const
int
var_offset
=
getDataOffset
(
slot
,
idx
);
const
uint8_t
io_mask
=
getIOMask
(
idx
);
uint8_t
data
=
GetProdVarData
(
var_offset
);
...
...
@@ -41,20 +37,9 @@ void DIOT_Crate::SetOutput(int slot, int idx, bool state)
}
bool
DIOT_Crate
::
GetInput
(
int
slot
,
int
idx
)
{
if
(
slot
>
card_count
)
{
throw
std
::
runtime_error
(
"DIOT_Crate::GetIO(): Too high slot number"
);
}
const
uint8_t
data
=
GetConsVarData
(
getVarOffset
(
slot
,
idx
));
return
data
&
getIOMask
(
idx
);
}
void
DIOT_Crate
::
SetSlotOutputs
(
int
slot
,
uint32_t
state
)
{
const
int
var_offset
=
get
Var
Offset
(
slot
,
0
);
const
int
var_offset
=
get
Data
Offset
(
slot
,
0
);
{
// mutex locked scope
auto
lock
=
getProdLock
();
...
...
@@ -66,24 +51,6 @@ void DIOT_Crate::SetSlotOutputs(int slot, uint32_t state)
}
uint32_t
DIOT_Crate
::
GetSlotInputs
(
int
slot
)
{
const
int
var_offset
=
getVarOffset
(
slot
,
0
);
uint32_t
ret
=
0
;
{
// mutex locked scope
auto
lock
=
getConsLock
();
for
(
int
i
=
3
;
i
>=
0
;
--
i
)
{
ret
<<=
8
;
ret
|=
getConsDataLock
(
var_offset
+
i
,
lock
);
}
}
return
ret
;
}
bool
DIOT_Crate
::
GetFanStatus
(
unsigned
int
fan
)
{
if
(
fan
>=
FAN_COUNT
)
...
...
@@ -159,6 +126,23 @@ DIOT_Crate::VOLTAGE DIOT_Crate::GetVoltEnum(unsigned int idx)
}
uint32_t
DIOT_Crate
::
getConsWord
(
int
address
)
{
uint32_t
ret
=
0
;
{
// mutex locked scope
auto
lock
=
getConsLock
();
for
(
int
i
=
3
;
i
>=
0
;
--
i
)
{
ret
<<=
8
;
ret
|=
getConsDataLock
(
address
+
i
,
lock
);
}
}
return
ret
;
}
const
std
::
vector
<
std
::
pair
<
DIOT_Crate
::
VOLTAGE
,
std
::
string
>>
DIOT_Crate
::
VOLTAGES
=
{
{
P3V3
,
"+3.3V"
},
{
P5V0
,
"+5V"
},
{
P12V0
,
"+12V"
},
{
M12V0
,
"-12V"
}
};
sw/diot-sw/gui_demo/diot_crate.h
View file @
8c42bc5f
...
...
@@ -50,7 +50,21 @@ public:
* @param idx is the input number (0 to IO_PER_SLOT - 1 range).
* @return True when the input is high, false otherwise.
*/
bool
GetInput
(
int
slot
,
int
idx
);
bool
GetInput
(
int
slot
,
int
idx
)
{
return
getConsBit
(
getDataOffset
(
slot
,
idx
),
getIOMask
(
idx
));
}
/**
* Return an input error state.
* @param slot is the card number (indexing from 0).
* @param idx is the input number (0 to IO_PER_SLOT - 1 range).
* @return True when there is an error, false otherwise.
*/
bool
GetInputErr
(
int
slot
,
int
idx
)
{
return
getConsBit
(
getInpErrOffset
(
slot
,
idx
),
getIOMask
(
idx
));
}
/**
* Change state of all outputs of a card in a particular slot.
...
...
@@ -64,7 +78,20 @@ public:
* @param slot is the card number (indexing from 0).
* @return the inputs state. The LSB corresponds to I/O number 0.
*/
uint32_t
GetSlotInputs
(
int
slot
);
uint32_t
GetSlotInputs
(
int
slot
)
{
return
getConsWord
(
getDataOffset
(
slot
,
0
));
}
/**
* Return state of all input errors of a card in a particular slot.
* @param slot is the card number (indexing from 0).
* @return the input errors state. The LSB corresponds to I/O number 0.
*/
uint32_t
GetSlotInputErrs
(
int
slot
)
{
return
getConsWord
(
getInpErrOffset
(
slot
,
0
));
}
/**
* Return the number of I/O cards installed in the crate.
...
...
@@ -190,18 +217,41 @@ public:
static
VOLTAGE
GetVoltEnum
(
unsigned
int
idx
);
private
:
///> Return
variabl
e offset corresponding to a particular I/O and slot.
static
int
getVar
Offset
(
int
slot
,
int
idx
)
///> Return
pin stat
e offset corresponding to a particular I/O and slot.
int
getData
Offset
(
int
slot
,
int
idx
)
{
if
(
slot
>
card_count
)
{
throw
std
::
runtime_error
(
"DIOT_Crate::GetIO(): Too high slot number"
);
}
return
slot
*
(
IO_PER_SLOT
/
8
)
+
idx
/
8
;
}
///> Return error status corresponding to a particular input and slot.
int
getInpErrOffset
(
int
slot
,
int
idx
)
{
if
(
slot
>
card_count
)
{
throw
std
::
runtime_error
(
"DIOT_Crate::GetIO(): Too high slot number"
);
}
return
SLOT1_IN_ERR
+
slot
*
(
IO_PER_SLOT
/
8
)
+
idx
/
8
;
}
///> Calculates bitmask for particular I/O.
static
uint8_t
getIOMask
(
int
idx
)
{
return
(
1
<<
(
idx
%
8
));
}
///> Returns state of a bit of a consumed variable.
bool
getConsBit
(
int
address
,
uint8_t
mask
)
{
return
GetConsVarData
(
address
)
&
mask
;
}
///> Returns a 32-bit word made of 4 consecutive consumed variables.
uint32_t
getConsWord
(
int
address
);
///> Produced/consumed variable size (expressed in bytes)
static
constexpr
int
VAR_SIZE
=
124
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment