Skip to content

Commit 2af164d

Browse files
vmyklebustvaishnavachath
authored andcommitted
simplelink: driver: add DPL and crypto drivers
Port MutexP, SemaphoreP, SwiP, and QueueP to LPF3. Add support for interrupts of INT_CPUIRQ4, INT_LRFD_IRQ0 and INT_LRFD_IRQ1 used by the RCL (TI's radio driver for F3 devices). Add AES and ECDH SimpleLink drivers and their dependencies. Signed-off-by: Vebjorn Myklebust <[email protected]> Signed-off-by: Lars Thalian Morstad <[email protected]> Signed-off-by: Min Xu <[email protected]>
1 parent 93ccf67 commit 2af164d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+23006
-58
lines changed

simplelink_lpf3/CMakeLists.txt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,49 @@ if(CONFIG_HAS_CC23X0_SDK)
1414
zephyr_library()
1515
zephyr_library_compile_definitions(${COMPILER})
1616
zephyr_library_sources(
17+
# Default Simplelink configurations
18+
source/ti/drivers/config_defaults.c
19+
1720
# Utils
1821
source/ti/drivers/utils/List.c
1922

2023
# Drivers
24+
source/ti/drivers/AESCCM.c
25+
source/ti/drivers/AESCMAC.c
26+
source/ti/drivers/AESCTR.c
27+
source/ti/drivers/AESCTRDRBG.c
28+
source/ti/drivers/AESECB.c
29+
source/ti/drivers/ECDH.c
30+
source/ti/drivers/aesccm/AESCCMLPF3.c
31+
source/ti/drivers/aescmac/AESCMACLPF3.c
32+
source/ti/drivers/aesctr/AESCTRLPF3.c
33+
source/ti/drivers/aesctrdrbg/AESCTRDRBGXX.c
34+
source/ti/drivers/aesecb/AESECBLPF3.c
35+
source/ti/drivers/cryptoutils/aes/AESCommonLPF3.c
36+
source/ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.c
37+
source/ti/drivers/cryptoutils/sharedresources/CryptoResourceLPF3.c
38+
source/ti/drivers/cryptoutils/utils/CryptoUtils.c
39+
source/ti/drivers/dma/UDMALPF3.c
40+
2141
source/ti/drivers/Temperature.c
2242
source/ti/drivers/power/PowerCC23X0.c
2343
source/ti/drivers/temperature/TemperatureLPF3.c
2444
source/ti/drivers/batterymonitor/BatMonSupportLPF3.c
2545
source/ti/drivers/batterymonitor/BatteryMonitorLPF3.c
2646

2747
# DPL
48+
kernel/zephyr/dpl/MutexP_zephyr.c
49+
kernel/zephyr/dpl/SemaphoreP_zephyr.c
2850
kernel/zephyr/dpl/ClockP_zephyr.c
2951
kernel/zephyr/dpl/HwiP_zephyr.c
52+
kernel/zephyr/dpl/SwiP_zephyr.c
3053
kernel/zephyr/dpl/TaskP_zephyr.c
3154
kernel/zephyr/dpl/MessageQueueP_zephyr.c
3255
)
33-
if(CONFIG_EVENTS)
34-
zephyr_library_sources(kernel/zephyr/dpl/EventP_zephyr.c)
35-
endif()
56+
if(CONFIG_EVENTS)
57+
zephyr_library_sources(kernel/zephyr/dpl/EventP_zephyr.c)
58+
endif()
59+
zephyr_linker_sources(RAM_SECTIONS
60+
${CMAKE_CURRENT_SOURCE_DIR}/source/ti/drivers/dma/dma.ld
61+
)
3662
endif()

simplelink_lpf3/kernel/zephyr/dpl/ClockP_zephyr.c

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,36 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
78
#include <zephyr/kernel.h>
89
#include <zephyr/sys/__assert.h>
9-
#include <zephyr/sys_clock.h>
10+
#include <kernel/zephyr/dpl/dpl.h>
1011
#include <ti/drivers/dpl/ClockP.h>
12+
#include <ti/drivers/dpl/HwiP.h>
13+
14+
/* Driverlib includes*/
15+
#include <ti/devices/DeviceFamily.h>
16+
#include DeviceFamily_constructPath(inc/hw_types.h)
17+
#include DeviceFamily_constructPath(inc/hw_memmap.h)
18+
#include DeviceFamily_constructPath(inc/hw_systim.h)
19+
20+
/** Max number of ClockP ticks into the future supported by this ClockP
21+
* implementation.
22+
*
23+
* Under the hood, ClockP uses the SysTimer whose events trigger immediately if
24+
* the compare value is less than 2^22 systimer ticks in the past
25+
* (4.194sec at 1us resolution). Therefore, the max number of SysTimer ticks you
26+
* can schedule into the future is 2^32 - 2^22 - 1 ticks (~= 4290 sec at 1us
27+
* resolution). */
28+
#define ClockP_PERIOD_MAX (0xFFBFFFFFU / ClockP_TICK_PERIOD)
29+
/** Max number of seconds into the future supported by this ClockP
30+
* implementation.
31+
*
32+
* This limit affects ClockP_sleep() */
33+
#define ClockP_PERIOD_MAX_SEC 4290U
34+
35+
/* Get the current ClockP tick value */
36+
#define getClockPTick() (HWREG(SYSTIM_BASE + SYSTIM_O_TIME1U) / ClockP_TICK_PERIOD)
1137

1238
/*
1339
* ClockP_STRUCT_SIZE in ClockP.h must be updated to match the size of this
@@ -36,6 +62,58 @@ static void expiry_fxn(struct k_timer *timer_id)
3662
obj->clock_fxn(obj->arg);
3763
}
3864

65+
#ifdef CONFIG_DYNAMIC_DPL_OBJECTS
66+
67+
/* We can't easily dynamically allocate kernel objects so we use memory slabs */
68+
#define DPL_MAX_CLOCKS 5
69+
K_MEM_SLAB_DEFINE(clock_slab, sizeof(ClockP_Obj), DPL_MAX_CLOCKS,\
70+
MEM_ALIGN);
71+
72+
static ClockP_Obj *dpl_clock_pool_alloc()
73+
{
74+
ClockP_Obj *clock_ptr = NULL;
75+
76+
if (k_mem_slab_alloc(&clock_slab, (void **)&clock_ptr, K_NO_WAIT) < 0) {
77+
78+
__ASSERT(0, "Increase size of DPL clock pool");
79+
}
80+
return clock_ptr;
81+
}
82+
83+
static void dpl_clock_pool_free(ClockP_Obj *clock)
84+
{
85+
k_mem_slab_free(&clock_slab, (void *)&clock);
86+
87+
return;
88+
}
89+
90+
/*
91+
* ======== ClockP_create ========
92+
*/
93+
ClockP_Handle ClockP_create(ClockP_Fxn clkFxn, uint32_t timeout, ClockP_Params *params)
94+
{
95+
ClockP_Handle handle;
96+
97+
handle = (ClockP_Handle)dpl_clock_pool_alloc();
98+
99+
/* ClockP_construct will check handle for NULL, no need here */
100+
handle = ClockP_construct((ClockP_Struct *)handle, clkFxn, timeout, params);
101+
102+
return (handle);
103+
}
104+
105+
/*
106+
* ======== ClockP_delete ========
107+
*/
108+
void ClockP_delete(ClockP_Handle handle)
109+
{
110+
ClockP_destruct((ClockP_Struct *)handle);
111+
112+
dpl_clock_pool_free((ClockP_Obj*) handle);
113+
}
114+
115+
#endif /* CONFIG_DYNAMIC_DPL_OBJECTS */
116+
39117
/*
40118
* ======== ClockP_construct ========
41119
*/
@@ -160,6 +238,37 @@ void ClockP_stop(ClockP_Handle handle)
160238
obj->active = false;
161239
}
162240

