Skip to content

Commit d2d6c5a

Browse files
Added Example : Multicore Scheduler
Signed-off-by: Aravind-Padma-Kumar <a-kumar13@ti.com>
1 parent fd5d1a2 commit d2d6c5a

Some content is hidden

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

43 files changed

+3543
-1
lines changed

examples/makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include ../imports.mak
33
SUBDIRS := \
44
custom_frequency_generator empty empty_c \
55
fft/split_radix_fft_4k_single_core fft/split_radix_fft_post_processing \
6-
LCD_interface logic_scope pru_emif rpmsg_echo_linux spi_loopback
6+
LCD_interface logic_scope pru_emif spi_loopback multicore_scheduler
77

88
# "make" or "make all" builds projects that match $(DEVICE) set in imports.mak
99
all: ARGUMENTS = all
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Multicore Scheduler
2+
This project uses IEP timer along with Task Manager in 6 cores to schedule tasks in 6 cores back to back with no delay in between. The tasks collectively generate a toggling pattern using PWM init state on a PIN (PWM2_A(BP.31)) and the toggling happens back to back with no delay in between. The project demonstrates how sequential tasks on multiple cores can be scheduled back-to-back without any scheduling delays if a time based scheduling strategy is used.
3+
4+
## Overview
5+
Each of the 6 PRUs in ICSSG0 is loaded with a task and mapped to different compare vents as shown below:
6+
7+
<figure>
8+
<img src="pictures/multicore_scheduling_overview.png" alt="Multicore Scheduler Overview" width = "500">
9+
<figcaption>Fig.1 : Multicore Scheduler Overview </figcaption>
10+
</figure>
11+
12+
IEP timer Cmp0 event is used for cyclic task scheduling. The compare events are all triggered such they are at adjacent cycles from each other. The tasks either set output PIN to high or low such that toggling pattern is achieved. Since RTU and TXPRU cores do not have access to GPOs via R30, we could either use EDIO or toggling of PWM init state. THe current project uses PWM init state on AM243x. A timing diagram that shows how the sequential task execution achieves the desired toggling pattern for 333Mhz (3ns TIme period)is shown below:
13+
![multicore_scheduling_timing_diagram](pictures/multicore_scheduling_timing_diagram.png)
14+
15+
## Configuration
16+
An overview into how the mapping is performed is discussed here. There are six projects, one for each core and PRU0 does all the event configuration and mapping in the file "pwm_toggle.asm" of project "PRU_Multicore_Scheduling_PRU0". It contains code or macros that can be used to change the configurations or mapping if needed:
17+
18+
1. Compare event timings for 250 Mhz or 4ns time period:
19+
20+
```
21+
; increment value for configured clock
22+
MS_TIMER_INC .set 4 ; 250 Mhz, 4ns
23+
24+
; set CMP0 time to desired time period in ns
25+
; (COUNT - increment value) is set as count starts from 0
26+
MS_CMP0_TIME .set (100-MS_TIMER_INC) ; cycle time
27+
MS_CMP1_TIME .set 2000 ; CMP1 time
28+
MS_CMP2_TIME .set (2*MS_TIMER_INC) ; CMP2 time
29+
MS_CMP3_TIME .set (3*MS_TIMER_INC) ; CMP3 time
30+
MS_CMP4_TIME .set (4*MS_TIMER_INC) ; CMP4 time
31+
MS_CMP5_TIME .set (5*MS_TIMER_INC) ; CMP5 time
32+
MS_CMP6_TIME .set (6*MS_TIMER_INC) ; CMP6 time
33+
MS_CMP7_TIME .set (1*MS_TIMER_INC) ; CMP7 time
34+
35+
```
36+
2. Task triggers are mapped to compare events as shown below:
37+
38+
```
39+
TRG_EVENT_PRU0 .set IEP0_CMP_7
40+
TRG_EVENT_PRU1 .set IEP0_CMP_2
41+
TRG_EVENT_RTU1 .set IEP0_CMP_3
42+
TRG_EVENT_RTU0 .set IEP0_CMP_4
43+
TRG_EVENT_TXPRU1 .set IEP0_CMP_5
44+
TRG_EVENT_TXPRU0 .set IEP0_CMP_6
45+
```
46+
47+
Event numbers of compare events are fixed for AM243 and are defined above this mapping as follows :
48+
```
49+
;relevant event mappings
50+
IEP0_CMP_0 .set (16+0)
51+
IEP0_CMP_1 .set (16+1)
52+
IEP0_CMP_2 .set (16+2)
53+
IEP0_CMP_3 .set (16+3)
54+
IEP0_CMP_4 .set (16+4)
55+
IEP0_CMP_5 .set (16+5)
56+
IEP0_CMP_6 .set (16+6)
57+
IEP0_CMP_7 .set (16+7)
58+
```
59+
60+
61+
Various tasks have to be mapped to the respective task manager in each core. The tasks in all cores are mapped to TS2_0 slot of the task manager as part of the code in the project that corresponds to that core. For example, 'FN_PWM_INIT_TOGGLE_PRU1_TASK' is the task to be called in PRU1 when the mapped event is triggered, and is mapped to TS2_0 as shown below in "main.c" of the project "PRU_Multicore_Scheduling_PRU1" as shown below:
62+
63+
```
64+
HW_WR_REG32((TM_REG_BASE_RTU1+TASKS_MGR_TS2_PC_S0), (unsigned int) FN_PWM_INIT_TOGGLE_RTU1_TASK);
65+
```
66+
67+
## How to Run
68+
69+
The multicore scheduler is run on ICSSG0 and the output can be traced from PIN BP.31 (PWM2_A). To view the results, a scope has to be connected to PIN BP.31 according to default configuration. Following are the steps for running on CCS:
70+
71+
1. Import six projects that correspond to six ICSSG0 PRU cores from "examples/multicore_scheduler/am243x-lp"
72+
73+
2. Power up AM243x Launchpad and connect to target
74+
75+
3. Load six cores with corresponding projects as follows:
76+
1. Project "multicore_scheduler_am243x-lp_icss_g0_pru0_fw_ti-pru-cgt" to core ICSSG0 PRU0
77+
2. Project "multicore_scheduler_am243x-lp_icss_g0_pru1_fw_ti-pru-cgt" to core ICSSG0 PRU1
78+
3. Project "multicore_scheduler_am243x-lp_icss_g0_rtu_pru0_fw_ti-pru-cgt" to core ICSSG0 RTU_PRU0
79+
4. Project "multicore_scheduler_am243x-lp_icss_g0_rtu_pru1_fw_ti-pru-cgt" to core ICSSG0 RTU_PRU1
80+
5. Project "multicore_scheduler_am243x-lp_icss_g0_tx_pru0_fw_ti-pru-cgt" to core ICSSG0 TX_PRU0
81+
6. Project "multicore_scheduler_am243x-lp_icss_g0_tx_pru1_fw_ti-pru-cgt" to core ICSSG0 TX_PRU1
82+
4. Run all the six cores in any order
83+
5. Connect a logic scope to pin BP.31 to observe the toggling pattern generated. An example for the pattern generated for 333Mhz clock is shown below :
84+
![PWM_init_toggle](pictures/multicore_scheduling_toggling.png)
85+
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/* ============================================================================
2+
* Copyright (C) 2002-2023 Texas Instruments Incorporated
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the
14+
* distribution.
15+
*
16+
* Neither the name of Texas Instruments Incorporated nor the names of
17+
* its contributors may be used to endorse or promote products derived
18+
* from this software without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*
32+
*/
33+
34+
/*
35+
file: AM243_AM64_PRU_pinmux.inc
36+
37+
brief: Device specific pinmux defines for direct PRU configuration
38+
SDK driver on PRU would consume too much memory
39+
This is a trade off between readablility and code size.
40+
41+
author: Thomas Leyrer
42+
43+
(C) Copyright 2024, Texas Instruments, Inc
44+
*/
45+
46+
#ifndef AM243_AM64_PRU_pinmux_h
47+
#define AM243_AM64_PRU_pinmux_h
48+
49+
// LOCK UNLOCK defines
50+
#define PAD_PARTITION0_L0 (0x000f1008)
51+
#define PAD_PARTITION0_L1 (0x000f100C)
52+
#define PAD_PARTITION1_L0 (0x000f5008)
53+
#define PAD_PARTITION1_L1 (0x000f500C)
54+
55+
#define PAD_KEY0 (0x68EF3490)
56+
#define PAD_KEY1 (0xD172BC5A)
57+
58+
// Input/Output defines
59+
#define PRU_GPI (0x00040001)
60+
#define PRU_GPO (0x00010000)
61+
#define IEP_SYNC_OUT (0x00010002)
62+
#define IEP_LATCH_IN (0x00040002)
63+
64+
// ICSS_G0 PRU0
65+
#define PRG0_PRU0_GPO0 (0x000F4160)
66+
#define PRG0_PRU0_GPO1 (0x000F4164)
67+
#define PRG0_PRU0_GPO2 (0x000F4168)
68+
#define PRG0_PRU0_GPO3 (0x000F416C)
69+
#define PRG0_PRU0_GPO4 (0x000F4170)
70+
#define PRG0_PRU0_GPO5 (0x000F4174)
71+
#define PRG0_PRU0_GPO6 (0x000F4178)
72+
#define PRG0_PRU0_GPO7 (0x000F417C)
73+
#define PRG0_PRU0_GPO8 (0x000F4180)
74+
#define PRG0_PRU0_GPO9 (0x000F4184)
75+
#define PRG0_PRU0_GPO10 (0x000F4188)
76+
#define PRG0_PRU0_GPO11 (0x000F418C)
77+
#define PRG0_PRU0_GPO12 (0x000F4190)
78+
#define PRG0_PRU0_GPO13 (0x000F4194)
79+
#define PRG0_PRU0_GPO14 (0x000F4198)
80+
#define PRG0_PRU0_GPO15 (0x000F419C)
81+
#define PRG0_PRU0_GPO16 (0x000F41A0)
82+
#define PRG0_PRU0_GPO17 (0x000F41A4)
83+
#define PRG0_PRU0_GPO18 (0x000F41A8)
84+
#define PRG0_PRU0_GPO19 (0x000F41AC)
85+
86+
// ICSS_G0 PRU1
87+
#define PRG0_PRU1_GPO0 (0x000F41B0)
88+
#define PRG0_PRU1_GPO1 (0x000F41B4)
89+
#define PRG0_PRU1_GPO2 (0x000F41B8)
90+
#define PRG0_PRU1_GPO3 (0x000F41BC)
91+
#define PRG0_PRU1_GPO4 (0x000F41C0)
92+
#define PRG0_PRU1_GPO5 (0x000F41C4)
93+
#define PRG0_PRU1_GPO6 (0x000F41C8)
94+
#define PRG0_PRU1_GPO7 (0x000F41CC)
95+
#define PRG0_PRU1_GPO8 (0x000F41D0)
96+
#define PRG0_PRU1_GPO9 (0x000F41D4)
97+
#define PRG0_PRU1_GPO10 (0x000F41D8)
98+
#define PRG0_PRU1_GPO11 (0x000F41DC)
99+
#define PRG0_PRU1_GPO12 (0x000F41E0)
100+
#define PRG0_PRU1_GPO13 (0x000F41E4)
101+
#define PRG0_PRU1_GPO14 (0x000F41E8)
102+
#define PRG0_PRU1_GPO15 (0x000F41EC)
103+
#define PRG0_PRU1_GPO16 (0x000F41F0)
104+
#define PRG0_PRU1_GPO17 (0x000F41F4)
105+
#define PRG0_PRU1_GPO18 (0x000F41F8)
106+
#define PRG0_PRU1_GPO19 (0x000F41FC)
107+
108+
// ICSS_G1 PRU0
109+
#define PRG1_PRU0_GPO0 (0x000F40B8)
110+
#define PRG1_PRU0_GPO1 (0x000F40BC)
111+
#define PRG1_PRU0_GPO2 (0x000F40C0)
112+
#define PRG1_PRU0_GPO3 (0x000F40C4)
113+
#define PRG1_PRU0_GPO4 (0x000F40C8)
114+
#define PRG1_PRU0_GPO5 (0x000F40CC)
115+
#define PRG1_PRU0_GPO6 (0x000F40D0)
116+
#define PRG1_PRU0_GPO7 (0x000F40D4)
117+
#define PRG1_PRU0_GPO8 (0x000F40D8)
118+
#define PRG1_PRU0_GPO9 (0x000F40DC)
119+
#define PRG1_PRU0_GP010 (0x000F40E0)
120+
#define PRG1_PRU0_GPO11 (0x000F40E4)
121+
#define PRG1_PRU0_GPO12 (0x000F40E8)
122+
#define PRG1_PRU0_GPO13 (0x000F40EC)
123+
#define PRG1_PRU0_GPO14 (0x000F40F0)
124+
#define PRG1_PRU0_GPO15 (0x000F40F4)
125+
#define PRG1_PRU0_GPO16 (0x000F40F8)
126+
#define PRG1_PRU0_GPO17 (0x000F40FC)
127+
#define PRG1_PRU0_GPO18 (0x000F4100)
128+
#define PRG1_PRU0_GPO19 (0x000F4104)
129+
130+
// ICSS_G1 PRU1
131+
#define PRG1_PRU1_GPO0 (0x000F4108)
132+
#define PRG1_PRU1_GPO1 (0x000F410C)
133+
#define PRG1_PRU1_GPO2 (0x000F4110)
134+
#define PRG1_PRU1_GPO3 (0x000F4114)
135+
#define PRG1_PRU1_GPO4 (0x000F4118)
136+
#define PRG1_PRU1_GPO5 (0x000F411C)
137+
#define PRG1_PRU1_GPO6 (0x000F4120)
138+
#define PRG1_PRU1_GPO7 (0x000F4124)
139+
#define PRG1_PRU1_GPO8 (0x000F4128)
140+
#define PRG1_PRU1_GPO9 (0x000F412C)
141+
#define PRG1_PRU1_GPO10 (0x000F4130)
142+
#define PRG1_PRU1_GPO11 (0x000F4134)
143+
#define PRG1_PRU1_GPO12 (0x000F4138)
144+
#define PRG1_PRU1_GPO13 (0x000F413C)
145+
#define PRG1_PRU1_GPO14 (0x000F4140)
146+
#define PRG1_PRU1_GPO15 (0x000F4144)
147+
#define PRG1_PRU1_GPO16 (0x000F4148)
148+
#define PRG1_PRU1_GPO17 (0x000F414C)
149+
#define PRG1_PRU1_GPO18 (0x000F4150)
150+
#define PRG1_PRU1_GPO19 (0x000F4154)
151+
152+
#endif
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectSpec>
3+
<applicability>
4+
<when>
5+
<context
6+
deviceFamily="PRU"
7+
deviceId="AM243x_LAUNCHPAD"
8+
/>
9+
</when>
10+
</applicability>
11+
12+
<project
13+
title="Multicore Scheduler"
14+
name = "multicore_scheduler_am243x-lp_icss_g0_pru0_fw_ti-pru-cgt"
15+
products="com.ti.OPEN_PRU;com.ti.MCU_PLUS_SDK_AM243X"
16+
configurations="
17+
Debug,
18+
Release,
19+
"
20+
connection="TIXDS110_Connection.xml"
21+
toolChain="TI"
22+
cgtVersion="2.3.3"
23+
device="AM243x_LAUNCHPAD"
24+
deviceCore="ICSS_G0_PRU_0"
25+
ignoreDefaultDeviceSettings="true"
26+
ignoreDefaultCCSSettings="true"
27+
endianness="little"
28+
outputFormat="ELF"
29+
outputType="executable"
30+
31+
compilerBuildOptions="
32+
-I${CG_TOOL_ROOT}/include
33+
-I${MCU_PLUS_SDK_PATH}/source
34+
-I${OPEN_PRU_PATH}/source
35+
-I${MCU_PLUS_SDK_PATH}/source/pru_io/firmware/common
36+
-DPRU0
37+
-DSLICE0
38+
-v4
39+
-DSOC_AM243X
40+
"
41+
linkerBuildOptions="
42+
-m=multicore_scheduler.${ConfigName}.map
43+
--disable_auto_rts
44+
--diag_suppress=10063-D
45+
-i${CG_TOOL_ROOT}/lib
46+
-i${CG_TOOL_ROOT}/include
47+
-llibc.a
48+
"
49+
50+
postBuildStep="
51+
$(CG_TOOL_ROOT)/bin/hexpru --diag_wrap=off --array --array:name_prefix=PRU0Firmware -o pru0_load_bin.h multicore_scheduler_am243x-lp_icss_g0_pru0_fw_ti-pru-cgt.out;if ${CCS_HOST_OS} == linux cat ${MCU_PLUS_SDK_PATH}/source/pru_io/firmware/pru_load_bin_copyright.h pru0_load_bin.h > ${OPEN_PRU_PATH}/examples/multicore_scheduler/firmware/am243x-lp/pru0_load_bin.h ;if ${CCS_HOST_OS} == linux rm pru0_load_bin.h;if ${CCS_HOST_OS} == win32 $(CCS_INSTALL_DIR)/utils/cygwin/cat ${MCU_PLUS_SDK_PATH}/source/pru_io/firmware/pru_load_bin_copyright.h pru0_load_bin.h > ${OPEN_PRU_PATH}/examples/multicore_scheduler/firmware/am243x-lp/pru0_load_bin.h ;if ${CCS_HOST_OS} == win32 $(CCS_INSTALL_DIR)/utils/cygwin/rm pru0_load_bin.h;
52+
"
53+
54+
description="A Multicore Scheduler FW project">
55+
56+
<configuration name="Debug"
57+
compilerBuildOptions="
58+
-D_DEBUG_=1
59+
"
60+
linkerBuildOptions="
61+
"
62+
></configuration>
63+
<configuration name="Release"
64+
compilerBuildOptions="
65+
-O3
66+
"
67+
linkerBuildOptions="
68+
"
69+
></configuration>
70+
<pathVariable name="MCU_PLUS_SDK_PATH" path="${COM_TI_MCU_PLUS_SDK_AM243X_INSTALL_DIR}" scope="project" />
71+
<pathVariable name="OPEN_PRU_PATH" path="${COM_TI_OPEN_PRU_INSTALL_DIR}" scope="project" />
72+
<file path="./linker.cmd" openOnCreation="false" excludeFromBuild="false" action="copy">
73+
</file>
74+
<file path="./main.c" openOnCreation="false" excludeFromBuild="false" action="copy">
75+
</file>
76+
<file path="./pwm_toggle.asm" openOnCreation="false" excludeFromBuild="false" action="copy">
77+
</file>
78+
<file path="./am243_am64_pru_pinmux.h" openOnCreation="false" excludeFromBuild="false" action="copy">
79+
</file>
80+
</project>
81+
</projectSpec>

0 commit comments

Comments
 (0)