pv_psoc6.c
Go to the documentation of this file.
1 /*
2  Copyright 2021 Picovoice Inc.
3 
4  You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
5  file accompanying this source.
6 
7  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8  an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  specific language governing permissions and limitations under the License.
10 */
11 
12 #include "pv_psoc6.h"
13 
14 #include "cy_pdl.h"
15 #include "cy_retarget_io.h"
16 #include "cy_rgb_led.h"
17 #include "cybsp.h"
18 #include "cyhal.h"
19 
20 #define CPU_CLOCK_150MHZ (150000000)
21 #define UUID_SIZE (8)
22 
23 static uint8_t uuid[UUID_SIZE];
24 
25 cyhal_clock_t pll_cpu_clock;
26 cyhal_clock_t cpu_clock;
27 
28 static cy_rslt_t cpu_clock_init(void) {
29  cy_rslt_t result;
30  result = cyhal_clock_get(&pll_cpu_clock, &CYHAL_CLOCK_PLL[0]);
31 
32  if (result == CY_RSLT_SUCCESS) {
33  result = cyhal_clock_init(&pll_cpu_clock);
34  }
35 
36  if (result == CY_RSLT_SUCCESS) {
37  result = cyhal_clock_set_frequency(&pll_cpu_clock, CPU_CLOCK_150MHZ, NULL);
38  }
39 
40  if (result == CY_RSLT_SUCCESS) {
41  result = cyhal_clock_set_enabled(&pll_cpu_clock, true, true);
42  }
43 
44  if (result == CY_RSLT_SUCCESS) {
45  result = cyhal_clock_get(&cpu_clock, &CYHAL_CLOCK_HF[0]);
46  }
47 
48  if (result == CY_RSLT_SUCCESS) {
49  result = cyhal_clock_init(&cpu_clock);
50  }
51 
52  if (result == CY_RSLT_SUCCESS) {
53  result = cyhal_clock_set_source(&cpu_clock, &pll_cpu_clock);
54  }
55 
56  return result;
57 }
58 
60  cy_rslt_t result;
61 
62  result = cybsp_init();
63  if (result != CY_RSLT_SUCCESS) {
65  }
66 
67  result = cpu_clock_init();
68  if (result != CY_RSLT_SUCCESS) {
70  }
71 
72  result = cy_rgb_led_init(CYBSP_LED_RGB_RED, CYBSP_LED_RGB_GREEN, CYBSP_LED_RGB_BLUE, CY_RGB_LED_ACTIVE_LOW);
73  if (result != CY_RSLT_SUCCESS) {
75  }
76 
77  __enable_irq();
78 
79  uint64_t board_uuid = Cy_SysLib_GetUniqueId();
80  memcpy(uuid, (const uint8_t *)&board_uuid, UUID_SIZE);
81 
82 
83  return PV_STATUS_SUCCESS;
84 }
85 
87  cy_rslt_t result;
88 
89  result = cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE);
90  if (result != CY_RSLT_SUCCESS) {
92  }
93 
94  return PV_STATUS_SUCCESS;
95 }
96 
98 }
99 
100 const uint8_t *pv_get_uuid(void) {
101  return (const uint8_t *) uuid;
102 }
103 
104 const uint32_t pv_get_uuid_size(void) {
105  return UUID_SIZE;
106 }
107 
108 void pv_error_handler(void) {
109  __disable_irq();
110  while(true);
111 }
UUID_SIZE
#define UUID_SIZE
Definition: pv_psoc6.c:21
CPU_CLOCK_150MHZ
#define CPU_CLOCK_150MHZ
Definition: pv_psoc6.c:20
pv_psoc6.h
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
PV_STATUS_INVALID_STATE
@ PV_STATUS_INVALID_STATE
Definition: porcupine/include/picovoice.h:40
__disable_irq
__STATIC_FORCEINLINE void __disable_irq(void)
Disable IRQ Interrupts.
Definition: imxrt1050/imxrt1050-evkb/CMSIS/cmsis_gcc.h:207
pv_get_uuid
const uint8_t * pv_get_uuid(void)
Definition: pv_psoc6.c:100
uuid
static uint8_t uuid[UUID_SIZE]
Definition: pv_psoc6.c:23
PV_STATUS_SUCCESS
@ PV_STATUS_SUCCESS
Definition: porcupine/include/picovoice.h:34
pv_status_t
pv_status_t
Definition: porcupine/include/picovoice.h:33
__enable_irq
__STATIC_FORCEINLINE void __enable_irq(void)
Enable IRQ Interrupts.
Definition: imxrt1050/imxrt1050-evkb/CMSIS/cmsis_gcc.h:196
cpu_clock_init
static cy_rslt_t cpu_clock_init(void)
Definition: pv_psoc6.c:28
pv_board_deinit
void pv_board_deinit()
Definition: pv_psoc6.c:97
pv_message_init
pv_status_t pv_message_init(void)
Definition: pv_psoc6.c:86
pv_error_handler
void pv_error_handler(void)
Definition: pv_psoc6.c:108
cpu_clock
cyhal_clock_t cpu_clock
Definition: pv_psoc6.c:26
pv_board_init
pv_status_t pv_board_init(void)
Definition: pv_psoc6.c:59
pv_get_uuid_size
const uint32_t pv_get_uuid_size(void)
Definition: pv_psoc6.c:104
pll_cpu_clock
cyhal_clock_t pll_cpu_clock
Definition: pv_psoc6.c:25


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:50