241+
/*
242+
* ======== ClockP_setFunc ========
243+
*/
244+
void ClockP_setFunc(ClockP_Handle handle, ClockP_Fxn clockFxn, uintptr_t arg)
245+
{
246+
ClockP_Obj *obj = (ClockP_Obj *)handle;
247+
248+
uintptr_t key = HwiP_disable();
249+
250+
obj->clock_fxn = clockFxn;
251+
obj->arg = arg;
252+
253+
HwiP_restore(key);
254+
}
255+
256+
/*
257+
* ======== ClockP_sleep ========
258+
*/
259+
void ClockP_sleep(uint32_t sec)
260+
{
261+
uint32_t ticksToSleep;
262+
263+
if (sec > ClockP_PERIOD_MAX_SEC)
264+
{
265+
sec = ClockP_PERIOD_MAX_SEC;
266+
}
267+
/* Convert from seconds to number of ticks */
268+
ticksToSleep = (sec * USEC_PER_SEC) / ClockP_TICK_PERIOD;
269+
k_sleep(K_TICKS(ticksToSleep));
270+
}
271+
163272
/*
164273
* ======== ClockP_usleep ========
165274
*/
@@ -186,6 +295,15 @@ bool ClockP_isActive(ClockP_Handle handle)
186295
return obj->active;
187296
}
188297

