Пример #1
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  int result;

  /* Initialize DK board register access */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize USART and map LF to CRLF */
  RETARGET_SerialInit();
  RETARGET_SerialCrLf(1);

  printf("\nEFM32LG_DK3650 HardFault handler example\n");

  HardFault_TrapDivByZero();
  HardFault_TrapUnaligned();

  /* Enable one of these function calls */
  // result = BadFunctionAccess();
  // result = BadFunctionDiv();
  result = BadFunctionUnaligned();

  printf("ERROR: The fault was not trapped (result=%d)\n", result);

  while(1);
}
Пример #2
0
int main(void)
{
  /* Chip errata */
  CHIP_Init();
  
  /* Enable HFXO */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
    
  /* Enable deboug output over UART */
  RETARGET_SerialInit();                     
  RETARGET_SerialCrLf(1); 
  
  /* Enable the segment LCD */
  SegmentLCD_Init(false);
  SegmentLCD_Write("USB");
  
  printf("\nStarting USB Device...\n");
  
  /* Set up GPIO interrupts */
  gpioInit();
  
  /* Start USB stack. Callback routines in callbacks.c will be called
   * when connected to a host.  */
  USBD_Init(&initstruct);;

  /*
   * When using a debugger it is pratical to uncomment the following three
   * lines to force host to re-enumerate the device.
   */
  /* USBD_Disconnect(); */
  /* USBTIMER_DelayMs( 1000 ); */
  /* USBD_Connect(); */
    
  while(1)
  {
    if ( USBD_SafeToEnterEM2() )
    {
      /* Enter EM2 when in suspend or disconnected */
      EMU_EnterEM2(true);
    } 
    else
    {
      /* When USB is active we can sleep in EM1. */
      EMU_EnterEM1();
    }
  } 
}
Пример #3
0
/*
*********************************************************************************************************
*                                                main()
*
* Description : This is the standard entry point for C code.  It is assumed that your code will call
*               main() once you have performed all necessary initialization.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/
int main(void)
{
#if (OS_TASK_NAME_EN > 0)
  CPU_INT08U  err;
#endif

  /* Disable all interrupts until we are ready to accept
   * them.                                                */
  CPU_IntDis();

  /* Chip errata */
  CHIP_Init();

  /* setup SW0 for energyAware Profiler */
  BSP_TraceSwoSetup();

  /* Initialize serial port                               */
  RETARGET_SerialInit();

  /* Map LF to CRLF                                       */
  RETARGET_SerialCrLf(1);

  /* Initialize "uC/OS-II, The Real-Time Kernel".         */
  OSInit();

  /* Create the start task                                */
  OSTaskCreateExt((void (*)(void *)) App_TaskStart,
                  (void           *) 0,
                  (OS_STK         *)&App_TaskStartStk[APP_CFG_TASK_START_STK_SIZE - 1],
                  (INT8U           ) APP_CFG_TASK_START_PRIO,
                  (INT16U          ) APP_CFG_TASK_START_PRIO,
                  (OS_STK         *)&App_TaskStartStk[0],
                  (INT32U          ) APP_CFG_TASK_START_STK_SIZE,
                  (void           *) 0,
                  (INT16U          )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));

#if (OS_TASK_NAME_EN > 0)
  OSTaskNameSet(APP_CFG_TASK_START_PRIO, (INT8U *)"Start", &err);
#endif

  /* Start multitasking (i.e. give control to uC/OS-II).  */
  OSStart();

  /* OSStart() never returns, serious error had occured if
   * code execution reached this point                    */
  while(1) ;
}
Пример #4
0
/**************************************************************************//**
 * @brief main - the entrypoint after reset.
 *****************************************************************************/
int main( void )
{
#if !defined(BUSPOWERED)
  BSP_Init(BSP_INIT_DEFAULT);   /* Initialize DK board register access */

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();
#endif

  CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
  CMU_OscillatorEnable(cmuOsc_LFXO, true, false);

#if !defined(BUSPOWERED)
  RETARGET_SerialInit();        /* Initialize DK UART port */
  RETARGET_SerialCrLf( 1 );     /* Map LF to CRLF          */
  printf( "\nEFM32 Mass Storage Device example\n" );
#endif

  if ( !MSDDMEDIA_Init() )
  {
#if !defined(BUSPOWERED)
    printf( "\nMedia error !\n" );
#endif
    EFM_ASSERT( false );
    for( ;; ){}
  }

  MSDD_Init(gpioPortE, 1);

  for (;;)
  {
    if ( MSDD_Handler() )
    {
      /* There is no pending activity in the MSDD handler.  */
      /* Enter sleep mode to conserve energy.               */

      if ( USBD_SafeToEnterEM2() )
        EMU_EnterEM2(true);
      else
        EMU_EnterEM1();
    }
  }
}
Пример #5
0
/*
*********************************************************************************************************
*                                          AppTaskStart()
*
* Description : The startup task. The uC/OS-III ticker should only be initialize once multitasking starts.
*
* Argument(s) : p_arg       Argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                   used.  The compiler should not generate any code for this statement.
*
*               (2) Interrupts are enabled once the task starts because the I-bit of the CCR register was
*                   set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void App_TaskStart(void *p_arg)
{
  uint16_t osVersion1, osVersion2, osVersion3;

  OS_ERR err = OS_ERR_NONE;

  (void)p_arg; /* Note(1) */

  /* Initialize BSP functions                             */
  BSPOS_Init();

  /* Initialize the uC/OS-III ticker                       */
  OS_CPU_SysTickInit(OS_CPU_SysTickClkFreq() / OS_CFG_TICK_RATE_HZ);

