Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:03

0001 /**
0002  * @file
0003  *
0004  * @ingroup RTEMSBSPsARMLPC176X
0005  *
0006  * @brief Timer API for the lpc176x bsp.
0007  */
0008 
0009 /*
0010  * Copyright (c) 2014 Taller Technologies.
0011  *
0012  * @author  Boretto Martin    (martin.boretto@tallertechnologies.com)
0013  * @author  Diaz Marcos (marcos.diaz@tallertechnologies.com)
0014  * @author  Lenarduzzi Federico  (federico.lenarduzzi@tallertechnologies.com)
0015  * @author  Daniel Chicco  (daniel.chicco@tallertechnologies.com)
0016  *
0017  * The license and distribution terms for this file may be
0018  * found in the file LICENSE in this distribution or at
0019  * http://www.rtems.org/license/LICENSE.
0020  */
0021 
0022 #ifndef LIBBSP_ARM_LPC176X_TIMER_H
0023 #define LIBBSP_ARM_LPC176X_TIMER_H
0024 
0025 #include <bsp/timer-defs.h>
0026 
0027 #ifdef __cplusplus
0028 extern "C" {
0029 #endif /* __cplusplus */
0030 
0031 /**
0032  * @brief resets timer counter and stops it.
0033  *
0034  * @param tnumber the device to be reseted
0035  * @return RTEMS_SUCCESSFUL if the timer was reseted successfuly.
0036  */
0037 rtems_status_code lpc176x_timer_reset( lpc176x_timer_number tnumber );
0038 
0039 /**
0040  * @brief Sets mode of the timer (timer, counter rising, counter falling
0041  *        or counter both edges)
0042  *
0043  * @param tnumber: the device to be setted
0044  * @param mode: the desired mode
0045  * @return RTEMS_SUCCESSFUL if the timer's mode was setted successfuly.
0046  */
0047 rtems_status_code lpc176x_timer_set_mode(
0048   lpc176x_timer_number tnumber,
0049   lpc176x_timer_mode   mode
0050 );
0051 
0052 /**
0053  * @brief Starts the timer counter
0054  *
0055  * @param tnumber: the device to be started
0056  * @return RTEMS_SUCCESSFUL if the timer's was started successfuly.
0057  */
0058 rtems_status_code lpc176x_timer_start( lpc176x_timer_number tnumber );
0059 
0060 /**
0061  * @brief true if timer is started.
0062  *
0063  * @param tnumber: the timer number to check.
0064  * @param is_started: TRUE if the timer is running.
0065  * @return RTEMS_SUCCESSFUL if the started timer check was successfuly.
0066  */
0067 rtems_status_code lpc176x_timer_is_started(
0068   lpc176x_timer_number tnumber,
0069   bool                *is_started
0070 );
0071 
0072 /**
0073  * @brief sets the resolution in microseconds of the timer
0074  *
0075  * @param tnumber: the device to be modified.
0076  * @param resolution: how many microseconds will mean each timer
0077  *                    counter unit.
0078  * @return RTEMS_SUCCESSFUL if the timer resolution was setted successfuly.
0079  */
0080 rtems_status_code lpc176x_timer_set_resolution(
0081   lpc176x_timer_number tnumber,
0082   lpc176x_microseconds resolution
0083 );
0084 
0085 /**
0086  * @brief Configures the timer match
0087  *
0088  * @param tnumber: the device to be modified
0089  * @param match_port: which port of this timer will be setted
0090  * @param function: what the timer should do when match: stop timer, clear,
0091  *                  and/or interrupt
0092  * @param match_value: the value that the timer should match.
0093  * @return RTEMS_SUCCESSFUL if the timer was configured successfuly.
0094  */
0095 rtems_status_code lpc176x_timer_match_config(
0096   lpc176x_timer_number   tnumber,
0097   lpc176x_match_port     match_port,
0098   lpc176x_match_function function,
0099   uint32_t               match_value
0100 );
0101 
0102 /**
0103  * @brief Configures the capture ports
0104  *
0105  * @param tnumber: the device to be modified
0106  * @param capture_port: which port of this timer will be setted
0107  * @param function: At which edge/s will the capture work, and
0108  *                  if it will interrupt
0109  */
0110 rtems_status_code lpc176x_timer_capture_config(
0111   lpc176x_timer_number     tnumber,
0112   lpc176x_capture_port     capture_port,
0113   lpc176x_capture_function function
0114 );
0115 
0116 /**
0117  * @brief Configures the external match ports
0118  *
0119  * @param tnumber: the device to be modified
0120  * @param match_port: which match for this timer
0121  * @param function: what should do when match: set, clear toggle or nothing
0122  */
0123 rtems_status_code lpc176x_timer_external_match_config(
0124   lpc176x_timer_number       tnumber,
0125   lpc176x_match_port         match_port,
0126   lpc176x_ext_match_function function
0127 );
0128 
0129 /**
0130  * @brief Gets the captured value
0131  *
0132  * @param tnumber: the device to be modified
0133  * @param capnumber: which capture port for this timer
0134  * @return the captured value
0135  */
0136 uint32_t lpc176x_timer_get_capvalue(
0137   lpc176x_timer_number tnumber,
0138   lpc176x_capture_port capnumber
0139 );
0140 
0141 /**
0142  * @brief Gets the timer value
0143  *
0144  * @param tnumber: the device
0145  * @return the timer value
0146  */
0147 uint32_t lpc176x_timer_get_timer_value( lpc176x_timer_number tnumber );
0148 
0149 /**
0150  * @brief Sets the timer value
0151  *
0152  * @param tnumber: the timer to modify.
0153  * @param timer_value the value to set.
0154  */
0155 rtems_status_code lpc176x_timer_set_timer_value(
0156   lpc176x_timer_number tnumber,
0157   uint32_t             lpc176x_timer_value
0158 );
0159 
0160 /**
0161  * @brief Timer generic isroutine.
0162  *
0163  * @param timernumber the number of timer.
0164  */
0165 void lpc176x_timer_isr( void *lpc176x_timer_number );
0166 
0167 /**
0168  * @brief Initializes timer in timer mode and resets counter but
0169  *        without starting it, and without any capture or
0170  *        match function.
0171  *
0172  * @param tnumber which timer
0173  * @return RTEMS_SUCCESSFUL when everything ok.
0174  */
0175 rtems_status_code lpc176x_timer_init( lpc176x_timer_number tnumber );
0176 
0177 /**
0178  * @brief Initializes timer in timer mode and resets counter but
0179  *        without starting it, and without any capture or
0180  *        match function.
0181  *
0182  * @param tnumber which timer to init
0183  * @param vector the functions to be used by the isr.
0184  * @return RTEMS_SUCCESSFUL when everything ok.
0185  */
0186 rtems_status_code lpc176x_timer_init_with_interrupt(
0187   lpc176x_timer_number            tnumber,
0188   const lpc176x_isr_funct_vector *vector
0189 );
0190 
0191 #ifdef __cplusplus
0192 }
0193 #endif /* __cplusplus */
0194 
0195 #endif /* LIBBSP_ARM_LPC176X_TIMER_H */