Bruno Allaire-Lemay
/
APP1test
df
Fork of APP1 by
HomemadeMbed.cpp@15:b38d9d210e32, 2017-01-17 (annotated)
- Committer:
- dupm2216
- Date:
- Tue Jan 17 00:06:38 2017 +0000
- Revision:
- 15:b38d9d210e32
- Parent:
- 14:2f89279586cb
- Child:
- 16:c77e34bc69bc
Fini?
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GaiSensei | 13:bb9669053eb3 | 1 | #include "HomemadeMbed.hpp" |
GaiSensei | 13:bb9669053eb3 | 2 | #include "Utility.hpp" |
dupm2216 | 15:b38d9d210e32 | 3 | #include <cassert> |
dupm2216 | 15:b38d9d210e32 | 4 | #include "mbed.h" |
GaiSensei | 13:bb9669053eb3 | 5 | |
GaiSensei | 13:bb9669053eb3 | 6 | namespace homemade_mbed |
GaiSensei | 13:bb9669053eb3 | 7 | { |
GaiSensei | 14:2f89279586cb | 8 | unsigned int read_bits(unsigned int* address_4_bytes, const int start_bit, const int stop_bit) |
GaiSensei | 13:bb9669053eb3 | 9 | { |
GaiSensei | 13:bb9669053eb3 | 10 | const unsigned int all_4_bytes = *address_4_bytes; |
GaiSensei | 13:bb9669053eb3 | 11 | const unsigned int left_shifted = all_4_bytes << (31 - stop_bit); |
GaiSensei | 13:bb9669053eb3 | 12 | const unsigned int right_shifted = left_shifted >> (31 - stop_bit + start_bit); |
GaiSensei | 13:bb9669053eb3 | 13 | return right_shifted; |
GaiSensei | 13:bb9669053eb3 | 14 | } |
GaiSensei | 13:bb9669053eb3 | 15 | |
GaiSensei | 14:2f89279586cb | 16 | void write_bits(unsigned int* address_4_bytes, const int start_bit, const int stop_bit, const unsigned int new_value) |
GaiSensei | 13:bb9669053eb3 | 17 | { |
GaiSensei | 13:bb9669053eb3 | 18 | const unsigned int all_4_bytes = *address_4_bytes; |
dupm2216 | 15:b38d9d210e32 | 19 | const unsigned int reserved_bits_mask = get_reserved_bits_mask(address_4_bytes); |
dupm2216 | 15:b38d9d210e32 | 20 | const unsigned int new_bits = utility::update_bits(all_4_bytes, start_bit, stop_bit, reserved_bits_mask, new_value); |
GaiSensei | 13:bb9669053eb3 | 21 | *address_4_bytes = new_bits; |
dupm2216 | 15:b38d9d210e32 | 22 | |
dupm2216 | 15:b38d9d210e32 | 23 | assert(new_value == homemade_mbed::read_bits(address_4_bytes, start_bit, stop_bit)); |
dupm2216 | 15:b38d9d210e32 | 24 | } |
dupm2216 | 15:b38d9d210e32 | 25 | |
dupm2216 | 15:b38d9d210e32 | 26 | unsigned int get_reserved_bits_mask(unsigned int* address_4_bytes) |
dupm2216 | 15:b38d9d210e32 | 27 | { |
dupm2216 | 15:b38d9d210e32 | 28 | switch((unsigned int)address_4_bytes) |
dupm2216 | 15:b38d9d210e32 | 29 | { |
dupm2216 | 15:b38d9d210e32 | 30 | case 0x400FC1C8: return 0x000003FF; |
dupm2216 | 15:b38d9d210e32 | 31 | case 0x400FC0C4: return 0xEFEFF7DE; |
dupm2216 | 15:b38d9d210e32 | 32 | case 0x4000C000: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 33 | case 0x40098000: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 34 | case 0x4009C000: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 35 | case 0x4009800C: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 36 | case 0x4009C00C: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 37 | case 0x4000C00C: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 38 | case 0x400FC088: return 0x07FF7FFF; |
dupm2216 | 15:b38d9d210e32 | 39 | case 0x4000C008: return 0x000003CF; |
dupm2216 | 15:b38d9d210e32 | 40 | case 0x40098008: return 0x000003CF; |
dupm2216 | 15:b38d9d210e32 | 41 | case 0x4007C008: return 0x000000CF; |
dupm2216 | 15:b38d9d210e32 | 42 | default: break; //Unknown address. Should never happen |
dupm2216 | 15:b38d9d210e32 | 43 | } |
dupm2216 | 15:b38d9d210e32 | 44 | |
dupm2216 | 15:b38d9d210e32 | 45 | //Crash |
dupm2216 | 15:b38d9d210e32 | 46 | printf("Unknown address: %d\r\n", (unsigned int)address_4_bytes); |
dupm2216 | 15:b38d9d210e32 | 47 | assert(false); |
dupm2216 | 15:b38d9d210e32 | 48 | return 0xFFFFFFFF; |
GaiSensei | 13:bb9669053eb3 | 49 | } |
GaiSensei | 13:bb9669053eb3 | 50 | } |