This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Hal Timer count setting for OSAL timer in Z stack 1.4.3-1.2.1

OSAL timer uses timer4 which is a 8 bit timer. However, it uses halTimerSetCount in Hal_timer.c to configure its timepertick value

uint8 halTimerSetCount (uint8 hwtimerid, uint32 timePerTick)
{
  uint16  count;
  uint8   high, low;

  /* Load count = ((sec/tick) x clock) / prescale */
  count = (uint16)((timePerTick * halTimerRecord[hwtimerid].clock) / halTimerRecord[hwtimerid].prescaleVal);
  high = (uint8) (count >> 8);
  low = (uint8) count;

  *(halTimerChannel[hwtimerid].TxCCH) = high;
  *(halTimerChannel[hwtimerid].TxCCL) = low;

  return HAL_TIMER_OK;
}

This function is used to configure 16 bit timer. OSAL timer is 1ms tick , "timePerTick" is 1000 and the "count" value in this function is 250, which only occupies low 8 bit. So looks like it still works.

 

But my questions are:

1. T4CC0 register is only 8 bits, so I assume " *(halTimerChannel[hwtimerid].TxCCL) = low" will set the T4CC0 value to 250. But then how this code " *(halTimerChannel[hwtimerid].TxCCH) = high" is executed, In definition,  

uint8 volatile XDATA *TxCCH;
  uint8 volatile XDATA *TxCCL;

 

Both are volatile value in XDATA, so it seems both are register values, which register it will set by executing "*(halTimerChannel[hwtimerid].TxCCH) = high"?

 

2. if somehow I miss set "timePerTick" and "count" is larger than 256 which need High 8 bit timer setup, how is the outcome?(related to 1 question)

 

Thanks very much

 

Rui

 

 

  • I get it,

     

    #define TCHN_T4CCL    &(X_T4CC0)
    #define TCHN_T4CCH    &(X_T4CC0)

     

    so both low and high are T4CC0 register, as the code is like:

      *(halTimerChannel[hwtimerid].TxCCH) = high;
      *(halTimerChannel[hwtimerid].TxCCL) = low;

    so low value will overwrite high value which is correct.

     

    Thanks

     

    Rui

    ,