Bruno Allaire-Lemay
/
APP1test
df
Fork of APP1 by
HomemadeMbed.cpp@21:a111be2582be, 2017-01-18 (annotated)
- Committer:
- dupm2216
- Date:
- Wed Jan 18 02:38:05 2017 +0000
- Revision:
- 21:a111be2582be
- Parent:
- 16:c77e34bc69bc
Add code header
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dupm2216 | 21:a111be2582be | 1 | ///////////////////////////////////////////////////////////// |
dupm2216 | 21:a111be2582be | 2 | // APP 1: Systèmes à microprocesseurs // |
dupm2216 | 21:a111be2582be | 3 | // // |
dupm2216 | 21:a111be2582be | 4 | // Université de Sherbrooke // |
dupm2216 | 21:a111be2582be | 5 | // Génie informatique // |
dupm2216 | 21:a111be2582be | 6 | // Session 5, Hiver 2017 // |
dupm2216 | 21:a111be2582be | 7 | // // |
dupm2216 | 21:a111be2582be | 8 | // Date: 17 janvier 2017 // |
dupm2216 | 21:a111be2582be | 9 | // // |
dupm2216 | 21:a111be2582be | 10 | // Auteurs: Maxime Dupuis, dupm2216 // |
dupm2216 | 21:a111be2582be | 11 | // Bruno Allaire-Lemay, allb2701 // |
dupm2216 | 21:a111be2582be | 12 | ///////////////////////////////////////////////////////////// |
dupm2216 | 21:a111be2582be | 13 | |
GaiSensei | 13:bb9669053eb3 | 14 | #include "HomemadeMbed.hpp" |
GaiSensei | 13:bb9669053eb3 | 15 | #include "Utility.hpp" |
dupm2216 | 15:b38d9d210e32 | 16 | #include <cassert> |
dupm2216 | 15:b38d9d210e32 | 17 | #include "mbed.h" |
GaiSensei | 13:bb9669053eb3 | 18 | |
GaiSensei | 13:bb9669053eb3 | 19 | namespace homemade_mbed |
GaiSensei | 13:bb9669053eb3 | 20 | { |
GaiSensei | 14:2f89279586cb | 21 | unsigned int read_bits(unsigned int* address_4_bytes, const int start_bit, const int stop_bit) |
GaiSensei | 13:bb9669053eb3 | 22 | { |
GaiSensei | 13:bb9669053eb3 | 23 | const unsigned int all_4_bytes = *address_4_bytes; |
GaiSensei | 13:bb9669053eb3 | 24 | const unsigned int left_shifted = all_4_bytes << (31 - stop_bit); |
GaiSensei | 13:bb9669053eb3 | 25 | const unsigned int right_shifted = left_shifted >> (31 - stop_bit + start_bit); |
GaiSensei | 13:bb9669053eb3 | 26 | return right_shifted; |
GaiSensei | 13:bb9669053eb3 | 27 | } |
GaiSensei | 13:bb9669053eb3 | 28 | |
GaiSensei | 14:2f89279586cb | 29 | void write_bits(unsigned int* address_4_bytes, const int start_bit, const int stop_bit, const unsigned int new_value) |
GaiSensei | 13:bb9669053eb3 | 30 | { |
GaiSensei | 13:bb9669053eb3 | 31 | const unsigned int all_4_bytes = *address_4_bytes; |
dupm2216 | 15:b38d9d210e32 | 32 | const unsigned int reserved_bits_mask = get_reserved_bits_mask(address_4_bytes); |
dupm2216 | 15:b38d9d210e32 | 33 | const unsigned int new_bits = utility::update_bits(all_4_bytes, start_bit, stop_bit, reserved_bits_mask, new_value); |
GaiSensei | 13:bb9669053eb3 | 34 | *address_4_bytes = new_bits; |
dupm2216 | 15:b38d9d210e32 | 35 | |
dupm2216 | 15:b38d9d210e32 | 36 | assert(new_value == homemade_mbed::read_bits(address_4_bytes, start_bit, stop_bit)); |
dupm2216 | 15:b38d9d210e32 | 37 | } |
dupm2216 | 15:b38d9d210e32 | 38 | |
dupm2216 | 15:b38d9d210e32 | 39 | unsigned int get_reserved_bits_mask(unsigned int* address_4_bytes) |
dupm2216 | 15:b38d9d210e32 | 40 | { |
dupm2216 | 15:b38d9d210e32 | 41 | switch((unsigned int)address_4_bytes) |
dupm2216 | 15:b38d9d210e32 | 42 | { |
dupm2216 | 15:b38d9d210e32 | 43 | case 0x400FC1C8: return 0x000003FF; |
dupm2216 | 15:b38d9d210e32 | 44 | case 0x400FC0C4: return 0xEFEFF7DE; |
dupm2216 | 15:b38d9d210e32 | 45 | case 0x4000C000: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 46 | case 0x40098000: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 47 | case 0x4009C000: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 48 | case 0x4009800C: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 49 | case 0x4009C00C: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 50 | case 0x4000C00C: return 0x000000FF; |
dupm2216 | 15:b38d9d210e32 | 51 | case 0x400FC088: return 0x07FF7FFF; |
dupm2216 | 15:b38d9d210e32 | 52 | case 0x4000C008: return 0x000003CF; |
dupm2216 | 15:b38d9d210e32 | 53 | case 0x40098008: return 0x000003CF; |
dupm2216 | 15:b38d9d210e32 | 54 | case 0x4007C008: return 0x000000CF; |
dupm2216 | 16:c77e34bc69bc | 55 | case 0x4001000C: return 0x000000FF; |
dupm2216 | 16:c77e34bc69bc | 56 | case 0x40010000: return 0x000000FF; |
dupm2216 | 16:c77e34bc69bc | 57 | case 0x40010004: return 0x000000FF; |
dupm2216 | 16:c77e34bc69bc | 58 | case 0x400FC1A8: return 0xFFF3F3FF; |
dupm2216 | 16:c77e34bc69bc | 59 | case 0x40010008: return 0x000000CF; |
dupm2216 | 16:c77e34bc69bc | 60 | case 0x4002C000: return 0xFFFFFFFF; |
dupm2216 | 15:b38d9d210e32 | 61 | default: break; //Unknown address. Should never happen |
dupm2216 | 15:b38d9d210e32 | 62 | } |
dupm2216 | 15:b38d9d210e32 | 63 | |
dupm2216 | 15:b38d9d210e32 | 64 | //Crash |
dupm2216 | 15:b38d9d210e32 | 65 | printf("Unknown address: %d\r\n", (unsigned int)address_4_bytes); |
dupm2216 | 16:c77e34bc69bc | 66 | utility::blink(); |
dupm2216 | 16:c77e34bc69bc | 67 | return 0x00000000; |
GaiSensei | 13:bb9669053eb3 | 68 | } |
GaiSensei | 13:bb9669053eb3 | 69 | } |