{"id":20930321,"url":"https://github.com/seff34/software_timer_on_stm32","last_synced_at":"2026-04-29T03:34:46.964Z","repository":{"id":200289422,"uuid":"705199144","full_name":"seff34/Software_Timer_On_STM32","owner":"seff34","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-13T14:30:53.000Z","size":3000,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-19T18:52:03.598Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seff34.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-15T10:35:57.000Z","updated_at":"2023-10-15T10:36:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"59501560-f8de-43d3-b9ee-2eea870c3e5a","html_url":"https://github.com/seff34/Software_Timer_On_STM32","commit_stats":null,"previous_names":["seff34/software_timer_on_stm32"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seff34%2FSoftware_Timer_On_STM32","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seff34%2FSoftware_Timer_On_STM32/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seff34%2FSoftware_Timer_On_STM32/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seff34%2FSoftware_Timer_On_STM32/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seff34","download_url":"https://codeload.github.com/seff34/Software_Timer_On_STM32/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243324266,"owners_count":20273100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T21:31:57.527Z","updated_at":"2025-12-30T04:29:02.741Z","avatar_url":"https://github.com/seff34.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## Software Timer On STM32 and Embedded Systems\n\n### BASIC Usage with SYSTICK\n * Basic usage is basic :)\n * Include header file on your source file .\n * Define a Software Timer;\n * Init the Timer\n * Init the Callback function\n * Start the Timer\n * thats all.\n\n#### Example\n```c\n#include \"software_timer.h\"\n...\nvoid timer1_callback(void)\n{\n    ...\n}\n...\nvoid INIT() {\n    sw_timer_t* swTimer1;\n    swTimer1 = swTimer_init(1000, SW_TIMER_PERIODIC,timer1_callback);\n    swTimer_start(swTimer1);\n}\n...\n```\n\n### ADVANGE Usage with TIMER\n* Advanced usage not hard but its not basic.\n * This usage start same as basic usage.\n * Include header file on your source file .\n * Define a Software Timer;\n * Init the Timer\n * Init the Callback function\n * Start the Timer\n * Comment BASIC_USAGE definition in this header.\n * Create a Real Timer by CubeMx.\n * The timer set 1 millisecond.\n * Start the timer.\n * You must call swTimer_proses(swTimerX); function every software timer in your Timer handler.\n#### Example\n```c\n// (100MHz Prosesor) / (99 (Prescaler) * 999 *(Period)) =~ 1Khz =~ 1ms Timer\nstatic void MX_TIM1_Init(void)\n{\n    ...\n    htimx.Init.Prescaler = 100;\n    htimx.Init.Period = 1000;\n    ...\n}\nvoid HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){\nif ( htim-\u003eInstance == htimx.Instance ) {\n    swTimer_proses(swTimer1);\n    swTimer_proses(swTimer2);\n}\n...\nvoid INIT(){\n    HAL_TIM_Base_Start_IT(\u0026htimx);  // START TIMER\n    ...\n}\n```\n\n\n### Timeout Functions\n *\tTimeout Functions use SYSTICK_TIMER\n *\tswTimer_delay \t\t\t-\u003e Standard delay function similar to  HAL_Delay()\n *\tswTimer_waitFlag\t\t-\u003e Timeout Function: Control of a flag\n *\tswTimer_waitDoubleFlag  -\u003e Timeout Function: Control of two flag\n\n#### Example\n *\tIn this use, a delay of 10 seconds is set.\n *\tIf within 10 seconds the flag given as a parameter becomes true via another interrupt,\n *\tthe function returns true immediately. If not, it returns false.\n```c\nif (swTimer_waitFlag(10000,\u0026flag))\n\tfoo();\n```\n\n### API Functions\n```c\n#define SW_TIMER_LIMIT \t   \t100\n#define SW_TIMER_MAX_VALUE \tUINT32_MAX\n#define SW_TIMER_PERIODIC  \ttrue\n#define SW_TIMER_ONESHOT   \tfalse\n#define SW_TIMER_START     \ttrue\n#define SW_TIMER_STOP      \tfalse\n\ntypedef struct SOFTWARE_TIMER_INIT\n{\n\tvolatile uint32_t counter;\t\t\t// Timer Millisecond currunt value\n\tuint32_t target;\t\t\t\t// Timer Millisecond target/interrupt value\n\tbool status;\t\t\t\t\t// Timer Status (SW_TIMER_START-SW_TIMER_STOP)\n\tbool type;\t\t\t\t\t// Timer Type   (SW_TIMER_PERIODIC-SW_TIMER_ONESHOT)\n\tvoid(*callback)(void);\t\t\t\t// Timer Callback Function\n}sw_timer_t;\n\n/**\n  * @brief Software Timer Initalize\n  * @param uint32_t \t Timer Value on millisecond\n  * @param bool \t\t Timer Type( SW_TIMER_PERIODIC - SW_TIMER_ONESHOT)\n  * @param void(*)(void) Software Timer Callback Function\n  * @retval sw_timer_t   Software Timer Pointer\n  */\nsw_timer_t* swTimer_init(const uint32_t target,const bool type,void(*callback)(void));\n\n/**\n  * @brief Software Timer Get Status\n  * @param sw_timer_t Software Timer Pointer\n  * @retval bool Software Timer Status ( Running = true / Stop = false )\n  */\nbool swTimer_status(sw_timer_t* swTimer);\n\n/**\n  * @brief Software Timer Start\n  * @param sw_timer_t Software Timer Pointer\n  * @retval none\n  */\nvoid swTimer_start(sw_timer_t* swTimer);\n\n/**\n  * @brief Software Timer Stop\n  * @param sw_timer_t Software Timer Pointer\n  * @retval none\n  */\nvoid swTimer_stop(sw_timer_t* swTimer);\n\n/**\n  * @brief Software Timer Reset\n  * @note  Counter value reset but timer status unchanged\n  * @param sw_timer_t Software Timer Pointer\n  * @retval none\n  */\nvoid swTimer_reset(sw_timer_t* swTimer);\n\n/**\n  * @brief Software Timer Restart\n  * @note  Counter value reset and timer started\n  * @param sw_timer_t Software Timer Pointer\n  * @retval none\n  */\nvoid swTimer_restart(sw_timer_t* swTimer);\n\n/**\n  * @brief  Software   Timer Set Target Value\n  * @param  sw_timer_t Software Timer Pointer\n  * @param  uint32_t   New Timer Target Value\n  * @retval uint32_t   Old Timer Target Value\n  */\nuint32_t swTimer_setTargetValue(sw_timer_t* swTimer,uint32_t newTarget);\n\n/**\n  * @brief  Software   Timer Get Target Value\n  * @param  sw_timer_t Software Timer Pointer\n  * @retval uint32_t   Timer Target Value\n  */\nuint32_t swTimer_getTargetValue(const sw_timer_t* swTimer);\n\n#ifndef USE_SYSTICK_TIMER\n/**\n  * @note  This function has been removed in the interface.\n  * \t   If you want to use a different timer. Comment to USE_SYSTICK_TIMER on top.\n  * @brief Software Timer Proses\n  * @param sw_timer_t Software Timer Pointer\n  * @retval none\n  */\nvoid swTimer_proses(sw_timer_t* swTimer);\n#endif\n\n/**\n  * @brief  Standart Delay\n  * @param  uint32_t Delay Period\n  * @retval none\n  */\nvoid swTimer_delay(const uint32_t delay);\n\n/**\n  * @brief  Delay With a Flag\n  * @param  uint32_t Delay Period\n  * @param  bool*    First Flag\n  * @retval bool \t Returns true if delay ended early\n  */\nbool swTimer_waitFlag(const uint32_t delay,bool* flag);\n\n/**\n  * @brief  Delay With a Flag\n  * @param  uint32_t Delay Period\n  * @param  bool*    First Flag\n  * @param  bool*\t Second Flag\n  * @retval bool     Returns true if delay ended early\n  */\nbool swTimer_waitDoubleFlag(const uint32_t delay,bool* flag1,bool* flag2);\n\n/**\n  * @brief  Get Run Time Seceond\n  * @retval uint32_t Run Time Second Value\n  */\nuint32_t getRunTimeSec();\n\n/**\n  * @brief  Get Run Time Miliseceond\n  * @retval uint32_t Run Time Miliseceond Value\n  */\nuint32_t getRunTimeMsec();\n\n/**\n  * @brief  Get Run Time Value on string\n  * @retval char* Run Time Value on string\n  */\nconst char* getRunTimeStr();\n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseff34%2Fsoftware_timer_on_stm32","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseff34%2Fsoftware_timer_on_stm32","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseff34%2Fsoftware_timer_on_stm32/lists"}