Ejemplo n.º 1
0
void ANIM_prerenderFrames(void)
{
  uint32_t i;
  uint32_t magicWord = 0xef32;
  
  /* Get the starting address of the prerendered frames */
  uint32_t *addr = (uint32_t *)FRAMES_START;
  
  /* Get the end of the prerendered frames */
  uint32_t *lastAddr = addr + FRAME_BUFFER_SIZE_WORDS * NUM_FRAMES;
  
  /* Get the address of the current frame buffer */
  uint16_t *frameBuffer = FB_getActiveBuffer();
  
  /* Check the last address for the magic word. 
   * If this has been written the frames are already in flash 
   * and we can skip the entire prerendering step */
  if ( *lastAddr == magicWord ) {
    return;
  }
  
  MSC_Init();
  
  /* Make emWin draw to the frame buffer */
  FB_activateFrameBuffer();
  
  /* Add meta data to frame buffer */
  FB_writeControlSignals((uint8_t*)frameBuffer);
  
  /* Erase all the pages we are going to write to */
  while ( addr < lastAddr ) {
    MSC_ErasePage(addr);
    addr += FRAME_BUFFER_SIZE_WORDS;
  }
  
  addr = (uint32_t *)FRAMES_START;
    
  for ( i=0; i<NUM_FRAMES; i++ ) {
    
    /* Render a frame */
    GUI_DrawBitmap(frames[i], 0, 0);
    
    /* Copy entire frame buffer to flash */
    MSC_WriteWord(addr, frameBuffer, FRAME_BUFFER_SIZE_BYTES);
    addr += FRAME_BUFFER_SIZE_WORDS;
  }
  
  /* Write magic word to indicate that the frames are ready in Flash */
  MSC_WriteWord(lastAddr, &magicWord, 4);
  
  MSC_Deinit();
}
Ejemplo n.º 2
0
msc_Return_TypeDef Serialnum_write (uint32_t number)
{
	msc_Return_TypeDef ret;
	uint32_t *addr = (uint32_t *)USER_PAGE_ADDR;
	MSC_Init();
	ret = MSC_WriteWord(addr, &number, sizeof(number));
	MSC_Deinit();
	return ret;
}
Ejemplo n.º 3
0
Archivo: hw.c Proyecto: grissiom/fvs
rt_err_t fvs_native_write_m(void *addr, rt_uint8_t *data, rt_size_t len)
{
	msc_Return_TypeDef res;
	fvs_debug("FVS: write %d bytes of data to 0x%p\n", len, addr);
	res = MSC_WriteWord(addr, data, len);
	if (res != mscReturnOk)
		return -RT_ERROR;

	return RT_EOK;
}
Ejemplo n.º 4
0
Archivo: hw.c Proyecto: grissiom/fvs
rt_err_t fvs_native_write_r(void *addr, fvs_native_t data)
{
	msc_Return_TypeDef res;
	fvs_debug("FVS: write %X to 0x%p\n", data, addr);
	res = MSC_WriteWord(addr, &data, sizeof(data));
	if (res != mscReturnOk)
		return -RT_ERROR;

	return RT_EOK;
}
Ejemplo n.º 5
0
uint32_t utilsFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
{
    uint32_t rval = aSize;
    int32_t  status;

    otEXPECT_ACTION(aData, rval = 0);
    otEXPECT_ACTION(((aAddress + aSize) < utilsFlashGetSize()) && (!(aAddress & 3)) && (!(aSize & 3)), rval = 0);

    status = MSC_WriteWord((uint32_t *)mapAddress(aAddress), aData, aSize);
    otEXPECT_ACTION(returnTypeConvert(status) == OT_ERROR_NONE, rval = 0);

exit:
    return rval;
}
Ejemplo n.º 6
0
/**************************************************************************//**
 * @brief GPIO Interrupt handler (PB11)
 *        Saves the number to the userpage
 *****************************************************************************/
