X-Git-Url: https://robinkrens.nl/gitweb/?p=cortex-from-scratch;a=blobdiff_plain;f=lib%2Fregfunc.c;h=b783901249c5ffba66906a5d21d565be266e6db7;hp=6add22082eeb70fcc6b52c8c795699a5a4ebd324;hb=094f4defd7ee3b672f9c690f57125893a64901c8;hpb=d35408aabe7ea757d406bf8a7dba669ee8736bd5 diff --git a/lib/regfunc.c b/lib/regfunc.c index 6add220..b783901 100644 --- a/lib/regfunc.c +++ b/lib/regfunc.c @@ -40,8 +40,7 @@ void regw_u32(volatile uint32_t * reg, uint32_t val, short shift, short flag) { } /* Print out the hexidecimal representation of an integer - After implementation of a printf function, this code - will be obsolete. */ + After implementation of scanf or sth this will be obsolete. */ char hexbuf[8]; char * regtohex(uint32_t addr) { @@ -62,3 +61,28 @@ char * regtohex(uint32_t addr) { } return &hexbuf[0]; } +int singlehextoreg(char hex) { + + int conv = 0; + if (hex >= 'A' && hex <= 'F') + conv = hex - '7'; + + else { + conv = hex - '0'; + } + return conv; + +} + +uint32_t hextoreg(char * a) { + + uint32_t x = 0; + int tmp; + for(int i = 0; i < 8; i++) { + tmp = singlehextoreg(*a++); + x += tmp << (28 - (i * 4)); + } + return x; + +} +