#if (OS_TASK_STAT_EN > 0U)
  /* Determine CPU capacity                               */
  OSStatInit();
#endif

  /* Create application tasks                             */
  App_TaskCreate();

  /* Create application mailboxes                         */
  App_MailboxCreate();

  /* Enable RS232A peripheral                             */
  BSP_PeripheralAccess(BSP_RS232A, true);

  /* Initialize Serial                                    */
  RETARGET_SerialInit();

  /* Map LF to CRLF                                       */
  RETARGET_SerialCrLf(1);

  /* Initialize LCD                                       */
  SegmentLCD_Init(true);

  /* Turn gecko symbol ON                                 */
  SegmentLCD_Symbol(LCD_SYMBOL_GECKO, 1);

  /* Turn EFM32 symbol ON                                 */
  SegmentLCD_Symbol(LCD_SYMBOL_EFM32, 1);

  /* Write welcome message on LCD                         */
  SegmentLCD_Write("uC/OS-3");

  osVersion3 = OSVersion( &err );
  osVersion1 = osVersion3 / 10000;
  osVersion3 -= osVersion1 * 10000;
  osVersion2 = osVersion3 / 100;
  osVersion3 -= osVersion2 * 100;
  osVersion3 %= 100;

  /* Write welcome message on serial                      */
  printf("\n*****************************************************************************");
  printf("\n                    uC/OS-III v%d.%02d.%02d on Energy Micro EFM32 DVK             ",
         osVersion1, osVersion2, osVersion3 );
  printf("\n                               Demo Application                              \n");
  printf("\n                                   uC/OS-III                                  ");
  printf("\n                           \"The real time kernel\"                            ");
  printf("\n                               www.micrium.com                               ");
  printf("\n\n                                is running on                              ");
  printf("\n\n                             Energy Micro EFM32                              ");
  printf("\n            \"The world's most energy friendly microcontrollers\"              ");
  printf("\n                            www.energymicro.com                              \n");
  printf("\nDescription:");
  printf("\nTask1: LED blink task");
  printf("\nTask2: Receives characters from serial  and posts message to Task3");
  printf("\nTask3: Receives message from Task2 and writes it on LCD and serial ");
  printf("\n*****************************************************************************\n");
  printf("\nStart typing...\n");

  /* Suspend this task as it is only used once in one Reset cycle */
  OSTaskSuspend(&AppTaskStartTCB, &err);

  /* Error had occured if code execution reached this point as suspend calls the scheduler
   * that performs a context switch */
  while (1U) ;
}
Пример #6
0
/*
*********************************************************************************************************
*                                          AppTaskStart()
*
* Description : The startup task.  The uC/OS-II ticker should only be initialize once multitasking starts.
*
* Argument(s) : p_arg       Argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                   used.  The compiler should not generate any code for this statement.
*
*               (2) Interrupts are enabled once the task starts because the I-bit of the CCR register was
*                   set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void App_TaskStart(void *p_arg)
{
  (void)p_arg; /* Note(1) */
  uint16_t osVersion1, osVersion2, osVersion3;

  /* Initialize BSP functions                             */
  BSPOS_Init();

  /* Initialize the uC/OS-II ticker                       */
  OS_CPU_SysTickInit(CMU_ClockFreqGet(cmuClock_HFPER)/OS_TICKS_PER_SEC);

#if (OS_TASK_STAT_EN > 0)
  /* Determine CPU capacity                               */
  OSStatInit();
#endif

  /* Create application tasks                             */
  App_TaskCreate();

  /* Create application mailboxes                         */
  App_MailboxCreate();

  /* Initialize LCD                                       */
  SegmentLCD_Init(true);

  /* Turn gecko symbol ON                                 */
  SegmentLCD_Symbol(LCD_SYMBOL_GECKO, 1);

  /* Turn EFM32 symbol ON                                 */
  SegmentLCD_Symbol(LCD_SYMBOL_EFM32, 1);

  /* Write welcome message on LCD                         */
  SegmentLCD_Write("uC/OS-2");

