📄 cf_irq.c
字号:
//cf_irq.c:when comes a irq ,reserve 1 row(360 dots)
//include files
#include <stdio.h>
#include <sysreg.h>
#include <builtins.h>
#include <defTS101.h>
#include <signal.h>
#include "cf.h"
//just can add data to the new created file
unsigned char AddToFile(unsigned int *Ptr_add,unsigned int line_in_cnt)
{
unsigned int i=0,j=0,ModifyIndex=0,l=0,n=0,tmp=0;
for(l=0;l<360;l++)
{
tmp=*Ptr_add;
AddFileBuf[4*l]=tmp&0x000000ff;
AddFileBuf[4*l+1]=(tmp&0x0000ff00)>>8;
AddFileBuf[4*l+2]=(tmp&0x00ff0000)>>16;
AddFileBuf[4*l+3]=(tmp&0xff000000)>>24;
Ptr_add++;
}
AddGroup(NEWBEGINGRP+line_in_cnt,0);
//modify destination cluster
i = (NEWBEGINGRP+line_in_cnt) * 2 / 512;
j = (NEWBEGINGRP+line_in_cnt) - i * 512 / 2;
atadev_get_block(CPartition.FAT1BeginSector + i, 1, uRcvBuffer);
uRcvBuffer[2*j+0] = 0xFF;
uRcvBuffer[2*j+1] = 0xFF;
atadev_put_block(CPartition.FAT1BeginSector + i, 1, uRcvBuffer);
if(line_in_cnt>0)
{
//modify the cluster number to point to the first cluster number of the added file
/* atadev_get_block(CPartition.FAT1BeginSector + i, 1, uRcvBuffer);
for(n=4;n<2*j;n++)
{
if((uRcvBuffer[n]==0xff)&&(uRcvBuffer[n+1]==0xff))
ModifyIndex = n/2;
}
*/
ModifyIndex = NEWBEGINGRP + line_in_cnt - 1;
i = ModifyIndex * 2 / 512;
j = ModifyIndex - i * 512 / 2;
atadev_get_block(CPartition.FAT1BeginSector + i, 1, uRcvBuffer);
uRcvBuffer[2*j+0] = (ModifyIndex+1) & 0x000000FF;
uRcvBuffer[2*j+1] = ((ModifyIndex+1) & 0x0000FF00) >> 8;
atadev_put_block(CPartition.FAT1BeginSector + i, 1, uRcvBuffer);
}
return 1;
}
//add the cluster content of the new created file (the content does not occupy the whole cluster)
unsigned char AddGroup(unsigned int dstgroup,unsigned int ClusNums)
{
unsigned int i=0,j=0,t=0,m=0,l=0,k=0,dstsector=0;
unsigned char flag=0;
t = (ADDLENGTH - ClusNums * CPartition.bpb.SectorPerGroup * CPartition.bpb.BytePerSector) / CPartition.bpb.BytePerSector;
m = (ADDLENGTH - ClusNums * CPartition.bpb.SectorPerGroup * CPartition.bpb.BytePerSector) - CPartition.bpb.BytePerSector * t;
for(i=0; i<CPartition.bpb.SectorPerGroup; i++)
{
dstsector = i + (dstgroup-2)*CPartition.bpb.SectorPerGroup +
CPartition.DATABeginSector;
flag=1;
while(flag)
{
for(l = 0; l < t; l++)
{
for(k = 0; k < 512; k++)
uRcvBuffer[k] = AddFileBuf[k + 512 * l + ClusNums * CPartition.bpb.SectorPerGroup * CPartition.bpb.BytePerSector];
atadev_put_block(dstsector + l, 1, uRcvBuffer);
//translate uRcvBuffer[256] to uRcvBuffer[512]
for (j = 0; j < 256; j++)
{
temp[2*j] = uRcvBuffer[j] & 0x000000FF;
temp[2*j+1] = (uRcvBuffer[j] & 0x0000FF00) >> 8;
}
for (j = 0;j < 512; j++)
uRcvBuffer[j]=temp[j];
flag = 0;
atadev_get_block(dstsector + l, 1, uRcvBuffer1);
for(j=0; j<512; j++)
{
if(uRcvBuffer[j]!=uRcvBuffer1[j])
{
flag = 1;
printf("\n\r Write sector error, now repeating!");
}
}
}
for(k = 0; k < m; k++)
uRcvBuffer[k] = AddFileBuf[k + 512*t + ClusNums * CPartition.bpb.SectorPerGroup * CPartition.bpb.BytePerSector];
for(k = m; k < 512; k++)
uRcvBuffer[k]=' ';
atadev_put_block(dstsector + t, 1, uRcvBuffer);
//translate uRcvBuffer[256] to uRcvBuffer[512]
for (j = 0; j < 256; j++)
{
temp[2*j] = uRcvBuffer[j] & 0x000000FF;
temp[2*j+1] = (uRcvBuffer[j] & 0x0000FF00) >> 8;
}
for (j = 0;j < 512; j++)
uRcvBuffer[j]=temp[j];
flag = 0;
atadev_get_block(dstsector + t, 1, uRcvBuffer1);
for(j=0; j<512; j++)
{
if(uRcvBuffer[j]!=uRcvBuffer1[j])
{
flag = 1;
printf("\n\r Write sector error, now repeating!");
}
}
}
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -