You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.8 KiB

  1. /***************************************************************************
  2. * Copyright (C) 10/2010 by Olaf Rempel *
  3. * razzor@kopf-tisch.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; version 2 of the License, *
  8. * *
  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. * *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program; if not, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. ***************************************************************************/
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <unistd.h>
  22. #include <string.h>
  23. #include <stdint.h>
  24. #include "chipinfo_avr.h"
  25. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
  26. static avr_chipinfo_t chips[] =
  27. {
  28. { { 0x1E, 0x93, 0x07 }, "ATmega8", 0x2000, 0x200 },
  29. { { 0x1E, 0x93, 0x0A }, "ATmega88", 0x2000, 0x200 },
  30. { { 0x1E, 0x94, 0x06 }, "ATmega168", 0x4000, 0x200 },
  31. { { 0x1E, 0x95, 0x02 }, "ATmega32", 0x8000, 0x400 },
  32. { { 0x1E, 0x95, 0x0F }, "ATmega328p", 0x8000, 0x400 },
  33. };
  34. /* *************************************************************************
  35. * chipinfo_get_by_signature
  36. * ************************************************************************* */
  37. const avr_chipinfo_t * chipinfo_get_by_signature(const uint8_t *sig)
  38. {
  39. unsigned int i;
  40. for (i = 0; i < ARRAY_SIZE(chips); i++)
  41. {
  42. avr_chipinfo_t *chip = &chips[i];
  43. if ((chip->sig[0] == sig[0]) &&
  44. (chip->sig[1] == sig[1]) &&
  45. (chip->sig[2] == sig[2])
  46. )
  47. {
  48. return chip;
  49. }
  50. }
  51. return NULL;
  52. } /* chipinfo_get_by_signature */
  53. /* *************************************************************************
  54. * chipinfo_get_avr_name
  55. * ************************************************************************* */
  56. const char * chipinfo_get_avr_name(const uint8_t *sig)
  57. {
  58. const avr_chipinfo_t * p_chipinfo;
  59. p_chipinfo = chipinfo_get_by_signature(sig);
  60. return (p_chipinfo != NULL) ? p_chipinfo->name : "unknown";
  61. } /* chipinfo_get_avr_name */