/* As USART connectors are not available on the STK by default,
 * therefore printf() functions are turned off.
 * Uncomment the macro definition in includes.h if serial
 * is connected to your STK board (USART1 or LEUART0)!    */
#ifdef USART_CONNECTED

  /* Initialize serial port                               */
  RETARGET_SerialInit();
  RETARGET_SerialCrLf(1);

  osVersion3 = OSVersion();
  osVersion1 = osVersion3 / 10000;
  osVersion3 -= osVersion1 * 10000;
  osVersion2 = osVersion3 / 100;
  osVersion3 -= osVersion2 * 100;
  osVersion3 %= 100;

  /* Write welcome message on serial              */
  printf("\n*****************************************************************************");
  printf("\n                uC/OS-II v%d.%02d.%02d on Silicon Labs EFM32WG STK             ",
         osVersion1, osVersion2, osVersion3 );
  printf("\n                               Demo Application                              \n");
  printf("\n                                   uC/OS-II                                  ");
  printf("\n                           \"The real time kernel\"                            ");
  printf("\n                               www.micrium.com                               ");
  printf("\n\n                                is running on                              ");
  printf("\n\n                             Silicon Labs EFM32                              ");
  printf("\n            \"The world's most energy friendly microcontrollers\"              ");
  printf("\n                              www.silabs.com                                 \n");
  printf("\nDescription:");
  printf("\nTask1: LED blink task");
  printf("\nTask2: Receives characters from serial and posts message to Task3");
  printf("\nTask3: Receives message from Task2 and writes it on LCD and serial");
  printf("\n*****************************************************************************\n");
  printf("\nStart typing...\n");

#endif /* end of #ifndef USART_CONNECTED */

  /* Suspend this task as it is only used once in one Reset cycle */
  OSTaskSuspend(APP_CFG_TASK_START_PRIO);

  while (1)
  {/* endless loop of Start task                          */
    ;
  }
}
Пример #7
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  int c;
  MPU_RegionInit_TypeDef flashInit       = MPU_INIT_FLASH_DEFAULT;
  MPU_RegionInit_TypeDef sramInit        = MPU_INIT_SRAM_DEFAULT;
  MPU_RegionInit_TypeDef peripheralInit  = MPU_INIT_PERIPHERAL_DEFAULT;

  /* Chip revision alignment and errata fixes */
  CHIP_Init();

  /* Initialize DK board register access */
  BSP_Init(BSP_INIT_DK_SPI);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Enable printf on RS232 port - this example only supports LEUART */
  RETARGET_SerialInit();
  RETARGET_SerialCrLf(1);

  printf("\nEFM32 MPU access violation example.\n"
           "Hit lowercase 'x' to force access violations.\n");

  MPU_Disable();

  /* Flash memory */
  MPU_ConfigureRegion( &flashInit );

  /* SRAM */
  MPU_ConfigureRegion( &sramInit );

  /* SRAM, a 4k part with priviledged only access, this regions settings  */
  /* will override those of the previous region                           */
  sramInit.regionNo         = 2;
  sramInit.baseAddress      = RAM_MEM_BASE + 0x2000;
  sramInit.size             = mpuRegionSize4Kb;
  sramInit.accessPermission = mpuRegionApPRw;
  MPU_ConfigureRegion( &sramInit );

  /* LEUART, priviledged only access */
  peripheralInit.regionNo         = 3;
  peripheralInit.baseAddress      = LEUART1_BASE;
  peripheralInit.size             = mpuRegionSize128b;
  peripheralInit.accessPermission = mpuRegionApPRw;
  MPU_ConfigureRegion( &peripheralInit );

  MPU_Enable( MPU_CTRL_PRIVDEFENA ); /* Full access to default memory map */
                                     /* in priviledged state              */

  while (1)
  {
    EMU_EnterEM2(true);

    /* Retrieve new character */
    c = getchar();
    if (c > 0)
    {
      if ( c == 'x' )
      {
        /* Generate an access violation in LEUART1 peripheral     */
        __set_CONTROL( 1 );   /* Enter User (unpriviledged) state */
        putchar( c );

        /* MemManage_Handler() will set back to priviledged state */

        /* Generate an access violation in internal SRAM          */
        __set_CONTROL( 1 );   /* Enter User (unpriviledged) state */
        *(volatile uint32_t *)(RAM_MEM_BASE + 0x2000) = 1;

        /* MemManage_Handler() will set back to priviledged state */
      }
    else
      {
      /* Echo character */
      putchar(c);
      }
    }

    /* Most terminals issue CR when pressing enter, add LF */
    if (c == '\r')
    {
      putchar('\n');
    }
  }
}
Пример #8
0
/**************************************************************************//**
 * @brief Initialize console I/O redirection.
 *****************************************************************************/
