Skip to content
Ryan Summers edited this page Dec 31, 2015 · 13 revisions

Functions

This page contains information about the functions used within the timer peripheral library of SUBLIBinal. Please use the following list to read more about individual timer functions available.

Timer Functions:


initialize_Timer

Prototype
Error initialize_Timer(Timer_Config config);

Description:
This function will initialize a timer. The function will attempt to generate appropriate dividers and periods to acquire the provided frequency. If the function can not achieve the required frequency, it will set parameters to as close as it can to the defined frequency. That is, if a frequency is supplied that is beyond the capabilities of the timer, it will be set for the maximum divider and the maximum period.

Parameters:

  • Timer_Config config: config is a Timer_Config structure that has been filled out with all relevant parameters. All parameters should be filled out, with the exception of the callback function, which is optional.

Return:

  • ERR_INVALID_ENUM: This error code will be thrown if the enumeration of the parameter config.which_timer is not a valid timer enumeration.
  • ERR_TIMER_FREQ_UNATTAINABLE: This code will be thrown when a frequency is specified that the timer can not achieve (this will occur if the frequency is too low). When this occurs, the period is set to 65535 and the divider is set to Div_256 and the function will complete normally.
  • ERR_NO_ERR: There is no error and the function completed successfully.

disable_Timer

Prototype
Error disable_Timer(Timer_Type which_timer);

Description:
This function will disable a timer and its associated interrupts. The current TIMER value is not reset.

Parameters:

  • Timer_Type which_timer: This is a 'Timer_Type' enumeration specifying which timer to use.

Return:

  • ERR_INVALID_ENUM: This error code will be thrown if the enumeration of the parameter 'which_timer' is not a valid timer enumeration.
  • ERR_NO_ERR: The function completed normally.

enable_Timer

Prototype
Error enable_Timer(Timer_Type which_timer);

Description:
This function will enable a timer and its associated interrupt. The interrupt is only activated if the callback function parameter is not NULL.

Parameters:

  • Timer_Type which_timer: This is a 'Timer_Type' enumeration specifying which timer to use.

Return:

  • ERR_INVALID_ENUM: This error code will be thrown if the enumeration of the parameter 'which_timer' is not a valid timer enumeration.
  • ERR_NO_ERR: The function completed normally.

update_period_Timer

Prototype
Error update_period_Timer(Timer_Type which_timer, int period);

Description:
This function updates the period of a timer. This function will only touch the period register of a timer and will not change the divider or the enable of the timer. This function will also reset the current value in the timer register to avoid problems associated with timer overflow.

Parameters:

  • Timer_Type which_timer: This is a 'Timer_Type' enumeration specifying which timer to use.
  • int period: The period parameter should be an integer that you would like the timer period to be set to.

Return:

  • ERR_INVALID_ENUM: This error code will be thrown if the enumeration of the parameter 'which_timer' is not a valid timer enumeration.
  • ERR_NO_ERR: The function completed normally.
  • ERR_INVALID_PERIOD: This error code will be thrown if a period greater than 65535 or less than 1 is entered into the function. When this occurs, period will be set to either 1 if it was less than 1 or 65535 if it was greater than 65535 and the function will complete normally.

update_frequency_Timer

Prototype
Error update_frequency_Timer(Timer_Type which_timer, uint pbclk, float frequency);

Description:
This function will manually update the frequency of the supplied timer. Both the divider and the period of the timer will be changed. The calculation that update_frequency_Timer completes to determine divider and period is identical to that used by the initialize_Timer function, and behavior will be identical. The TIMER value will also be reset to 0 to avoid issues associated with timer overflow.

Parameters:

  • Timer_Type which_timer: This is a 'Timer_Type' enumeration specifying which timer to use.
  • uint pbclk: This specifies the peripheral bus clock that the timer is using. Supply the peripheral bus clock supplied in the timer configuration structure.
  • float frequency: The frequency parameter is a value that the specified timer should be set to interrupt at.

Return:

  • ERR_INVALID_ENUM: This error code will be thrown if the enumeration of the parameter which_timer is not a valid timer enumeration.
  • ERR_TIMER_FREQ_UNATTAINABLE: This code will be thrown when a frequency is specified that the timer can not achieve (this will occur if the frequency is too low). When this occurs, the period is set to 65535 and the divider is set to Div_256 and the function will complete normally.
  • ERR_NO_ERR: There is no error and the function completed successfully.

update_divider_Timer

Prototype:
Error update_divider_Timer(Timer_Type which_timer, Clock_Divider div);

Description:
The update_divider_Timer function will simply update the timer divider associated with the configuration parameter. This function will not modify the period register or the current TIMER value.

Parameters:

  • Timer_Type which_timer: This is a 'Timer_Type' enumeration specifying which timer to use.
  • Clock_Divider div: The div parameter is used to specify what the divider should be. Please note, if you are specifying a new divider for Timer_1, it will automatically upgrade to the closest divider available for timer 1. That is, if you attempt to update to Div_2, it will instead update to Div_8.

Return:

  • ERR_INVALID_ENUM: This error code will be thrown if the enumeration of the parameter which_timer is not a valid timer enumeration.
  • ERR_INVALID_DIVIDER: Returned if a divider is specified for Timer_1 that Timer_1 can not achieve. Timer_1 may only accept dividers of Div_1, Div_8, Div_64, or Div_256. Any other divider will cause an error.
  • ERR_NO_ERR: The function completed successfully

top

Clone this wiki locally