Bruno Allaire-Lemay
/
APP1test
df
Fork of APP1 by
Diff: HomemadeMbed.cpp
- Revision:
- 13:bb9669053eb3
- Child:
- 14:2f89279586cb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HomemadeMbed.cpp Mon Jan 16 00:06:45 2017 +0000 @@ -0,0 +1,20 @@ +#include "HomemadeMbed.hpp" +#include "Utility.hpp" + +namespace homemade_mbed +{ + unsigned int read_bits(int* address_4_bytes, const int start_bit, const int stop_bit) + { + const unsigned int all_4_bytes = *address_4_bytes; + const unsigned int left_shifted = all_4_bytes << (31 - stop_bit); + const unsigned int right_shifted = left_shifted >> (31 - stop_bit + start_bit); + return right_shifted; + } + + void write_bits(int* address_4_bytes, const int start_bit, const int stop_bit, const unsigned int new_value) + { + const unsigned int all_4_bytes = *address_4_bytes; + const unsigned int new_bits = utility::update_bits(all_4_bytes, start_bit, stop_bit, new_value); + *address_4_bytes = new_bits; + } +} \ No newline at end of file