static void ConsoleDebugInit(void)
{
  RETARGET_SerialInit();                        /* Initialize USART   */
  RETARGET_SerialCrLf(1);                       /* Map LF to CRLF     */
}
Пример #9
0
/*
*********************************************************************************************************
*                                                main()
*
* Description : This is the standard entry point for C code.  It is assumed that your code will call
*               main() once you have performed all necessary initialization.
*
* Argument(s) : none.
*
* Return(s)   : none.
*********************************************************************************************************
*/
int main(void)
{
  uint16_t osVersion1, osVersion2, osVersion3;
#if (OS_TASK_NAME_EN > 0)
  CPU_INT08U  err;
#endif


  /* Disable all interrupts until we are ready to accept
   * them.                                                */
  CPU_IntDis();

  /* Chip errata */
  CHIP_Init();

  /* setup SW0 for energyAware Profiler */
  setupSWO();

  /* Initialize BSP functions                             */
  BSPOS_Init();

  /* Initialize "uC/OS-II, The Real-Time Kernel".         */
  OSInit();

  /* Initialize the uC/OS-II ticker                       */
   OS_CPU_SysTickInit(CMU_ClockFreqGet(cmuClock_HFPER)/OS_TICKS_PER_SEC);

 #if (OS_TASK_STAT_EN > 0)
   /* Determine CPU capacity                               */
   OSStatInit();
 #endif

   /* Create application tasks                             */
   App_TaskCreate();

   /* Create application mailboxes                         */
   App_MailboxCreate();

   /* Initialize LCD                                       */
   SegmentLCD_Init(true);

   /* Turn gecko symbol ON                                 */
   SegmentLCD_Symbol(LCD_SYMBOL_GECKO, 1);

   /* Turn EFM32 symbol ON                                 */
   SegmentLCD_Symbol(LCD_SYMBOL_EFM32, 1);

   /* Write welcome message on LCD                         */
   SegmentLCD_Write("uC/OS-2");

/* As USART connectors are not available on the STK by default,
 * therefore printf() functions are turned off.
 * Uncomment the macro definition in includes.h if serial
 * is connected to your STK board (USART1 or LEUART0)!    */
 #ifdef USART_CONNECTED

   /* Initialize                                          */
   RETARGET_SerialInit();
   RETARGET_SerialCrLf(1);

  osVersion3 = OSVersion();
  osVersion1 = osVersion3 / 10000;
  osVersion3 -= osVersion1 * 10000;
  osVersion2 = osVersion3 / 100;
  osVersion3 -= osVersion2 * 100;
  osVersion3 %= 100;

   /* Write welcome message on serial                     */
   printf("\n*****************************************************************************");
   printf("\n                uC/OS-II v%d.%02d.%02d on Silicon Labs EFM32TG STK             ",
         osVersion1, osVersion2, osVersion3 );
   printf("\n                               Demo Application                              \n");
   printf("\n                                   uC/OS-II                                  ");
   printf("\n                           \"The real time kernel\"                            ");
   printf("\n                               www.micrium.com                               ");
   printf("\n\n                                is running on                              ");
   printf("\n\n                             Silicon Labs EFM32                              ");
   printf("\n            \"The world's most energy friendly microcontrollers\"              ");
   printf("\n                              www.silabs.com                                 \n");
   printf("\nDescription:");
   printf("\nTask1: LED blink task");
   printf("\nTask2: Receives characters from serial and posts message to Task3");
   printf("\nTask3: Receives message from Task2 and writes it on LCD and serial ");
   printf("\n*****************************************************************************\n");
   printf("\nStart typing...\n");

 #endif /* end of #ifndef USART_CONNECTED */

  /* Start multitasking (i.e. give control to uC/OS-II).  */
  OSStart();

  /* OSStart() never returns, serious error had occured if
   * code execution reached this point                    */
  while(1) ;
}
Пример #10
0
/*
*********************************************************************************************************
*                                          AppTaskStart()
*
* Description : The startup task. The uC/OS-III ticker should only be initialize once multitasking starts.
*
* Argument(s) : p_arg       Argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                   used.  The compiler should not generate any code for this statement.
*
*               (2) Interrupts are enabled once the task starts because the I-bit of the CCR register was
*                   set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void App_TaskStart(void *p_arg)
{
  uint16_t osVersion1, osVersion2, osVersion3;

  OS_ERR err = OS_ERR_NONE;

  (void)p_arg; /* Note(1) */


  /* Initialize BSP functions                             */
  BSPOS_Init();

  /* Initialize the uC/OS-III ticker                       */
  OS_CPU_SysTickInit(OS_CPU_SysTickClkFreq() / OS_CFG_TICK_RATE_HZ);

