[an error occurred while processing this directive]
См. внутри
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено _MiniMax- 17 октября 2006 г. 21:28
В ответ на: LPC213X программирование - контр сумма отправлено <font color=gray>AndAnd</font> 17 октября 2006 г. 19:43

ERRCODE WriteToRAM(CComms& comm, ULONG numBytes, const UBYTE* pData, char errMsg[80] )
{
ERRCODE ec = SUCCESS;
UBYTE outbuf[2*ARM_SECTOR_SIZE];
ULONG indx =0;
ULONG ondx =0;
ULONG totalBytes;
ULONG totalBytesUU;
ULONG bytesPerLine = 45;
ULONG bytesPerPacket = 900;
int currentLine =0;
char dataLine[512];
int ndx,lenLine;
ULONG checkSum;
// Convert to UU
for (indx =0; ;)
{
Encode((UBYTE*)(pData+indx), &outbuf[ondx]);
ondx +=4;
indx +=3;
if (indx >= numBytes)
if (!(indx % 4)) break;
}
totalBytes = indx;
totalBytesUU = ondx;
// Send all bytes to ARM
ondx =0;
for( indx =0; indx < totalBytes;)
{
if(totalBytes-indx < bytesPerLine) bytesPerLine = totalBytes - indx;
// Send "CopyToRAM" command
if (currentLine == 0)
{
bytesPerPacket = (totalBytes-indx > bytesPerPacket) ? bytesPerPacket:totalBytes-indx;
sprintf(dataLine,"W %lu %d\r\n",0x40000200+indx,bytesPerPacket);
ec = comm.Write((UBYTE*)dataLine,strlen(dataLine));
if(ec) goto func_end;
ec = GetSUCCESS(comm);
if(ec) goto func_end;
checkSum = 0;
}
Sleep(10);
// NEXT LINE
currentLine++;
// Calculate check sum
for (ndx = 0; ndx < (int)bytesPerLine ; ndx++)
checkSum += *(pData+indx+ndx);
// Prepare next line
ndx =0;
dataLine[ndx++] = (UBYTE)(bytesPerLine + 0x20);
lenLine = (bytesPerLine * 4)/3;
lenLine++;
for (; ndx < lenLine ; ndx++)
dataLine[ndx] = outbuf[ondx++];
dataLine[ndx++] = CR;
dataLine[ndx++] = LF;
dataLine[ndx] = 0;
ec = comm.Write((UBYTE*)dataLine,strlen(dataLine));
if(ec) goto func_end;
//
indx+= bytesPerLine;
if (( indx >= totalBytes)||( currentLine == 20))
{
// Send check sum
sprintf(dataLine,"%lu\r\n",checkSum);
ec = comm.Write((UBYTE*)dataLine,strlen(dataLine));
if(ec) goto func_end;
ec = GetOK(comm);
if(ec) goto func_end;
currentLine = 0;
}
}
func_end:
return ec;
}

Составить ответ  |||  Конференция  |||  Архив

Ответы


Отправка ответа
Имя (обязательно): 
Пароль: 
E-mail: 

Тема (обязательно):
Сообщение:

Ссылка на URL: 
Название ссылки: 
URL изображения: 


Rambler's Top100 Рейтинг@Mail.ru
Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание