utils.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* sd2iec - SD/MMC to Commodore serial bus interface/controller
  2. Copyright (C) 2007-2009 Ingo Korb <ingo@akana.de>
  3. Inspiration and low-level SD/MMC access based on code from MMC2IEC
  4. by Lars Pontoppidan et al., see sdcard.c|h and config.h.
  5. FAT filesystem access based on code from ChaN and Jim Brain, see ff.c|h.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; version 2 of the License only.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. utils.c: Misc. utility functions that didn't fit elsewhere
  17. */
  18. #ifndef UTILS_H
  19. #define UTILS_H
  20. /* Side-effect safe min/max */
  21. #define max(a,b) \
  22. ({ typeof (a) _a = (a); \
  23. typeof (b) _b = (b); \
  24. _a > _b ? _a : _b; })
  25. #define min(a,b) \
  26. ({ typeof (a) _a = (a); \
  27. typeof (b) _b = (b); \
  28. _a < _b ? _a : _b; })
  29. /* Write a number to a string as ASCII */
  30. uint8_t *appendnumber(uint8_t *msg, uint8_t value);
  31. /* Convert between integer and BCD */
  32. uint8_t bcd2int(uint8_t value);
  33. uint8_t int2bcd(uint8_t value);
  34. /* Tokenize a string like strtok_r, but with a single delimiter character only */
  35. uint8_t *ustr1tok(uint8_t *str, const uint8_t delim, uint8_t **saveptr);
  36. #endif