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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. @property
  36. def sector_segments(self):
  37. """Returns a list of (start, end) tuples for each flash sector"""
  38. sector_segments = []
  39. for i in range(len(self.sectors)):
  40. sector_segments.append((sum(self.sectors[:i]),
  41. sum(self.sectors[:i+1])))
  42. return sector_segments
  43. def sectors_used(self, segments):
  44. """Returns a list of sectors used by the given memory segments
  45. segments: a list of (start, end) tuples representing segments of used
  46. memory
  47. """
  48. sector_segments = self.sector_segments
  49. s = set()
  50. for dseg in segments:
  51. for i, sseg in enumerate(sector_segments):
  52. if ((dseg[0] >= sseg[0] and dseg[1] <= sseg[1])
  53. or (dseg[0] < sseg[0] and dseg[1] > sseg[1])
  54. or (sseg[0] <= dseg[0] < sseg[1])
  55. or (sseg[0] < dseg[1] <= sseg[1])):
  56. s.add(i)
  57. return sorted(s)
  58. chips = {
  59. 0x00008221: Chip(
  60. name="LPC822M101JHI33",
  61. family=LPC8xx,
  62. flash=16,
  63. ram=4,
  64. ram_start=0x10000000,
  65. ram_base=0x10000300,
  66. max_copy=1024,
  67. sectors=(1024,)*16),
  68. 0x00008222: Chip(
  69. name="LPC822M101JDH20",
  70. family=LPC8xx,
  71. flash=16,
  72. ram=4,
  73. ram_start=0x10000000,
  74. ram_base=0x10000300,
  75. max_copy=1024,
  76. sectors=(1024,)*16),
  77. 0x00008241: Chip(
  78. name="LPC824M201JHI33",
  79. family=LPC8xx,
  80. flash=32,
  81. ram=8,
  82. ram_start=0x10000000,
  83. ram_base=0x10000300,
  84. max_copy=1024,
  85. sectors=(1024,)*32),
  86. 0x00008242: Chip(
  87. name="LPC824M201JDH20",
  88. family=LPC8xx,
  89. flash=32,
  90. ram=8,
  91. ram_start=0x10000000,
  92. ram_base=0x10000300,
  93. max_copy=1024,
  94. sectors=(1024,)*32)
  95. }