Compare commits
6 Commits
master
...
cae559a7be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cae559a7be | ||
|
|
039fafd2c4 | ||
|
|
1ee6bcc841 | ||
|
|
4c4338c309 | ||
|
|
1353e12dd7 | ||
|
|
0424d69bcd |
17
Makefile
17
Makefile
@@ -25,11 +25,12 @@ OUT_DIR = ./out
|
|||||||
|
|
||||||
TARGET := $(APP)_$(ARCH)_core$(CORE)
|
TARGET := $(APP)_$(ARCH)_core$(CORE)
|
||||||
TARGET_DIR := $(SRC_DIR)/APP/$(APP)/$(ARCH)/core$(CORE)/
|
TARGET_DIR := $(SRC_DIR)/APP/$(APP)/$(ARCH)/core$(CORE)/
|
||||||
|
$(info TARGET_DIR : ${TARGET_DIR})
|
||||||
|
|
||||||
OBJ_DIR = ./$(OUT_DIR)/$(TARGET)
|
OBJ_DIR = ./$(OUT_DIR)/$(TARGET)
|
||||||
|
|
||||||
# Load specific config for compiler, linker, ...
|
# Load specific config for compiler, linker, ...
|
||||||
-include $(TARGET_DIR)/build/config.mk
|
include $(TARGET_DIR)/build/config.mk
|
||||||
|
|
||||||
#Output files: elf, map and list-file
|
#Output files: elf, map and list-file
|
||||||
EXECUTABLE=$(OBJ_DIR)/../$(TARGET).elf
|
EXECUTABLE=$(OBJ_DIR)/../$(TARGET).elf
|
||||||
@@ -42,16 +43,18 @@ LDSCRIPT = -T$(TARGET_DIR)/linker/lscript.ld
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
#Include source-files:
|
#Include source-files:
|
||||||
SRC =
|
$(info TARGET_DIR : ${TARGET_DIR})
|
||||||
-include $(TARGET_DIR)/build/Sources.mk
|
INC = -I.
|
||||||
|
include $(TARGET_DIR)/build/includes.mk
|
||||||
|
|
||||||
|
SRC =
|
||||||
|
include $(TARGET_DIR)/build/sources.mk
|
||||||
|
|
||||||
INC = -I./
|
|
||||||
-include $(TARGET_DIR)/build/includes.mk
|
|
||||||
|
|
||||||
# C source files
|
# C source files
|
||||||
CFILES = $(filter %.c, $(SRC))
|
CFILES = $(filter %.c, $(SRC))
|
||||||
# Assembly source files
|
# Assembly source files
|
||||||
ASMFILES = $(filter %.s, $(SRC))
|
ASMFILES = $(filter %.S, $(SRC))
|
||||||
# Object files
|
# Object files
|
||||||
COBJ = $(CFILES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
|
COBJ = $(CFILES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
|
||||||
SOBJ = $(ASMFILES:$(SRC_DIR)/%.S=$(OBJ_DIR)/%.o)
|
SOBJ = $(ASMFILES:$(SRC_DIR)/%.S=$(OBJ_DIR)/%.o)
|
||||||
@@ -72,7 +75,7 @@ $(LISTFILE): $(EXECUTABLE)
|
|||||||
|
|
||||||
$(EXECUTABLE): $(OBJ)
|
$(EXECUTABLE): $(OBJ)
|
||||||
@echo 'Linking: $@'
|
@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
|
$(COBJ): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
||||||
@echo 'Building file: $<'
|
@echo 'Building file: $<'
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ INC += -I"$(SRC_DIR)/ucos_v1_42/ucos/components/ucos_standalone/src/common"
|
|||||||
INC += -I"$(SRC_DIR)/Xilinx/libsrc/ipipsu_v2_3/src/"
|
INC += -I"$(SRC_DIR)/Xilinx/libsrc/ipipsu_v2_3/src/"
|
||||||
INC += -I"$(SRC_DIR)/Modules/MMU"
|
INC += -I"$(SRC_DIR)/Modules/MMU"
|
||||||
|
|
||||||
|
INC += -I"$(SRC_DIR)/Xilinx/include/"
|
||||||
|
|
||||||
|
|
||||||
INC += -I"$(SRC_DIR)/Xilinx/libsrc/ipipsu_v2_3/src/"
|
INC += -I"$(SRC_DIR)/Xilinx/libsrc/ipipsu_v2_3/src/"
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
-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)/ucos_v1_42/ucos/components/ucos_common/src/$(ARCH)/cpu_bsp.c
|
||||||
|
|
||||||
SRC += $(SRC_DIR)/Modules/MMU/mmu.c
|
SRC += $(SRC_DIR)/Modules/MMU/mmu.c
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#Startup file
|
#Startup file
|
||||||
SRC += $(SRC_DIR)/ucos_v1_42/ucos/bsp/src/$(ARCH)/asm_vectors.S
|
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/$(ARCH)/subdir.mk
|
||||||
-include $(SRC_DIR)/ucos_v1_42/ucos/bsp/src/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_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)/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_l2cachec/src/ucos_l2cachec.c
|
||||||
SRC += $(SRC_DIR)/ucos_v1_42/ucos/drivers/ucos_emacps/src/ucos_emacps.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/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/Collections/slist.c
|
||||||
SRC += $(SRC_DIR)/ucos_v1_42/micrium_source/uC-Common/Auth/auth.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,39 +16,97 @@
|
|||||||
#include "xil_testmem.h"
|
#include "xil_testmem.h"
|
||||||
#include "xil_printf.h"
|
#include "xil_printf.h"
|
||||||
|
|
||||||
#define HELLO_WORLD_TASK_PRIO 64
|
#define HELLO_WORLD_TASK_PRIO 30
|
||||||
#define CALC_TASK_PRIO 64
|
#define CALC_TASK_PRIO 31
|
||||||
|
#define TASK1_PRIO 32
|
||||||
|
#define TASK2_PRIO 33
|
||||||
|
|
||||||
#define HELLO_WORLD_TASK_STK_SIZE 16
|
#define HELLO_WORLD_TASK_STK_SIZE 16000
|
||||||
#define CALC_TASK_STK_SIZE 32
|
#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 HelloWorldTaskStk[HELLO_WORLD_TASK_STK_SIZE];
|
||||||
static OS_STK CalcTaskStk[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;
|
return n;
|
||||||
else
|
else
|
||||||
return (f(n-1) + f(n-3));
|
return (f(n-1) + f(n-2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HelloWorldTask (void *pdata)
|
void HelloWorldTask (void *pdata)
|
||||||
{
|
{
|
||||||
while(1){
|
while(1){
|
||||||
UCOS_Printf("Hello World!");
|
UCOS_Printf("Hello World!\n");
|
||||||
OSTimeDly(OS_TICKS_PER_SEC*50);
|
OSTimeDly(OS_TICKS_PER_SEC*50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CalcTask (void *pdata)
|
void CalcTask (void *pdata)
|
||||||
{
|
{
|
||||||
uint8_t n=50;
|
while(1){
|
||||||
for (uint8_t i = 1; i <= n; i)
|
uint8_t n=50;
|
||||||
{
|
for (uint8_t i = 1; i <= n; i++)
|
||||||
UCOS_Printf("%u", f(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 InitDoneCallback(void * p_arg){
|
||||||
@@ -56,28 +114,58 @@ void InitDoneCallback(void * p_arg){
|
|||||||
UCOS_Print("OS started!\r\n");
|
UCOS_Print("OS started!\r\n");
|
||||||
|
|
||||||
OSTaskCreateExt(HelloWorldTask,
|
OSTaskCreateExt(HelloWorldTask,
|
||||||
0,
|
0,
|
||||||
&HelloWorldTaskStk[0],
|
&HelloWorldTaskStk[HELLO_WORLD_TASK_STK_SIZE-1],
|
||||||
HELLO_WORLD_TASK_PRIO,
|
HELLO_WORLD_TASK_PRIO,
|
||||||
&HelloWorldTaskStk[0],
|
HELLO_WORLD_TASK_PRIO,
|
||||||
0,
|
&HelloWorldTaskStk[0],
|
||||||
0);
|
HELLO_WORLD_TASK_STK_SIZE,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
|
||||||
OSTaskCreateExt(CalcTask,
|
OSTaskCreateExt(CalcTask,
|
||||||
0,
|
0,
|
||||||
CALC_TASK_PRIO,
|
&CalcTaskStk[CALC_TASK_STK_SIZE-1],
|
||||||
CALC_TASK_PRIO,
|
CALC_TASK_PRIO,
|
||||||
&CalcTaskStk[0],
|
CALC_TASK_PRIO,
|
||||||
CALC_TASK_STK_SIZE,
|
&CalcTaskStk[0],
|
||||||
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){
|
while(1){
|
||||||
OSTimeDly();
|
OSTimeDly(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
MMUInit();
|
MMUInit();
|
||||||
|
UCOSStartup(InitDoneCallback);
|
||||||
while (1);;
|
while (1);;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int timer_Task(void *pdata);
|
void timer_Task(void *pdata);
|
||||||
int timer_Init();
|
int timer_Init();
|
||||||
|
|
||||||
#endif /* SRC_APP_AUFGABE3_PS7_CORE0_CFG_TTC_TIMER_H_ */
|
#endif /* SRC_APP_AUFGABE3_PS7_CORE0_CFG_TTC_TIMER_H_ */
|
||||||
|
|||||||
@@ -17,21 +17,68 @@
|
|||||||
#include "xil_printf.h"
|
#include "xil_printf.h"
|
||||||
#include "ttc_timer.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;
|
int16_t pidValue = 0;
|
||||||
|
|
||||||
void InitDoneCallback(void * p_arg) {
|
void InitDoneCallback(void * p_arg) {
|
||||||
(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");
|
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
|
||||||
|
// );
|
||||||
|
|
||||||
|
timer_Init();
|
||||||
|
|
||||||
|
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++){
|
||||||
|
CPU_SR cpu_sr;
|
||||||
|
OS_ENTER_CRITICAL();
|
||||||
|
pidValue = melody[i][0];
|
||||||
|
OS_EXIT_CRITICAL();
|
||||||
|
timer_Task(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) {
|
int main(void) {
|
||||||
MMUInit();
|
MMUInit();
|
||||||
UCOSStartup(InitDoneCallback);
|
UCOSStartup(InitDoneCallback);
|
||||||
while (1)
|
while (1);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,6 @@
|
|||||||
#include "xgpiops.h"
|
#include "xgpiops.h"
|
||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void timer_Start(uint32_t Id);
|
static void timer_Start(uint32_t Id);
|
||||||
static void timer_Stop(uint32_t Id);
|
static void timer_Stop(uint32_t Id);
|
||||||
static void timer_Set_Interval_Length(uint32_t Id, uint16_t intervalLength);
|
static void timer_Set_Interval_Length(uint32_t Id, uint16_t intervalLength);
|
||||||
@@ -26,52 +23,97 @@ 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 motor_Set_Moving_Direction (u32 pin, int16_t value);
|
||||||
static void timer_gpio_Init();
|
static void timer_gpio_Init();
|
||||||
|
|
||||||
int timer_Task(void *pdata) {
|
XTtcPs xttcps[2];
|
||||||
|
|
||||||
return 0;
|
XGpioPs xgpiops;
|
||||||
|
XGpioPs_Config* gpioCfg;
|
||||||
|
|
||||||
|
extern int16_t pidValue;
|
||||||
|
|
||||||
|
void timer_Task(void *pdata) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* * * intializes and starts two timers with respective puls generation on gpio pins * * */
|
/* * * 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");
|
UCOS_Print("Setting up Timer!\r\n");
|
||||||
|
|
||||||
|
timer_Dual_Timer_Setup();
|
||||||
|
|
||||||
|
timer_gpio_Init();
|
||||||
|
motor_Set_Moving_Direction(54, 1);
|
||||||
|
|
||||||
UCOS_Print("Done!\r\n");
|
UCOS_Print("Done!\r\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* * * checks the desired moving direction and sets the direction pin for the steppers * * */
|
/* * * 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) {
|
static void motor_Set_Moving_Direction (uint32_t pin, int16_t value) {
|
||||||
|
XGpioPs_WritePin(&xgpiops, pin, value);;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* * * init gpio, connects IRQ to gpio * * */
|
/* * * init gpio, connects IRQ to gpio * * */
|
||||||
static void timer_gpio_Init(){
|
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 * * */
|
/* * * * * * 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)
|
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 * * */
|
/* * * * * * 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)
|
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" * * */
|
/* * * starts timer number "Id" * * */
|
||||||
static void timer_Start(uint32_t Id){
|
static void timer_Start(uint32_t Id){
|
||||||
|
XTtcPs_Start(&xttcps[Id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* * * stops timer number "Id" * * */
|
/* * * stops timer number "Id" * * */
|
||||||
static void timer_Stop(uint32_t Id){
|
static void timer_Stop(uint32_t Id){
|
||||||
|
XTtcPs_Stop(&xttcps[Id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* * * sets new interval length and the correct matchvalue * * */
|
/* * * sets new interval length and the correct matchvalue * * */
|
||||||
static void timer_Set_Interval_Length(uint32_t Id, uint16_t interval_length){
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user