Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0c1ce3e07 | ||
|
|
559860f969 | ||
|
|
0a6f487746 | ||
|
|
53b79389bf | ||
|
|
66f32e30c0 | ||
|
|
e23b2f4109 | ||
|
|
47f75e5b40 | ||
|
|
e242231814 | ||
|
|
4da90cfabe | ||
|
|
67c0c2c90e | ||
|
|
f18a2e4fb5 | ||
|
|
cae559a7be | ||
|
|
039fafd2c4 | ||
|
|
1ee6bcc841 | ||
|
|
4c4338c309 | ||
|
|
1353e12dd7 | ||
|
|
0424d69bcd |
4
Debug/ps7/Aufgabe7/draw.bak
Normal file
4
Debug/ps7/Aufgabe7/draw.bak
Normal file
@@ -0,0 +1,4 @@
|
||||
var.draw acceleBuffer
|
||||
var.draw gyroBuffer
|
||||
var.draw angleBuffer
|
||||
var.draw pidArray
|
||||
4
Debug/ps7/Aufgabe7/draw.cmm
Normal file
4
Debug/ps7/Aufgabe7/draw.cmm
Normal file
@@ -0,0 +1,4 @@
|
||||
var.draw accelBuffer
|
||||
var.draw gyroBuffer
|
||||
var.draw angleBuffer
|
||||
var.draw pidArray
|
||||
50
Debug/ps7/Aufgabe7/windowSetting.bak
Normal file
50
Debug/ps7/Aufgabe7/windowSetting.bak
Normal file
@@ -0,0 +1,50 @@
|
||||
// T32_PORT38791 Tue Nov 18 20:10:58 2025
|
||||
|
||||
B::
|
||||
|
||||
TOOLBAR ON
|
||||
STATUSBAR ON
|
||||
FramePOS 273.86,-1.875,,,Maximized
|
||||
WinPAGE.RESet
|
||||
|
||||
WinPAGE.Create P000
|
||||
WinCLEAR
|
||||
|
||||
WinPOS 136.43 0.0 77. 12. 26. 1. W001
|
||||
WinTABS 13. 0. 0. 0. 0. 0. 0. 0. 0. 23.
|
||||
wl.Break.List
|
||||
|
||||
WinPOS 136.43 18.25 77. 38. 0. 0. W002
|
||||
wl.Var.Watch %Hex %Decimal
|
||||
|
||||
VAR.ADDWATCH OSPrioCur
|
||||
|
||||
WinPOS 218.29 0.0 50. 26. 0. 0. W003
|
||||
wl.Register /SPOTLIGHT
|
||||
|
||||
WinPOS 0.0 48.75 132. 8. 41. 1. W004
|
||||
WinTABS 41. 31.
|
||||
wl.Symbol.browse \\*\*\*
|
||||
|
||||
WinPOS 218.29 30.5 50. 26. 5. 0. W006
|
||||
wl.Frame /Locals
|
||||
|
||||
WinPOS 1.4286 0.0 132. 42. 16. 1. W000
|
||||
WinTABS 10. 10. 25.
|
||||
wl.List.auto
|
||||
|
||||
WinPOS 149.43 13.563 116. 17. 16. 2. W005
|
||||
wl.var.draw accelBuffer
|
||||
|
||||
WinPOS 148.86 36.0 116. 17. 16. 2. W007
|
||||
wl.var.draw gyroBuffer
|
||||
|
||||
WinPOS 30.0 13.125 116. 17. 16. 2. W008
|
||||
wl.var.draw angleBuffer
|
||||
|
||||
WinPOS 29.429 35.938 116. 17. 16. 2. W010
|
||||
wl.var.draw pidArray
|
||||
|
||||
WinPAGE.select P000
|
||||
|
||||
ENDDO
|
||||
8
Makefile
8
Makefile
@@ -43,7 +43,7 @@ endif
|
||||
|
||||
#Include source-files:
|
||||
SRC =
|
||||
-include $(TARGET_DIR)/build/Sources.mk
|
||||
-include $(TARGET_DIR)/build/sources.mk
|
||||
|
||||
INC = -I./
|
||||
-include $(TARGET_DIR)/build/includes.mk
|
||||
@@ -51,7 +51,7 @@ INC = -I./
|
||||
# C source files
|
||||
CFILES = $(filter %.c, $(SRC))
|
||||
# Assembly source files
|
||||
ASMFILES = $(filter %.s, $(SRC))
|
||||
ASMFILES = $(filter %.S, $(SRC))
|
||||
# Object files
|
||||
COBJ = $(CFILES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
|
||||
SOBJ = $(ASMFILES:$(SRC_DIR)/%.S=$(OBJ_DIR)/%.o)
|
||||
@@ -60,7 +60,7 @@ OBJ = $(SOBJ) $(COBJ)
|
||||
$(info CFILES : ${CFILES})
|
||||
|
||||
# Flags
|
||||
CFLAGS = $(MCFLAGS) $(DEBUG) $(OPTIMIZE) -MP -MMD -std=gnu11
|
||||
CFLAGS = $(MCFLAGS) $(DEBUG) $(OPTIMIZE) -MP -MMD -std=gnu11 -DGT_CPU_CYCLE_SCALE=1.33
|
||||
ASFLAGS = $(MCFLAGS) $(DEBUG) $(OPTIMIZE) -MP -MMD -x assembler-with-cpp
|
||||
ODFLAGS = --source --all-headers --demangle --line-numbers --wide
|
||||
|
||||
@@ -72,7 +72,7 @@ $(LISTFILE): $(EXECUTABLE)
|
||||
|
||||
$(EXECUTABLE): $(OBJ)
|
||||
@echo 'Linking: $@'
|
||||
$(CD) $(CFLAGS) $(LDSCRIPT) -Wl,-Map,"$(MAPFILE)" -o "$@" $(sort $(OBJ)) $(LDFLAGS)
|
||||
$(CC) $(CFLAGS) $(LDSCRIPT) -Wl,-Map,"$(MAPFILE)" -o "$@" $(sort $(OBJ)) $(LDFLAGS)
|
||||
|
||||
$(COBJ): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
@echo 'Building file: $<'
|
||||
|
||||
42
antworten
Normal file
42
antworten
Normal file
@@ -0,0 +1,42 @@
|
||||
aufgabe 5
|
||||
|
||||
|
||||
CPU_Init()
|
||||
|
||||
initialisiert die CPU, zb Stack growth direction
|
||||
|
||||
Mem_init() richtet memory partitionen ein für kernel speicher. muss aufgerufen werden laut code commentar
|
||||
|
||||
OS_Init erstellt 2 Taks, einen IDLE und einen Monitoring Task
|
||||
|
||||
|
||||
|
||||
|
||||
OS_InitMisc() is called to initialize miscellaneous variables. It performs various initialization tasks related to miscellaneous features and options within the uC/OS-II kernel. The actions that are performed are:
|
||||
a) Clear the 32-bit OS System clock.
|
||||
b) Clear the interrupt nesting counter.
|
||||
c) Clear the scheduling lock counter.
|
||||
d) Clear the number of tasks.
|
||||
e) Indicate the OS that the multitasking has not started.
|
||||
f) Clear the context switch counter.
|
||||
g) Let know the kernel that Statistic task is not ready.
|
||||
h) Initialize the OSSafetyCriticalStartFlag(Related to windows) to FALSE indicating safety functionality is not yet enabled or active.
|
||||
i) Initialize the task register ID.
|
||||
|
||||
OS_InitRdyList() is called to initialize the ready list. The ready list is the task of priorities maintained by the kernel. It keeps tracks of which tasks are ready to run based on the priority levels. It is called to ensure that the ready list is in clean state before the scheduler starts scheduling. All the values in the ready table is set to 0 by this function. The Ready table size is defined by the macro OS_RDY_TBL_SIZE in uC/OS-II . It is defined as:
|
||||
#define OS_RDY_TBL_SIZE ((OS_LOWEST/PRIO) / 8u +1u). The OS_LOWEST is 63 that can be found in os_cfg_r.h of uC/OS-II source code.
|
||||
|
||||
OS_InitTCBList() is called to initialize the free list of OS_TCBs. The initialization process typically involves setting up the necessary data structures and variables to manage the free list. This includes linking the TCBs together in the list and configuring any associated fields or flags within the TCBs.
|
||||
|
||||
|
||||
|
||||
OSStart() is then called to start multitasking and give control to µC/OS-II. It is very important that you create at least one task before calling OSStart(). Failure to do this will certainly make your application crash. In fact, you may always want to create only one task if you are planning on using the CPU usage statistic task.
|
||||
|
||||
|
||||
|
||||
OSTaskCreateExt() komplizierte Fkt um Tasks zu erstellen mit 9 Argumenten, wie Prio und Interrupt foo
|
||||
|
||||
|
||||
OSTaskStackInit() nur OSTaskStckInit() gefunden, which is responsible for setting up the task stack.
|
||||
|
||||
OS_TCBInit entnimmt einen OS_TCB aus dem Pool, initialisiert die relevanten Felder abhängig von den aktivierten Features (z. B. erweiterte Task-Felder, Event-Pointer, Delete-Flag) und ruft dabei – mit wieder aktivierten Interrupts – die Hook-Funktionen OSTCBInitHook und OSTaskCreateHook auf. Anschließend werden die Interrupts kurz deaktiviert, der TCB an den Anfang der verketteten Task-Liste eingefügt und der Task als “ready” markiert. Zuletzt gibt die Funktion einen Statuscode zurück, der den erfolgreichen Abschluss der Initialisierung signalisiert.
|
||||
12
aufg6_tabelle_soll_ist.txt
Normal file
12
aufg6_tabelle_soll_ist.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
i delay soll zeit
|
||||
0 1 0.1ms 0.067ms
|
||||
1 2 0.2ms 0.142ms
|
||||
2 4 0.4ms 0.292ms
|
||||
3 8 0.8ms 0.592ms
|
||||
4 16 1.6ms 1.193ms
|
||||
5 32 3.2ms 2.394ms
|
||||
6 64 6.4ms 4.797ms
|
||||
7 128 12.8ms 9.601ms
|
||||
8 256 25.6ms 19.211ms
|
||||
9 512 51.2ms 38.430ms
|
||||
|
||||
2601
feedgnuplot
Executable file
2601
feedgnuplot
Executable file
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,7 @@ INC += -I"$(SRC_DIR)/ucos_v1_42/ucos/drivers/ucos_emacps/src"
|
||||
INC += -I"$(SRC_DIR)/ucos_v1_42/ucos/drivers/ucos_scuc/src"
|
||||
INC += -I"$(SRC_DIR)/ucos_v1_42/ucos/drivers/ucos_ttcps/src"
|
||||
|
||||
INC += -I"$(SRC_DIR)/ucos_v1_42/ucos/components/ucos_standalone/src/cortexa9"
|
||||
INC += -I"$(SRC_DIR)/ucos_v1_42/ucos/components/ucos_standalone/src/cortexa9/gcc"
|
||||
INC += -I"$(SRC_DIR)/ucos_v1_42/ucos/components/ucos_standalone/src/common"
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ SRC += $(SRC_DIR)/ucos_v1_42/ucos/bsp/src/$(ARCH)/asm_vectors.S
|
||||
|
||||
-include $(SRC_DIR)/ucos_v1_42/micrium_source/uC-LIB/subdir.mk
|
||||
|
||||
SRC += $(SRC_DIR)/ucos_v1_42/ucos/components/ucos_osii/bsp/$(ARCH)/ucos_osii_bsp.c
|
||||
SRC += $(SRC_DIR)/ucos_v1_42/ucos/components/ucos_osii/src/bsp/$(ARCH)/ucos_osii_bsp.c
|
||||
SRC += $(SRC_DIR)/ucos_v1_42/ucos/components/ucos_common/src/$(ARCH)/cpu_bsp.c
|
||||
|
||||
SRC += $(SRC_DIR)/Modules/MMU/mmu.c
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#Startup file
|
||||
SRC += $(SRC_DIR)/ucos_v1_42/ucos/bsp/src/$(ARCH)/asm_vectors.S
|
||||
-include $(SRC_DIR)/ucos_v1_42/ucos/bsp/src/$(ARCH)/subdir.mk
|
||||
-include $(SRC_DIR)/ucos_v1_42/ucos/bsp/src/subdir.mk
|
||||
include $(SRC_DIR)/ucos_v1_42/ucos/bsp/src/$(ARCH)/subdir.mk
|
||||
include $(SRC_DIR)/ucos_v1_42/ucos/bsp/src/subdir.mk
|
||||
|
||||
-include $(SRC_DIR)/ucos_v1_42/micrium_source/uC-LIB/subdir.mk
|
||||
include $(SRC_DIR)/ucos_v1_42/micrium_source/uC-LIB/subdir.mk
|
||||
|
||||
SRC += $(SRC_DIR)/ucos_v1_42/ucos/components/ucos_osii/src/bsp/$(ARCH)/ucos_osii_bsp.c
|
||||
SRC += $(SRC_DIR)/ucos_v1_42/ucos/components/ucos_common/src/$(ARCH)/cpu_bsp.c
|
||||
@@ -29,10 +29,10 @@ SRC += $(SRC_DIR)/ucos_v1_42/ucos/drivers/ucos_scuc/src/ucos_scuc.c
|
||||
SRC += $(SRC_DIR)/ucos_v1_42/ucos/drivers/ucos_l2cachec/src/ucos_l2cachec.c
|
||||
SRC += $(SRC_DIR)/ucos_v1_42/ucos/drivers/ucos_emacps/src/ucos_emacps.c
|
||||
|
||||
-include $(SRC_DIR)/ucos_v1_42/ucos/components/ucos_standalone/src/cortexa9/subdir.mk
|
||||
include $(SRC_DIR)/ucos_v1_42/ucos/components/ucos_standalone/src/cortexa9/subdir.mk
|
||||
|
||||
SRC += $(SRC_DIR)/ucos_v1_42/micrium_source/uC-Common/KAL/uCOS-II/kal.c
|
||||
SRC += $(SRC_DIR)/ucos_v1_42/micrium_source/uC-Common/Collections/slist.c
|
||||
SRC += $(SRC_DIR)/ucos_v1_42/micrium_source/uC-Common/Auth/auth.c
|
||||
|
||||
-include $(SRC_DIR)/ucos_v1_42/micrium_source/uCOS-II/Source/subdir.mk
|
||||
include $(SRC_DIR)/ucos_v1_42/micrium_source/uCOS-II/Source/subdir.mk
|
||||
|
||||
@@ -16,68 +16,156 @@
|
||||
#include "xil_testmem.h"
|
||||
#include "xil_printf.h"
|
||||
|
||||
#define HELLO_WORLD_TASK_PRIO 64
|
||||
#define CALC_TASK_PRIO 64
|
||||
#define HELLO_WORLD_TASK_PRIO 30
|
||||
#define CALC_TASK_PRIO 31
|
||||
#define TASK1_PRIO 32
|
||||
#define TASK2_PRIO 33
|
||||
|
||||
#define HELLO_WORLD_TASK_STK_SIZE 16
|
||||
#define CALC_TASK_STK_SIZE 32
|
||||
#define HELLO_WORLD_TASK_STK_SIZE 16000
|
||||
#define CALC_TASK_STK_SIZE 32000
|
||||
#define TASK1_STK_SIZE 32000
|
||||
#define TASK2_STK_SIZE 32000
|
||||
|
||||
static OS_STK HelloWorldTaskStk[HELLO_WORLD_TASK_STK_SIZE];
|
||||
static OS_STK CalcTaskStk[HELLO_WORLD_TASK_STK_SIZE];
|
||||
static OS_STK Task1Stk[TASK1_STK_SIZE];
|
||||
static OS_STK Task2Stk[TASK2_STK_SIZE];
|
||||
|
||||
// Define the message queue buffer
|
||||
#define QUEUE_SIZE 5
|
||||
void *MsgQueueTbl[QUEUE_SIZE];
|
||||
|
||||
int f(int n)
|
||||
// Declare the queue's Event Control Block
|
||||
OS_EVENT *MsgQueue;
|
||||
|
||||
// Define a simple message structure
|
||||
typedef struct {
|
||||
INT32U MessageID;
|
||||
INT32U Data;
|
||||
} MyMessage;
|
||||
|
||||
// Declare message pointers
|
||||
MyMessage MyMessages[QUEUE_SIZE];
|
||||
|
||||
int f(uint8_t n)
|
||||
{
|
||||
if (n == 1)
|
||||
if (n <= 1)
|
||||
return n;
|
||||
else
|
||||
return (f(n-1) + f(n-3));
|
||||
return (f(n-1) + f(n-2));
|
||||
}
|
||||
|
||||
void HelloWorldTask (void *pdata)
|
||||
{
|
||||
while(1){
|
||||
UCOS_Printf("Hello World!");
|
||||
UCOS_Printf("Hello World!\n");
|
||||
OSTimeDly(OS_TICKS_PER_SEC*50);
|
||||
}
|
||||
}
|
||||
|
||||
void CalcTask (void *pdata)
|
||||
{
|
||||
uint8_t n=50;
|
||||
for (uint8_t i = 1; i <= n; i)
|
||||
{
|
||||
UCOS_Printf("%u", f(i));
|
||||
}
|
||||
while(1){
|
||||
uint8_t n=50;
|
||||
for (uint8_t i = 1; i <= n; i++)
|
||||
{
|
||||
UCOS_Printf("%d", f(i));
|
||||
OSTimeDly(OS_TICKS_PER_SEC*1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Task1(void *pdata){
|
||||
INT8U err;
|
||||
MyMessage *received_msg;
|
||||
|
||||
while (1) {
|
||||
// // Wait for a message from the queue. Wait indefinitely (0).
|
||||
received_msg = OSQPend(MsgQueue, 0, &err);
|
||||
|
||||
if (err == 0) {
|
||||
UCOS_Print("test");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Task2(void *pdata){
|
||||
INT8U i = 0;
|
||||
INT8U err;
|
||||
MyMessage *msg;
|
||||
|
||||
while (1) {
|
||||
// Prepare a new message
|
||||
msg = &MyMessages[i % QUEUE_SIZE]; // Reuse message memory
|
||||
msg->MessageID = i;
|
||||
msg->Data = i * 10;
|
||||
|
||||
// Post the message to the queue
|
||||
OSQPost(MsgQueue, msg);
|
||||
|
||||
// Pause the task for a period
|
||||
OSTimeDlyHMSM(0, 0, 1, 0);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void InitDoneCallback(void * p_arg){
|
||||
(void) p_arg;
|
||||
UCOS_Print("OS started!\r\n");
|
||||
|
||||
|
||||
OSTaskCreateExt(HelloWorldTask,
|
||||
0,
|
||||
&HelloWorldTaskStk[0],
|
||||
HELLO_WORLD_TASK_PRIO,
|
||||
&HelloWorldTaskStk[0],
|
||||
0,
|
||||
0);
|
||||
0,
|
||||
&HelloWorldTaskStk[HELLO_WORLD_TASK_STK_SIZE-1],
|
||||
HELLO_WORLD_TASK_PRIO,
|
||||
HELLO_WORLD_TASK_PRIO,
|
||||
&HelloWorldTaskStk[0],
|
||||
HELLO_WORLD_TASK_STK_SIZE,
|
||||
0,
|
||||
0);
|
||||
|
||||
OSTaskCreateExt(CalcTask,
|
||||
0,
|
||||
CALC_TASK_PRIO,
|
||||
CALC_TASK_PRIO,
|
||||
&CalcTaskStk[0],
|
||||
CALC_TASK_STK_SIZE,
|
||||
0
|
||||
);
|
||||
0,
|
||||
&CalcTaskStk[CALC_TASK_STK_SIZE-1],
|
||||
CALC_TASK_PRIO,
|
||||
CALC_TASK_PRIO,
|
||||
&CalcTaskStk[0],
|
||||
CALC_TASK_STK_SIZE,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
MsgQueue = OSQCreate((void **)&MsgQueueTbl[0], QUEUE_SIZE);
|
||||
|
||||
OSTaskCreateExt(Task1,
|
||||
0,
|
||||
&Task1Stk[TASK1_STK_SIZE-1],
|
||||
TASK1_PRIO,
|
||||
TASK1_PRIO,
|
||||
&Task1Stk[0],
|
||||
TASK1_STK_SIZE,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
OSTaskCreateExt(Task2,
|
||||
0,
|
||||
&Task2Stk[TASK2_STK_SIZE-1],
|
||||
TASK2_PRIO,
|
||||
TASK2_PRIO,
|
||||
&Task2Stk[0],
|
||||
TASK2_STK_SIZE,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
while(1){
|
||||
OSTimeDly();
|
||||
OSTimeDly(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
MMUInit();
|
||||
UCOSStartup(InitDoneCallback);
|
||||
while (1);;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
int timer_Task(void *pdata);
|
||||
void timer_Task(void *pdata);
|
||||
int timer_Init();
|
||||
|
||||
#endif /* SRC_APP_AUFGABE3_PS7_CORE0_CFG_TTC_TIMER_H_ */
|
||||
|
||||
@@ -17,21 +17,62 @@
|
||||
#include "xil_printf.h"
|
||||
#include "ttc_timer.h"
|
||||
|
||||
#define TIMER_PRIO 32
|
||||
#define TIMER_STK_SIZE 32000
|
||||
static OS_STK TimerStk[TIMER_STK_SIZE];
|
||||
|
||||
int16_t pidValue = 0;
|
||||
|
||||
void InitDoneCallback(void * p_arg) {
|
||||
(void) p_arg;
|
||||
CPU_SR cpu_sr;
|
||||
OS_ENTER_CRITICAL();
|
||||
// This is a critcal section. Usefull for accessing global variables shared between tasks
|
||||
OS_EXIT_CRITICAL();
|
||||
UCOS_Print("OS started!\r\n");
|
||||
|
||||
OSTaskCreateExt(timer_Task,
|
||||
0,
|
||||
&TimerStk[TIMER_STK_SIZE-1],
|
||||
TIMER_PRIO,
|
||||
TIMER_PRIO,
|
||||
&TimerStk[0],
|
||||
TIMER_STK_SIZE,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
uint16_t melody[][2] = {{440, 500}, {440, 500}, {440, 500}, {349, 350}, {523, 150}, {440, 500}, {349, 350}, {523, 150}, {440, 1000}, {659, 500}, {659, 500}, {659, 500}, {698, 350}, {523, 150}, {415, 500}, {349, 350}, {523, 150}, {440, 1000}};
|
||||
|
||||
while(1){
|
||||
for(uint8_t i=0; i<(sizeof(melody)/sizeof(melody[0])); i++){
|
||||
pidValue = melody[i][0];
|
||||
OSTimeDly(melody[i][1]);
|
||||
}
|
||||
//for(int16_t i = -1000; i<=1000; i++){
|
||||
// CPU_SR cpu_sr;
|
||||
// OS_ENTER_CRITICAL();
|
||||
// // This is a critcal section. Usefull for accessing global variables shared between tasks
|
||||
// pidValue = i;
|
||||
// OS_EXIT_CRITICAL();
|
||||
// timer_Task(0);
|
||||
// //UCOS_Printf("pid: %d\r\n", pidValue);
|
||||
// OSTimeDly(1);
|
||||
//}
|
||||
//for(int16_t i = 1000; i>=-1000; i--){
|
||||
// CPU_SR cpu_sr;
|
||||
// OS_ENTER_CRITICAL();
|
||||
// // This is a critcal section. Usefull for accessing global variables shared between tasks
|
||||
// pidValue = i;
|
||||
// timer_Task(0);
|
||||
// OS_EXIT_CRITICAL();
|
||||
// //UCOS_Printf("pid: %d\r\n", pidValue);
|
||||
// OSTimeDly(1);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
MMUInit();
|
||||
UCOSStartup(InitDoneCallback);
|
||||
while (1)
|
||||
;
|
||||
while (1);
|
||||
}
|
||||
|
||||
@@ -14,9 +14,6 @@
|
||||
#include "xgpiops.h"
|
||||
#include "pid.h"
|
||||
|
||||
|
||||
|
||||
|
||||
static void timer_Start(uint32_t Id);
|
||||
static void timer_Stop(uint32_t Id);
|
||||
static void timer_Set_Interval_Length(uint32_t Id, uint16_t intervalLength);
|
||||
@@ -26,52 +23,100 @@ static void motor_Set_Steering_Direction(uint8_t steeringDirection, int16_t *mot
|
||||
static void motor_Set_Moving_Direction (u32 pin, int16_t value);
|
||||
static void timer_gpio_Init();
|
||||
|
||||
int timer_Task(void *pdata) {
|
||||
XTtcPs xttcps[2];
|
||||
|
||||
return 0;
|
||||
XGpioPs xgpiops;
|
||||
XGpioPs_Config* gpioCfg;
|
||||
|
||||
extern int32_t pidValue;
|
||||
|
||||
void timer_Task(void *pdata) {
|
||||
while(1)
|
||||
{
|
||||
if(pidValue){
|
||||
uint16_t interval = 1.337*(64000/abs(pidValue));
|
||||
uint8_t direction = pidValue<0;
|
||||
//UCOS_Printf("%d %d\r\n", direction, interval);
|
||||
//UCOS_Printf("counter value: %d\r\n", XTtcPs_GetCounterValue(&xttcps));
|
||||
timer_Stop(0);
|
||||
timer_Stop(1);
|
||||
timer_Set_Interval_Length(0,interval);
|
||||
timer_Set_Interval_Length(1,interval);
|
||||
timer_Start(0);
|
||||
timer_Start(1);
|
||||
motor_Set_Moving_Direction(54, direction);
|
||||
motor_Set_Moving_Direction(55, !direction);
|
||||
}
|
||||
else
|
||||
{
|
||||
timer_Stop(0);
|
||||
timer_Stop(1);
|
||||
}
|
||||
OSTimeDly(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* * * intializes and starts two timers with respective puls generation on gpio pins * * */
|
||||
int timer_Init(void *pdata){
|
||||
int timer_Init(){
|
||||
UCOS_Print("Setting up Timer!\r\n");
|
||||
|
||||
timer_Dual_Timer_Setup();
|
||||
timer_gpio_Init();
|
||||
|
||||
UCOS_Print("Done!\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* * * checks the desired moving direction and sets the direction pin for the steppers * * */
|
||||
static void motor_Set_Moving_Direction (uint32_t pin, int16_t value) {
|
||||
|
||||
XGpioPs_WritePin(&xgpiops, pin, value);;
|
||||
}
|
||||
|
||||
/* * * init gpio, connects IRQ to gpio * * */
|
||||
static void timer_gpio_Init(){
|
||||
gpioCfg = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID);
|
||||
XGpioPs_CfgInitialize(&xgpiops, gpioCfg, gpioCfg->BaseAddr);
|
||||
|
||||
XGpioPs_SetDirectionPin(&xgpiops, 54, 1);
|
||||
XGpioPs_SetOutputEnablePin(&xgpiops, 54, 1);
|
||||
|
||||
XGpioPs_SetDirectionPin(&xgpiops, 55, 1);
|
||||
XGpioPs_SetOutputEnablePin(&xgpiops, 55, 1);
|
||||
}
|
||||
|
||||
/* * * * * * sets up two timers by calling timer_Setup() for each wheel, connects and activates an interrupt to one of timers * * */
|
||||
static int timer_Dual_Timer_Setup(void)
|
||||
{
|
||||
|
||||
timer_Setup(XPAR_PS7_TTC_0_DEVICE_ID);
|
||||
timer_Setup(XPAR_PS7_TTC_1_DEVICE_ID);
|
||||
}
|
||||
|
||||
/* * * * * * sets up a timer counter device, initialize device, set options, set interval and prescaler value for given output frequency * * */
|
||||
static int timer_Setup(int DeviceID)
|
||||
{
|
||||
|
||||
XTtcPs_Config* TimerSetup = XTtcPs_LookupConfig(DeviceID);
|
||||
XTtcPs_CfgInitialize(&xttcps[DeviceID], TimerSetup, TimerSetup->BaseAddress);
|
||||
XTtcPs_SetOptions(&xttcps[DeviceID], XTTCPS_OPTION_INTERVAL_MODE | XTTCPS_OPTION_MATCH_MODE);
|
||||
XTtcPs_SetPrescaler(&xttcps[DeviceID], 8);
|
||||
XTtcPs_SetMatchValue(&xttcps[DeviceID], 0, 1);
|
||||
XTtcPs_SetInterval(&xttcps[DeviceID], 2);
|
||||
}
|
||||
|
||||
/* * * starts timer number "Id" * * */
|
||||
static void timer_Start(uint32_t Id){
|
||||
|
||||
XTtcPs_Start(&xttcps[Id]);
|
||||
}
|
||||
|
||||
/* * * stops timer number "Id" * * */
|
||||
static void timer_Stop(uint32_t Id){
|
||||
|
||||
XTtcPs_Stop(&xttcps[Id]);
|
||||
}
|
||||
|
||||
|
||||
/* * * sets new interval length and the correct matchvalue * * */
|
||||
static void timer_Set_Interval_Length(uint32_t Id, uint16_t interval_length){
|
||||
|
||||
if(XTtcPs_GetCounterValue(&xttcps[Id]) >= interval_length)
|
||||
XTtcPs_ResetCounterValue(&xttcps[Id]);
|
||||
XTtcPs_SetMatchValue(&xttcps[Id], 0, interval_length/2);
|
||||
XTtcPs_SetInterval(&xttcps[Id], interval_length);
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
void InitDoneCallback(void * p_arg) {
|
||||
(void) p_arg;
|
||||
UCOS_Print("OS started!\r\n");
|
||||
mpu9250_Imu_Init(0);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
MMUInit();
|
||||
UCOSStartup(InitDoneCallback);
|
||||
while (1)
|
||||
|
||||
BIN
src/APP/Aufgabe4/ps7/core0/src/.imu.c.swp
Normal file
BIN
src/APP/Aufgabe4/ps7/core0/src/.imu.c.swp
Normal file
Binary file not shown.
@@ -18,6 +18,7 @@
|
||||
#include "ucos_ii.h"
|
||||
#include "ucos_bsp.h"
|
||||
|
||||
#include <math.h>
|
||||
/**
|
||||
* Global variables
|
||||
*/
|
||||
@@ -26,6 +27,18 @@
|
||||
static int16_t _imu_accMaxData[3]={0,0,0}; //x, y, z
|
||||
static int16_t _imu_accMinData[3]={0,0,0}; //x, y, z
|
||||
|
||||
float imu_current_angle;
|
||||
|
||||
int16_t accelData[3];
|
||||
int16_t gyroData[3];
|
||||
|
||||
int16_t accelBuffer[5000];
|
||||
int16_t gyroBuffer[5000];
|
||||
int16_t angleBuffer[5000];
|
||||
|
||||
static XIicPs Iic;
|
||||
XIicPs_Config *Config;
|
||||
OS_EVENT * iic_sem;
|
||||
|
||||
/**
|
||||
* Function Prototypes
|
||||
@@ -43,15 +56,75 @@ static void mpu9250_Get_Acc_Min_Max();
|
||||
* Read sensor data and calculate angle
|
||||
*/
|
||||
int mpu9250_CalculateAngle(void *pdata){
|
||||
static uint16_t i=0;
|
||||
|
||||
mpu9250_Read_Data(59, 6, (u8*)accelData);
|
||||
mpu9250_Read_Data(67, 6, (u8*)gyroData);
|
||||
|
||||
int16_t accelX = (int16_t)((accelData[0]&0xFF)<<8 | (accelData[0]&0xFF00)>>8);
|
||||
int16_t accelZ = (int16_t)((accelData[2]&0xFF)<<8 | (accelData[2]&0xFF00)>>8);
|
||||
double accelAngle = atan2(accelX,accelZ)*180/PI;
|
||||
double gyroAngleD = (int16_t)((gyroData[1]&0xFF)<<8 | (gyroData[1]&0xFF00)>>8);
|
||||
|
||||
accelBuffer[i] = accelAngle;
|
||||
gyroBuffer[i] = gyroAngleD;
|
||||
|
||||
imu_current_angle = 0.98*(imu_current_angle - (0.012*250*gyroAngleD/INT16_MAX)) + 0.02*accelAngle;
|
||||
//current_angle = current_angle - gyroBuffer[i];
|
||||
//UCOS_Printf("%d %d %d\n", current_angle, accelBuffer[i], gyroBuffer[i]);
|
||||
angleBuffer[i] = imu_current_angle;
|
||||
i=(i+1)%(sizeof(angleBuffer)/sizeof(angleBuffer[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize I2C and MPU
|
||||
*/
|
||||
int mpu9250_Imu_Init(void *pdata){
|
||||
|
||||
mpu9250_Iic_Init();
|
||||
mpu9250_Write_Reg(29, 5); // accel dlpf 10Hz
|
||||
mpu9250_Write_Reg(26, 5); // gyro dlpf 10Hz
|
||||
}
|
||||
|
||||
void iic_isr_recv(){
|
||||
OSSemPost(iic_sem);
|
||||
}
|
||||
|
||||
static uint8_t mpu9250_Iic_Init(){
|
||||
Config = XIicPs_LookupConfig(IIC_DEVICE_ID) ;
|
||||
XIicPs_CfgInitialize(&Iic, Config, Config->BaseAddress);
|
||||
iic_sem = OSSemCreate(1);
|
||||
|
||||
s32 err;
|
||||
|
||||
err = XIicPs_SelfTest(&Iic);
|
||||
if(err == XST_SUCCESS)
|
||||
UCOS_Printf("i2c selftest succcess\r\n");
|
||||
else
|
||||
UCOS_Printf("i2c selftest fail\r\n");
|
||||
|
||||
err = XIicPs_SetSClk(&Iic, 400000);
|
||||
if(err != XST_SUCCESS)
|
||||
UCOS_Printf("failed to set i2c speed\r\n");
|
||||
|
||||
Iic.StatusHandler = iic_isr_recv;
|
||||
UCOS_IntVectSet(XPS_I2C1_INT_ID, 0, 0, XIicPs_MasterInterruptHandler, &Iic);
|
||||
UCOS_IntSrcEn(XPS_I2C1_INT_ID);
|
||||
}
|
||||
|
||||
static uint8_t mpu9250_Write_Reg(uint8_t iic_address, uint8_t data){
|
||||
uint8_t tx_buf[] = {iic_address, data};
|
||||
uint8_t err;
|
||||
OSSemPend(iic_sem, 0, &err);
|
||||
XIicPs_MasterSend(&Iic, tx_buf, sizeof(tx_buf), MPU9250_AD);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int8_t mpu9250_Read_Data(uint8_t iic_address, uint8_t length, u8 RecvBuffer []){
|
||||
uint8_t err;
|
||||
OSSemPend(iic_sem, 0, &err);
|
||||
XIicPs_MasterSend(&Iic, &iic_address, 1, MPU9250_AD);
|
||||
OSSemPend(iic_sem, 0, &err);
|
||||
XIicPs_MasterRecv(&Iic, RecvBuffer, length, MPU9250_AD);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
void InitDoneCallback(void * p_arg) {
|
||||
(void) p_arg;
|
||||
UCOS_Print("OS started!\r\n");
|
||||
//UCOS_Print("OS started!\r\n");
|
||||
GT_Init();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
#include <string.h> /* memset */
|
||||
|
||||
#define TASK_A_PRIO 11
|
||||
#define TASK_B_PRIO
|
||||
#define TASK_C_PRIO
|
||||
#define TASK_D_PRIO
|
||||
#define TASK_E_PRIO
|
||||
#define TASK_A_PRIO 10
|
||||
#define TASK_B_PRIO 11
|
||||
#define TASK_C_PRIO 12
|
||||
#define TASK_D_PRIO 13
|
||||
#define TASK_E_PRIO 14
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ GT_TASK_EXT_T GT_AllTasks[GT_NUM_OF_TASKS] = {
|
||||
/* Period Jitter Distance BCET WCET */
|
||||
{20, 0, 0, {5, 10}},
|
||||
{10, 0, 0, {1, 2}},
|
||||
{100, 0, 0, {2, 2}},
|
||||
{100, 0, 0, {2, 2}},
|
||||
{50, 0, 0, {2, 10}},
|
||||
{200, 0, 0, {2, 5}},
|
||||
};
|
||||
@@ -72,26 +72,151 @@ void _taskFinished(void){
|
||||
return;
|
||||
}
|
||||
|
||||
void task0_start(){
|
||||
asm("nop");
|
||||
}
|
||||
void task1_start(){
|
||||
asm("nop");
|
||||
}
|
||||
void task2_start(){
|
||||
asm("nop");
|
||||
}
|
||||
void task3_start(){
|
||||
asm("nop");
|
||||
}
|
||||
void task4_start(){
|
||||
asm("nop");
|
||||
}
|
||||
|
||||
void task0_act(){
|
||||
asm("nop");
|
||||
}
|
||||
void task1_act(){
|
||||
asm("nop");
|
||||
}
|
||||
void task2_act(){
|
||||
asm("nop");
|
||||
}
|
||||
void task3_act(){
|
||||
asm("nop");
|
||||
}
|
||||
void task4_act(){
|
||||
asm("nop");
|
||||
}
|
||||
|
||||
void task0_switch(){
|
||||
asm("nop");
|
||||
}
|
||||
void task1_switch(){
|
||||
asm("nop");
|
||||
}
|
||||
void task2_switch(){
|
||||
asm("nop");
|
||||
}
|
||||
void task3_switch(){
|
||||
asm("nop");
|
||||
}
|
||||
void task4_switch(){
|
||||
asm("nop");
|
||||
}
|
||||
|
||||
void task0_end(){
|
||||
asm("nop");
|
||||
}
|
||||
void task1_end(){
|
||||
asm("nop");
|
||||
}
|
||||
void task2_end(){
|
||||
asm("nop");
|
||||
}
|
||||
void task3_end(){
|
||||
asm("nop");
|
||||
}
|
||||
void task4_end(){
|
||||
asm("nop");
|
||||
}
|
||||
|
||||
void GT_TaskActivationHook(GT_TASK_T *pMyOwnTask) {
|
||||
if(pMyOwnTask == >_Tasks[0]){
|
||||
task0_act();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[1]){
|
||||
task1_act();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[2]){
|
||||
task2_act();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[3]){
|
||||
task3_act();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[4]){
|
||||
task4_act();
|
||||
}
|
||||
//call _taskActivated
|
||||
}
|
||||
|
||||
void GT_TaskStartHook(GT_TASK_T *pMyOwnTask) {
|
||||
if(pMyOwnTask == >_Tasks[0]){
|
||||
task0_start();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[1]){
|
||||
task1_start();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[2]){
|
||||
task2_start();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[3]){
|
||||
task3_start();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[4]){
|
||||
task4_start();
|
||||
}
|
||||
//call _taskStarted
|
||||
}
|
||||
|
||||
void GT_TaskEndHook(GT_TASK_T *pMyOwnTask){
|
||||
if(pMyOwnTask == >_Tasks[0]){
|
||||
task0_end();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[1]){
|
||||
task1_end();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[2]){
|
||||
task2_end();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[3]){
|
||||
task3_end();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[4]){
|
||||
task4_end();
|
||||
}
|
||||
|
||||
//Call _taskFinished
|
||||
}
|
||||
|
||||
void GT_TaskInitHook(GT_TASK_T *pMyOwnTask){
|
||||
if(pMyOwnTask->Id == 4){
|
||||
UCOS_Print("Init Task\n");
|
||||
}
|
||||
//if(pMyOwnTask->Id == 4){
|
||||
// UCOS_Print("Init Task\n");
|
||||
//}
|
||||
}
|
||||
|
||||
void GT_TaskSwHook(GT_TASK_T *pMyOwnTask) {
|
||||
//call Task scheduled or not
|
||||
if(pMyOwnTask == >_Tasks[0]){
|
||||
task0_switch();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[1]){
|
||||
task1_switch();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[2]){
|
||||
task2_switch();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[3]){
|
||||
task3_switch();
|
||||
}
|
||||
if(pMyOwnTask == >_Tasks[4]){
|
||||
task4_switch();
|
||||
}
|
||||
}
|
||||
|
||||
void GT_TaskMissHook(GT_TASK_T *pMyOwnTask){
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#define GT_USE_NP_REGIONS 1
|
||||
#define GT_USE_NP_MEAS 1
|
||||
#define GT_NUM_OF_TASKS 3
|
||||
#define GT_NUM_OF_TASKS 4
|
||||
#define GT_REPORT_CONSOLE 0
|
||||
#define GT_REPORT_SVC 0
|
||||
|
||||
|
||||
@@ -26,6 +26,10 @@ void InitDoneCallback(void * p_arg) {
|
||||
(void) p_arg;
|
||||
UCOS_Print("OS started!\r\n");
|
||||
GT_Init();
|
||||
uint8_t err;
|
||||
OSTaskNameSet(31, "IMU Task", &err);
|
||||
OSTaskNameSet(32, "Timer Task", &err);
|
||||
OSTaskNameSet(33, "PID Task", &err);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
@@ -32,7 +32,7 @@ GT_TASK_EXT_T GT_AllTasks[GT_NUM_OF_TASKS] = {
|
||||
{50, 0, 0, {1, 1}},
|
||||
{120, 0, 0, {2, 4}},
|
||||
{50, 0, 0, {3, 5}},
|
||||
//{50, 0, 0, {3, 5}},
|
||||
{50, 0, 0, {3, 5}},
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -41,10 +41,10 @@ GT_TASK_EXT_T GT_AllTasks[GT_NUM_OF_TASKS] = {
|
||||
GT_TASK_T GT_Tasks[GT_NUM_OF_TASKS] =
|
||||
{
|
||||
/*Type Activation Type Id Prio init Function Task Function TaskArg WL/Runable Internal External */
|
||||
{ GT_TASK_EXT , GT_ACT_INT , 0, 32, your-timer-taskinitfunction ,your-timer_Task , NULL, GT_RUNABLE_NULL, GT_INTERNAL_NULL, (void *)>_AllTasks[0]},
|
||||
{ GT_TASK_EXT , GT_ACT_INT , 1, 31, your-imu-taskinitfunction ,your-imu_Task , NULL, GT_RUNABLE_NULL, GT_INTERNAL_NULL, (void *)>_AllTasks[1]},
|
||||
{ GT_TASK_EXT , GT_ACT_INT , 2, 33, your-pid-taskinitfunction ,your-pid_Task , NULL, GT_RUNABLE_NULL, GT_INTERNAL_NULL, (void *)>_AllTasks[2]},
|
||||
//{ GT_TASK_DEF , GT_ACT_INT , 3, 33, _GT_GetNextActivation, _GT_GetTaskCet, NULL ,NULL , NULL, 20, GT_RUNABLE_NULL, GT_INTERNAL_NULL, (void *)>_AllTasks[3]},
|
||||
{ GT_TASK_EXT , GT_ACT_INT , 0, 32, timer_Init, timer_Task , NULL, GT_RUNABLE_NULL, GT_INTERNAL_NULL, (void *)>_AllTasks[0]},
|
||||
{ GT_TASK_EXT , GT_ACT_INT , 1, 31, mpu9250_Imu_Init, mpu9250_CalculateAngle , NULL, GT_RUNABLE_NULL, GT_INTERNAL_NULL, (void *)>_AllTasks[1]},
|
||||
{ GT_TASK_EXT , GT_ACT_INT , 2, 33, pid_Init, pid_Task , NULL, GT_RUNABLE_NULL, GT_INTERNAL_NULL, (void *)>_AllTasks[2]},
|
||||
{ GT_TASK_DEF , GT_ACT_INT , 3, 33, NULL, NULL , NULL, GT_RUNABLE_NULL, GT_INTERNAL_NULL, (void *)>_AllTasks[3]},
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user