Generate tick from XTHAL_GET_CCOUNT.
Posted: Tue Dec 08, 2020 11:02 am
- #define TICK_COUNT_1KHZ (CPU_FREQ / TICK_FREQ)
- void Init_Xthal_Count ( void )
- {
- xthal_val_i = XTHAL_GET_CCOUNT();
- }
- void Get_Tick_From_Xthal ( void )
- {
- if( (XTHAL_GET_CCOUNT() - xthal_val_i) > TICK_COUNT_1KHZ )
- {
- xthal_val_i = XTHAL_GET_CCOUNT();
- Tick1ms_u8 = 1U;
- }
- else
- {
- Tick1ms_u8 = 0U;
- }
- }
- void CORE1_Start ( void *pvParameters )
- {
- Init_Xthal_Count();
- while(1)
- {
- Get_Tick_From_Xthal();
- Tick_Check();
- }
- }
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 :
- void Init_Xthal_Count ( void )
- {
- xthal_set_ccompare( ID_REGISTER , TICK_COUNT_1KHZ );
- }
- void Get_Tick_From_Xthal ( void )
- {
- if( xthal_get_ccompare(ID_REGISTER) )
- {
- Tick1ms_u8 = 1U;
- }
- else
- {
- Tick1ms_u8 = 0U;
- }
- }
Tibi