alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | /* |
Isabella Gottardi | ee4920b | 2022-02-25 14:29:32 +0000 | [diff] [blame] | 2 | * Copyright (c) 2022 Arm Limited. All rights reserved. |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 3 | * SPDX-License-Identifier: Apache-2.0 |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 17 | #include "hal.h" /* API */ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 18 | |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 19 | #include "platform_drivers.h" /* Platform drivers */ |
| 20 | #include "log_macros.h" /* Logging macros */ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <assert.h> |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 24 | #include <string.h> |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 25 | |
Kshitij Sisodia | 68fdd11 | 2022-04-06 13:03:20 +0100 | [diff] [blame] | 26 | int hal_init(hal_platform* platform, platform_timer* timer) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 27 | { |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 28 | platform->timer = timer; |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 29 | platform->platform_init = platform_init; |
| 30 | platform->platform_release = platform_release; |
| 31 | platform_name(platform->plat_name, sizeof(platform->plat_name)); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @brief Local helper function to clean the slate for current platform. |
| 38 | **/ |
alexander | c350cdc | 2021-04-29 20:36:09 +0100 | [diff] [blame] | 39 | static void hal_platform_clear(hal_platform* platform) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 40 | { |
| 41 | assert(platform); |
| 42 | platform->inited = 0; |
| 43 | } |
| 44 | |
| 45 | int hal_platform_init(hal_platform* platform) |
| 46 | { |
| 47 | int state; |
| 48 | assert(platform && platform->platform_init); |
alexander | c350cdc | 2021-04-29 20:36:09 +0100 | [diff] [blame] | 49 | hal_platform_clear(platform); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 50 | |
| 51 | /* Initialise platform */ |
| 52 | if (0 != (state = platform->platform_init())) { |
Isabella Gottardi | ee4920b | 2022-02-25 14:29:32 +0000 | [diff] [blame] | 53 | printf_err("Failed to initialise platform %s\n", platform->plat_name); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 54 | return state; |
| 55 | } |
| 56 | |
Kshitij Sisodia | 68fdd11 | 2022-04-06 13:03:20 +0100 | [diff] [blame] | 57 | /* Initialise LCD */ |
| 58 | if (0 != (state = hal_lcd_init())) { |
| 59 | printf_err("hal_lcd_init failed\n"); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 60 | return state; |
| 61 | } |
| 62 | |
Kshitij Sisodia | 68fdd11 | 2022-04-06 13:03:20 +0100 | [diff] [blame] | 63 | /* Initialise the timer module */ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 64 | init_timer(platform->timer); |
| 65 | |
| 66 | info("%s platform initialised\n", platform->plat_name); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 67 | platform->inited = !state; |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 68 | return state; |
| 69 | } |
| 70 | |
| 71 | void hal_platform_release(hal_platform *platform) |
| 72 | { |
| 73 | assert(platform && platform->platform_release); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 74 | |
alexander | c350cdc | 2021-04-29 20:36:09 +0100 | [diff] [blame] | 75 | hal_platform_clear(platform); |
Isabella Gottardi | ee4920b | 2022-02-25 14:29:32 +0000 | [diff] [blame] | 76 | info("Releasing platform %s\n", platform->plat_name); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 77 | platform->platform_release(); |
| 78 | } |
Kshitij Sisodia | 68fdd11 | 2022-04-06 13:03:20 +0100 | [diff] [blame] | 79 | |
| 80 | bool hal_get_user_input(char* user_input, int size) |
| 81 | { |
| 82 | if (1 != GetLine(user_input, size - 1)) { |
| 83 | return true; |
| 84 | } |
| 85 | return false; |
| 86 | } |