Add C28x RS boot ports for F2812 and F28335
This commit is contained in:
4
c/rs485-boot/ports/tms320f2812/README.md
Normal file
4
c/rs485-boot/ports/tms320f2812/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# TMS320F2812
|
||||
BALZAM adapter using the common C28x transport, existing `RS485` helpers and
|
||||
`flash_tools`. BEGIN byte 8 bit 0 mirrors blocks to RAM while Flash remains the
|
||||
persistent recovery source.
|
||||
99
c/rs485-boot/ports/tms320f2812/rs_boot_port_f2812.c
Normal file
99
c/rs485-boot/ports/tms320f2812/rs_boot_port_f2812.c
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "DSP281x_Device.h"
|
||||
#include "RS485.h"
|
||||
#include "flash_tools.h"
|
||||
#include "rs_boot_port_f2812.h"
|
||||
|
||||
static rsbt_t boot;
|
||||
|
||||
/* Sector sizes of the external flash, in 16-bit words. */
|
||||
static const unsigned long sectors[] = {
|
||||
0x8000UL,0x8000UL,0x8000UL,0x8000UL,0x8000UL,0x8000UL,0x8000UL,
|
||||
0x8000UL,0x8000UL,0x8000UL,0x8000UL,0x8000UL,0x8000UL,0x8000UL,
|
||||
0x4000UL,0x1000UL,0x1000UL,0x2000UL
|
||||
};
|
||||
|
||||
static int port_tx(void *user, const rsbt_byte_t *data, rsbt_u16_t length)
|
||||
{
|
||||
rsbt_u16_t i; (void)user;
|
||||
RS_Line_to_send(COM_1); RS_SetBitMode(&rs_a,8);
|
||||
for(i=0U;i<length;++i){SCIa_Wait4OK();SCIa_send(data[i]&0xFFU);}
|
||||
SCIa_Wait4OK(); RS_SetBitMode(&rs_a,9); RS_Line_to_receive(COM_1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int port_erase(void *user, rsbt_u32_t image_size)
|
||||
{
|
||||
unsigned int i; unsigned long at=0UL, words=(image_size+1UL)/2UL;
|
||||
(void)user;
|
||||
if(!image_size || words>F2812_BOOT_FLASH_WORDS)return 0;
|
||||
for(i=0U;i<(sizeof(sectors)/sizeof(sectors[0])) && at<words;++i){
|
||||
if(flash_erase_sector(at))return 0; /* legacy API: zero means success */
|
||||
at+=sectors[i];
|
||||
}
|
||||
return at>=words;
|
||||
}
|
||||
|
||||
static int port_write(void *user, rsbt_u32_t offset,
|
||||
const rsbt_byte_t *data, rsbt_u16_t length)
|
||||
{
|
||||
rsbt_u16_t i=0U,word; unsigned long address;
|
||||
(void)user;
|
||||
if(offset+length>F2812_BOOT_APP_BYTES)return 0;
|
||||
address=offset/2UL;
|
||||
if(offset&1UL){
|
||||
word=flash_read_word(address);word=(word&0xFF00U)|(data[0]&0xFFU);
|
||||
if(!flash_write_word(address,word))return 0;++address;++i;
|
||||
}
|
||||
while(i<length){
|
||||
word=(data[i]&0xFFU)<<8;
|
||||
if(i+1U<length)word|=data[i+1U]&0xFFU;else word|=0x00FFU;
|
||||
if(!flash_write_word(address++,word))return 0;i+=2U;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int port_read(void *user, rsbt_u32_t offset,
|
||||
rsbt_byte_t *data, rsbt_u16_t length)
|
||||
{
|
||||
rsbt_u16_t i,word; (void)user;
|
||||
if(offset+length>F2812_BOOT_APP_BYTES)return 0;
|
||||
for(i=0U;i<length;++i){word=flash_read_word((offset+i)/2UL);
|
||||
data[i]=((offset+i)&1UL)?(word&0xFFU):((word>>8)&0xFFU);}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int port_write_ram(void *user, rsbt_u32_t offset,
|
||||
const rsbt_byte_t *data, rsbt_u16_t length)
|
||||
{
|
||||
rsbt_u16_t i,word; volatile unsigned int *ram;
|
||||
(void)user;
|
||||
if(offset+length>F2812_BOOT_RAM_WORDS*2UL)return 0;
|
||||
ram=(volatile unsigned int *)(F2812_BOOT_RAM_ADDRESS+offset/2UL);
|
||||
if(offset&1UL){word=*ram;*ram++=(word&0xFF00U)|(data[0]&0xFFU);i=1U;}else i=0U;
|
||||
while(i<length){word=(data[i]&0xFFU)<<8;
|
||||
if(i+1U<length)word|=data[i+1U]&0xFFU;else word|=0x00FFU;
|
||||
*ram++=word;i+=2U;}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int port_valid(void *user, rsbt_u32_t size, rsbt_u32_t expected)
|
||||
{
|
||||
rsbt_byte_t block[32]; rsbt_u32_t crc=0xFFFFFFFFUL,off; rsbt_u16_t i,n,bit;
|
||||
(void)user;
|
||||
for(off=0UL;off<size;off+=32UL){n=(rsbt_u16_t)(size-off);if(n>32U)n=32U;
|
||||
if(!port_read(0,off,block,n))return 0;
|
||||
for(i=0U;i<n;++i){crc^=block[i]&0xFFU;for(bit=0U;bit<8U;++bit)crc=(crc>>1)^((crc&1U)?0xEDB88320UL:0U);}}
|
||||
return (crc^0xFFFFFFFFUL)==expected;
|
||||
}
|
||||
|
||||
void BalzamBoot_Init(void)
|
||||
{
|
||||
rsbt_config_t c; rsbt_port_t p;
|
||||
c.app_address=F2812_BOOT_APP_ADDRESS;c.app_size=F2812_BOOT_APP_BYTES;c.max_block=RSBT_MAX_BLOCK;
|
||||
p.transmit=port_tx;p.erase=port_erase;p.write=port_write;p.read=port_read;
|
||||
p.write_ram=port_write_ram;p.image_valid=port_valid;p.reboot=0;
|
||||
init_flash();(void)rsbt_init(&boot,&c,&p,0);
|
||||
}
|
||||
|
||||
void BalzamBoot_FeedByte(unsigned int wire_byte){rsbt_feed(&boot,wire_byte&0xFFU);}
|
||||
rsbt_state_t BalzamBoot_State(void){return boot.state;}
|
||||
17
c/rs485-boot/ports/tms320f2812/rs_boot_port_f2812.h
Normal file
17
c/rs485-boot/ports/tms320f2812/rs_boot_port_f2812.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef RS_BOOT_PORT_F2812_H
|
||||
#define RS_BOOT_PORT_F2812_H
|
||||
|
||||
#include "rs_boot_transport.h"
|
||||
|
||||
/* External AM29-style flash is word-addressed by flash_tools.c. */
|
||||
#define F2812_BOOT_APP_ADDRESS 0x00100000UL
|
||||
#define F2812_BOOT_FLASH_WORDS 0x00078000UL
|
||||
#define F2812_BOOT_APP_BYTES (F2812_BOOT_FLASH_WORDS * 2UL)
|
||||
#define F2812_BOOT_RAM_ADDRESS 0x00080000UL
|
||||
#define F2812_BOOT_RAM_WORDS 0x00078000UL
|
||||
|
||||
void BalzamBoot_Init(void);
|
||||
void BalzamBoot_FeedByte(unsigned int wire_byte);
|
||||
rsbt_state_t BalzamBoot_State(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user