Пример #1
0
/******************************************************************************
 * @fn      bootMain
 *
 * @brief   ISR for the reset vector.
 *
 * @param   None.
 *
 * @return  None.
 */
void bootMain(void)
{
  extern void _ivecRst2(void);   // hal_ivec.s43 defines this reset re-direct operation.

  HAL_BOOT_INIT();
  vddWait(VDD_MIN_RUN);

  while (1)
  {
    uint16 crc[2];

    crc[0] = *((uint16*)LO_ROM_BEG);
    crc[1] = *((uint16*)LO_ROM_BEG+1);

    if (crc[0] == crc[1])
    {
      break;
    }
    else if ((crc[0] != 0) && (crc[0] == crcCalc()))
    {
      FCTL3 = FWKEY;                      // Clear Lock bit.
      FCTL1 = FWKEY + WRT;                // Set WRT bit for write operation
      *((uint16*)LO_ROM_BEG+1) = crc[0];  // Write CRC shadow
      FCTL1 = FWKEY;                      // Clear WRT bit
      FCTL3 = FWKEY + LOCK;               // Set LOCK bit
    }
    else
    {
      dl2rc();
    }
  }

  _ivecRst2();
}
Пример #2
0
void main(void)
{
  HAL_BOARD_INIT();
#if HAL_OTA_XNV_IS_SPI
  XNV_SPI_INIT();
#endif
  /* This is in place of calling HalDmaInit() which would require init of the
   * other 4 DMA descriptors in addition to just Channel 0.
   */
  HAL_DMA_SET_ADDR_DESC0( &dmaCh0 );

  while (1)
  {
    HalFlashRead(HAL_OTA_CRC_ADDR / HAL_FLASH_PAGE_SIZE,
                 HAL_OTA_CRC_ADDR % HAL_FLASH_PAGE_SIZE,
                 (uint8 *)&OTA_crcControl, sizeof(OTA_crcControl));

    if (OTA_crcControl.crc[0] == OTA_crcControl.crc[1])
    {
      break;
    }
    else if ((OTA_crcControl.crc[0] != 0) && (OTA_crcControl.crc[0] == crcCalc()))
    {
      OTA_crcControl.crc[1] = OTA_crcControl.crc[0];
      HalFlashWrite((HAL_OTA_CRC_ADDR / HAL_FLASH_WORD_SIZE), (uint8 *)OTA_crcControl.crc, 1);
    }
    else
    {
      dl2rc();
    }
  }

  // Simulate a reset for the Application code by an absolute jump to location 0x0800.
  asm("LJMP 0x800\n");
}
Пример #3
0
static void testCrc(const CRCConfig *config, uint32_t result) {
  uint32_t crc;

  crcAcquireUnit(&CRCD1);             /* Acquire ownership of the bus.    */
  crcStart(&CRCD1, config);           /* Activate CRC driver              */
  crcReset(&CRCD1);
  crc = crcCalc(&CRCD1, sizeof(data), &data);
  osalDbgAssert(crc == result, "CRC does not match expected result");
  crcStop(&CRCD1);                    /* Deactive CRC driver);            */
  crcReleaseUnit(&CRCD1);             /* Acquire ownership of the bus.    */
}
Пример #4
0
int serialReceive(char * data)
{
	char buffer[1028];
	char crchigh;
	char crclow;
	int read = 0;

	do
	{
        while(!(read = receivePackage(buffer)))
            {}

        // NOTICE: ONLY FOR TESTING. REMOVE AFTERWARDS
        int high = (unsigned char)buffer[0];
        int low = (unsigned char)buffer[1];
        int type = (unsigned char)buffer[2];
        int seq = (unsigned char)buffer[3];

        printf("High: %i\nLow: %i\nType: %i\nSeq: %i\nData: %s\n", high, low, type, seq, buffer+4);

        crcCalc(buffer+4, read-4, crchigh, crclow);

        if(crchigh == buffer[0] && crclow == buffer[1]) // Pakke rigtig
        {
            char ack[] = {0,0,1,buffer[3]};
            sendPackage(ack, 4);
            break;
        }
        else // Fejl i pakke
        {
            char wrong[] =  {0,0,0,buffer[3]};
            sendPackage(wrong , 4);
        }
	}while(1);

	for(int i = 4; i < read; i++) // Kopier til 'data'
		data[i-4] = buffer[i];

	return(read);

	SLIPClose();
}
Пример #5
0
void main(void)
{
  uint16 crc[2];

  HAL_BOARD_INIT();
#if HAL_OAD_XNV_IS_SPI
  XNV_SPI_INIT();
#endif
  /* This is in place of calling HalDmaInit() which would require init of the other 4 DMA
   * descriptors in addition to just Channel 0.
   */
  HAL_DMA_SET_ADDR_DESC0( &dmaCh0 );
  HalFlashInit();

  HalFlashRead(HAL_OAD_CRC_ADDR / HAL_FLASH_PAGE_SIZE,
               HAL_OAD_CRC_ADDR % HAL_FLASH_PAGE_SIZE,
               (uint8 *)crc, sizeof(crc));

  if (crc[0] != crc[1])
  {
    // If the CRC is erased or the RC code fails a sanity check, instantiate the DL code (again).
    if ((crc[0] == 0) || (crc[0] != crcCalc()))
    {
      dl2rc();

      /* If dl2rc() fails, a flawed image is allowed to run - 
       * maybe the damage is not fatal to OTA ops?
       */
    }
    else
    {
      crc[1] = crc[0];
      HalFlashWrite((HAL_OAD_CRC_ADDR / HAL_FLASH_WORD_SIZE), (uint8 *)crc, 1);
    }
  }

  // Simulate a reset for the Application code by an absolute jump to location 0x0800.
  asm("LJMP 0x800\n");
}
Пример #6
0
void serialSend(char * data , int size) // size = størrelse af hvad der skal sendes
{
	// Size checking
	if(size > MAX_DATA_LENGTH)
		size = MAX_DATA_LENGTH;

	static char seq = 0;
	char crchigh;
	char crclow;
	char array[1028];
	char buffer[1028];

	crcCalc(data, size, crchigh, crclow);

	array[0] = crchigh;
	array[1] = crclow;
	array[2] = 0;
	array[3] = seq;

	for(int i = 4; i < size+4; i++)
	{
		array[i] = data[i-4];
	}

	do
	{
	sendPackage(array, size+4);

    // NOTICE: ONLY FOR TESTING. REMOVE AFTERWARDS
    printf("Data: %u %u %u %u %s\n", (unsigned char)array[0], (unsigned char)array[1], (unsigned char)array[2], (unsigned char)array[3], array + 4);
	while(!receivePackage(buffer))
        {}

	}while(!buffer[2] == 1 && buffer[3] == seq);

	seq = !seq;
}
Пример #7
0
// fill out al and info for a given mate
// this does *not* fill in mapq, as that requires knowledge of which mate is the anchor as well as second-best scores
void DebugOutput::process_one_mate(DbgAlignment& al,
                                   DbgInfo& info,
                                   const AlignmentData& alignment,
                                   const AlignmentData& mate,
                                   const uint32 mapq)
{
    // output read_id as CRC of read name
    al.read_id = crcCalc(alignment.read_name, strlen(alignment.read_name));
    al.read_len = alignment.read_len;

    if (alignment.best->is_aligned())
    {
        // setup alignment information
        const io::BNTAnn* ann = std::upper_bound(
            bnt.data.anns,
            bnt.data.anns + bnt.info.n_seqs,
            alignment.cigar_pos,
            SeqFinder() ) - 1u;

        al.alignment_pos = alignment.cigar_pos - int32(ann->offset) + 1u;
        info.flag = (alignment.best->mate() ? DbgInfo::READ_2 : DbgInfo::READ_1) |
                    (alignment.best->is_rc() ? DbgInfo::REVERSE : 0u);

        if (alignment_type == PAIRED_END)
        {
            if (alignment.best->is_paired()) // FIXME: this should be other_mate.is_concordant()
            {
                info.flag |= DbgInfo::PROPER_PAIR;
            }

            if (mate.best->is_aligned() == false)
            {
                info.flag |= DbgInfo::MATE_UNMAPPED;
            }
        }

        const uint32 ref_cigar_len = reference_cigar_length(alignment.cigar, alignment.cigar_len);
        if (alignment.cigar_pos + ref_cigar_len > ann->offset + ann->len)
        {
            // flag UNMAPPED as this alignment bridges two adjacent reference sequences
            info.flag |= DbgInfo::UNMAPPED;
        }

        uint32 n_mm;
        uint32 n_gapo;
        uint32 n_gape;

        analyze_md_string(alignment.mds_vec, n_mm, n_gapo, n_gape);

        info.ref_id = uint32(ann - bnt.data.anns);
        info.mate   = alignment.best->mate();
        info.score  = alignment.best->score();
        info.mapQ   = mapq;
        info.ed     = alignment.best->ed();
        info.subs   = count_symbols(Cigar::SUBSTITUTION, alignment.cigar, alignment.cigar_len);
        info.ins    = count_symbols(Cigar::INSERTION, alignment.cigar, alignment.cigar_len);
        info.dels   = count_symbols(Cigar::DELETION, alignment.cigar, alignment.cigar_len);
        info.mms    = n_mm;
        info.gapo   = n_gapo;
        info.gape   = n_gape;
        info.sec_score = alignment.second_best->score();
        if (info.sec_score == alignment.second_best->is_aligned())
        {
            info.sec_score = alignment.second_best->score();
            info.has_second = 1;
        } else {
            info.sec_score = Field_traits<int16>::min();
            info.has_second = 0;
        }

        info.pad = 0x69;
    } else {
        // unmapped alignment
        al.alignment_pos = 0;
    }
}