📄 bug_init.c
字号:
/*********************************************************
Copyright (c) CMX Company. 1999. All rights reserved
*********************************************************/
/* version 5.30, adds the following:
1. counting semaphores
2. priority inversion on resources
3. highest priority task waiting on resource, is the one
that will get resource when it is released.
4. new int_pipe routine
*/
#define CMX_INIT_MODULE
#define CMXMODULE
#include <cxfuncs.h> /* get cmx include header file */
#include "bgconfig.h" /* get user configuration file */
#if CMXBUG_ENABLE > 0
#include <cmxbug.h> /* get cmx include header file */
#elif CMXTRACKER_ENABLE > 0
#include <cmxtrack.h> /* get cmx include header file */
#endif
#if C_PIPE_SIZE < 1 || C_PIPE_SIZE > 255
#error: C_PIPE_SIZE must be between 1 and 255
#endif
#if C_MAX_MESSAGES > 0
#define CMX_MAX_MESSAGES (C_MAX_MESSAGES + 2)
#endif
#if CMXBUG_ENABLE > 0 || CMXTRACKER_ENABLE > 0
#define CC_TASK_STK_SIZE (C_TASK_STK_SIZE + 256)
#else
#define CC_TASK_STK_SIZE C_TASK_STK_SIZE
#endif
#if CMXBUG_ENABLE > 0 || CMXTRACKER_ENABLE > 0
#define CC_MAX_TASKS (C_MAX_TASKS + 1)
#else
#define CC_MAX_TASKS C_MAX_TASKS
#endif
/***********************************************************
WARNING: these are assumed to be initailized by the "C" compiler
start up code. Also all non-initialized CMX variables are assumed
to be zeroed out by the "C" compiler startup code. This is normally
done. If NOT, then the user must set the CMX_RAM_INIT define to 1.
See cxconfig.h (or equivalent file).
***********************************************************/
byte MAX_TASKS = CC_MAX_TASKS;
byte MAX_RESOURCES = C_MAX_RESOURCES;
byte MAX_CYCLIC_TIMERS = C_MAX_CYCLIC_TIMERS;
byte MAX_MAILBOXES = C_MAX_MAILBOXES;
byte MAX_QUEUES = C_MAX_QUEUES;
byte RTC_SCALE = C_RTC_SCALE;
byte MAX_SEMAPHORES = C_MAX_SEMAPHORES;
byte near TSLICE_SCALE = C_TSLICE_SCALE;
/*******************************************************
The following sets up the necessary memory needed by CMX
*******************************************************/
/******************************************************
The cxvendor.h header file will actually add additional
CMX variables to ONLY this file. See that header file.
********************************************************/
struct _tcb cmx_tcb[CC_MAX_TASKS+1];
#if C_MAX_CYCLIC_TIMERS > 0
CYCLIC_TIMERS tcproc[C_MAX_CYCLIC_TIMERS];
#else
byte tcproc[1];
#endif
#if C_MAX_RESOURCES > 0
RESHDR res_que[C_MAX_RESOURCES];
#else
byte res_que[1];
#endif
#if C_MAX_MAILBOXES > 0
MAILBOX mail_box[C_MAX_MAILBOXES];
#else
byte mail_box[1];
#endif
#if C_MAX_MESSAGES > 0
MSG message_box[CMX_MAX_MESSAGES];
#else
byte message_box[1];
#endif
#if C_MAX_QUEUES > 0
QUEHDR queue[C_MAX_QUEUES];
#else
byte queue[1];
#endif
#if C_MAX_SEMAPHORES > 0
SEM sem_array[C_MAX_SEMAPHORES];
#else
byte sem_array[1];
#endif
struct {
word16 stack_space[CC_TASK_STK_SIZE / 2];
word16 dummy;
} near stack_storage;
word16 *stack_blk;
struct {
word16 interrupt_bytes[C_INTERRUPT_SIZE / 2];
word16 dummy;
} near int_storage;
word16 * near interrupt_stack;
CYCLIC_LNK cyclic_buf;
CYCLIC_LNK *cyclic_lnk;
TSK_TIMER_LNK *tsk_timer_lnk;
TSK_TIMER_LNK tsk_timer_buf;
MSG *message_ptr;
word16 message_free;
near byte tslice_count;
near byte SLICE_ON;
tcbpointer near activetcb;
near byte active_priority;
tcbpointer timertask;
byte rtc_count;
PIPE_STRUC *out_ptr;
PIPE_STRUC pipe[C_PIPE_SIZE];
#if CMX_RAM_INIT > 0
static void clear_ram(void *,word16);
static void init_cmx_variables(void);
#endif
#if CMXTRACKER_ENABLE > 0
near byte CMXTRACKER_ACTIVE;
byte CMXTRACKER_ON;
struct _tcb * near previoustcb;
extern byte cmxtracker_slot;
extern void cmxtracker(void);
extern void cmxtracker_mode(byte,word16);
extern word16 cmxtracker_ctr;
extern byte *cmxtracker_in_ptr;
extern word16 num_records;
void init_cmxtracker(void);
byte cmxtracker_array[CMXTRACKER_SIZE];
#define LOG_DISPLAY_LEN 18
word16 rec_cnt[((sizeof (cmxtracker_array) / 4) / LOG_DISPLAY_LEN) + 2];
#endif
#if CMXBUG_ENABLE > 0
long stat_array[CC_MAX_TASKS+1];
#endif
#if CMXBUG_ENABLE > 0 || CMXTRACKER_ENABLE > 0
char *task_name[CC_MAX_TASKS + 1];
byte BUG_WAIT_TICKS;
void setup_bug(void);
byte K_Bug_Getchr(byte *ptr);
void K_Bug_Putchr(char);
#endif
word32 cmx_tick_count; /* total number of CMX system ticks accumulated */
#if (defined(WINTRACKER))
word32 track_tick_count; /* total number of CMX system ticks accumulated */
word16 compute_tick_count;
#endif
void K_OS_Init(void)
{
MSG *link; /* scratch pointer */
locked_out = 1; /* set lock so it will never goto K_I_Scheduler */
cmx_tick_count = 0; /* reset CMX long counter */
#if (defined(WINTRACKER))
track_tick_count = 0;
compute_tick_count = 0;
#endif
#if CMX_RAM_INIT > 0 /* Should we initialize CMX variables */
init_cmx_variables();
#endif
#if C_MAX_MESSAGES > 0
link = message_box; /* address of 1st block */
message_free = CMX_MAX_MESSAGES; /* use pipe_max to hold count */
while (message_free--)
{
message_ptr = link; /* point head at 1st block */
link++; /* compute addr of next block */
message_ptr->env_link = link; /* create link to it */
}
message_ptr->env_link = message_box; /* last link in chain is null */
message_ptr = message_box; /* point head at 1st block */
message_free = CMX_MAX_MESSAGES-2;
#endif
in_ctr = out_ctr = cmx_flag1 = 0;
/* set up interrupt pipe. */
pipe_slots_avail = C_PIPE_SIZE;
cyclic_lnk = &cyclic_buf; /* set up cyclic timers time link. */
cyclic_lnk->ftlink = cyclic_lnk->btlink = (struct _tcproc *)cyclic_lnk;
tsk_timer_lnk = &tsk_timer_buf; /* set up task timer link. */
tsk_timer_lnk->ftlink = tsk_timer_lnk->btlink = (tcbpointer)tsk_timer_lnk;
/* now set up stack block to release memory to task's stacks as
they are created. Also interrupt stack if used. */
stack_blk = &stack_storage.dummy;
interrupt_stack = &int_storage.dummy;
activetcb = timertask = cmx_tcb; /* dummy tcb */
timertask->nxttcb = cmx_tcb; /* set up link. */
#if CMXBUG_ENABLE > 0 || CMXTRACKER_ENABLE > 0
setup_bug();
BUG_WAIT_TICKS = 10; /* Number of system ticks to wait, before checking
to see if the + (plus key) has been received
by UART. */
#endif
RTC_SCALE = C_RTC_SCALE; /* number of timer ticks, before running
CMX task timer if needed. */
rtc_count = C_RTC_SCALE; /* number of timer ticks, before running
CMX task timer if needed. */
TSLICE_SCALE = C_TSLICE_SCALE;
} /* K_OS_Init */
#if CMX_RAM_INIT > 0
static void init_cmx_variables(void)
{
MAX_TASKS = CC_MAX_TASKS;
MAX_RESOURCES = C_MAX_RESOURCES;
MAX_CYCLIC_TIMERS = C_MAX_CYCLIC_TIMERS;
MAX_MAILBOXES = C_MAX_MAILBOXES;
MAX_QUEUES = C_MAX_QUEUES;
MAX_SEMAPHORES = C_MAX_SEMAPHORES;
clear_ram(cmx_tcb,sizeof cmx_tcb);
clear_ram(&stack_storage.stack_space[0],sizeof stack_storage);
#if C_MAX_CYCLIC_TIMERS > 0
clear_ram(tcproc,sizeof tcproc);
#endif
#if C_MAX_RESOURCES > 0
clear_ram(res_que,sizeof res_que);
#endif
#if C_MAX_MAILBOXES > 0
clear_ram(mail_box,sizeof mail_box);
#endif
#if C_MAX_MESSAGES > 0
clear_ram(message_box,sizeof message_box);
#endif
#if C_MAX_QUEUES > 0
clear_ram(queue,sizeof queue);
#endif
#if C_MAX_SEMAPHORES > 0
clear_ram(sem_array,sizeof sem_array);
#endif
}
static void clear_ram(void *addr_ptr,word16 size)
{
byte *crap_ptr;
crap_ptr = (byte *)addr_ptr;
while(size--)
{
*crap_ptr++ = 0;
}
}
#endif
#if CMXBUG_ENABLE > 0 || CMXTRACKER_ENABLE > 0
void setup_bug(void)
{
/* Do NOT change the "cmxbug_slot" or "cmxbug", for
CMXBug expects these names. You could change the priority
or stack size if need be, but we highly suggest you do not. */
#if CMXBUG_ENABLE > 0
K_Task_Create(1,&cmxbug_slot,cmxbug,256); /* create CMXBug task */
K_Task_Name(cmxbug_slot,"CMXBug"); /* Name for task */
K_Task_Start(cmxbug_slot); /* start CMXBug task */
#else
K_Task_Create(1,&cmxtracker_slot,cmxtracker,256); /* create CMXTracker task */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -