Problem with Micruim C24/PORT

Discussion in 'Embedded Systems and Microcontrollers' started by aripod, Aug 11, 2012.

  1. aripod

    Thread Starter New Member

    Aug 11, 2012
    4
    0
    I have downloaded the port from micruim website for PIC24 and i have "clean" it, leaving the things that i would use (it includes the code for an eval-board). For now, i just want to make a led blik. Therefore, i want the main task that it's used to create "user tasks".
    I've managed to build project, which did not build when i downloaded the original.
    Even though it builds, the code gets stucks in a funcion called OSTimeDly(100), when it access the Scheduler function (OS_Sched())...

    Has anyone worked with micrium, and even better, with the C24 PORT?

    I've attached my project in case anyone might want to download it to try it. Micrium folder needs to be in C:\. The project is in C:\Micrium\Software\EvalBoards\Microchip\Explorer16\PIC24FJ128\MPLAB_C30\OS-Probe and the "user app" is app.c
     
  2. JohnInTX

    Moderator

    Jun 26, 2012
    2,348
    1,029
    Have you configured a timer to generate the system tik? (IRQ routine that calls an OS system routine that maintains system timers).
     
  3. aripod

    Thread Starter New Member

    Aug 11, 2012
    4
    0
    Hi John, thanks for the fast answer.
    On the app not tht it is included in the PORT, it describes the problem, and i think it says the same thing you are saying:
    I assume that the kernell itself configures the timer to generate the system tick....but i cannot figure it out where or if it does that.
     
  4. JohnInTX

    Moderator

    Jun 26, 2012
    2,348
    1,029
    MicroC/OS-II 2ed edition, pp 108:
    You have to provide a timer driven interrupt routine that interrupts the processor every 1msec (or whatever you decide your systik is). This timer will be one of the PIC hardware timers configured to generate periodic interrupts. Depending on the actual port you are using, this may or may not be done for you (probably isn't).

    The timer IRQ service routine calls OSTimeTick() once each timer IRQ to maintain the OS timers (including task delays, wait times etc).

    You must not enable interrupts (and call OSTimeTick()) until you have called OSStart() (which inits the OS).
     
  5. aripod

    Thread Starter New Member

    Aug 11, 2012
    4
    0
    In bsp.h i have selected timer 2
    I saw step by step that the timer2 is well configured and the interrupts occurs in function:
    In OSTimeTick(), it never returns to app.c where i called OSTimeDly();

    By the way, I'm debuggin with MPLABSIM and I'm not sure if it would have anythiing to do with the problem. Do you think it could be a problem?
     
  6. JohnInTX

    Moderator

    Jun 26, 2012
    2,348
    1,029
    OSTimeTick() should be called only by the IRQ. I'm not sure I know what you mean that it should be returning to app.c

    Before turning on the IRQs and calling OSTimeTick():
    Call OSInit();
    Have at least one task created by calling OSTaskCreate();
    Call OSStart();
    Then turn on the IRQs.

    Also, the pseudocode for the IRQ handler shows calling OSIntEnter() and OSIntExit() to keep track of IRQ nesting.


    MPSIM should be able to do the job. If you have built the OS source you should be able to step into OSTimeTick() (or manually stop it when its hung). If not, you can look at the object code in the Disassembly window. Look to see what its waiting for.

    I've not used uCOS on the PIC so don't have any real concrete advice (and the book is an early edition that I am sure is out of date) but it sounds like an init issue from here.

    Maybe you could revert to the uncleaned code, get it working or at least examine it and see what you are missing.

    Good luck!
     
  7. aripod

    Thread Starter New Member

    Aug 11, 2012
    4
    0
    App.c is the file where the main it is supposed to be. This is my app.c
    Code ( (Unknown Language)):
    1.  
    2.  
    3. /*
    4. *********************************************************************************************************
    5. *                                               uC/OS-II
    6. *                                         The Real-Time Kernel
    7. *
    8. *                               (c) Copyright 2006, Micrium, Weston, FL
    9. *                                          All Rights Reserved
    10. *
    11. *
    12. *                                      Microchip Application Code
    13. *
    14. * File : APP.C
    15. * By   : Eric Shufo
    16. *********************************************************************************************************
    17. */
    18.  
    19. #include <includes.h>
    20.  
    21.  
    22. /*
    23. *********************************************************************************************************
    24. *                                                CONSTANTS
    25. *********************************************************************************************************
    26. */
    27.  
    28. /*
    29. *********************************************************************************************************
    30. *                                                STACKS
    31. *********************************************************************************************************
    32. */
    33.  
    34. #define  APP_TASK_START_STK_SIZE              128
    35.  
    36. /*
    37. *********************************************************************************************************
    38. *                                                VARIABLES
    39. *********************************************************************************************************
    40. */
    41.  
    42. OS_STK    Start_TaskStk[APP_TASK_START_STK_SIZE];
    43. OS_STK    DisplayStk[APP_TASK_START_STK_SIZE];
    44.  
    45.  
    46. /*
    47. *********************************************************************************************************
    48. *                                            FUNCTION PROTOTYPES
    49. *********************************************************************************************************
    50. */
    51.  
    52. void Displays(void *pdata);
    53.  
    54.  
    55. /*
    56. *********************************************************************************************************
    57. *                                          STARTUP TASK
    58. *
    59. * Description : This is an example of a startup task.  As mentioned in the book's text, you MUST
    60. *               initialize the ticker only once multitasking has started.
    61. *
    62. * Arguments   : p_arg   is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
    63. *
    64. * Notes       : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
    65. *                  used.  The compiler should not generate any code for this statement.
    66. *               2) Interrupts are enabled once the task start because the I-bit of the CCR register was
    67. *                  set to 0 by 'OSTaskCreate()'.
    68. *********************************************************************************************************
    69. */
    70.  
    71. void Task_START(void *p_arg)
    72. {
    73.     int        i_data;
    74.     CPU_INT08U  i;
    75.     CPU_INT08U  j;
    76.  
    77.    (void)p_arg;
    78.  
    79.     BSP_Init();                                                         /* Initialize BSP functions                                 */
    80.  
    81.  
    82. //#if OS_TASK_STAT_EN > 0
    83. //    OSStatInit();                                                       /* Determine CPU capacity                                   */
    84. //#endif
    85.  
    86.    
    87.     OSTaskCreate(Displays, (void *)0, &DisplayStk[0], 1);
    88.  
    89.    
    90.     i_data = *((int *)p_arg);
    91.  
    92.     // task loop
    93.     for(;;)
    94.     {
    95.         OSTimeDly(100);
    96.     }
    97. }
    98.  
    99. /*
    100. *********************************************************************************************************
    101. *                                                main()
    102. *
    103. * Description : This is the standard entry point for C code.
    104. * Arguments   : none
    105. *********************************************************************************************************
    106. */
    107.  
    108. CPU_INT16S  main (void)
    109. {
    110.     CPU_INT08U  err;
    111.     int        i_data;
    112.  
    113.     BSP_IntDisAll();                                                    /* Disable all interrupts until we are ready to accept them */
    114.  
    115.     OSInit();                                                           /* Initialize "uC/OS-II, The Real-Time Kernel"              */
    116.  
    117.     OSTaskCreate(Task_START, (void *)0, &Start_TaskStk[0], 0);
    118.  
    119.     OSStart();                                                          /* Start multitasking (i.e. give control to uC/OS-II)       */
    120.  
    121.     return (-1);                                                        /* Return an error - This line of code is unreachable       */
    122. }
    123.  
    124.  
    125.  
    126.  
    127.  
    128. void Displays(void *p_arg)
    129. {
    130. while(1)
    131.     {
    132.     PORTFbits.PORTF3=1;
    133.     OSTimeDlyHMSM(0,0,1,0);
    134.     PORTFbits.PORTF3=0;
    135.     OSTimeDlyHMSM(0,0,2,0);
    136.     }
    137. }
    138.  
    In Tast_START(), it goes to OSTaskCreate(Displays, (void *)0, &DisplayStk[0], 1); and it never returns. Inside OSTaskCreate(Displays, (void *)0, &DisplayStk[0], 1), at same point, it calls the "OS Time Tick ISR Handler", which does this:

    Code ( (Unknown Language)):
    1. ]
    2. ;********************************************************************************************************
    3. ;                                            OS Time Tick ISR Handler
    4. ;
    5. ; Description : This function services the OS Time Tick Interrupt when configured using Timer #2
    6. ;
    7. ; Notes       : All user interrupts should be defined as follows.
    8. ;********************************************************************************************************
    9. ;
    10.  
    11. __T2Interrupt:
    12.     OS_REGS_SAVE                                                        ; 1) Save processor registers
    13.  
    14.     mov   #_OSIntNesting, w1
    15.     inc.b [w1], [w1]                                                    ; 2) Call OSIntEnter() or increment OSIntNesting
    16.  
    17.     dec.b _OSIntNesting, wreg                                           ; 3) Check OSIntNesting. if OSIntNesting == 1, then save the stack pointer, otherwise jump to T2_Cont
    18.     bra nz, T2_Cont
    19.     mov _OSTCBCur, w0
    20.     mov w15, [w0]
    21.  
    22. T2_Cont:
    23.     call _OS_Tick_ISR_Handler                                           ; 4) Call YOUR ISR Handler (May be a C function). In this case, the OS Tick ISR Handler
    24.     call _OSIntExit                                                     ; 5) Call OSIntExit() or decrement 1 from OSIntNesting
    25.  
    26.     OS_REGS_RESTORE                                                     ; 6) Restore registers
    27.  
    28.     retfie                                                              ; 7) Return from interrupt
    29.  
    It that what you meant by
    ??
     
    Last edited by a moderator: Aug 12, 2012
  8. JohnInTX

    Moderator

    Jun 26, 2012
    2,348
    1,029
    but if so, its a different name than OSTimeTik(). You might want to resolve that difference.

    I'm puzzled by this. If the OS Time Tick ISR Handler is a real IRQ service routine, why is it called at all by the background code? It should be called only as a result of a timer interrupt. I do note that the book says that instead of maintaining the system tik using a timer interrupt calling OSTimeTick(), you can do it instead at the task level by creating a very high priority task that presumably checks some timing reference and manually calls OSTimeTick(). The two methods are mutually exclusive. I wonder why the display task would be calling the tik when you have an interrupt to do it. Not only would timing be weird but if the tik routine was not reentrant.. KABOOM.

    Other than that, I'm not up enough on uCOS to be of much help beyond what's here. Sorry!
     
    Last edited: Aug 12, 2012
Loading...