unsigned int flashc_set_bootloader_protected_size (unsigned int bootprot_size)
{
    flashc_set_gp_fuse_bitfield (AVR32_FLASHC_FGPFRLO_BOOTPROT_OFFSET,
                                 AVR32_FLASHC_FGPFRLO_BOOTPROT_SIZE,
                                 (1 << AVR32_FLASHC_FGPFRLO_BOOTPROT_SIZE) - 1 -
                                 ((bootprot_size) ?
                                  32 - clz ((((min (max (bootprot_size, AVR32_FLASHC_PAGE_SIZE << 1),
                                                    AVR32_FLASHC_PAGE_SIZE <<
                                                    ((1 << AVR32_FLASHC_FGPFRLO_BOOTPROT_SIZE) - 1)) +
                                               AVR32_FLASHC_PAGE_SIZE - 1) / AVR32_FLASHC_PAGE_SIZE) << 1) - 1) - 1 : 0));
    return flashc_get_bootloader_protected_size ();
}
Esempio n. 2
0
void IBN_DFU_Tests (unsigned char nParamsGet_u8,unsigned char CMD_u8,unsigned int Param_u32,unsigned char *String_pu8)
{
  u8 DFU_String_au8[4];

  if (0 == nParamsGet_u8)
  {
    CI_LocalPrintf ("DFU test functions\r\n");
    CI_LocalPrintf ("\r\n");
    CI_LocalPrintf ("0   Show ISP Config 1 word\r\n");
    CI_LocalPrintf ("1   Enable DFU at next start\r\n");
    CI_LocalPrintf ("2   Disable DFU at next start\r\n");
    CI_LocalPrintf ("3   Show security bit\r\n");
    CI_LocalPrintf ("4   Set security bit\r\n");
    CI_LocalPrintf ("5   Show bootloader protected size\r\n");
    CI_LocalPrintf ("6   Set bootloader protected size = 0x2000\r\n");
    CI_LocalPrintf ("7   Reset system\r\n");
    CI_LocalPrintf ("\r\n");
    return;
  }

  switch (CMD_u8)
  {
    case 0:
      memcpy (DFU_String_au8,(void*)TOOL_DFU_ISP_CONFIG_ADDR_1,4);
      CI_LocalPrintf ("ISP Config 1 word : ");
      HexPrint (4,DFU_String_au8);
      CI_LocalPrintf ("\r\n");
      break;

    case 1 :
      CI_LocalPrintf ("Enable DFU\r\n");
      DFU_EnableFirmwareUpdate ();
      break;

    case 2 :
      CI_LocalPrintf ("Disable DFU\r\n");
      DFU_DisableFirmwareUpdate ();
      break;

    case 3 :
      CI_LocalPrintf ("Security bit : %d\r\n",flashc_is_security_bit_active ());
      break;

    case 4 :
      CI_LocalPrintf ("Activate security bit\r\n");
      flashc_activate_security_bit ();
      break;

    case 5 :
      CI_LocalPrintf ("Bootloader protected : 0x%04x\r\n",flashc_get_bootloader_protected_size ());
      break;

    case 6 :
      CI_LocalPrintf ("Set bootloader protected 0x2000\r\n");
      flashc_set_bootloader_protected_size (0x2000);
      break;

    case 7 :
      DFU_ResetCPU ();
      break;

  }
}