AVR ISP adapter (avr109/910 compatible, using ATmega16)
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.

115 lines
5.0 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2006 - 2020 by Olaf Rempel *
  3. * razzor AT kopf MINUS tisch DOT 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 <avr/pgmspace.h>
  20. #include <string.h>
  21. #include "avrdevice.h"
  22. /* *********************************************************************** */
  23. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
  24. /* *********************************************************************** */
  25. static const avr_device_t devices[] PROGMEM = {
  26. { "at90s1200", { 0x1E, 0x90, 0x01 }, 0x13, 0x00, POLL_00 | POLL_FF },
  27. { "at90s2313", { 0x1E, 0x91, 0x01 }, 0x20, 0x00, POLL_7F | POLL_80 | POLL_FF },
  28. { "tiny25", { 0x1E, 0x91, 0x08 }, 0x20, 0x0F, POLL_FF }, /* at90s2313 devcode */
  29. { "tiny26", { 0x1E, 0x91, 0x09 }, 0x5E, 0x0F, POLL_FF },
  30. { "tiny2313", { 0x1E, 0x91, 0x0A }, 0x5E, 0x0F, POLL_FF }, /* tiny26 devcode */
  31. { "tiny24", { 0x1E, 0x91, 0x0B }, 0x20, 0x0F, POLL_FF }, /* at90s2313 devcode */
  32. { "tiny45", { 0x1E, 0x92, 0x06 }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
  33. { "tiny44", { 0x1E, 0x92, 0x07 }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
  34. { "at90s8515", { 0x1E, 0x93, 0x01 }, 0x38, 0x00, POLL_7F | POLL_80 | POLL_FF },
  35. { "mega8", { 0x1E, 0x93, 0x07 }, 0x76, 0x1F, POLL_FF },
  36. { "mega88", { 0x1E, 0x93, 0x0A }, 0xFF, 0x1F, POLL_FF },
  37. { "tiny85", { 0x1E, 0x93, 0x0B }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
  38. { "tiny84", { 0x1E, 0x93, 0x0C }, 0x20, 0x1F, POLL_FF }, /* at90s2313 devcode */
  39. { "mega16", { 0x1E, 0x94, 0x03 }, 0x74, 0x3F, POLL_FF },
  40. { "mega168", { 0x1E, 0x94, 0x06 }, 0xFF, 0x3F, POLL_FF },
  41. { "mega32", { 0x1E, 0x95, 0x02 }, 0x72, 0x3F, POLL_FF },
  42. { "mega328p", { 0x1E, 0x95, 0x0F }, 0xFF, 0x3F, POLL_FF },
  43. { "mega32u4", { 0x1E, 0x95, 0x87 }, 0xFF, 0x3F, POLL_FF },
  44. { "mega32u2", { 0x1E, 0x95, 0x8A }, 0xFF, 0x3F, POLL_FF },
  45. { "mega64", { 0x1E, 0x96, 0x02 }, 0x45, 0x7F, POLL_FF },
  46. { "mega644a", { 0x1E, 0x96, 0x09 }, 0x74, 0x7F, POLL_FF }, /* mega16 devcode */
  47. { "mega644p", { 0x1E, 0x96, 0x0A }, 0x74, 0x7F, POLL_FF }, /* mega16 devcode */
  48. { "mega103", { 0x1E, 0x97, 0x01 }, 0x41, 0x7F, POLL_7F | POLL_80 | POLL_FF },
  49. { "mega128", { 0x1E, 0x97, 0x02 }, 0x43, 0x7F, POLL_FF },
  50. };
  51. /* ***********************************************************************
  52. * avrdevice_iterate_devcodes
  53. * *********************************************************************** */
  54. void avrdevice_iterate_devcodes(avrdevice_callback_t callback)
  55. {
  56. uint8_t limit = 0x00;
  57. while (1)
  58. {
  59. uint8_t i;
  60. uint8_t search = 0xFF;
  61. for (i = 0; i < ARRAY_SIZE(devices); i++)
  62. {
  63. uint8_t devcode = pgm_read_byte(&devices[i].devcode);
  64. if ((devcode > limit) && (devcode < search))
  65. {
  66. search = devcode;
  67. }
  68. }
  69. if (search == 0xFF)
  70. {
  71. break;
  72. }
  73. callback(search);
  74. limit = search;
  75. }
  76. } /* avrdevice_iterate_devcodes */
  77. /* ***********************************************************************
  78. * avrdevice_get_by_signature
  79. * *********************************************************************** */
  80. void avrdevice_get_by_signature(avr_device_t * p_device,
  81. const uint8_t * p_signature)
  82. {
  83. uint8_t i;
  84. for (i = 0; i < ARRAY_SIZE(devices); i++)
  85. {
  86. if (memcmp_P(p_signature, devices[i].sig, sizeof(p_device->sig)) == 0)
  87. {
  88. memcpy_P(p_device, &devices[i], sizeof(avr_device_t));
  89. break;
  90. }
  91. }
  92. } /* avrdevice_get_by_signature */