Ejemplo n.º 1
0
int main(void)
{
    DelayInit();
    UART_QuickInit(UART0_RX_PD06_TX_PD07, 115200);
    printf("CHBootloader\r\n");
    
    UART_CallbackRxInstall(HW_UART0, UART_ISR);
    FLASH_Init();
    
    Boot.name = "MK6xDN1M(512)VLQ12";
    Boot.AppStartAddr = 0x5000;
    Boot.TimeOut = 2000;
    Boot.FlashPageSize = FLASH_GetSectorSize();
    Boot.send = send;
    Boot.flash_erase = flash_erase;
    Boot.flash_write = flash_write;
    
    BootloaderInit(&Boot);
    
    UART_ITDMAConfig(HW_UART0, kUART_IT_Rx, true);
    
    while(1)
    {
        BootloaderProc();
    }
}
Ejemplo n.º 2
0
// Main
void main (void)
{
	// Init the system clock
	SystemInitClock();
	
	// Enable the peripherals
	SystemEnablePeripheral(PERIPHERAL_AFIO);
	SystemEnablePeripheral(PERIPHERAL_IOPA);
	SystemEnablePeripheral(PERIPHERAL_IOPB);
	SystemEnablePeripheral(PERIPHERAL_IOPC);
	SystemEnablePeripheral(PERIPHERAL_IOPD);
	SystemEnablePeripheral(PERIPHERAL_IOPE);
	SystemEnablePeripheral(PERIPHERAL_DMA1);

	// Init the FLASH chip and SPI module
	// Init the ENC chip and SPI module
	FLASH_Init();
	SPI1_Init();
	SPI2_Init();
	ENC_Init();

	// Init kernel
	KERNEL_Init();

	// Create tasks
	KERNEL_AddTask(&TaskDescriptor_TaskENC);

	// Start kernel (this function never returns)
	KERNEL_Start();
}
Ejemplo n.º 3
0
/**
 * \brief Method to test the flash chip.
 * @return void
 */
static void TestFlash(void) {
	uint8_t errCode;
	uint8_t test=55;
	uint8_t result=27;
	uint32_t testAddr=0x0000F300;
	uint8_t status=1;

	FLASH_Init();
	WAIT1_Waitms(1000);
	errCode = FLASH_ReadStatusReg(&status);
	if(errCode!=ERR_OK) {
		for(;;) {}
	}
	CLS1_SendStr((const unsigned char*)"\r\nStatus: ",CLS1_GetStdio()->stdOut);
	CLS1_SendNum16u(status,CLS1_GetStdio()->stdOut);
	for(;;) {}
	errCode = FLASH_WriteByte(testAddr,&test);
	if(errCode!=ERR_OK) {
		for(;;) {}
	}
	errCode = FLASH_ReadByte(testAddr,&result);
	if(errCode!=ERR_OK) {
		for(;;) {}
	}
	CLS1_SendStr((const unsigned char*)"\r\nOutput: ",CLS1_GetStdio()->stdOut);
	CLS1_SendNum16u(result,CLS1_GetStdio()->stdOut);
}
Ejemplo n.º 4
0
static int flash_mcux_init(struct device *dev)
{
	struct flash_priv *priv = dev->driver_data;
	status_t rc;

	rc = FLASH_Init(&priv->config);

	return (rc == kStatus_Success) ? 0 : -EIO;
}
Ejemplo n.º 5
0
otError utilsFlashInit(void)
{
    otError error = OT_ERROR_NONE;

    if (FLASH_Init(&sFlashConfig) != kStatus_FLASH_Success)
    {
        error = OT_ERROR_FAILED;
    }

    return error;
}
Ejemplo n.º 6
0
static int
mk64f12_flash_init(const struct hal_flash *dev)
{
    if (FLASH_Init(&mk64f12_config) == kStatus_Success) {
        mk64f12_flash_dev.hf_base_addr = mk64f12_config.PFlashBlockBase;
        mk64f12_flash_dev.hf_size = mk64f12_config.PFlashTotalSize;
        mk64f12_flash_dev.hf_sector_cnt =
             (mk64f12_config.PFlashTotalSize / mk64f12_config.PFlashSectorSize);
    }
    return 0;
}
Ejemplo n.º 7
0
static rt_err_t rt_dflash_init (rt_device_t dev)
{
    FLASH_Init();
    
    SectorSize = FLASH_GetSectorSize();
    StartAddr = RT_ALIGN(((uint32_t)&Image$$ER_IROM1$$RO$$Limit + SectorSize), SectorSize);
    DiskSize = FLASH_SIZE - StartAddr;
    rt_kprintf("dflash sector size:%d 0ffset:0x%X\r\n", SectorSize, StartAddr);
    
    mutex = rt_mutex_create("_mu", RT_IPC_FLAG_FIFO);
    
    return RT_EOK;
}
Ejemplo n.º 8
0
static int flash_mcux_init(struct device *dev)
{
	struct flash_priv *priv = dev->driver_data;
	uint32_t pflash_block_base;
	status_t rc;

	k_sem_init(&priv->write_lock, 0, 1);

	rc = FLASH_Init(&priv->config);

	FLASH_GetProperty(&priv->config, kFLASH_PropertyPflash0BlockBaseAddr,
			  &pflash_block_base);
	priv->pflash_block_base = (u32_t) pflash_block_base;

	return (rc == kStatus_Success) ? 0 : -EIO;
}
Ejemplo n.º 9
0
uint32_t FLASH_Test(uint32_t startAddr, uint32_t size)
{
    int addr, i,err;
    
    uint8_t *p;
    uint8_t buf[SECTOR_SIZE];
    
    FLASH_Init();
    
    for(i=0;i<SECTOR_SIZE;i++)
    {
        buf[i] = i % 0xFF;
    }
    
    for (addr = startAddr; addr<size; addr+=SECTOR_SIZE)
    {
        LIB_TRACE("program addr:0x%X ...", addr);
        err = FLASH_EraseSector(addr);
        err += FLASH_WriteSector(addr, buf, SECTOR_SIZE);
        if(err)
        {
            LIB_TRACE("issue command failed\r\n");
            return 1;
        }
        p = (uint8_t*)addr;
        LIB_TRACE("varify addr:0x%X ...", addr);
        for(i=0;i<SECTOR_SIZE;i++)
        {
            if(*p++ != (i%0xFF))
            {
                err++;
                LIB_TRACE("ERR:[%d]:0x%02X ", i, *p);
            }
        }
        if(!err)
            LIB_TRACE("OK\r\n");
        else
            LIB_TRACE("ERR\r\n");
    }
    return err;
}
Ejemplo n.º 10
0
int main(void)
{
    DelayInit();

    
    UART_Init(UART0_RX_PA01_TX_PA02, 115200);
    FLASH_Init();
    
    Boot.name = "Uranus";
    Boot.AppStartAddr = 0x5000;
    Boot.TimeOut = 2000;
    Boot.FlashPageSize = FLASH_GetSectorSize();
    Boot.send = send;
    Boot.flash_erase = flash_erase;
    Boot.flash_write = flash_write;
    
    BootloaderInit(&Boot);
    UART_SetIntMode(HW_UART0, kUART_IntRx, true);
    while(1)
    {
        BootloaderProc();
    }
}
Ejemplo n.º 11
0
void hal_Init_Flash(void)
{
  FLASH_Init();
}
Ejemplo n.º 12
0
int main (
  void
  )
{
  static UNSIGNED16 checksum;
  UNSIGNED8 bootCrcValid;
  UNSIGNED8 appCrcValid;

  // Disable all interrupts (just in case we jumped here)
  Disable_interrupt();
  
  // Initialize low-level hardware
  HW_Init();

  // Initialize Flash/EEPROM module and routines
  FLASH_Init();

  // Read node configuration and initialize status/error variables
  MAIN_Init();

  // Initialize Timer
  TIMER_Init();

  // Initialize CAN contoller
  CANHW_Init();

  // Initialize SDO handler
  SDO_Init();

  // Initialize Controls
  bootCrcValid = 0;
  appCrcValid = 0;

#if 0
  // If the bootloader is executed from power-up reset, initiate
  // waiting period of 60 seconds before attempting to start the
  // application.
  // Otherwise, we assume that the bootloader was called from the
  // application. In this case, send the bootup message (and don't
  // wait the 60 seconds).
  if ( gNodeStatus.run_mode == EXECMODE_POWERUP )
  {
    // Set the timer for the main waiting period in number of ticks
    TIMER_Set(TIMER_MAIN, WAIT_TIMEOUT*(1000/TIMERTICK_MS));
    gNodeStatus.run_mode = EXECMODE_TIMER;
  }
  else
  {
    gNodeStatus.run_mode = EXECMODE_NORMAL;
  }
#endif

  // Calculat bootloader checksum
  bootCrcValid = FLASH_Checksum_OK(BL_CHECKSUM_START, BL_CHECKSUM_END, BL_CHECKSUM_ADR, &checksum);

  // Check the bootloader (provides reference for embedded CRC)
  if ((0 == bootCrcValid) || (boot_crc == checksum))
  { // no error - do nothing
    ;
  }
  else
  { // Signal error. Extra info is the calculated checksum.
    MAIN_Signal_Error(ERRCODE_INTERNAL, checksum);
  }

  appCrcValid = FLASH_Checksum_OK(AP_CHECKSUM_START, AP_CHECKSUM_END, AP_CHECKSUM_ADR,   &checksum);

  // Check the main application checksum and set error status if wrong
  if (0 == appCrcValid)
  { // no error - do nothing
    ;
  }
  else
  { // Signal error. Extra info is the calculated checksum.
    MAIN_Signal_Error(ERRCODE_USER, checksum);
    // Don't auto-start application after timeout
    gNodeStatus.run_mode = EXECMODE_NORMAL;
  }

   // start_code: 0=power-up, 1=external, 2=brown-out, 3=watchdog, 4=J-Tag, 5=jump
   if ( (0 == bootCrcValid) ||
        (0 == appCrcValid) ||
        (2 == gNodeStatus.start_code) ||
        (3 == gNodeStatus.start_code) )
   {
      CANHW_Send_Boot();
      
      if ( (0 == bootCrcValid) )
      {
         CANHW_Send_Emergency(0x8000, 1, 0, 0, 0, 0);
      }
      else  if ( (2 == gNodeStatus.start_code) )
      {
         CANHW_Send_Emergency(0x8000, 2, 0, 0, 0, 0);
      }
      else if ( (3 == gNodeStatus.start_code) )
      {
         CANHW_Send_Emergency(0x8000, 3, 0, 0, 0, 0);
      }
      else if ( (0 == appCrcValid) )
      {
         CANHW_Send_Emergency(0x8000, 4, 0, 0, 0, 0);
      }

      gNodeStatus.run_mode = EXECMODE_NORMAL;
   }
   else if ( (0 == gNodeStatus.start_code) ||
             (1 == gNodeStatus.start_code) ||
             (4 == gNodeStatus.start_code) )
   {
      TIMER_Set(TIMER_MAIN, WAIT_TIMEOUT*(1000/TIMERTICK_MS));
      gNodeStatus.run_mode = EXECMODE_TIMER;
   }
   else if ( (5 == gNodeStatus.start_code) )
   {
      gNodeStatus.run_mode = EXECMODE_NORMAL;
   }
   else
   {
      // Set the location of the interrupt vectors to 0
      MCUCR = BIT(IVCE);
      MCUCR = 0x00;
      // Call the absolute address RESVEC_ADR
      ((void(*)(void))RESVEC_ADR)();
   }

  // Endless loop to execute the bootloader. The only exit point is
  // a jump to the application if the condition for execution is
  // fulfilled.
  for ( ;; )
  {
    BOOLEAN message_processed;

    // Update timers
    TIMER_Poll();

    // Serve the watchdog
    COP_Serve();

    // Check for a waiting CAN message and process them (SDO, NMT).
    // This can change the execution mode!
    message_processed = CANHW_Process_Messages();

    // If requested, check the application and jump to it, if successful
    if ( gNodeStatus.run_mode == EXECMODE_RUN )
    {
      // Jump to main application, if the checksum is ok
      if ( FLASH_Checksum_OK(AP_CHECKSUM_START, AP_CHECKSUM_END,
                             AP_CHECKSUM_ADR,   &checksum)     )
      {
        // Set the location of the interrupt vectors to 0
        MCUCR = BIT(IVCE);
        MCUCR = 0x00;
        // Call the absolute address RESVEC_ADR
        ((void(*)(void))RESVEC_ADR)();
      }
      else
      { // Checksum not valid: Don't start application and report error, stay here
        CANHW_Send_Emergency(0x8000, 4, 0, 0, 0, 0);
        MAIN_Signal_Error(ERRCODE_USER, checksum); // Signal error. Extra info is the calculated checksum.
        gNodeStatus.run_mode = EXECMODE_NORMAL;
      }
    }
    else if ( gNodeStatus.run_mode == EXECMODE_TIMER )
    { // check for other conditions when running in timed mode

      if ( message_processed )
      { // After a successfully received message leave the timed mode
        gNodeStatus.run_mode = EXECMODE_NORMAL;
      }
      else if ( TIMER_Expired(TIMER_MAIN) )
      { // Check for initial 60 second waiting period, if expired prepare
        // for running the application.
        gNodeStatus.run_mode = EXECMODE_RUN;
      }
      else
      { // do nothing
        ;
      }
    }
    else
    { // do nothing
      ;
    }
  } // for ever loop

  // don't return from here
  return(0);
}
Ejemplo n.º 13
0
void HEXIWEAR_startup( task_param_t param )
{
    uint8_t
    status = 0;

    /** output GPIO config */

    GPIO_DRV_Init( NULL, OLED_cfg );
    GPIO_DRV_Init( NULL, FLASH_cfg );
    GPIO_DRV_Init( NULL, PWR_cfg );
    GPIO_DRV_Init( NULL, VIBRO_cfg );
    GPIO_DRV_Init( NULL, RGB_cfg );
    GPIO_DRV_Init( NULL, KW40_GPIO_cfg );
    GPIO_DRV_Init( NULL, REL_GPIO_cfg );


    /** input GPIO config */

    GPIO_DRV_Init( BAT_CHG_cfg, NULL );
    GPIO_DRV_Init( TAP_cfg, NULL );

    // lajkatest
    // GPIO_DRV_Init( GPIO_TEST_CFG, NULL );

#if defined( HEXIWEAR_DEBUG )
    GPIO_DRV_Init( NULL, DEBUG_cfg );
#endif

    power_ResetKW40();
    timer_Init( HEXIWEAR_TIMER_SENSOR );

    status |= RTC_Init();
    status |= FLASH_Init( &flashModule, &flashSettings );

    // intern flash initialization
    INTFLASH_Init();

    // enable power save by default
    // power_EnablePowerSave();
    power_DisablePowerSave();

    // set to deep sleep by default
    // power_SetSleepMode( POWER_SLEEP_TYPE_DEEP );

    // RGB off
    FLASH_SetOFF();

    // visual indication for testing HR sensor
//  MAXIM_Test();

    /** create basic tasks */
    status |= Notification_Init();
    status |= HostInterface_Init();
    status |= sensor_Init();
    status |= power_Init();
    status |= GuiDriver_Init();

    haptic_MutexCreate();

    sensor_InitAcc();

    /** set GPIO interrupt for the tap function */
    PORT_HAL_SetPinIntMode( PORTC, 1, kPortIntFallingEdge );

    /** set charging battery interrupt */
    PORT_HAL_SetPinIntMode( PORTC, 12, kPortIntEitherEdge );
    NVIC_SetPriority( PORTC_IRQn, HEXIWEAR_CHG_IRQ_PRIO );
    INT_SYS_EnableIRQ( PORTC_IRQn );

    // status |= Run_USB_Task();

    if ( HEXIWEAR_STATUS_SUCCESS != status )
    {
        catch( CATCH_INIT );
    }

    /** check for settings in flash at startup */
    gui_sensorTag_CheckAtStartup();
    haptic_CheckAtStartup();

    CLOCK_SYS_Init( g_clockManConfigsArr, FSL_CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, FSL_CLOCK_MANAGER_CALLBACK_CNT );
    POWER_SYS_Init( powerConfigsArr, 2U, powerStaticCallbacksConfigsArr , 2U );

    // make battery readings regular
    sensor_SetPacketTargets( PACKET_BAT, sensor_GetPacketTargets( PACKET_BAT) | PACKET_PUSH_POWER_MGMT, true );

    volatile uint32_t
    foo = CLOCK_SYS_GetSystemClockFreq();

    while (1)
    {
        OSA_TaskDestroy( NULL );
    }
}
Ejemplo n.º 14
0
void HEXIWEAR_startup( task_param_t param )
{
  uint8_t
    status = 0;

  /** output GPIO configuration */

  GPIO_DRV_Init( NULL, OLED_cfg );
  GPIO_DRV_Init( NULL, FLASH_cfg );
  GPIO_DRV_Init( NULL, PWR_cfg );
  GPIO_DRV_Init( NULL, VIBRO_cfg );
  GPIO_DRV_Init( NULL, RGB_cfg );
  GPIO_DRV_Init( NULL, KW40_GPIO_cfg );


  /** input GPIO configuration */

  GPIO_DRV_Init( BAT_CHG_cfg, NULL );
  GPIO_DRV_Init( TAP_cfg, NULL );

#if defined( HEXIWEAR_DEBUG )
  GPIO_DRV_Init( NULL, DEBUG_cfg );
#endif

  power_ResetKW40();
  timer_Init( HEXIWEAR_TIMER_SENSOR );

  status |= RTC_Init();
  status |= FLASH_Init( &flashModule, &flashSettings );

  // intern flash initialization
  INTFLASH_Init();

  // RGB off
  FLASH_SetOFF();

  /** create basic tasks */
  status |= Notification_Init();
  status |= HostInterface_Init();
  status |= sensor_Init();
  status |= GuiDriver_Init();

  haptic_MutexCreate();

  sensor_InitAcc();

  /** set GPIO interrupt for the tap function */
  PORT_HAL_SetPinIntMode( PORTC, 1, kPortIntFallingEdge );

  /** set charging battery interrupt */
  PORT_HAL_SetPinIntMode( PORTC, 12, kPortIntEitherEdge );
  NVIC_SetPriority( PORTC_IRQn, HEXIWEAR_CHG_IRQ_PRIO );
  INT_SYS_EnableIRQ( PORTC_IRQn );

  if ( HEXIWEAR_STATUS_SUCCESS != status )
  {
    catch( CATCH_INIT );
  }

  /** check for settings in flash at startup */
  gui_sensorTag_CheckAtStartup();
  haptic_CheckAtStartup();

  CLOCK_SYS_Init( g_clockManConfigsArr, FSL_CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, FSL_CLOCK_MANAGER_CALLBACK_CNT );
  POWER_SYS_Init( powerConfigsArr, 2U, powerStaticCallbacksConfigsArr , 2U );

  // turn on regular battery readings
  sensor_SetPacketTargets( PACKET_BAT, sensor_GetPacketTargets( PACKET_BAT) | PACKET_PUSH_POWER_MGMT, true );

  while (1)
  {
    power_Init();
    OSA_TaskDestroy( NULL );
  }
}