Keil Logo

Starting a virtual timer in RTOSv2 returns: osErrorResource

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Author
Paul Bonnie
Posted
6-Jan-2018 19:27 GMT
Toolset
ARM
New! Starting a virtual timer in RTOSv2 returns: osErrorResource

All, I created a simple program to start a virtual timer object in CMSIS OS2. After succesfully creating the periodic timer, I can't start the timer. The return code is: 0xFFFFFFFD osErrorResource. I use Keil uVision5 and an NXP LPC1768 processor

Following is my code:

#include <RTE_Components.h>
#include  CMSIS_device_header
#include <cmsis_os2.h>                                                                                                                                    /* ARM::CMSIS:RTOS:Keil RTX5 */
#include "LED.h"

static void Callback (void *argument);                                                                  /* Function prototype Call back function */
static uint32_t timerDelay;                                                     /* Holds timer value */

/*----------------------------------------------------------------------------
 * Main Entry point, execution starts here
 *---------------------------------------------------------------------------*/
int main (void)
{
        osTimerId_t periodic_id;                                                                                                                        /* Thread handle */
        osStatus_t  status;                                                     /* Function return status */

        SystemCoreClockUpdate();                                                                                                                        /* Evaluate clock register settings and calculate current core clock */
        LED_Initialize ();                                                                                                                                              /* Initialize LEDs */
        osKernelInitialize ();                                                                                                                          /* Initialize CMSIS-RTOS2 */

        periodic_id = osTimerNew (Callback, osTimerPeriodic, (void *)5, NULL); /* Create a periodic timer, */
                                                                                                                                                                                                                                /* (void*)5 is passed as argument to the callback function */
  if (periodic_id != NULL)
        {
                timerDelay = 1000;                                                                                                                                      /* Number of Time Ticks */
    status = osTimerStart (periodic_id, timerDelay);    /* Start timer */
    if (status != osOK)
                {
      /* Error: Timer could not be started */
                        status = osTimerStop (periodic_id);                                             /* Stop timer */
    }
  }
        osKernelStart();                                                                                                                                                        /* Start thread execution */
}

void Callback (void *argument)
{
        int32_t arg = (int32_t)argument;                                                                                        /* cast back argument '5' */
        LED_Flash ();
}

In RTXConfig.h, I defined 5 User Threads with 'Object Specific Memory Allocation' and 2 Timer Objects (priority 'High') also with 'Object Specific Memory Allocation'. The default 'Thread Stack size' and the 'Timer Thread Stach size' both are 200 bytes.

Does anyone have an idea what might cause this error?

Author
Robert McNamara
Posted
6-Jan-2018 22:50 GMT
Toolset
ARM
New! RE: Starting a virtual timer in RTOSv2 returns: osErrorResource

You probably need to start the Kernel before you try to start the timer.

Author
Paul Bonnie
Posted
7-Jan-2018 13:23 GMT
Toolset
ARM
New! RE: Starting a virtual timer in RTOSv2 returns: osErrorResource

Robert, thanks for responding. Regrettably, your suggestion does not solve the problem. Starting the Kernel first results in running an OS Idle Thread, concluded with an infinite loop. The code for starting the timer in Main() isn't even executed.

Author
Robert McNamara
Posted
7-Jan-2018 19:12 GMT
Toolset
ARM
New! RE: Starting a virtual timer in RTOSv2 returns: osErrorResource

Well, technically it DID remove the osErrorResource problem! (HaHa)

It looks like you will need to create at least 1 thread of your own using osThreadNew() before you start the kernel; This thread should be able to start the timer. The osStartKernel() does not return if all goes well...

Author
Paul Bonnie
Posted
9-Jan-2018 22:01 GMT
Toolset
ARM
New! RE: Starting a virtual timer in RTOSv2 returns: osErrorResource

Robert, thanks. That worked out well. The timer now starts.

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.