////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Filename: taskp.c
|
// Filename: taskp.c
|
//
|
//
|
// Project: CMod S6 System on a Chip, ZipCPU demonstration project
|
// Project: CMod S6 System on a Chip, ZipCPU demonstration project
|
//
|
//
|
// Purpose: Implements the new_task function to create a new task, as well
|
// Purpose: Implements the new_task function to create a new task, as well
|
// as the idle_task's entry function and body.
|
// as the idle_task's entry function and body.
|
//
|
//
|
// Creator: Dan Gisselquist, Ph.D.
|
// Creator: Dan Gisselquist, Ph.D.
|
// Gisselquist Technology, LLC
|
// Gisselquist Technology, LLC
|
//
|
//
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
//
|
//
|
// This program is free software (firmware): you can redistribute it and/or
|
// This program is free software (firmware): you can redistribute it and/or
|
// modify it under the terms of the GNU General Public License as published
|
// modify it under the terms of the GNU General Public License as published
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
// your option) any later version.
|
// your option) any later version.
|
//
|
//
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// for more details.
|
// for more details.
|
//
|
//
|
// You should have received a copy of the GNU General Public License along
|
// You should have received a copy of the GNU General Public License along
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
// target there if the PDF file isn't present.) If not, see
|
// target there if the PDF file isn't present.) If not, see
|
// <http://www.gnu.org/licenses/> for a copy.
|
// <http://www.gnu.org/licenses/> for a copy.
|
//
|
//
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
// http://www.gnu.org/licenses/gpl.html
|
// http://www.gnu.org/licenses/gpl.html
|
//
|
//
|
//
|
//
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
//
|
//
|
//
|
//
|
#include "ksched.h"
|
#include "ksched.h"
|
#include "kfildes.h"
|
#include "kfildes.h"
|
#include "taskp.h"
|
#include "taskp.h"
|
|
#include "txfns.h"
|
|
|
extern void *sys_malloc(int sz);
|
extern void *sys_malloc(int sz);
|
TASKP new_task(unsigned ln, VENTRYP entry) {
|
TASKP new_task(unsigned ln, VENTRYP entry) {
|
int i;
|
int i;
|
TASKP tsk = (TASKP)sys_malloc(sizeof(struct TASK_S)+ln);
|
TASKP tsk = (TASKP)sys_malloc(sizeof(struct TASK_S)+ln);
|
|
|
for(i=0; (unsigned)i<sizeof(struct TASK_S)+ln; i++)
|
for(i=0; (unsigned)i<sizeof(struct TASK_S)+ln; i++)
|
((unsigned int *)tsk)[i] = 0;
|
((unsigned int *)tsk)[i] = 0;
|
tsk->context[ 0] = (int)((long)(int *)idle_task);
|
tsk->context[ 0] = (int)(idle_task);
|
tsk->context[12] = (int)&tsk->user_data[ln]; // Set the stack pointer
|
tsk->context[12] = (int)&tsk->user_data[ln]; // Set the stack pointer
|
tsk->context[13] = (int)&tsk->user_data[ln]; // Set the stack pointer
|
tsk->context[13] = (int)&tsk->user_data[ln]; // Set the stack pointer
|
tsk->context[14] = 0x20; // GIE bit only
|
tsk->context[14] = 0x20; // GIE bit only
|
tsk->context[15] = (int)((long)(int *)entry);
|
tsk->context[15] = (int)((int *)entry);
|
tsk->user_heap = &tsk->user_data[0];
|
tsk->user_heap = &tsk->user_data[0];
|
tsk->state = SCHED_READY;
|
tsk->state = SCHED_READY;
|
|
|
return tsk;
|
return tsk;
|
}
|
}
|
|
|
//
|
//
|
// zip_idle is really an assembly language builtin. It translates into the
|
// zip_idle is really an assembly language builtin. It translates into the
|
// WAIT (i.e. for interrupt) instruction. Even this, though, is a derived
|
// WAIT (i.e. for interrupt) instruction. Even this, though, is a derived
|
// instruction. More specifically, the WAIT instruction OR's a constant
|
// instruction. More specifically, the WAIT instruction OR's a constant
|
// to the CC register.
|
// to the CC register.
|
//
|
//
|
extern void zip_idle(void);
|
extern void zip_idle(void);
|
void idle_task(void) {
|
void idle_task(void) {
|
do {
|
do {
|
zip_idle();
|
zip_idle();
|
} while(1);
|
} while(1);
|
}
|
}
|
|
|
|
|