print log in port.c

Discussions about all things Bitcraze
Post Reply
bnblzq
Beginner
Posts: 15
Joined: Wed Jul 24, 2019 3:07 am

print log in port.c

Post by bnblzq » Tue Aug 06, 2019 3:28 am

Hi everybody,
I am trying to print some infomation in port.c with DEBUG_PRINT() ,but I got nothing in the console in cfclient. Is there anything wrong I made during the code ?
1.png

Code: Select all

--- a/src/lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c
+++ b/src/lib/FreeRTOS/portable/GCC/ARM_CM4F/port.c
@@ -74,6 +74,8 @@
 /* Scheduler includes. */
 #include "FreeRTOS.h"
 #include "task.h"
+#include "debug.h"
 
 #ifndef __VFP_FP__
        #error This port can only be used when the project options are configured to enable hardware floating point support.
@@ -662,6 +664,7 @@ void xPortSysTickHandler( void )
  * Setup the systick timer to generate the tick interrupts at the required
  * frequency.
  */
+static uint32_t timeAcc =configTICK_RATE_HZ;//1000
 __attribute__(( weak )) void vPortSetupTimerInterrupt( void )
 {
        /* Calculate the constants required to configure the tick interrupt. */
@@ -673,8 +676,17 @@ __attribute__(( weak )) void vPortSetupTimerInterrupt( void )
        }
        #endif /* configUSE_TICKLESS_IDLE */
 
+    //maybe change time slice dynamically to observe phenomenon
+    if(timeAcc < 50) {
+        timeAcc = configTICK_RATE_HZ;        
+        DEBUG_PRINT("timeacc restore\n");
+    }
+    else {
+        timeAcc -=1;
+    }
+
        /* Configure SysTick to interrupt at the requested rate. */
-       portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / 2000 ) - 1UL;
+       portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / timeAcc ) - 1UL;
        portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );
 }



kimberly
Expert
Posts: 107
Joined: Fri Jul 06, 2018 11:13 am

Re: print log in port.c

Post by kimberly » Tue Aug 06, 2019 7:45 am

Hi!

Hmmm... let's see. Your debug_print is now within an if statement. Are you sure that this line is hit? Maybe you could try to put a debugprint first somewhere where you are sure it will be read out, like before the if statement.

If that doesn't not work, I'll try to investigate it with you

bnblzq
Beginner
Posts: 15
Joined: Wed Jul 24, 2019 3:07 am

Re: print log in port.c

Post by bnblzq » Tue Aug 06, 2019 8:09 am

Hi kimberly,
here is my new modification. I add an log "check!!!" just outside the if condition, but I still got nothing to show in the cfclient.
but when I hit the "task dump" button, I got a task list in the console window, which means that the link between crazyflie and my pc functions well.

So any further test I can do to figure out the problem ? thanks a lot ~

1.png

Code: Select all

@@ -673,8 +676,19 @@ __attribute__(( weak )) void vPortSetupTimerInterrupt( void )
        }
        #endif /* configUSE_TICKLESS_IDLE */
 
+    //maybe change time slice dynamically to observe phenomenon
+    if(timeAcc < 50) {
+        timeAcc = configTICK_RATE_HZ;        
+        DEBUG_PRINT("timeacc restore\n");
+    }
+    else {
+        timeAcc -=1;
+    }
+
+    DEBUG_PRINT("check!!!\n");
+
        /* Configure SysTick to interrupt at the requested rate. */
-       portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / 2000 ) - 1UL;
+       portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / timeAcc ) - 1UL;

bnblzq
Beginner
Posts: 15
Joined: Wed Jul 24, 2019 3:07 am

Re: print log in port.c

Post by bnblzq » Tue Aug 06, 2019 8:15 am

by the way , I am convinced that is ISR function is called, because when I set a fixed figure to the timer counting down, the time slice is indeed shorter than before.From the crazyflie, I can hear the interval the "beep" sound when initiating becomes more compact.