#if (OS_TASK_STAT_EN > 0U)
  /* Determine CPU capacity                               */
  OSStatInit();
#endif

  /* Create application tasks                             */
  App_TaskCreate();

  /* Create application mailboxes                         */
  App_MailboxCreate();

  /* Initialize LCD                                       */
  SegmentLCD_Init(true);

  /* Turn gecko symbol ON                                 */
  SegmentLCD_Symbol(LCD_SYMBOL_GECKO, 1);

  /* Turn EFM32 symbol ON                                 */
  SegmentLCD_Symbol(LCD_SYMBOL_EFM32, 1);

  /* Write welcome message on LCD                         */
  SegmentLCD_Write("uC/OS-3");

/* As USART connectors are not available on the STK by default,
 * therefore printf() functions are turned off.
 * Uncomment the macro definition in includes.h if serial
 * is connected to your STK board (USART1 or LEUART0)!    */
#ifdef USART_CONNECTED

  /* Initialize serial port                               */
  RETARGET_SerialInit();
  RETARGET_SerialCrLf(1);

  osVersion3 = OSVersion( &err );
  osVersion1 = osVersion3 / 10000;
  osVersion3 -= osVersion1 * 10000;
  osVersion2 = osVersion3 / 100;
  osVersion3 -= osVersion2 * 100;
  osVersion3 %= 100;

  /* Write welcome message on serial                      */
  printf("\n*****************************************************************************");
  printf("\n                    uC/OS-III v%d.%02d.%02d on Energy Micro EFM32 STK             ",
         osVersion1, osVersion2, osVersion3 );
  printf("\n                               Demo Application                              \n");
  printf("\n                                   uC/OS-III                                  ");
  printf("\n                           \"The real time kernel\"                            ");
  printf("\n                               www.micrium.com                               ");
  printf("\n\n                                is running on                              ");
  printf("\n\n                             Energy Micro EFM32                              ");
  printf("\n            \"The world's most energy friendly microcontrollers\"              ");
  printf("\n                            www.energymicro.com                              \n");
  printf("\nDescription:");
  printf("\nTask1: LED blink task");
  printf("\nTask2: Receives characters from serial and posts message to Task3");
  printf("\nTask3: Receives message from Task2 and writes it on LCD and serial.");
  printf("\n*****************************************************************************\n");
  printf("\nStart typing...\n");

#endif /* end of #ifndef USART_CONNECTED */

  /* Suspend this task as it is only used once in one Reset cycle */
  OSTaskSuspend(&AppTaskStartTCB, &err);

  /* Error had occured if code execution reached this point as suspend calls the scheduler
   * that performs a context switch */
  while (1U) ;
}
Пример #11
0
/*
*********************************************************************************************************
*                                          AppTaskStart()
*
* Description : The startup task.  The uC/OS-II ticker should only be initialize once multitasking starts.
*
* Argument(s) : p_arg       Argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                   used.  The compiler should not generate any code for this statement.
*
*               (2) Interrupts are enabled once the task starts because the I-bit of the CCR register was
*                   set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void App_TaskStart(void *p_arg)
{
  (void)p_arg; /* Note(1) */
  uint16_t osVersion1, osVersion2, osVersion3;

  /* Initialize BSP functions                             */
  BSPOS_Init();

  /* Initialize the uC/OS-II ticker                       */
  OS_CPU_SysTickInit(CMU_ClockFreqGet(cmuClock_HFPER)/OS_TICKS_PER_SEC);

#if (OS_TASK_STAT_EN > 0)
  /* Determine CPU capacity                               */
  OSStatInit();
