; ***************************************************************************
; Source file for base system node on AtMega 8515
;
; This is for the maintenance system (i.e. the flash loader).
;
; All definitions and changes should go into this file.
; ***************************************************************************

.equ clock=8000000 ; Define the clock frequency

.nolist
.include "include/m8515def.inc" ; Define device ATmega8515
.list

.include "../defs.asm"
.include "devices/all/defs.asm"

.include "common/calls.asm"
.include "common/utils_wait.asm"
.include "common/utils_io.asm"



; ***************************************************************************
; defines

; ---------------------------------------------------------------------------
; generic


.equ NET_BUFFERS_NUM            = 6
.equ NET_BUFFERS_SIZE           = 32



; ---------------------------------------------------------------------------
; firmware settings

.equ FIRMWARE_VERSION_MAJOR       = 0
.equ FIRMWARE_VERSION_MINOR       = 0
.equ FIRMWARE_VERSION_PATCHLEVEL  = 1



; ---------------------------------------------------------------------------
; LED

.equ LED_DDR             = DDRE
.equ LED_PORT            = PORTE
.equ LED_PIN             = PINE
.equ LED_PINNUM          = PORTE2





; ***************************************************************************
; code segment

.cseg
.org 0x0000



; ---------------------------------------------------------------------------
; Reset and interrupt vectors
  rjmp main ;  1: Reset vector   RESET
  reti      ;  2: INT0           External Interrupt Request 0
  reti      ;  3: INT1           External Interrupt Request 1
  reti      ;  4: TIMER1_CAPT    Timer/Counter1 Capture Event
  reti      ;  5: TIMER1_COMPA   Timer/Counter1 Compare Match A
  reti      ;  6: TIMER1_COMPB   Timer/Counter1 Compare Match B
  reti      ;  7: TIMER1_OVF     Timer/Counter1 Overflow
  reti      ;  8: TIMER0_OVF     Timer/Counter0 Overflow
  reti      ;  9: SPI_STC        Serial Transfer Complete
  reti      ; 10: USART_RXC      USART Rx Complete
  reti      ; 11: USART_UDRE     USART Data Register Empty
  reti      ; 12: USART_TXC      USART Tx Complete
  reti      ; 13: ANA_COMP       Analog Comparator
  reti      ; 14: INT2           External Interrupt Request 2
  reti      ; 15: TIMER0_COMP    Timer/Counter0 Compare Match
  reti      ; 16: EE_RDY         EEPROM Ready
  reti      ; 17: SPM_RDY        Store Program Memory Ready



; ---------------------------------------------------------------------------
; Device Info Block

devInfoBlock:        ; 12 bytes
devInfoManufacturer: .db 'A', 'Q', 'U', 'A'
devInfoId:           .db DEVICEINFO_ID, 0
devInfoVersion:      .db DEVICEINFO_VERSION, DEVICEINFO_REVISION             ; version, revision
firmwareVersion:     .db FIRMWARE_VARIANT_BOOT, FIRMWARE_VERSION_MAJOR
                     .db FIRMWARE_VERSION_MINOR, FIRMWARE_VERSION_PATCHLEVEL

firmwareStart:
  rjmp main       ; will be overwritten when flashing



; ***************************************************************************
; main code


.org BOOTLOADER_ADDR


main:
  ldi r16, 0xb0   ; orig: a0
  out OSCCAL, r16
  rjmp bootLoader ; this routine is in modules/bootloader/main.asm



; ***************************************************************************
; includes

.include "common/wait_10us.asm"
.include "common/utils_copy_from_flash.asm"
.include "common/utils_copy_sdram.asm"

.include "modules/flash/defs.asm"
.include "modules/flash/eeprom.asm"
.include "modules/flash/io.asm"
;.include "modules/flash/io_attn.asm"
.include "modules/flash/io_uart.asm"
;.include "modules/flash/io_uart_all_attn.asm"

.include "modules/flash/io_uart_attn_small.asm"

.include "modules/flash/flash1pmega.asm"
.include "modules/flash/flashxp.asm"
.include "modules/flash/flashprocess.asm"
.include "modules/flash/wait.asm"
.include "modules/bootloader/main.asm"
.include "modules/network/msg/defs.asm"
.include "modules/network/msg/crc.asm"

;.include "common/debug.asm"



systemSetSpeed:
  ; speed not changeable at runtime on this device
  ret