298+
/*
299+
* ======== ClockP_getCpuFreq ========
300+
*/
301+
void ClockP_getCpuFreq(ClockP_FreqHz *freq)
302+
{
303+
freq->lo = (uint32_t)CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;
304+
freq->hi = 0;
305+
}
306+
189307
void ClockP_destruct(ClockP_Struct *clockP)
190308
{
191309
ClockP_Obj *obj = (ClockP_Obj *)clockP->data;

simplelink_lpf3/kernel/zephyr/dpl/EventP_zephyr.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@
2323
/* We can't easily dynamically allocate kernel objects */
2424
#define DPL_MAX_EVENTS 5
2525
K_MEM_SLAB_DEFINE(event_slab, sizeof(struct k_event), DPL_MAX_EVENTS,\
26-
MEM_ALIGN);
26+
MEM_ALIGN);
2727

2828

2929
static struct k_event *dpl_event_pool_alloc()
3030
{
31-
struct k_event *event_ptr = NULL;
31+
struct k_event *event_ptr = NULL;
3232

33-
if (k_mem_slab_alloc(&event_slab, (void **)&event_ptr, K_NO_WAIT) < 0) {
33+
if (k_mem_slab_alloc(&event_slab, (void **)&event_ptr, K_NO_WAIT) < 0) {
3434

35-
__ASSERT(0, "Increase size of DPL event pool");
36-
}
37-
return event_ptr;
35+
__ASSERT(0, "Increase size of DPL event pool");
36+
}
37+
return event_ptr;
3838
}
3939

4040
static void dpl_event_pool_free(struct k_event *event)
4141
{
42-
k_mem_slab_free(&event_slab, (void *)event);
42+
k_mem_slab_free(&event_slab, (void *)event);
4343

44-
return;
44+
return;
4545
}
4646

4747
/*
@@ -116,7 +116,7 @@ uint32_t EventP_pend(EventP_Handle event, uint32_t eventMask, bool waitForAll, u
116116
{
117117
/* if necessary, convert ClockP ticks to Zephyr ticks */
118118
/* Should really be ClockP_getSystemTickPeriod() but this causes issues with ielftool post build step */
119-
tickPeriod = CLOCKP_TICK_PERIOD;
119+
tickPeriod = ClockP_TICK_PERIOD;
120120
eventTimeout = K_TICKS(timeout);
121121
}
122122

simplelink_lpf3/kernel/zephyr/dpl/HwiP_zephyr.c

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ typedef struct _HwiP_Obj
4343
struct sl_isr_args *cb;
4444
} HwiP_Obj;
4545

46+
/* interrupt reserved for SwiP */
47+
int HwiP_swiPIntNum = INT_CPUIRQ1;
48+
49+
static struct sl_isr_args sl_IRQ01_cb = {NULL, 0};
4650
static struct sl_isr_args sl_IRQ03_cb = {NULL, 0};
51+
static struct sl_isr_args s1_IRQ04_cb = {NULL, 0};
4752
static struct sl_isr_args sl_IRQ16_cb = {NULL, 0};
53+
static struct sl_isr_args s1_LRFD_IRQ0_cb = {NULL, 0};
54+
static struct sl_isr_args s1_LRFD_IRQ1_cb = {NULL, 0};
4855