#endif

  /* Create application tasks                             */
  App_TaskCreate();

  /* Create application mailboxes                         */
  App_MailboxCreate();

  /* Enable RS232A peripheral                             */
  BSP_PeripheralAccess(BSP_RS232_UART, true);

  /* Initialize serial port                               */
  RETARGET_SerialInit();

  /* Map LF to CRLF                                       */
  RETARGET_SerialCrLf(1);

  /* Initialize LCD                                       */
  SegmentLCD_Init(true);

  /* Turn gecko symbol ON                                 */
  SegmentLCD_Symbol(LCD_SYMBOL_GECKO, 1);

  /* Turn EFM32 symbol ON                                 */
  SegmentLCD_Symbol(LCD_SYMBOL_EFM32, 1);

  /* Write welcome message on LCD                         */
  SegmentLCD_Write("uC/OS-2");

  osVersion3 = OSVersion();
  osVersion1 = osVersion3 / 10000;
  osVersion3 -= osVersion1 * 10000;
  osVersion2 = osVersion3 / 100;
  osVersion3 -= osVersion2 * 100;
  osVersion3 %= 100;

  /* Write welcome message on serial                      */
  printf("\n*****************************************************************************");
  printf("\n                uC/OS-II v%d.%02d.%02d on Silicon Labs EFM32G_DK3550              ",
         osVersion1, osVersion2, osVersion3 );
  printf("\n                               Demo Application                              \n");
  printf("\n                                   uC/OS-II                                  ");
  printf("\n                           \"The real time kernel\"                            ");
  printf("\n                               www.micrium.com                               ");
  printf("\n\n                                is running on                              ");
  printf("\n\n                             Silicon Labs EFM32                              ");
  printf("\n            \"The world's most energy friendly microcontrollers\"              ");
  printf("\n                              www.silabs.com                                 \n");
  printf("\nDescription:");
  printf("\nTask1: LED blink task");
  printf("\nTask2: Receives characters from serial and posts message to Task3");
  printf("\nTask3: Receives message from Task2 and writes it on LCD and serial.");
  printf("\n*****************************************************************************\n");
  printf("\nStart typing...\n");

  /* Suspend this task as it is only used once in one Reset cycle */
  OSTaskSuspend(APP_CFG_TASK_START_PRIO);

  while (1)
  {/* endless loop of Start task                          */
    ;
  }
}
Пример #12
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  int c;
  int index;

  /* Initialize DK board register access */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Initialize USART and map LF to CRLF */
  RETARGET_SerialInit();
  RETARGET_SerialCrLf(1);

#ifdef RETARGET_LEUART1
  printf("\nEFM32WG_DK3850 LEUART1 example\n");
#else
  printf("\nEFM32WG_DK3850 UART1 example\n");
#endif
  for (index = 0; index < ECHOBUFSIZE; index++)
  {
    echoBuffer[index] = (char) 'a' + index;
  }

  /* Retrieve characters, print local echo and full line back */
  index = 0;
  while (1)
  {
    /* Retrieve new character */
    c = getchar();
    if (c > 0)
    {
      /* Output character - most terminals use CRLF */
      if (c == '\r')
      {
        echoBuffer[index] = '\0';
        /* Output entire line */
        printf("\n%s\n", echoBuffer);
        index = 0;
      }
      else
      {
        /* Filter non-printable characters */
        if ((c < ' ') || (c > '~'))
          continue;

        /* Enter into buffer */
        echoBuffer[index] = c;
        index++;
        if (index == ECHOBUFSIZE)
        {
          /* Flush buffer */
          index = 0;
        }
        /* Local echo */
        putchar(c);
      }
    }
    else
    {
      #ifdef RETARGET_LEUART1
        /* Enter EM2 when idle */
        EMU_EnterEM2(true);
      #else
        /* Enter EM1 when idle */
        EMU_EnterEM1();
      #endif
    }
  }
}
Пример #13
0
/**************************************************************************//**
 * @brief main - the entrypoint after reset.
 *****************************************************************************/
