In-system programming tool for LPC microcontrollers
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.

chips.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright 2017 Clayton G. Hobbs
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Chips supported by Alpaca ISP"""
  15. from collections import namedtuple
  16. from alpaca_isp.lpc import LPC8xx
  17. class Chip(namedtuple("Chip", [
  18. # Name of the chip
  19. "name",
  20. # Class that represents this chip
  21. "family",
  22. # Size of flash in KiB
  23. "flash",
  24. # Size of RAM in KiB
  25. "ram",
  26. # Address of the start of RAM
  27. "ram_start",
  28. # RAM location to which we can safely write
  29. "ram_base",
  30. # Maximum number of bytes we can copy
  31. "max_copy",
  32. # Sector table
  33. "sectors"])):
  34. __slots__ = ()
  35. def sectors_used(self, segments):
  36. """Returns a list of sectors used by the given memory segments
  37. segments: a list of (start, end) tuples representing segments of used
  38. memory
  39. """
  40. sector_segments = []
  41. for i in range(len(self.sectors)):
  42. sector_segments.append((sum(self.sectors[:i]),
  43. sum(self.sectors[:i+1])))
  44. s = set()
  45. for dseg in segments:
  46. for i, sseg in enumerate(sector_segments):
  47. if ((dseg[0] >= sseg[0] and dseg[1] <= sseg[1])
  48. or (dseg[0] < sseg[0] and dseg[1] > sseg[1])
  49. or (sseg[0] <= dseg[0] < sseg[1])
  50. or (sseg[0] < dseg[1] <= sseg[1])):
  51. s.add(i)
  52. return sorted(s)
  53. chips = {
  54. 0x00008221: Chip(
  55. name="LPC822M101JHI33",
  56. family=LPC8xx,
  57. flash=16,
  58. ram=4,
  59. ram_start=0x10000000,
  60. ram_base=0x10000300,
  61. max_copy=1024,
  62. sectors=(1024,)*16),
  63. 0x00008222: Chip(
  64. name="LPC822M101JDH20",
  65. family=LPC8xx,
  66. flash=16,
  67. ram=4,
  68. ram_start=0x10000000,
  69. ram_base=0x10000300,
  70. max_copy=1024,
  71. sectors=(1024,)*16),
  72. 0x00008241: Chip(
  73. name="LPC824M201JHI33",
  74. family=LPC8xx,
  75. flash=32,
  76. ram=8,
  77. ram_start=0x10000000,
  78. ram_base=0x10000300,
  79. max_copy=1024,
  80. sectors=(1024,)*32),
  81. 0x00008242: Chip(
  82. name="LPC824M201JDH20",
  83. family=LPC8xx,
  84. flash=32,
  85. ram=8,
  86. ram_start=0x10000000,
  87. ram_base=0x10000300,
  88. max_copy=1024,
  89. sectors=(1024,)*32)
  90. }