cleanup up and remove huffman stuff

This commit is contained in:
David Voswinkel 2009-08-04 08:38:26 +02:00
parent 92762d7f51
commit af45ed720b
10 changed files with 2165 additions and 2300 deletions

View File

@ -30,7 +30,7 @@ SIZE = avr-size
ifeq ($(DEBUG),1) ifeq ($(DEBUG),1)
LDFLAGS = -Wl,-u,vfprintf -lprintf_flt LDFLAGS = -Wl,-u,vfprintf -lprintf_flt
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o dump.o timer.o watchdog.o huffman-decode.o rle.c loader.o info.o shared_memory.o OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o
else else
LDFLAGS = -Wl,-u LDFLAGS = -Wl,-u
CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO

View File

@ -1,267 +0,0 @@
/*
* =====================================================================================
*
* ________ .__ __ ________ ____ ________
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
* \__> \/ \/ \/ \/ \/
*
* www.optixx.org
*
*
* Version: 1.0
* Created: 07/21/2009 03:32:16 PM
*
* =====================================================================================
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "huffman-decode.h"
#include "info.h"
#include "debug.h"
#ifdef DEBUG
#undef DEBUG
#endif
#define DEBUG 1
#if DEBUG
#include <avr/pgmspace.h>
#endif
#define V_NODE (-2)
#define V_EOF (-1)
#define PREFIX_SIZE_B 32
#define ALLOC_ERROR {}
#undef BLOCK_ALLOC 1
typedef struct {
int16_t value;
void* left;
void* right;
} node_t;
#if HUFFMAN_USE_ADDR_16
void huffman_dec_init(huffman_dec_ctx_t* ctx, uint16_t(*rb_func)(uint16_t)){
#else
void huffman_dec_init(huffman_dec_ctx_t* ctx, uint16_t(*rb_func)(uint32_t)){
#endif
ctx->tree = NULL;
ctx->addr = 0;
ctx->read_byte = rb_func;
ctx->rbuffer_index = 8;
}
#if HUFFMAN_USE_ADDR_16
void huffman_dec_set_addr(huffman_dec_ctx_t* ctx, uint16_t addr){
#else
void huffman_dec_set_addr(huffman_dec_ctx_t* ctx, uint32_t addr){
#endif
ctx->addr = addr;
}
static inline void prefix_increment(uint8_t* prefix){
uint8_t i;
for(i=0; i<PREFIX_SIZE_B; ++i){
prefix[i] += 1;
if(prefix[i]!=0)
return;
}
}
static inline void prefix_shiftleft(uint8_t* prefix){
uint8_t i;
uint8_t c[2]={0,0};
uint8_t ci=0;
for(i=0; i<PREFIX_SIZE_B; ++i){
c[ci] = (prefix[i])>>7;
prefix[i]<<=1;
ci ^= 1;
prefix[i]|=c[ci];
}
}
static inline void set_last_to_eof(node_t* start){
node_t* current = start;
while(current->value==V_NODE){
current=current->right;
}
current->value=V_EOF;
}
#if DEBUG
void print_tree(node_t* node){
if(node->value==V_NODE){
info("\n%p --> node->left=%p node->right=%p",node,node->left, node->right);
print_tree(node->left);
print_tree(node->right);
}else{
info("\n%p => %i",node,node->value);
}
}
#endif
uint8_t build_tree(huffman_dec_ctx_t* ctx){
uint16_t treesize;
uint16_t treeindex=1;
int8_t i,t;
if(ctx->read_byte(ctx->addr++)!=0xC0)
return 1;
if(((treesize=ctx->read_byte(ctx->addr++))&0xFE)!=0xDE)
return 1;
treesize = (treesize&1)<<8;
treesize += ctx->read_byte(ctx->addr++);
if(treesize>0x1ff)
return 2;
#if BLOCK_ALLOC
ctx->tree = calloc(2*treesize-1, sizeof(node_t));
#else
ctx->tree = calloc(1, sizeof(node_t));
#endif
((node_t*)(ctx->tree))->value = V_NODE;
uint16_t depth=0;
uint16_t count=0;
uint16_t v;
uint8_t prefix[PREFIX_SIZE_B];
uint8_t cdepth=0;
node_t* current=ctx->tree;
current->value = V_NODE;
memset(prefix, 0, PREFIX_SIZE_B);
do{
while(count==0){
depth++;
count= ctx->read_byte(ctx->addr++);
if(count==255)
count += ctx->read_byte(ctx->addr++);
}
v = ctx->read_byte(ctx->addr++);
if(v>0xff)
return 3;
--count;
for(;cdepth<depth;++cdepth){
prefix_shiftleft(prefix);
}
#if DEBUG
printf("\n value %x => ",v);
#endif
current=ctx->tree;
for(i=depth-1; i>=0; --i){
t=(prefix[i/8])&(1<<(i%8));
if(t==0){
#if DEBUG
printf("0");
#endif
if(current->left==NULL){
#if BLOCK_ALLOC
current->left=&(((node_t*)(ctx->tree))[treeindex++]);
#else
current->left=calloc(1, sizeof(node_t));
#endif
((node_t*)(current->left))->value = V_NODE;
}
current = current->left;
} else {
#if DEBUG
printf("1");
#endif
if(current->right==NULL){
#if BLOCK_ALLOC
current->right=&(((node_t*)(ctx->tree))[treeindex++]);
#else
current->right=calloc(1, sizeof(node_t));
#endif
((node_t*)(current->right))->value=V_NODE;
}
current = current->right;
}
}
#if !BLOCK_ALLOC
if(current==NULL)
ALLOC_ERROR
#endif
current->value=v;
prefix_increment(prefix);
}while(!(prefix[depth/8]&(1<<(depth%8))));
#if DEBUG
print_tree(ctx->tree);
#endif
set_last_to_eof(ctx->tree);
return 0;
}
void free_tree(node_t* node){
#if !BLOCK_ALLOC
if(node->value==V_NODE){
free_tree(node->left);
free_tree(node->right);
}
#endif
free(node);
}
static uint8_t read_bit(huffman_dec_ctx_t* ctx){
uint16_t x;
uint8_t t;
if(ctx->rbuffer_index==8){
x=ctx->read_byte(ctx->addr);
ctx->addr++;
if(t>0xff)
return 0xFF;
ctx->rbuffer = (uint8_t)x;
ctx->rbuffer_index=0;
}
t=(ctx->rbuffer)>>7;
ctx->rbuffer<<=1;
ctx->rbuffer_index++;
return t;
}
uint16_t huffman_dec_byte(huffman_dec_ctx_t* ctx){
node_t* current=ctx->tree;
uint8_t t;
if(current==NULL){
#if DEBUG
printf("\nbuild tree");
#endif
t=build_tree(ctx);
if(t!=0){
#if DEBUG
printf("\n!!! building tree failed !!!\r\n");
#endif
return 0xFFFF;
}
#if DEBUG
printf("\ntree build successful");
#endif
current=ctx->tree;
}
while(current->value==V_NODE){
t=read_bit(ctx);
if(t==0xFF)
goto eof_detected;
if(t==0){
current=current->left;
} else {
current=current->right;
}
}
if(current->value!=V_EOF){
return current->value;
}
eof_detected:
free_tree(ctx->tree);
ctx->tree = NULL;
return 0xFFFF;
}

View File

@ -1,51 +0,0 @@
/*
* =====================================================================================
*
* ________ .__ __ ________ ____ ________
* \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
* / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
* / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
* \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
* \__> \/ \/ \/ \/ \/
*
* www.optixx.org
*
*
* Version: 1.0
* Created: 07/21/2009 03:32:16 PM
*
* =====================================================================================
*/
#ifndef AVR_HUFFMAN_DECODE_H_
#define AVR_HUFFMAN_DECODE_H_
#include <stdint.h>
#define HUFFMAN_USE_ADDR_16 1
typedef struct {
void* tree;
uint8_t rbuffer;
uint8_t rbuffer_index;
#if HUFFMAN_USE_ADDR_16
uint16_t(*read_byte)(uint16_t addr);
uint16_t addr;
#else
uint16_t(*read_byte)(uint32_t addr);
uint32_t addr;
#endif
} huffman_dec_ctx_t;
#if HUFFMAN_USE_ADDR_16
void huffman_dec_init(huffman_dec_ctx_t* ctx, uint16_t(*rb_func)(uint16_t));
void huffman_dec_set_addr(huffman_dec_ctx_t* ctx,uint16_t addr);
#else
void huffman_dec_init(huffman_dec_ctx_t* ctx, uint16_t(*rb_func)(uint32_t));
void huffman_dec_set_addr(huffman_dec_ctx_t* ctx,uint32_t addr);
#endif
uint16_t huffman_dec_byte(huffman_dec_ctx_t* ctx);
#endif /* AVR_HUFFMAN_DECODE_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,8 @@
#ifndef __FIFO_H__ #ifndef __FIFO_H__
#define __FIFO_H__ #define __FIFO_H__
#define ROM_BUFFER_SIZE 27288 #define ROM_BUFFER_SIZE 30344
#define ROM_HUFFMAN_SIZE 27288 #define ROM_HUFFMAN_SIZE 0
#define ROM_RLE_SIZE 30344 #define ROM_RLE_SIZE 30344
#endif #endif