int main(void)
{
  uint32_t time;

  /* Chip errata */
  CHIP_Init();

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Select 48MHz clock. */
  CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );

  /* Setup EBI for NAND Flash. */
  BSP_EbiInit();

  /* Enable DWT */
  CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
  /* Make sure CYCCNT is running */
  DWT_CTRL |= 1;

  /* Initialize USART and map LF to CRLF */
  RETARGET_SerialInit();
  RETARGET_SerialCrLf(1);

  printf("\nEFM32GG_STK3700 NAND Flash example\n");
  printHelp();

  /* Initialize nand flash module, use DMA channel 5. */
  NANDFLASH_Init( 5 );

  while (1)
  {
    getCommand();

    /* Get misc. NAND flash info */
    if ( !strcmp( argv[0], "fi" ) )
    {
      printf( " NAND flash device information:\n" );
      printf( "\n  Manufacturer Code :  0x%02X", NANDFLASH_DeviceInfo()->manufacturerCode );
      printf( "\n  Device Code       :  0x%02X", NANDFLASH_DeviceInfo()->deviceCode );
      printf( "\n  Device size       :  %ld (%ldMB)", NANDFLASH_DeviceInfo()->deviceSize,
                                                      NANDFLASH_DeviceInfo()->deviceSize/1024/1024 );
      printf( "\n  Page size         :  %ld", NANDFLASH_DeviceInfo()->pageSize );
      printf( "\n  Spare size        :  %ld", NANDFLASH_DeviceInfo()->spareSize );
      printf( "\n  Block size        :  %ld", NANDFLASH_DeviceInfo()->blockSize );
      putchar( '\n' );
    }

    /* Read a page */
    else if ( !strcmp( argv[0], "rp" ) )
    {
      int status;
      uint32_t pageNum, addr;

      pageNum = strtoul( argv[1], NULL, 0 );
      addr = PAGENUM_2_ADDR( pageNum );

      if ( !NANDFLASH_AddressValid( addr ) )
      {
        printf( " Read page content, page %ld is not a valid page\n", pageNum );
      }
      else
      {
        time = DWT_CYCCNT;
        status = NANDFLASH_ReadPage( addr, buffer[0] );
        time = DWT_CYCCNT - time;
        if ( status == NANDFLASH_STATUS_OK )
        {
          printf( " Read page %ld content, %ld cpu-cycles used\n", pageNum, time );
        }
        else
        {
          printf( " Read page error %d, %ld cpu-cycles used\n", status, time );
        }
        dumpPage( addr, buffer[0] );
      }
    }

    /* Blankcheck a page */
    else if ( !strcmp( argv[0], "bp" ) )
    {
      uint32_t pageNum, addr;

      pageNum = strtoul( argv[1], NULL, 0 );
      addr = PAGENUM_2_ADDR( pageNum );

      if ( !NANDFLASH_AddressValid( addr ) )
      {
        printf( " Blankcheck page, page %ld is not a valid page\n", pageNum );
      }
      else
      {
        printf( " Blankchecking page %ld\n", pageNum );
        if ( blankCheckPage( addr, buffer[0] ) )
        {
          printf( " Page %ld is blank\n", pageNum );
        }
      }
    }

    /* Blankcheck entire device */
    else if ( !strcmp( argv[0], "bd" ) )
    {
      uint32_t addr;
      int i, pageSize, pageCount;

      pageSize  = NANDFLASH_DeviceInfo()->pageSize;
      pageCount = NANDFLASH_DeviceInfo()->deviceSize / pageSize;
      addr      = NANDFLASH_DeviceInfo()->baseAddress;

      printf( " Blankchecking entire device\n" );
      for ( i=0; i<pageCount; i++, addr+=pageSize )
      {
        if ( !blankCheckPage( addr, buffer[0] ) )
        {
          break;
        }
      }

      if ( i == pageCount )
      {
        printf( " Device is blank\n" );
      }
    }

    /* Check bad-block info */
    else if ( !strcmp( argv[0], "bb" ) )
    {
      uint32_t addr;
      int i, blockSize, blockCount, badBlockCount = 0;

      blockCount = NANDFLASH_DeviceInfo()->deviceSize / NANDFLASH_DeviceInfo()->blockSize;
      blockSize  = NANDFLASH_DeviceInfo()->blockSize;
      addr       = NANDFLASH_DeviceInfo()->baseAddress;

      for ( i=0; i<blockCount; i++, addr+=blockSize )
      {
        NANDFLASH_ReadSpare( addr, buffer[0] );
        /* Manufacturer puts bad-block info in byte 6 of the spare area */
        /* of the first page in each block.                             */
        if ( buffer[0][NAND_SPARE_BADBLOCK_POS] != 0xFF )
        {
          printf( " ---> Bad-block at address 0x%08lX (block %ld) <---\n",
                  addr, ADDR_2_BLOCKNUM(addr) );
          badBlockCount++;
        }
      }

      if ( badBlockCount == 0 )
      {
        printf( " Device has no bad-blocks\n" );
      }
    }

    /* Write a page */
    else if ( !strcmp( argv[0], "wp" ) )
    {
      int i, status;
      uint32_t pageNum, addr;

      pageNum = strtoul( argv[1], NULL, 0 );
      addr = PAGENUM_2_ADDR( pageNum );

      if ( !NANDFLASH_AddressValid( addr ) )
      {
        printf( " Write page, page %ld is not a valid page\n", pageNum );
      }
      else
      {
        printf( " Write page %ld, ", pageNum );

        for ( i=0; i<BUF_SIZ; i++ )
        {
          buffer[0][i] = i;
        }

        time = DWT_CYCCNT;
        status = NANDFLASH_WritePage( addr, buffer[0] );
        time = DWT_CYCCNT - time;
        printf( "ecc : 0x%08lX\n", NANDFLASH_DeviceInfo()->ecc );

        if ( status == NANDFLASH_STATUS_OK )
        {
          printf( " Page written OK, %ld cpu-cycles used\n", time );
        }
        else if ( status == NANDFLASH_WRITE_ERROR )
        {
          printf( " Page write failure, bad-block\n" );
        }
        else
        {
          printf( " Page write error %d\n", status );
        }
      }
    }

    /* Erase a block */
    else if ( !strcmp( argv[0], "eb" ) )
    {
      int status;
      uint32_t blockNum, addr;

      blockNum = strtoul( argv[1], NULL, 0 );
      addr = BLOCKNUM_2_ADDR( blockNum );

      if ( !NANDFLASH_AddressValid( addr ) )
      {
        printf( " Erase block, block %ld is not a valid block\n", blockNum );
      }
      else
      {
        printf( " Erase block %ld, ", blockNum );

        status = NANDFLASH_EraseBlock( addr );

        if ( status == NANDFLASH_STATUS_OK )
        {
          printf( " Block erased OK\n" );
        }
        else if ( status == NANDFLASH_WRITE_ERROR )
        {
          printf( " Block erase failure, bad-block\n" );
        }
        else
        {
          printf( " Block erase error %d\n", status );
        }
      }
    }

    /* Check ECC algorithm */
    else if ( !strcmp( argv[0], "ecc" ) )
    {
      int i, status;
      uint32_t addr0, addr1, ecc0, ecc1, pageNum;

      for ( i=0; i<BUF_SIZ; i++ )
      {
        buffer[0][i] = i;
        buffer[1][i] = i;
      }

      pageNum = strtoul( argv[1], NULL, 0 );
      addr0   = PAGENUM_2_ADDR( pageNum );
      addr1   = PAGENUM_2_ADDR( pageNum + 1 );

      if ( !NANDFLASH_AddressValid( addr0 ) ||
           !NANDFLASH_AddressValid( addr1 )    )
      {
        printf( " Check ECC algorithm, page %ld or %ld is not a valid page\n",
                pageNum, pageNum+1 );
      }
      else
      {
        printf( " Checking ECC algorithm\n" );
        status = NANDFLASH_WritePage( addr0, buffer[0] );
        if ( status != NANDFLASH_STATUS_OK )
        {
          printf( " Write in page <n> failed\n" );
        }
        ecc0 = NANDFLASH_DeviceInfo()->ecc; /* Get ECC generated during write*/

        /* Patch one bit in the second buffer. */
        buffer[1][147] ^= 4;

        status = NANDFLASH_WritePage( addr1, buffer[1] );
        if ( status != NANDFLASH_STATUS_OK )
        {
          printf( " Write in page <n+1> failed\n" );
        }
        ecc1 = NANDFLASH_DeviceInfo()->ecc; /* Get ECC generated during write*/

        /* Try to correct the second buffer using ECC from first buffer */
        NANDFLASH_EccCorrect( ecc0, ecc1, buffer[1] );
        if ( memcmp( buffer[0], buffer[1], BUF_SIZ ) == 0 )
        {
          printf( " ECC correction succeeded\n" );
        }
        else
        {
          printf( " ECC correction failed\n" );
        }

        /* Byte 147 (addr 0x93) of page n+1 is now 0x97.                    */
        /* Single step next function call, stop when ECC is read, set the   */
        /* read ECC to ecc10 (0) and verify that 0x97 is corrected to 0x93! */
        NANDFLASH_ReadPage( addr1, buffer[1] );
      }
    }

    /* Copy a page */
    else if ( !strcmp( argv[0], "cp" ) )
    {
      int status;
      uint32_t dstPageNum, srcPageNum, dstAddr, srcAddr;

      dstPageNum = strtoul( argv[2], NULL, 0 );
      srcPageNum = strtoul( argv[1], NULL, 0 );
      dstAddr    = PAGENUM_2_ADDR( dstPageNum );
      srcAddr    = PAGENUM_2_ADDR( srcPageNum );

      if ( !NANDFLASH_AddressValid( dstAddr ) ||
           !NANDFLASH_AddressValid( srcAddr )    )
      {
        printf( " Copy page, page %ld or %ld is not a valid page\n",
                srcPageNum, dstPageNum );
      }
      else
      {
        printf( " Copying page %ld to page %ld\n", srcPageNum, dstPageNum );

        status = NANDFLASH_CopyPage( dstAddr, srcAddr );

        if ( status == NANDFLASH_STATUS_OK )
        {
          printf( " Page copied OK\n" );
        }
        else if ( status == NANDFLASH_WRITE_ERROR )
        {
          printf( " Page copy failure, bad-block\n" );
        }
        else
        {
          printf( " Page copy error %d\n", status );
        }
      }
    }

    /* Mark block as bad */
    else if ( !strcmp( argv[0], "mb" ) )
    {
      uint32_t blockNum, addr;

      blockNum = strtoul( argv[1], NULL, 0 );
      addr = BLOCKNUM_2_ADDR( blockNum );

      if ( !NANDFLASH_AddressValid( addr ) )
      {
        printf( " Mark bad block, %ld is not a valid block\n", blockNum );
      }
      else
      {
        printf( " Marked block %ld as bad\n", blockNum );
        NANDFLASH_MarkBadBlock( addr );
      }
    }

    /* Display help */
    else if ( !strcmp( argv[0], "h" ) )
    {
      printHelp();
    }
    else
    {
      printf( " Unknown command" );
    }
  }
}