1 // Copyright (C) 2022 Beken Corporation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <common/bk_include.h>
16 #include "mailbox_hal.h"
17
mailbox_hal_addr_init(mailbox_hal_t * hal)18 bk_err_t mailbox_hal_addr_init(mailbox_hal_t *hal)
19 {
20 if (hal->id >= SOC_MAILBOX_NUM)
21 return BK_FAIL;
22
23 mailbox_ll_addr_init(hal);
24
25 return BK_OK;
26 }
27
mailbox_hal_set_identity(mailbox_hal_t * hal)28 void mailbox_hal_set_identity(mailbox_hal_t *hal)
29
30 {
31 if (hal->id >= SOC_MAILBOX_NUM)
32 return;
33
34 switch (hal->id) {
35 case 0:
36 mailbox_ll_set_identity(hal->hw, hal->id);
37 break;
38 case 1:
39 mailbox_ll_set_identity(hal->hw, hal->id);
40 break;
41 case 2:
42 mailbox_ll_set_identity(hal->hw, hal->id);
43 break;
44 case 3:
45 mailbox_ll_set_identity(hal->hw, hal->id);
46 break;
47 default:
48 break;
49 }
50
51 }
52
mailbox_hal_check_which_box_ready(mailbox_hal_t * hal)53 mailbox_box_num_t mailbox_hal_check_which_box_ready(mailbox_hal_t *hal)
54 {
55 if (!mailbox_ll_read_box_ready((hal->hw), MAILBOX_BOX0))
56 return MAILBOX_BOX0;
57 else if (!mailbox_ll_read_box_ready((hal->hw), MAILBOX_BOX1))
58 return MAILBOX_BOX1;
59 else
60 return MAILBOX_NONE;
61 }
62
mailbox_hal_check_which_box_trigger(mailbox_hal_t * hal)63 mailbox_box_num_t mailbox_hal_check_which_box_trigger(mailbox_hal_t *hal)
64 {
65 if (mailbox_ll_read_box_ready((hal->hw), MAILBOX_BOX0))
66 return MAILBOX_BOX0;
67 else if (mailbox_ll_read_box_ready((hal->hw), MAILBOX_BOX1))
68 return MAILBOX_BOX1;
69 else
70 return MAILBOX_NONE;
71 }
72
73