Browse Source

Merge branch 'new/terminate-task/13'

DricomDragon 5 năm trước cách đây
mục cha
commit
d0bf68b23c
4 tập tin đã thay đổi với 30 bổ sung15 xóa
  1. 1 1
      prog/makefile.json
  2. 15 13
      prog/sources/user-tasks.cpp
  3. 10 0
      prog/sources/xtr.cpp
  4. 4 1
      prog/sources/xtr.h

+ 1 - 1
prog/makefile.json

@@ -4,7 +4,7 @@
 
   "CPU-MHZ" : 180,
 
-  "TASK-COUNT" : 1,
+  "TASK-COUNT" : 2,
 
   "SERVICE-SCHEME" : "svc",
 

+ 15 - 13
prog/sources/user-tasks.cpp

@@ -2,27 +2,29 @@
 
 static uint64_t gStack1 [64] ;
 
+static void task1 (USER_MODE) {
+	for (unsigned int i(0); i < 20; i++) {
+		digitalToggle(L0_LED);
+		printChar (MODE_ '>') ;
+		busyWaitDuring(MODE_ 500);
+	}
+}
 
-static uint32_t gDisplayTime = 0 ;
 
-static void task1 (USER_MODE) {
-	while (1) {
-		if (gDisplayTime <= millis (MODE)) {
-			const uint32_t s = systick (MODE) ;
-			gotoLineColumn (MODE_ 1, 0) ;
-			printUnsigned (MODE_ s) ;
-			gotoLineColumn (MODE_ 2, 0) ;
-			printUnsigned (MODE_ millis (MODE)) ;
-			gotoLineColumn (MODE_ 3, 0) ;
-			printUnsigned64 (MODE_ micros (MODE)) ;
-			gDisplayTime += 1000 ;
-		}
+static uint64_t gStack2 [64] ;
+
+static void task2 (USER_MODE) {
+	for (unsigned int i(0); i < 20; i++) {
+		digitalToggle(L1_LED);
+		printChar (MODE_ '<') ;
+		busyWaitDuring(MODE_ 400);
 	}
 }
 
 
 static void initTasks (INIT_MODE) {
 	kernel_createTask (MODE_ gStack1, sizeof (gStack1), task1) ;
+	kernel_createTask (MODE_ gStack2, sizeof (gStack2), task2) ;
 }
 
 MACRO_INIT_ROUTINE (initTasks) ;

+ 10 - 0
prog/sources/xtr.cpp

@@ -109,6 +109,9 @@ static void kernel_set_task_context (INIT_MODE_
 
 	// Initialize CPSR
 	ptr->mXPSR = 1 << 24 ; // Thumb bit
+
+	// Self termination
+	ptr->mLR = (uint32_t) taskSelfTerminates;
 }
 
 // T A S K    C O N T R O L    B L O C K                                                                             *
@@ -193,4 +196,11 @@ void kernel_createTask (INIT_MODE_
 	gTaskIndex += 1 ;
 }
 
+static void kernel_makeNoTaskRunning(KERNEL_MODE) {
+	gRunningTaskControlBlockPtr = nullptr; // No running task
+}
 
+// Task termination
+void service_taskSelfTerminates(KERNEL_MODE) {
+	kernel_makeNoTaskRunning(MODE);
+}

+ 4 - 1
prog/sources/xtr.h

@@ -21,4 +21,7 @@ TaskControlBlock * descriptorPointerForTaskIndex (const uint8_t inTaskIndex) ;
 
 uint8_t indexForDescriptorTask (const TaskControlBlock * inTaskPtr) ; // should be not nullptr
 
-
+// Task termination
+void taskSelfTerminates(USER_MODE) asm ("task.self.terminates");
+void service_taskSelfTerminates(KERNEL_MODE) asm ("service.task.self.terminates");
+//$service task.self.terminates