4956
/*
5057
* ======== HwiP_construct ========
@@ -67,10 +74,12 @@ HwiP_Handle HwiP_construct(HwiP_Struct *handle, int interruptNum, HwiP_Fxn hwiFx
6774
}
6875

6976
/*
70-
* Currently only support INT_CPUIRQ3 (Oscillator ISR) and INT_CPUIRQ16
71-
* (Batmon ISR)
77+
* Currently only support INT_CPUIRQ1 (SwiP), INT_CPUIRQ3 (Oscillator ISR),
78+
* INT_CPUIRQ16 (Batmon ISR), INT_CPUIRQ4 (RCL Scheduler ISR), INT_LRFD_IRQ0
79+
* (RCL Command Handler ISR) and INT_LRFD_IRQ1 (RCL Dispatcher ISR)
7280
*/
73-
__ASSERT(INT_CPUIRQ3 == interruptNum || INT_CPUIRQ16 == interruptNum,
81+
__ASSERT((INT_CPUIRQ1 == interruptNum) || (INT_CPUIRQ3 == interruptNum) || (INT_CPUIRQ4 == interruptNum) ||
82+
(INT_CPUIRQ16 == interruptNum) || (INT_LRFD_IRQ0 == interruptNum) || (INT_LRFD_IRQ1 == interruptNum),
7483
"Unexpected interruptNum: %d\r\n",
7584
interruptNum);
7685

@@ -95,18 +104,42 @@ HwiP_Handle HwiP_construct(HwiP_Struct *handle, int interruptNum, HwiP_Fxn hwiFx
95104

96105
switch (interruptNum)
97106
{
107+
case INT_CPUIRQ1:
108+
sl_IRQ01_cb.cb = hwiFxn;
109+
sl_IRQ01_cb.arg = arg;
110+
obj->cb = &sl_IRQ01_cb;
111+
irq_connect_dynamic(INT_CPUIRQ1 - 16, priority, sl_isr, &sl_IRQ01_cb, 0);
112+
break;
98113
case INT_CPUIRQ3:
99114
sl_IRQ03_cb.cb = hwiFxn;
100115
sl_IRQ03_cb.arg = arg;
101116
obj->cb = &sl_IRQ03_cb;
102117
irq_connect_dynamic(INT_CPUIRQ3 - 16, priority, sl_isr, &sl_IRQ03_cb, 0);
103118
break;
119+
case INT_CPUIRQ4:
120+
s1_IRQ04_cb.cb = hwiFxn;
121+
s1_IRQ04_cb.arg = arg;
122+
obj->cb = &s1_IRQ04_cb;
123+
irq_connect_dynamic(INT_CPUIRQ4 - 16, priority, sl_isr, &s1_IRQ04_cb, 0);
124+
break;
104125
case INT_CPUIRQ16:
105126
sl_IRQ16_cb.cb = hwiFxn;
106127
sl_IRQ16_cb.arg = arg;
107128
obj->cb = &sl_IRQ16_cb;
108129
irq_connect_dynamic(INT_CPUIRQ16 - 16, priority, sl_isr, &sl_IRQ16_cb, 0);
109130
break;
131+
case INT_LRFD_IRQ0:
132+
s1_LRFD_IRQ0_cb.cb = hwiFxn;
133+
s1_LRFD_IRQ0_cb.arg = arg;
134+
obj->cb = &s1_LRFD_IRQ0_cb;
135+
irq_connect_dynamic(INT_LRFD_IRQ0 - 16, priority, sl_isr, &s1_LRFD_IRQ0_cb, 0);
136+
break;
137+
case INT_LRFD_IRQ1:
138+
s1_LRFD_IRQ1_cb.cb = hwiFxn;
139+
s1_LRFD_IRQ1_cb.arg = arg;
140+
obj->cb = &s1_LRFD_IRQ1_cb;
141+
irq_connect_dynamic(INT_LRFD_IRQ1 - 16, priority, sl_isr, &s1_LRFD_IRQ1_cb, 0);
142+
break;
110143
default:
111144
return (NULL);
112145
}
@@ -182,3 +215,61 @@ void HwiP_destruct(HwiP_Struct *hwiP)
182215
obj->cb->arg = (uintptr_t)NULL;
183216
obj->cb = NULL;
184217
}
218+
219+
void HwiP_setPriority(int interruptNum, uint32_t priority)
220+
{
221+
/*
222+
* On CM0+, dynamically changing priorities is not allowed. In order to
223+
* change priority of an interrupt, after it already has been enabled, the
224+
* following must be done:
225+
* - Disable the interrupt whose priority needs to be updated
226+
* - Set the priority to be at the desired priority level
227+
* - Re-enable the interrupt.
228+
*
229+
* These steps are all handled by IntSetPriority().
230+
*
231+
* HwiP_disable/enable here serves the purpose of deferring the handling of
232+
* user interrupts until the priority of interruptNum has been changed. This
233+
* prevents another interrupt from changing the global state potentially
234+
* altering the outcome of this function.
235+
*/
236+
237+
uintptr_t key = HwiP_disable();
238+
IntSetPriority((uint32_t)interruptNum, (uint8_t)priority);
239+
HwiP_restore(key);
240+
}
241+
242+
/*
243+
* ======== HwiP_inISR ========
244+
*/
245+
bool HwiP_inISR(void)
246+
{
247+
bool stat;
248+
249+
if ((SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) == 0)
250+
{
251+
/* Not currently in an ISR */
252+
stat = false;
253+
}
254+
else
255+
{
256+
stat = true;
257+
}
258+
259+
return (stat);
260+
}
261+
262+
/*
263+
* ======== HwiP_inSwi ========
264+
*/
265+
bool HwiP_inSwi(void)
266+
{
267+
uint32_t intNum = SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk;
268+
if (intNum == HwiP_swiPIntNum)
269+
{
270+
/* Currently in a Swi */
271+
return (true);
272+
}
273+
274+
return (false);
275+
}

0 commit comments

Comments
 (0)