1 /* port/ti/ti_ccm.c
2 *
3 * Copyright (C) 2006-2021 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
6 *
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20 */
21
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <wolfssl/wolfcrypt/settings.h>
28
29 #if defined(WOLFSSL_TI_CRYPT) || defined(WOLFSSL_TI_HASH)
30
31 #include "wolfssl/wolfcrypt/port/ti/ti-ccm.h"
32 #include <stdbool.h>
33 #include <stdint.h>
34
35 #ifndef TI_DUMMY_BUILD
36 #include "driverlib/sysctl.h"
37 #include "driverlib/rom_map.h"
38 #include "driverlib/rom.h"
39
40 #ifndef SINGLE_THREADED
41 #include <wolfssl/wolfcrypt/wc_port.h>
42 static wolfSSL_Mutex TI_CCM_Mutex;
43 #endif
44 #endif /* TI_DUMMY_BUILD */
45
46 #define TIMEOUT 500000
47 #define WAIT(stat) { volatile int i; for(i=0; i<TIMEOUT; i++)if(stat)break; if(i==TIMEOUT)return(false); }
48
49 static bool ccm_init = false;
wolfSSL_TI_CCMInit(void)50 int wolfSSL_TI_CCMInit(void)
51 {
52 if (ccm_init)
53 return true;
54 ccm_init = true;
55
56 #ifndef TI_DUMMY_BUILD
57 SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
58 SYSCTL_OSC_MAIN |
59 SYSCTL_USE_PLL |
60 SYSCTL_CFG_VCO_480), 120000000);
61
62 if (!ROM_SysCtlPeripheralPresent(SYSCTL_PERIPH_CCM0))
63 return false;
64
65 ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_CCM0);
66 WAIT(ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0));
67 ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_CCM0);
68 WAIT(ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0));
69
70 #ifndef SINGLE_THREADED
71 if (wc_InitMutex(&TI_CCM_Mutex))
72 return false;
73 #endif
74 #endif /* !TI_DUMMY_BUILD */
75
76 return true;
77 }
78
79 #ifndef SINGLE_THREADED
wolfSSL_TI_lockCCM(void)80 void wolfSSL_TI_lockCCM(void)
81 {
82 #ifndef TI_DUMMY_BUILD
83 wc_LockMutex(&TI_CCM_Mutex);
84 #endif
85 }
86
wolfSSL_TI_unlockCCM(void)87 void wolfSSL_TI_unlockCCM(void){
88 #ifndef TI_DUMMY_BUILD
89 wc_UnLockMutex(&TI_CCM_Mutex);
90 #endif
91 }
92 #endif /* !SINGLE_THREADED */
93
94 #endif /* WOLFSSL_TI_CRYPT || WOLFSSL_TI_HASH */
95