View File

@ -28,8 +28,7 @@
#include <avr/eeprom.h> #include <avr/eeprom.h>
#include "usbdrv.h" #include "usbdrv.h"
#include "oddebug.h" /* This is also an example for using debug #include "oddebug.h" /* This is also an example for using debug macros */
* macros */
#include "config.h" #include "config.h"
#include "requests.h" /* The custom request numbers we use */ #include "requests.h" /* The custom request numbers we use */
#include "uart.h" #include "uart.h"
@ -41,7 +40,6 @@
#include "usb_bulk.h" #include "usb_bulk.h"
#include "timer.h" #include "timer.h"
#include "watchdog.h" #include "watchdog.h"
#include "huffman-decode.h"
#include "rle.h" #include "rle.h"
#include "loader.h" #include "loader.h"
#include "shared_memory.h" #include "shared_memory.h"
@ -82,7 +80,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
if (rq->bRequest == USB_UPLOAD_INIT) { if (rq->bRequest == USB_UPLOAD_INIT) {
if (req_state != REQ_STATUS_IDLE) { if (req_state != REQ_STATUS_IDLE) {
debug(DEBUG_USB,"USB_UPLOAD_INIT: ERROR state is not REQ_STATUS_IDLE\n"); debug(DEBUG_USB,
"USB_UPLOAD_INIT: ERROR state is not REQ_STATUS_IDLE\n");
return 0; return 0;
} }
@ -105,7 +104,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
if (rx_remaining) { if (rx_remaining) {
sync_errors++; sync_errors++;
debug debug
(DEBUG_USB,"USB_UPLOAD_ADDR: Out of sync addr=0x%lx remain=%i packet=%i sync_error=%i\n", (DEBUG_USB,
"USB_UPLOAD_ADDR: Out of sync addr=0x%lx remain=%i packet=%i sync_error=%i\n",
req_addr, rx_remaining, rq->wLength.word, sync_errors); req_addr, rx_remaining, rq->wLength.word, sync_errors);
ret_len = 0; ret_len = 0;
} }
@ -114,8 +114,11 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
if (req_addr && (req_addr % 0x1000) == 0) { if (req_addr && (req_addr % 0x1000) == 0) {
debug(DEBUG_USB,"USB_UPLOAD_ADDR: bank=0x%02x addr=0x%08lx crc=%04x\n", debug(DEBUG_USB,
req_bank, req_addr,crc_check_bulk_memory(req_addr - 0x1000,req_addr,req_bank_size)); "USB_UPLOAD_ADDR: bank=0x%02x addr=0x%08lx crc=%04x\n",
req_bank, req_addr, crc_check_bulk_memory(req_addr - 0x1000,
req_addr,
req_bank_size));
} }
if (req_addr && req_addr % req_bank_size == 0) { if (req_addr && req_addr % req_bank_size == 0) {
@ -144,13 +147,15 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
req_bank = 0; req_bank = 0;
rx_remaining = 0; rx_remaining = 0;
debug(DEBUG_USB,"USB_BULK_UPLOAD_INIT: %i %i\n",rq->wValue.word, rq->wIndex.word); debug(DEBUG_USB, "USB_BULK_UPLOAD_INIT: %i %i\n", rq->wValue.word,
rq->wIndex.word);
req_bank_size = (uint32_t) (1L << rq->wValue.word); req_bank_size = (uint32_t) (1L << rq->wValue.word);
req_bank_cnt = rq->wIndex.word; req_bank_cnt = rq->wIndex.word;
req_addr_end = (uint32_t) req_bank_size *req_bank_cnt; req_addr_end = (uint32_t) req_bank_size *req_bank_cnt;
sync_errors = 0; sync_errors = 0;
debug(DEBUG_USB,"USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n", debug(DEBUG_USB,
"USB_BULK_UPLOAD_INIT: bank_size=0x%08lx bank_cnt=0x%x end_addr=0x%08lx\n",
req_bank_size, req_bank_cnt, req_addr_end); req_bank_size, req_bank_cnt, req_addr_end);
shared_memory_put(SHARED_MEM_CMD_BANK_COUNT, req_bank_cnt); shared_memory_put(SHARED_MEM_CMD_BANK_COUNT, req_bank_cnt);
@ -170,10 +175,12 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
if (req_addr && req_addr % req_bank_size == 0) { if (req_addr && req_addr % req_bank_size == 0) {
#ifdef FLT_DEBUG #ifdef FLT_DEBUG
debug(DEBUG_USB,"USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n", debug(DEBUG_USB,
"USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%.4f\n",
req_bank, req_addr, timer_stop()); req_bank, req_addr, timer_stop());
#else #else
debug(DEBUG_USB,"USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n", debug(DEBUG_USB,
"USB_BULK_UPLOAD_ADDR: req_bank=0x%02x addr=0x%08lx time=%i\n",
req_bank, req_addr, timer_stop_int()); req_bank, req_addr, timer_stop_int());
#endif #endif
req_bank++; req_bank++;
@ -198,18 +205,23 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
rx_remaining = rq->wLength.word; rx_remaining = rq->wLength.word;
#if 0 #if 0
if (req_addr && (req_addr % 0x1000) == 0) { if (req_addr && (req_addr % 0x1000) == 0) {
debug(DEBUG_USB,"USB_BULK_UPLOAD_NEXT: bank=0x%02x addr=0x%08lx crc=%04x\n", debug(DEBUG_USB,
req_bank, req_addr,crc_check_bulk_memory(req_addr - 0x1000,req_addr,req_bank_size)); "USB_BULK_UPLOAD_NEXT: bank=0x%02x addr=0x%08lx crc=%04x\n",
req_bank, req_addr, crc_check_bulk_memory(req_addr - 0x1000,
req_addr,
req_bank_size));
} }
sram_bulk_write_start(req_addr); sram_bulk_write_start(req_addr);
#endif #endif
if (req_addr && (req_addr % req_bank_size) == 0) { if (req_addr && (req_addr % req_bank_size) == 0) {
#ifdef FLT_DEBUG #ifdef FLT_DEBUG
debug(DEBUG_USB,"USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n", debug(DEBUG_USB,
"USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%.4f\n",
req_bank, req_addr, timer_stop()); req_bank, req_addr, timer_stop());
#else #else
debug(DEBUG_USB,"USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n", debug(DEBUG_USB,
"USB_BULK_UPLOAD_NEXT: req_bank=0x%02x addr=0x%08lx time=%i\n",
req_bank, req_addr, timer_stop_int()); req_bank, req_addr, timer_stop_int());
#endif #endif
req_bank++; req_bank++;
@ -224,7 +236,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
*/ */
} else if (rq->bRequest == USB_BULK_UPLOAD_END) { } else if (rq->bRequest == USB_BULK_UPLOAD_END) {
if (req_state != REQ_STATUS_BULK_UPLOAD) { if (req_state != REQ_STATUS_BULK_UPLOAD) {
debug(DEBUG_USB,"USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n"); debug(DEBUG_USB,
"USB_BULK_UPLOAD_END: ERROR state is not REQ_STATUS_BULK_UPLOAD\n");
return 0; return 0;
} }
debug(DEBUG_USB, "USB_BULK_UPLOAD_END:\n"); debug(DEBUG_USB, "USB_BULK_UPLOAD_END:\n");
@ -278,7 +291,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
req_size = rq->wLength.word; req_size = rq->wLength.word;
req_size = req_size << 2; req_size = req_size << 2;
tx_remaining = 2; tx_remaining = 2;
debug(DEBUG_USB,"USB_CRC_ADDR: addr=0x%lx size=%li\n", req_addr, req_size); debug(DEBUG_USB, "USB_CRC_ADDR: addr=0x%lx size=%li\n", req_addr,
req_size);
crc = crc_check_memory_range(req_addr, req_size, read_buffer); crc = crc_check_memory_range(req_addr, req_size, read_buffer);
tx_buffer[0] = crc & 0xff; tx_buffer[0] = crc & 0xff;
@ -288,8 +302,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
} }
usbMsgPtr = data_buffer; usbMsgPtr = data_buffer;
return ret_len; /* default for not implemented requests: return return ret_len; /* default for not implemented requests: return no data back to host */
* no data back to host */
} }
@ -297,7 +310,8 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
void test_read_write(){ void test_read_write()
{
uint8_t i; uint8_t i;
uint32_t addr; uint32_t addr;
@ -315,7 +329,8 @@ void test_read_write(){
void test_bulk_read_write(){ void test_bulk_read_write()
{
uint8_t i; uint8_t i;
uint32_t addr; uint32_t addr;
@ -356,7 +371,8 @@ void test_non_zero_memory(uint32_t bottom_addr,uint32_t top_addr)
void test_crc(){ void test_crc()
{
info("test_crc: clear\n"); info("test_crc: clear\n");
avr_bus_active(); avr_bus_active();
sram_bulk_set(0x000000, 0x10000, 0xff); sram_bulk_set(0x000000, 0x10000, 0xff);
@ -366,45 +382,19 @@ void test_crc(){
test_non_zero_memory(0x000000, 0x10000); test_non_zero_memory(0x000000, 0x10000);
} }
uint16_t read_byte_pgm(uint16_t addr){ uint16_t read_byte_pgm(uint16_t addr)
{
return pgm_read_byte((PGM_VOID_P) addr); return pgm_read_byte((PGM_VOID_P) addr);
} }
uint16_t read_byte_ee(uint16_t addr){ uint16_t read_byte_ee(uint16_t addr)
{
return eeprom_read_byte((uint8_t *) addr); return eeprom_read_byte((uint8_t *) addr);
} }
void decompress(PGM_VOID_P addr, uint16_t(*fp)(uint16_t)){ void send_reset()
uint16_t c; {
uint32_t i = 0;
huffman_dec_ctx_t ctx;
huffman_dec_init(&ctx, fp);
huffman_dec_set_addr(&ctx, (uint16_t)addr);
while(1){
i++;
c=huffman_dec_byte(&ctx);
if (i%1024==0)
info(".");
if(c>0xff){
return;
}
c&=0xff;
sram_bulk_write(c);
}
}
void decompress_huffman(void){
info("Decompress Rom %p to 0x000000\n",(void*)_rom);
sram_bulk_write_start(0x000000);
decompress(&_rom,read_byte_pgm);
sram_bulk_write_end();
info("Done\n");
}
void send_reset(){
info("Reset Snes\n"); info("Reset Snes\n");
snes_reset_on(); snes_reset_on();
snes_reset_lo(); snes_reset_lo();
@ -413,7 +403,8 @@ void send_reset(){
snes_reset_off(); snes_reset_off();
} }
void send_irq(){ void send_irq()
{
snes_irq_on(); snes_irq_on();
snes_irq_lo(); snes_irq_lo();
_delay_us(20); _delay_us(20);
@ -421,7 +412,8 @@ void send_irq(){
snes_irq_off(); snes_irq_off();
} }
void set_rom_mode(){ void set_rom_mode()
{
if (req_bank_size == 0x8000) { if (req_bank_size == 0x8000) {
snes_lorom(); snes_lorom();
info("Set Snes lowrom \n"); info("Set Snes lowrom \n");
@ -432,7 +424,8 @@ void set_rom_mode(){
} }
void usb_connect(){ void usb_connect()
{
uint8_t i = 0; uint8_t i = 0;
info("USB init\n"); info("USB init\n");
usbDeviceDisconnect(); /* enforce re-enumeration, do this while */ usbDeviceDisconnect(); /* enforce re-enumeration, do this while */
@ -451,7 +444,8 @@ void usb_connect(){
} }
void boot_startup_rom(){ void boot_startup_rom()
{
info("Activate AVR bus\n"); info("Activate AVR bus\n");
@ -464,18 +458,7 @@ void boot_startup_rom(){
snes_lorom(); snes_lorom();
info("Set Snes lowrom \n"); info("Set Snes lowrom \n");
/* rle_decode(&_rom, ROM_BUFFER_SIZE, 0x000000);
info("Set Snes hirom\n");
snes_hirom();
info("Disable snes WR\n");
snes_wr_disable();
info("IRQ off\n");
snes_irq_lo();
snes_irq_off();
*/
rle_decode(&_rom, ROM_SIZE, 0x000000);
dump_memory(0x10000 - 0x100, 0x10000); dump_memory(0x10000 - 0x100, 0x10000);
snes_reset_hi(); snes_reset_hi();
@ -601,4 +584,3 @@ int main(void)
return 0; return 0;
} }

View File

@ -78,16 +78,22 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
if (in_byte == RUNCHAR) { if (in_byte == RUNCHAR) {
INBYTE(in_repeat); INBYTE(in_repeat);
if (in_repeat == 0) { if (in_repeat == 0) {
/* Just an escaped RUNCHAR value */ /*
* Just an escaped RUNCHAR value
*/
OUTBYTE(RUNCHAR); OUTBYTE(RUNCHAR);
} else { } else {
/* Pick up value and output a sequence of it */ /*
* Pick up value and output a sequence of it
*/
in_byte = last_byte; // ;out_data[-1]; in_byte = last_byte; // ;out_data[-1];
while (--in_repeat > 0) while (--in_repeat > 0)
OUTBYTE(in_byte); OUTBYTE(in_byte);
} }
} else { } else {
/* Normal byte */ /*
* Normal byte
*/
OUTBYTE(in_byte); OUTBYTE(in_byte);
} }
last_byte = in_byte; last_byte = in_byte;
@ -95,4 +101,3 @@ uint8_t rle_decode(PGM_VOID_P in_addr, int32_t in_len, uint32_t out_addr)
sram_bulk_write_end(); sram_bulk_write_end();
return 0; return 0;
} }

View File

@ -38,33 +38,39 @@ uint8_t scratchpad_state;
uint8_t scratchpad_cmd; uint8_t scratchpad_cmd;
uint8_t scratchpad_payload; uint8_t scratchpad_payload;
void shared_memory_scratchpad_save(){ void shared_memory_scratchpad_save()
{
scratchpad_state = sram_read(SHARED_MEM_LOC_STATE); scratchpad_state = sram_read(SHARED_MEM_LOC_STATE);
scratchpad_cmd = sram_read(SHARED_MEM_LOC_CMD); scratchpad_cmd = sram_read(SHARED_MEM_LOC_CMD);
scratchpad_payload = sram_read(SHARED_MEM_LOC_PAYLOAD); scratchpad_payload = sram_read(SHARED_MEM_LOC_PAYLOAD);
} }
void shared_memory_scratchpad_restore(){ void shared_memory_scratchpad_restore()
{
sram_write(SHARED_MEM_LOC_STATE, scratchpad_state); sram_write(SHARED_MEM_LOC_STATE, scratchpad_state);
sram_write(SHARED_MEM_LOC_CMD, scratchpad_cmd); sram_write(SHARED_MEM_LOC_CMD, scratchpad_cmd);
sram_write(SHARED_MEM_LOC_PAYLOAD, scratchpad_payload); sram_write(SHARED_MEM_LOC_PAYLOAD, scratchpad_payload);
} }
void shared_memory_irq_hook(){ void shared_memory_irq_hook()
{
irq_addr_lo = sram_read(SHARED_IRQ_LOC_LO); irq_addr_lo = sram_read(SHARED_IRQ_LOC_LO);
irq_addr_hi = sram_read(SHARED_IRQ_LOC_HI); irq_addr_hi = sram_read(SHARED_IRQ_LOC_HI);
sram_write(SHARED_IRQ_HANDLER_LO, 0); sram_write(SHARED_IRQ_HANDLER_LO, 0);
sram_write(SHARED_IRQ_HANDLER_HI, 0); sram_write(SHARED_IRQ_HANDLER_HI, 0);
} }
void shared_memory_irq_restore(){ void shared_memory_irq_restore()
{
sram_write(SHARED_IRQ_LOC_LO, irq_addr_lo); sram_write(SHARED_IRQ_LOC_LO, irq_addr_lo);
sram_write(SHARED_IRQ_LOC_HI, irq_addr_hi); sram_write(SHARED_IRQ_LOC_HI, irq_addr_hi);
} }
void shared_memory_put(uint8_t cmd, uint8_t value){ void shared_memory_put(uint8_t cmd, uint8_t value)
{
info("Write shared memory 0x%04x=0x%02x 0x%04x=0x%02x \n",SHARED_MEM_LOC_CMD,cmd,SHARED_MEM_LOC_PAYLOAD,value); info("Write shared memory 0x%04x=0x%02x 0x%04x=0x%02x \n",
SHARED_MEM_LOC_CMD, cmd, SHARED_MEM_LOC_PAYLOAD, value);
shared_memory_scratchpad_save(); shared_memory_scratchpad_save();
shared_memory_irq_hook(); shared_memory_irq_hook();
@ -89,4 +95,3 @@ void shared_memory_put(uint8_t cmd, uint8_t value){
shared_memory_irq_restore(); shared_memory_irq_restore();
} }