blob: d6028e7d71182a2bc3309d4d0ca6acf5a0792281 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
Isabella Gottardiee4920b2022-02-25 14:29:32 +00002 * Copyright (c) 2022 Arm Limited. All rights reserved.
alexander3c798932021-03-26 21:42:19 +00003 * 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 Sisodiaa1256e32022-02-23 14:40:45 +000017#include "hal.h" /* API */
alexander3c798932021-03-26 21:42:19 +000018
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000019#include "platform_drivers.h" /* Platform drivers */
20#include "log_macros.h" /* Logging macros */
alexander3c798932021-03-26 21:42:19 +000021
22#include <stdio.h>
23#include <assert.h>
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000024#include <string.h>
alexander3c798932021-03-26 21:42:19 +000025
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010026int hal_init(hal_platform* platform, platform_timer* timer)
alexander3c798932021-03-26 21:42:19 +000027{
alexander3c798932021-03-26 21:42:19 +000028 platform->timer = timer;
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000029 platform->platform_init = platform_init;
30 platform->platform_release = platform_release;
31 platform_name(platform->plat_name, sizeof(platform->plat_name));
alexander3c798932021-03-26 21:42:19 +000032
33 return 0;
34}
35
36/**
37 * @brief Local helper function to clean the slate for current platform.
38 **/
alexanderc350cdc2021-04-29 20:36:09 +010039static void hal_platform_clear(hal_platform* platform)
alexander3c798932021-03-26 21:42:19 +000040{
41 assert(platform);
42 platform->inited = 0;
43}
44
45int hal_platform_init(hal_platform* platform)
46{
47 int state;
48 assert(platform && platform->platform_init);
alexanderc350cdc2021-04-29 20:36:09 +010049 hal_platform_clear(platform);
alexander3c798932021-03-26 21:42:19 +000050
51 /* Initialise platform */
52 if (0 != (state = platform->platform_init())) {
Isabella Gottardiee4920b2022-02-25 14:29:32 +000053 printf_err("Failed to initialise platform %s\n", platform->plat_name);
alexander3c798932021-03-26 21:42:19 +000054 return state;
55 }
56
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010057 /* Initialise LCD */
58 if (0 != (state = hal_lcd_init())) {
59 printf_err("hal_lcd_init failed\n");
alexander3c798932021-03-26 21:42:19 +000060 return state;
61 }
62
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010063 /* Initialise the timer module */
alexander3c798932021-03-26 21:42:19 +000064 init_timer(platform->timer);
65
66 info("%s platform initialised\n", platform->plat_name);
alexander3c798932021-03-26 21:42:19 +000067 platform->inited = !state;
alexander3c798932021-03-26 21:42:19 +000068 return state;
69}
70
71void hal_platform_release(hal_platform *platform)
72{
73 assert(platform && platform->platform_release);
alexander3c798932021-03-26 21:42:19 +000074
alexanderc350cdc2021-04-29 20:36:09 +010075 hal_platform_clear(platform);
Isabella Gottardiee4920b2022-02-25 14:29:32 +000076 info("Releasing platform %s\n", platform->plat_name);
alexander3c798932021-03-26 21:42:19 +000077 platform->platform_release();
78}
Kshitij Sisodia68fdd112022-04-06 13:03:20 +010079
80bool 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}