Generate tick from XTHAL_GET_CCOUNT.

TibiToz
Posts: 7
Joined: Mon Aug 10, 2020 1:46 pm

Generate tick from XTHAL_GET_CCOUNT.

Postby TibiToz » Tue Dec 08, 2020 11:02 am

  1. #define TICK_COUNT_1KHZ  (CPU_FREQ / TICK_FREQ)
  2. void Init_Xthal_Count ( void )
  3. {
  4.     xthal_val_i =  XTHAL_GET_CCOUNT();
  5. }
  6.  
  7. void Get_Tick_From_Xthal ( void )
  8. {
  9.    
  10.     if( (XTHAL_GET_CCOUNT() - xthal_val_i) > TICK_COUNT_1KHZ )
  11.     {
  12.         xthal_val_i =  XTHAL_GET_CCOUNT();
  13.         Tick1ms_u8 = 1U;
  14.     }
  15.     else
  16.     {
  17.         Tick1ms_u8 = 0U;
  18.     }
  19.    
  20. }
  21.  
  22. void CORE1_Start ( void *pvParameters )
  23. {
  24.     Init_Xthal_Count();
  25.     while(1)
  26.     {
  27.         Get_Tick_From_Xthal();
  28.         Tick_Check();
  29.     }
  30. }
I'm trying to use this idea for core usage : viewtopic.php?f=2&t=10006&start=20

I'm creating a Freertos task CORE1_Start() on core1, in this task, i'm trying to generate a 1ms tick from the XTHAL_GET_CCOUNT(), i dont want to use the esp API or freertos inside my CORE1_Start().

The Get_Tick_From_Xthal() is running in a while(1) and going in a function to check flag. Using the code above is working fine until the XTHAL_GET_CCOUNT() value goes negative. The idea to solve the problem was to use XTHAL_SET_COUNT to reset the xthal_ccount value when the tick is reach. It is not working. I assume, the XTHAL_COUNT register in used by the freertos or something else on core0 and we just cant modify this value.

After that i tried to use xthal_set_ccompare() and xthal_get_ccompare() like this :
  1. void Init_Xthal_Count ( void )
  2. {
  3.    
  4.     xthal_set_ccompare( ID_REGISTER ,  TICK_COUNT_1KHZ );
  5.  
  6.    
  7. }
  8. void Get_Tick_From_Xthal ( void )
  9. {
  10.    
  11.     if( xthal_get_ccompare(ID_REGISTER) )
  12.     {
  13.         Tick1ms_u8 = 1U;
  14.     }
  15.     else
  16.     {
  17.         Tick1ms_u8 = 0U;
  18.     }
  19.    
  20. }
But the value seems to never be reached, Am i using those functions right ? Is there a solution for my first idea ? Thank you for your replies

Tibi

Who is online

Users browsing this forum: No registered users and 368 guests