Skip to content

Commit

Permalink
BitManipulation mock
Browse files Browse the repository at this point in the history
  • Loading branch information
annika committed Nov 20, 2019
1 parent c81f2a8 commit 308b19f
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .clwb/.bazelproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
directories:
# Add the directories you want added as source here
# By default, we've added your entire workspace ('.')
.

# Automatically includes all relevant targets under the 'directories' above
derive_targets_from_directories: true

targets:
# If source code isn't resolving, add additional targets that compile it here

additional_languages:
# Uncomment any additional languages you want supported
# dart
# javascript
# python
# typescript
11 changes: 11 additions & 0 deletions .clwb/.blaze/modules/.project-data-dir.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.system.id="Blaze" type="BLAZE_CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/../..">
<excludeFolder url="file://$MODULE_DIR$/.." />
<excludeFolder url="file://$MODULE_DIR$/../../.idea" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
16 changes: 16 additions & 0 deletions .clwb/.blaze/modules/.workspace.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.system.id="Blaze" type="BLAZE_CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/../../..">
<sourceFolder url="file://$MODULE_DIR$/../../.." isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/../.." />
<excludeFolder url="file://$MODULE_DIR$/../../../bazel-EmbeddedUtilities" />
<excludeFolder url="file://$MODULE_DIR$/../../../bazel-bin" />
<excludeFolder url="file://$MODULE_DIR$/../../../bazel-genfiles" />
<excludeFolder url="file://$MODULE_DIR$/../../../bazel-out" />
<excludeFolder url="file://$MODULE_DIR$/../../../bazel-testlogs" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
1 change: 1 addition & 0 deletions .clwb/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .clwb/.idea/externalDependencies.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .clwb/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions .clwb/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .clwb/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .clwb/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion EmbeddedUtilities/BitManipulation.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef COMMUNICATIONMODULE_BITMANIPULATION_H
#define COMMUNICATIONMODULE_BITMANIPULATION_H

#ifdef TEST
#include "EmbeddedUtilities/BitManipulation_Test.h"
#else
#include <stdint.h>
#include <stdbool.h>

Expand Down Expand Up @@ -147,7 +150,15 @@ BitManipulation_get16BitFromBigEndianByteArray(volatile const uint8_t *array) {

static inline void BitManipulation_clearBit(volatile uint8_t *byte_ptr, uint8_t offset) {
*(byte_ptr) &= ~(1 << offset);
}
}byte_index = (uint8_t) (offset / 8);
uint8_t local_offset = (uint8_t) (offset % 8);
uint8_t lower_bitmask = bitmask << local_offset;
uint8_t upper_bitmask = bitmask >> (8 - local_offset);
uint8_t value = (field[byte_index] & lower_bitmask) >> local_offset;
if (upper_bitmask != 0) {
value |= (field[byte_index + 1] & upper_bitmask) << (8 - local_offset);
}
return value;

static inline void BitManipulation_setBit(volatile uint8_t *byte_ptr, uint8_t offset) {
*(byte_ptr) |= (1 << offset);
Expand Down Expand Up @@ -190,4 +201,6 @@ BitManipulation_getLengthOfContinuousSetBitsFromByte(uint8_t byte)
}
return length;
}

#endif
#endif //COMMUNICATIONMODULE_BITMANIPULATION_H
14 changes: 14 additions & 0 deletions EmbeddedUtilities/BitManipulation_Test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Created by annika on 20.11.19.
//

#ifndef EMBEDDEDUTILITIES_BITMANIPULATION_TEST_H
#define EMBEDDEDUTILITIES_BITMANIPULATION_TEST_H

#include <stdint.h>

void BitManipulation_clearBit(volatile uint8_t *byte_ptr, uint8_t offset);

void BitManipulation_setBit(volatile uint8_t *byte_ptr, uint8_t offset);

#endif //EMBEDDEDUTILITIES_BITMANIPULATION_TEST_H
2 changes: 1 addition & 1 deletion test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ unity_test(
deps = [
"//:BitManipulation",
"@CException"
]
],
)

0 comments on commit 308b19f

Please sign in to comment.