1 /*
2  * Copyright (c) 2015 Travis Geiselbrecht
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files
6  * (the "Software"), to deal in the Software without restriction,
7  * including without limitation the rights to use, copy, modify, merge,
8  * publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #include <lk/debug.h>
24 #include <platform.h>
25 #include <platform/stm32.h>
26 
27 /* overrides for certain hal routines, implemented in terms of LK's api  */
28 
29 /**
30   * @brief Provides a tick value in millisecond.
31   * @retval tick value
32   */
HAL_GetTick(void)33 uint32_t HAL_GetTick(void)
34 {
35     return current_time();
36 }
37 
38 /**
39   * @brief This function provides accurate delay (in milliseconds) based
40   *        on variable incremented.
41   * @param Delay: specifies the delay time length, in milliseconds.
42   * @retval None
43   */
HAL_Delay(__IO uint32_t Delay)44 void HAL_Delay(__IO uint32_t Delay)
45 {
46     spin(Delay * 1000);
47 }
48 
49 /**
50   * @brief Suspend Tick increment.
51   * @note In the default implementation , SysTick timer is the source of time base. It is
52   *       used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
53   *       is called, the the SysTick interrupt will be disabled and so Tick increment
54   *       is suspended.
55   * @retval None
56   */
HAL_SuspendTick(void)57 void HAL_SuspendTick(void)
58 {
59     /* we don't want any one calling this */
60     PANIC_UNIMPLEMENTED;
61 }
62 
63 /**
64   * @brief Resume Tick increment.
65   * @note In the default implementation , SysTick timer is the source of time base. It is
66   *       used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
67   *       is called, the the SysTick interrupt will be enabled and so Tick increment
68   *       is resumed.
69   * @retval None
70   */
HAL_ResumeTick(void)71 void HAL_ResumeTick(void)
72 {
73     /* we don't want any one calling this */
74     PANIC_UNIMPLEMENTED;
75 }
76 
HAL_InitTick(uint32_t TickPriority)77 HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
78 {
79     /* Start the systick at 10ms. The kernel will later override this */
80     HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/10000);
81 
82     return HAL_OK;
83 }
84 
85