Blame view

include/bcd.h 548 Bytes
758c037ae   Stefan Roese   rtc: Add Xicor/In...
1
2
3
4
  /* Permission is hereby granted to copy, modify and redistribute this code
   * in terms of the GNU Library General Public License, Version 2 or later,
   * at your option.
   */
e84aba135   Albin Tonnerre   Replace BCD2BIN a...
5
6
  /* inline functions to translate to/from binary and binary-coded decimal
   * (frequently found in RTC chips).
758c037ae   Stefan Roese   rtc: Add Xicor/In...
7
8
9
10
   */
  
  #ifndef _BCD_H
  #define _BCD_H
be47aa652   Simon Glass   dm: Remove unnece...
11
  static inline unsigned int bcd2bin(unsigned int val)
e84aba135   Albin Tonnerre   Replace BCD2BIN a...
12
  {
be47aa652   Simon Glass   dm: Remove unnece...
13
  	return ((val) & 0x0f) + ((val & 0xff) >> 4) * 10;
e84aba135   Albin Tonnerre   Replace BCD2BIN a...
14
  }
be47aa652   Simon Glass   dm: Remove unnece...
15
  static inline unsigned int bin2bcd(unsigned int val)
e84aba135   Albin Tonnerre   Replace BCD2BIN a...
16
17
18
  {
  	return (((val / 10) << 4) | (val % 10));
  }
758c037ae   Stefan Roese   rtc: Add Xicor/In...
19
20
  
  #endif /* _BCD_H */