kristoffer
Bitcraze
Posts: 107
Joined: Tue Jun 30, 2015 7:47 am

Re: print log in port.c

Post by kristoffer » Tue Aug 06, 2019 9:25 am

I don't think it will be possible to print in the vPortSetupTimerInterrupt() function. I have not checked exactly when it is called in the start up sequence, but it is very likely that sys ticks (very basic OS functionality) is set up before the debug module and that there are not yet any debug buffers to write into.

What is the goal you are trying to achieve (a part from debug printing)?

bnblzq
Beginner
Posts: 15
Joined: Wed Jul 24, 2019 3:07 am

Re: print log in port.c

Post by bnblzq » Tue Aug 06, 2019 10:41 am

"it is very likely that sys ticks (very basic OS functionality) is set up before the debug module and that there are not yet any debug buffers to write into"

==> I agree with you . But I also think that sys ticks is a periodical setting, so everytime the timer overflows, the ISR function should be run into.Even at the very first beginning, the buffer is not ready , later when the rtos runs normally, the debug info should be printed out.

"What is the goal you are trying to achieve (a part from debug printing)?"
==> now I am trying to alter the time slice , which is defined by this ISR function. And I want to observe the behavior of the drone. So I want to print out this value to check the exact time slice. ( I just manage to get that,but I dont know if it is the correct way)


Thank you for your attention~

kristoffer
Bitcraze
Posts: 107
Joined: Tue Jun 30, 2015 7:47 am

Re: print log in port.c

Post by kristoffer » Tue Aug 06, 2019 11:08 am

But I also think that sys ticks is a periodical setting, so everytime the timer overflows, the ISR function should be run into.Even at the very first beginning, the buffer is not ready , later when the rtos runs normally, the debug info should be printed out.
As far as I understand, vPortSetupTimerInterrupt() is only called one time during start up to set up the sys tick interrupt, while xPortSysTickHandler() is the interrupt handler for sys tick

bnblzq
Beginner
Posts: 15
Joined: Wed Jul 24, 2019 3:07 am

Re: print log in port.c

Post by bnblzq » Tue Aug 06, 2019 11:25 am

you are right ! it is indeed called once.
I should find another way to implement my idea.... :D

bnblzq
Beginner
Posts: 15
Joined: Wed Jul 24, 2019 3:07 am

Re: print log in port.c

Post by bnblzq » Thu Aug 08, 2019 4:11 am

Hi ,
After considering some details, I decide to move the timeslice alteration as an system task. But now, I am facing with a problem with CRTP . The problem is that the task occpuys all the timeslice, seen from task dump information ,becase I use a forever loop inside the task as other system tasks do. But I want to implement a block approach to receive the parameter from cfclient and alter the register value . I dont know if there is a existing API ? or what should I do ?

thank you very much ~

Code: Select all

static void timesliceTask(void *param)
{
    while(1){
	//some work shoud be done here to block the task and yield the cpu
	//this is the place I dont know the API
	
	//when reveive ctrp from cfclient, wake up and update the value
	REGISTER_VALUE = _timeslice;
    }
}


void timeSliceInit(){
    xTaskCreate(timesliceTask, TIMESLICE_TASK_NAME, TIMESLICE_TASK_STACKSIZE, NULL,
                 TIMESLICE_TASK_PRI, NULL);
}

PARAM_GROUP_START(timeslice)
PARAM_ADD(PARAM_UINT32, TimeSlice, &_timeslice)
PARAM_GROUP_STOP(timeslice)

kristoffer
Bitcraze
Posts: 107
Joined: Tue Jun 30, 2015 7:47 am

Re: print log in port.c

Post by kristoffer » Mon Aug 12, 2019 12:04 pm

A common solution to let other tasks run, is to wait on a queue
If you search for xQueueReceive you will find a bunch of examples that might give you some inspiration

Good luck!

Post Reply