Project

General

Profile

Revision 6030b995

ID6030b99531025d5cf606ececd5a8598343384864
Parent 3a25bcb9
Child 89f527ad

Added by Aaron Perley about 10 years ago

Bootloader code test

View differences:

scout_avr/bom/bootloader.c
3 3
#include <avr/pgmspace.h>
4 4
#include "tiny-twi-sync.h"
5 5

  
6
uint32_t current_page;
7

  
6 8
void boot_program_page (uint32_t page, uint8_t *buf)
7 9
{
8 10
  uint16_t i;
......
21 23
  for (i=0; i<SPM_PAGESIZE; i+=2)
22 24
  {
23 25
    // Set up little-endian word.
24

  
25 26
    uint16_t w = *buf++;
26 27
    w += (*buf++) << 8;
27 28

  
......
41 42
  SREG = sreg;
42 43
}
43 44

  
45
static void bom_pgrm(uint8_t *buf, int len) {
46
  if (len == SPM_PAGESIZE) {
47
    if (current_page == 0) {
48
      uint16_t w = 0xC000 | ((START_ADDR >> 1) - 1);
49
      buf[0] = w & 0xFF;
50
      buf[1] = (w >> 16) & 0xFF;
51
    }
52
    boot_program_page(current_page, buf);
53
    current_page++;
54
  }
55
}
56

  
57
static void slave_rx(uint8_t *buf, int len) {
58
  if (len > 1) {
59
    switch (buf[0]) {
60
      case BOM_I2C_PGRM:
61
        bom_pgrm(buf+1, len-1);
62
        break;
63
      case BOM_I2C_STRT:
64
        strt_pgrm(); //yolo
65
        break;
66
    }
67
  }
68
}
69

  
70

  
71

  
72

  
44 73
int main() {
45 74
  return 0;
46 75
}
scout_avr/bom/bootloader.h
1 1
#ifndef BOOTLOADER_H
2 2
#define BOOTLOADER_H
3 3

  
4
#define BOM_I2C_PGRM 30
5
#define BOM_I2C_STRT 31
6
#define START_ADDR 0xA00
7

  
8
#define strt_pgrm ((void (*)(void)) _VECTORS_SIZE)
9

  
4 10
void boot_program_page (uint32_t page, uint8_t *buf);
5 11

  
6 12
#endif

Also available in: Unified diff