df

Dependencies:   mbed

Fork of APP1 by Team APP

Committer:
GaiSensei
Date:
Mon Jan 16 02:28:40 2017 +0000
Revision:
14:2f89279586cb
Parent:
13:bb9669053eb3
Child:
15:b38d9d210e32
Bonne nuit; ; Tout est bris?; ; Ajouter mask dans write_bits pour que les reserved soit des 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GaiSensei 13:bb9669053eb3 1 #include "HomemadeMbed.hpp"
GaiSensei 13:bb9669053eb3 2 #include "Utility.hpp"
GaiSensei 14:2f89279586cb 3 #include <cstdio>
GaiSensei 13:bb9669053eb3 4
GaiSensei 13:bb9669053eb3 5 namespace homemade_mbed
GaiSensei 13:bb9669053eb3 6 {
GaiSensei 14:2f89279586cb 7 unsigned int read_bits(unsigned int* address_4_bytes, const int start_bit, const int stop_bit)
GaiSensei 13:bb9669053eb3 8 {
GaiSensei 13:bb9669053eb3 9 const unsigned int all_4_bytes = *address_4_bytes;
GaiSensei 13:bb9669053eb3 10 const unsigned int left_shifted = all_4_bytes << (31 - stop_bit);
GaiSensei 13:bb9669053eb3 11 const unsigned int right_shifted = left_shifted >> (31 - stop_bit + start_bit);
GaiSensei 13:bb9669053eb3 12 return right_shifted;
GaiSensei 13:bb9669053eb3 13 }
GaiSensei 13:bb9669053eb3 14
GaiSensei 14:2f89279586cb 15 void write_bits(unsigned int* address_4_bytes, const int start_bit, const int stop_bit, const unsigned int new_value)
GaiSensei 13:bb9669053eb3 16 {
GaiSensei 14:2f89279586cb 17 //std::printf("write_bits()\r\n");
GaiSensei 14:2f89279586cb 18
GaiSensei 13:bb9669053eb3 19 const unsigned int all_4_bytes = *address_4_bytes;
GaiSensei 13:bb9669053eb3 20 const unsigned int new_bits = utility::update_bits(all_4_bytes, start_bit, stop_bit, new_value);
GaiSensei 13:bb9669053eb3 21 *address_4_bytes = new_bits;
GaiSensei 13:bb9669053eb3 22 }
GaiSensei 13:bb9669053eb3 23 }