void GPIO_ODD_IRQHandler(void)
{
  msc_Return_TypeDef ret;

  /* Acknowledge interrupt */
  GPIO_IntClear(1 << 11);

  /* Initialize the MSC for writing */
  MSC_Init();

  /* Erase the page */
  //ret = MSC_ErasePage((uint32_t *) (USERPAGE + userData.numWrites * 256 ) );

  /* Check for errors. If there are errors, set the global error variable and
   * deinitialize the MSC */
  /*if (ret != mscReturnOk)
  {
    currentError = ret;
    MSC_Deinit();
    return;
  }*/



  /* Write data to the userpage */
  memset(userData.payload, userData.numWrites, 256);
  ret = MSC_WriteWord((uint32_t *) (USERPAGE + userData.numWrites * 256 ),
					  (void *) &userData.payload,
                      sizeof(UserData_TypeDef));

  /* Increase the number of saves */
  userData.numWrites++;

  /* Check for errors. If there are errors, set the global error variable and
   * deinitialize the MSC */
  if (ret != mscReturnOk)
  {
    currentError = ret;
    MSC_Deinit();
    return;
  }
  /* Deinitialize the MSC. This disables writing and locks the MSC */
  MSC_Deinit();

  /* Signal completion of save. The number of saves will be displayed */
  recentlySaved = true;
}
Ejemplo n.º 7
0
/***************************************************************************//**
 * @brief
 *   Write data to NVM.
 *
 * @details
 *   This function is used to write data to the NVM. This is a blocking
 *   function.
 *
 * @param[in] *pAddress
 *   NVM address to write to.
 *
 * @param[in] *pObject
 *   Pointer to source data.
 *
 * @param[in] len
 *   The length of the data in bytes.
 *
 * @return
 *   Returns the result of the write operation.
 ******************************************************************************/
Ecode_t NVMHAL_Write(uint8_t *pAddress, void const *pObject, uint16_t len)
{
  /* Used to carry return data. */
  MSC_Status_TypeDef mscStatus = mscReturnOk;
  /* Used as a temporary variable to create the blocks to write when padding to closest word. */
  uint32_t tempWord;

  /* Pointer to let us traverse the given pObject by single bytes. */
  uint8_t *pObjectInt = (uint8_t*)pObject;

  /* Temporary variable to cache length of padding needed. */
  uint8_t padLen;

  /* Get length of pad in front. */
  padLen = (uint32_t) pAddress % sizeof(tempWord);

  if (padLen != 0)
  {
    /* Get first word. */
    tempWord = readUnalignedWord((uint8_t *)pObject);

    /* Shift to offset. */
    tempWord = tempWord << 8 * padLen;
    /* Add nochanging padding. */
    tempWord |= NVMHAL_FFFFFFFF >> (8 * (sizeof(tempWord) - padLen));

    /* Special case for unaligned writes smaller than 1 word. */
    if (len < sizeof(tempWord) - padLen)
    {
      /* Add nochanging padding. */
      tempWord |= NVMHAL_FFFFFFFF << (8 * (padLen + len));
      len       = 0;
    }
    else
    {
      len -= sizeof(tempWord) - padLen;
    }

    /* Align the NVM write address */
    pAddress -= padLen;
    mscStatus = MSC_WriteWord((uint32_t *) pAddress, &tempWord, sizeof(tempWord));

    pObjectInt += sizeof(tempWord) - padLen;
    pAddress   += sizeof(tempWord);
  }
Ejemplo n.º 8
0
__ramfunc void FlushFlash( void )
#endif
{
  /* We can't serve interrupts while erasing or writing to flash. */
  INT_Disable();

  MSC->LOCK = MSC_UNLOCK_CODE;

  /* Erase flash page */
  MSC_ErasePage( (uint32_t*)flashStatus.pPageBase );

  /* Program flash page */
  MSC_WriteWord( (uint32_t*)flashStatus.pPageBase, flashPageBuf, flashPageSize );

  MSC->LOCK = 0;

  INT_Enable();
}