📄 test_api.c
字号:
error = 1;
}
send_cr_lf();
send_cr_lf();
/*---- Test special read --------------------------------------------------*/
/*--------------------------------------------------------------------------*/
// Read manufacturer
printf("manufacturer = ");
value = __api_rd_manufacturer();
send_byte_ascii(value);
if (value != 0x58)
{
printf(" - ERROR READ manufacrurer ID");
error = 1;
}
send_cr_lf();
// Read device id1
printf("device id1 = ");
value = __api_rd_device_id1();
send_byte_ascii(value);
if (value != 0xD7)
{
printf(" - ERROR READ device ID 1");
error = 1;
}
send_cr_lf();
// Read device id2
printf("device id2 = ");
value = __api_rd_device_id2();
send_byte_ascii(value);
if (value != 0xF7)
{
printf(" - ERROR READ device ID 2");
error = 1;
}
send_cr_lf();
// Read device id3
printf("device id3 = ");
value = __api_rd_device_id3();
send_byte_ascii(value);
if (value != 0xDF)
{
printf(" - ERROR READ device ID 3");
error = 1;
}
send_cr_lf();
// Read device boot version
printf("boot version = 1.");
value = __api_rd_bootloader_version ();
send_byte_ascii(value);
send_cr_lf();
send_cr_lf();
/*---- Test Fuse ----------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
printf("Fuse bit test:");
send_cr_lf();
printf("--------------");
send_cr_lf();
// Read fuse bits
printf("HSB initial value = ");
value = __api_rd_HSB();
send_byte_ascii(value);
send_cr_lf();
printf("X2 mode = ");
if (value & 0x80)
{
printf("on, ");
}
else
{
printf("off, ");
}
printf("BLJB = ");
if (value & 0x40)
{
printf("1");
}
else
{
printf("0");
}
send_cr_lf();
send_cr_lf();
// Write fuse bit X2
printf("set bit X2 ");
value = __api_set_X2();
send_cr_lf();
// Read fuse bits
printf("HSB = ");
value = __api_rd_HSB();
send_byte_ascii(value);
if (value & 0x80)
{
}
else
{
printf(" - ERROR SET X2 bit ");
error = 1;
}
send_cr_lf();
// Clear fuse bit X2
printf("clear bit X2 ");
value = __api_clr_X2();
send_cr_lf();
// Read fuse bits
printf("HSB = ");
value = __api_rd_HSB();
send_byte_ascii(value);
if (value & 0x80)
{
printf(" - ERROR CLEAR X2 bit ");
error = 1;
}
send_cr_lf();
// Write fuse bit BLJB
printf("set bit BLJB ");
value = __api_set_BLJB();
send_cr_lf();
// Read fuse bits
printf("HSB = ");
value = __api_rd_HSB();
send_byte_ascii(value);
if (value & 0x40)
{
}
else
{
printf(" - ERROR SET BLJB bit ");
error = 1;
}
send_cr_lf();
// Clear fuse bit BLJB
printf("clear bit BLJB ");
value = __api_clr_BLJB();
send_cr_lf();
// Read fuse bits
printf("HSB = ");
value = __api_rd_HSB();
send_byte_ascii(value);
if (value & 0x40)
{
printf(" - ERROR CLEAR BLJB bit ");
error = 1;
}
send_cr_lf();
// Write fuse bit BLJB
printf("set bit BLJB ");
value = __api_set_BLJB();
send_cr_lf();
// Read fuse bits
printf("HSB = ");
value = __api_rd_HSB();
send_byte_ascii(value);
if (value & 0x40)
{
}
else
{
printf(" - ERROR SET BLJB bit ");
error = 1;
}
send_cr_lf();
// Write fuse bit X2
printf("set bit X2 ");
value = __api_set_X2();
send_cr_lf();
// Read fuse bits
printf("HSB = ");
value = __api_rd_HSB();
send_byte_ascii(value);
if (value & 0x80)
{
}
else
{
printf(" - ERROR SET X2 bit ");
error = 1;
}
send_cr_lf();
send_cr_lf();
/*---- Test FLASH ---------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
printf("Flash test:");
send_cr_lf();
printf("-----------");
send_cr_lf();
// Read data address 0x7F00
printf("read data at 0x7F00 : ");
value = __api_rd_code_byte (0x7F00);
send_byte_ascii(value);
send_cr_lf();
// Write data at address 0x7F00 = 0xAA
printf("Write Data at add 0x7F00 the value 0xAA \n");
__api_wr_code_byte(0x7F00, 0xAA);
// Read data address 0x7F00
printf("read data at 0x7F00 : ");
value = __api_rd_code_byte(0x7F00);
send_byte_ascii(value);
if (value != 0xAA)
{
printf(" - WRITE ERROR IN FLASH");
error = 1;
}
send_cr_lf();
for (cpt = 0; cpt< 0x10; cpt++)
{
tab[cpt] = 0x55;
}
// Write data at address 0x2000 = 0x55
printf("Write Data page at 0x2000 = 0x55 \n");
__api_wr_code_page(0x2000, tab ,0x10);
// Read data address 0x1000
printf("read data at 0x2000-0x2010 : \n");
for (cpt = 0x2000; cpt< 0x2010; cpt++)
{
value = __api_rd_code_byte(cpt);
send_byte_ascii(value);
if (value != 0x55)
{
printf(" ERROR, ");
error = 1;
}
}
send_cr_lf();
for (cpt = 0; cpt< 0x10; cpt++)
{
tab[cpt] = 0xAA;
}
printf("Write code page FIX test:");
send_cr_lf();
// Write data at address 0x2000 = 0xAA Fix for version >= 1.0.2
printf("Write Data page at 0x2000 = 0xAA \n");
__api_wr_code_page_fix(0x2000, tab ,0x10);
// Read data address 0x2000
printf("read data at 0x2000-0x2010 : \n");
for (cpt = 0x2000; cpt< 0x2010; cpt++)
{
value = __api_rd_code_byte(cpt);
send_byte_ascii(value);
if (value != 0xAA)
{
printf(" ERROR, ");
error = 1;
}
}
send_cr_lf();
send_cr_lf();
/*---- Test EEPROM ---------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
printf("EEPROM test:");
send_cr_lf();
printf("------------");
send_cr_lf();
// Read data address 0xF200
printf("read data at 0xF200 : ");
value = __api_rd_eeprom_byte (0xF200);
send_byte_ascii(value);
send_cr_lf();
// Write data at address 0xF200 = 0xAA
printf("Write Data at add 0xF200 the value 0xAA \n");
__api_wr_eeprom_byte(0xF200, 0xAA);
// Read data address 0xF200
printf("read data at 0xF200 : ");
value = __api_rd_eeprom_byte(0xF200);
send_byte_ascii(value);
if (value != 0xAA)
{
printf(" - WRITE ERROR IN EEPROM");
error = 1;
}
send_cr_lf();
/*
for (cpt = 0; cpt< 0x10; cpt++)
{
tab[cpt] = 0x55;
}
// Write data at address 0xF300 = 0x55
printf("Write Data page at 0xF300 = 0x55 \n");
__api_wr_eeprom_page(0xF300, tab ,0x10);
// Read data address 0x1000
printf("read data at 0xF300-0xF310 : \n");
for (cpt = 0xF300; cpt< 0xF310; cpt++)
{
value = __api_rd_eeprom_byte(cpt);
send_byte_ascii(value);
if (value != 0x55)
{
printf(" ERROR, ");
error = 1;
}
}
send_cr_lf();
send_cr_lf();
*/
printf(" general result = ");
if (error == 1)
{
printf("test failed");
}
else
{
printf("test passed");
}
send_cr_lf();
send_cr_lf();
printf(" END OF c5131 USB FLASH API TEST \n");
printf(" Jumping to Bootloader ");
printf(" ...");
__api_set_BLJB();
__api_wr_SBV (0xF4);
send_cr_lf();
cpt=0;
while(cpt != 255)
{
tab[cpt]=0;
cpt++;
}
__api_start_bootloader();
while(1);
send_cr_lf();
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -