1 /* -------------------------------------------------------------------------- */
2 /*                           Copyright 2021-2023 NXP                          */
3 /*                            All rights reserved.                            */
4 /*                    SPDX-License-Identifier: BSD-3-Clause                   */
5 /* -------------------------------------------------------------------------- */
6 
7 /* -------------------------------------------------------------------------- */
8 /*                                  Includes                                  */
9 /* -------------------------------------------------------------------------- */
10 
11 #include <stdint.h>
12 #include <stdbool.h>
13 
14 #include "fwk_platform_ot.h"
15 #include "fwk_platform_coex.h"
16 #include "fwk_platform_ble.h"
17 #include "fwk_platform_hdlc.h"
18 
19 /* -------------------------------------------------------------------------- */
20 /*                               Private macros                               */
21 /* -------------------------------------------------------------------------- */
22 
23 /* -------------------------------------------------------------------------- */
24 /*                                Private types                               */
25 /* -------------------------------------------------------------------------- */
26 
27 /* -------------------------------------------------------------------------- */
28 /*                               Private memory                               */
29 /* -------------------------------------------------------------------------- */
30 
31 static bool initialized = false;
32 
33 /* -------------------------------------------------------------------------- */
34 /*                             Private prototypes                             */
35 /* -------------------------------------------------------------------------- */
36 
37 /* -------------------------------------------------------------------------- */
38 /*                              Public functions                              */
39 /* -------------------------------------------------------------------------- */
40 
PLATFORM_InitOt(void)41 int PLATFORM_InitOt(void)
42 {
43     int ret = 0;
44 
45     do
46     {
47         if (initialized == true)
48         {
49             break;
50         }
51 
52         /* Initialize the 802.15.4 controller */
53         if (PLATFORM_InitControllers(conn802_15_4_c) != 0)
54         {
55             ret = -1;
56             break;
57         }
58 
59         /* Initialize the BLE Controller as it is part of the same combo firmware */
60         if (PLATFORM_InitBle() != 0)
61         {
62             ret = -2;
63             break;
64         }
65 
66         /* Setup HCI link and make sure it is ready
67          * Used for low power control of the BLE/15.4 firmware */
68         if (PLATFORM_StartHci() != 0)
69         {
70             ret = -3;
71             break;
72         }
73 
74         initialized = true;
75     } while (false);
76 
77     return ret;
78 }
79 
PLATFORM_TerminateOt(void)80 int PLATFORM_TerminateOt(void)
81 {
82     int ret = 0;
83 
84     do
85     {
86         if (PLATFORM_TerminateHdlcInterface() != 0)
87         {
88             ret = -1;
89             break;
90         }
91 
92         if (PLATFORM_TerminateBle() != 0)
93         {
94             ret = -2;
95             break;
96         }
97 
98         if (PLATFORM_TerminateControllers((uint8_t)conn802_15_4_c) != 0)
99         {
100             ret = -3;
101             break;
102         }
103 
104     } while (false);
105 
106     return ret;
107 }
108 
PLATFORM_ResetOt(void)109 int PLATFORM_ResetOt(void)
110 {
111     int ret = 0;
112 
113     initialized = false;
114 
115     do
116     {
117         if (PLATFORM_TerminateOt() != 0)
118         {
119             ret = -1;
120             break;
121         }
122 
123         if (PLATFORM_InitOt() != 0)
124         {
125             ret = -2;
126             break;
127         }
128 
129         if (PLATFORM_ResetHdlcInterface() != 0)
130         {
131             ret = -3;
132             break;
133         }
134 
135     } while (false);
136 
137     return ret;
138 }
139 
140 /* -------------------------------------------------------------------------- */
141 /*                              Private functions                             */
142 /* -------------------------------------------------------------------------- */
143