📄 uue.c
字号:
/* * xmodem.c - the xmodem protocol * * Author: yu feng <progeryf@gmail.com> * Date: 2007-6-2 *//* *************************************************************** */#include "my_string.h"#include "my_printf.h"#include "uart.h"/*#define SYSCFG 0x03FF0000#define IOPMOD (SYSCFG + 0x5000)#define IOPCON (SYSCFG + 0x5004)#define IOPDATA (SYSCFG + 0x5008)#define LED_BANK IOPDATA#define ALL_LEDS 0xF0 */extern int count;int ReadC(void){ char tempch; uart_getchar( UART0_BASE, &tempch ); return tempch;}#define LF ('\n')#define CR ('\r')#define CTRL_D ('D'-'@')#define BEGIN "begin"#define END "end"int ReadLineZ(char *buffer, int maxlen){ int pos = 0; int c; do { c =ReadC(); if (c == CR || c == LF) { buffer[pos] = 0; return pos; } if (c == CTRL_D) { buffer[0] = 0; return -1; } if (c >= ' ' && pos < maxlen) buffer[pos++] = c; } while (1);}int cistreq(char *s, char *t, int term){ for ( ; ((*s | 0x20) == (*t | 0x20)) || (*s <= term && *t <= term); s++, t++) if (*s <= term) return 1; return 0;}char *nextword(char *word){ while (*word > ' ') word++; while (*word == ' ') word++; return word;}int uue_download(unsigned address){ char *buffer = (char *)address; char *s; int errs = 0; int i; unsigned c, w; int offset = 0; int len; char command_line[256]; char gpbuff[256]; s = command_line; do { if (ReadLineZ(s, sizeof(command_line)-1) == -1) return -1; } while (!cistreq(s, BEGIN, ' ')); s = nextword(s); s = nextword(s); my_strcpy(gpbuff, s); do { s = command_line; len = ReadLineZ(s, sizeof(command_line)-1); if (len == -1 || cistreq(s, END, ' ')) break; c = *s++; if (!c) continue; len = c - 0x20; if (len == 0) continue; if (len > 45) { errs++; continue; } i = 0; while (1) { c = *s; if (c) { c -= 0x20; if (c >= 0x40) { errs++; break; } s++; } w = (w << 6) + c; if ((++i & 3) == 0) { buffer[offset++] = w >> 16; if (--len == 0) break; buffer[offset++] = w >> 8; if (--len == 0) break; buffer[offset++] = w; if (--len == 0) break; } } } while (1); if (errs) my_printf("Error: %d errors encountered during download. \n\r", errs); count = offset; my_printf("Loaded file %s at address 0x%x, size = %d \n\r", gpbuff, buffer, offset); return 0;}int uue_receive(unsigned download_addr)//int uue_receive(char * download_addr){ my_printf( " \nbotloader download 0x%x\n\r",download_addr ); uue_download( download_addr ); return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -