flash.s 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ; Copyright (C) 2002-2004 by egnite Software GmbH. All rights reserved.
  2. ;
  3. ; Redistribution and use in source and binary forms, with or without
  4. ; modification, are permitted provided that the following conditions
  5. ; are met:
  6. ;
  7. ; 1. Redistributions of source code must retain the above copyright
  8. ; notice, this list of conditions and the following disclaimer.
  9. ; 2. Redistributions in binary form must reproduce the above copyright
  10. ; notice, this list of conditions and the following disclaimer in the
  11. ; documentation and/or other materials provided with the distribution.
  12. ; 3. All advertising materials mentioning features or use of this
  13. ; software must display the following acknowledgement:
  14. ;
  15. ; This product includes software developed by egnite Software GmbH
  16. ; and its contributors.
  17. ;
  18. ; THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  19. ; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. ; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  22. ; SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  24. ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  25. ; OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  26. ; AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. ; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  28. ; THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. ; SUCH DAMAGE.
  30. ;
  31. ; For additional information see http://www.ethernut.de/
  32. ;
  33. ;
  34. ; This file has its orgin in following sources:
  35. ;
  36. ; - Jaroslaw Karwik's RS232 boot loader
  37. ; - Atmel's AVR109 application note "Self programming" ( www.atmel.com )
  38. ; - Andy's Hutchinson modifications/optimizations of the original Atmel's code
  39. ; - Bryce Denney's patches ( bryce@tlw.com)
  40. ;
  41. ;
  42. ; $Log$
  43. ; Revision 1.3 2007/11/15 01:36:56 hwmaier
  44. ; Uses avr/io.h include file for register definitions so it works for ATmega128, AT90CAN128 and AT90CAN128
  45. ;
  46. ; Revision 1.2 2007/07/30 09:47:55 olereinhardt
  47. ; ATMega2561 port. Makedefs need to be modifies by hand (uncomment LDFLAGS
  48. ; line and comment out LDFLAGS for mega128
  49. ;
  50. ; Revision 1.1 2004/04/15 10:42:39 haraldkipp
  51. ; Checked in
  52. ;
  53. ;
  54. #include <avr/io.h>
  55. .global SpmBufferFill
  56. .global SpmCommand
  57. SpmCommand:
  58. movw r30, r24 ; First argument is page address
  59. rjmp DoSpm
  60. SpmBufferFill:
  61. movw r30, r24 ; First argument is page address
  62. movw r0, r22 ; Second argument is data pointer
  63. ldi r22, 1 ; SPMEN bit
  64. DoSpm:
  65. #if defined(__AVR_ATmega2561__)
  66. out SPMCSR, r22 ; Store function in SPMCR
  67. #else
  68. sts SPMCSR, r22 ; Store function in SPMCR
  69. #endif
  70. spm ; store program memory
  71. WaitSpm:
  72. #if defined(__AVR_ATmega2561__)
  73. in r22, SPMCSR ; Loop until SPMEN in SPMCR is cleared
  74. #else
  75. lds r22, SPMCSR ; Loop until SPMEN in SPMCR is cleared
  76. #endif
  77. sbrc r22, 0
  78. rjmp WaitSpm
  79. clr r1 ; Compiler depends on R1 set to zero.
  80. ret