df

Dependencies:   mbed

Fork of APP1 by Team APP

Committer:
dupm2216
Date:
Tue Jan 17 06:01:05 2017 +0000
Revision:
16:c77e34bc69bc
Parent:
15:b38d9d210e32
Child:
21:a111be2582be
Fix everything; ; - Change UART0 (USB) to UART1 (pin 13); - Add the pin select instructions; - Reintroduced the tests run; - Reintegrate with the accelerometer

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"
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 16:c77e34bc69bc 42 case 0x4001000C: return 0x000000FF;
dupm2216 16:c77e34bc69bc 43 case 0x40010000: return 0x000000FF;
dupm2216 16:c77e34bc69bc 44 case 0x40010004: return 0x000000FF;
dupm2216 16:c77e34bc69bc 45 case 0x400FC1A8: return 0xFFF3F3FF;
dupm2216 16:c77e34bc69bc 46 case 0x40010008: return 0x000000CF;
dupm2216 16:c77e34bc69bc 47 case 0x4002C000: return 0xFFFFFFFF;
dupm2216 15:b38d9d210e32 48 default: break; //Unknown address. Should never happen
dupm2216 15:b38d9d210e32 49 }
dupm2216 15:b38d9d210e32 50
dupm2216 15:b38d9d210e32 51 //Crash
dupm2216 15:b38d9d210e32 52 printf("Unknown address: %d\r\n", (unsigned int)address_4_bytes);
dupm2216 16:c77e34bc69bc 53 utility::blink();
dupm2216 16:c77e34bc69bc 54 return 0x00000000;
GaiSensei 13:bb9669053eb3 55 }
GaiSensei 13:bb9669053eb3 56 }