1 |
22 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: taskp.c
|
4 |
|
|
//
|
5 |
|
|
// Project: CMod S6 System on a Chip, ZipCPU demonstration project
|
6 |
|
|
//
|
7 |
|
|
// Purpose: Implements the new_task function to create a new task, as well
|
8 |
|
|
// as the idle_task's entry function and body.
|
9 |
|
|
//
|
10 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
11 |
|
|
// Gisselquist Technology, LLC
|
12 |
|
|
//
|
13 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
14 |
|
|
//
|
15 |
|
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
16 |
|
|
//
|
17 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
18 |
|
|
// modify it under the terms of the GNU General Public License as published
|
19 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
20 |
|
|
// your option) any later version.
|
21 |
|
|
//
|
22 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
23 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
24 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
25 |
|
|
// for more details.
|
26 |
|
|
//
|
27 |
|
|
// You should have received a copy of the GNU General Public License along
|
28 |
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
29 |
|
|
// target there if the PDF file isn't present.) If not, see
|
30 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
31 |
|
|
//
|
32 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
33 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
34 |
|
|
//
|
35 |
|
|
//
|
36 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
//
|
38 |
|
|
//
|
39 |
|
|
#include "ksched.h"
|
40 |
|
|
#include "kfildes.h"
|
41 |
|
|
#include "taskp.h"
|
42 |
45 |
dgisselq |
#include "txfns.h"
|
43 |
22 |
dgisselq |
|
44 |
|
|
extern void *sys_malloc(int sz);
|
45 |
|
|
TASKP new_task(unsigned ln, VENTRYP entry) {
|
46 |
|
|
int i;
|
47 |
|
|
TASKP tsk = (TASKP)sys_malloc(sizeof(struct TASK_S)+ln);
|
48 |
|
|
|
49 |
|
|
for(i=0; (unsigned)i<sizeof(struct TASK_S)+ln; i++)
|
50 |
|
|
((unsigned int *)tsk)[i] = 0;
|
51 |
45 |
dgisselq |
tsk->context[ 0] = (int)(idle_task);
|
52 |
22 |
dgisselq |
tsk->context[12] = (int)&tsk->user_data[ln]; // Set the stack pointer
|
53 |
|
|
tsk->context[13] = (int)&tsk->user_data[ln]; // Set the stack pointer
|
54 |
|
|
tsk->context[14] = 0x20; // GIE bit only
|
55 |
45 |
dgisselq |
tsk->context[15] = (int)((int *)entry);
|
56 |
22 |
dgisselq |
tsk->user_heap = &tsk->user_data[0];
|
57 |
|
|
tsk->state = SCHED_READY;
|
58 |
|
|
|
59 |
|
|
return tsk;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
//
|
63 |
|
|
// zip_idle is really an assembly language builtin. It translates into the
|
64 |
|
|
// WAIT (i.e. for interrupt) instruction. Even this, though, is a derived
|
65 |
|
|
// instruction. More specifically, the WAIT instruction OR's a constant
|
66 |
|
|
// to the CC register.
|
67 |
|
|
//
|
68 |
|
|
extern void zip_idle(void);
|
69 |
|
|
void idle_task(void) {
|
70 |
|
|
do {
|
71 |
|
|
zip_idle();
|
72 |
|
|
} while(1);
|
73 |
|
|
}
|
74 |
|
|
|