📄 ctdemo.c
字号:
/* test_program.c - CodeTEST demo program *//*modification history--------------------01a,11jun98,bjl written.*//*DESCRIPTIONSample program to demonstrate some capabilitiesof CodeTEST, to be used in conjunction withthe 'Getting Started' chapter of the CodeTESTfor Tornado User's Guide. *//* includes */#include "vxWorks.h"#include "stdio.h"#include "taskLib.h"#include "sysLib.h"/* globals */int programcount;char *buf1, *buf2;/********************************************************************************* task1 - Allocates memory to the global buffers.**/void task1() { buf1 = (char*) malloc(programcount * 100); buf2 = (char*) malloc(programcount * 100);}/********************************************************************************* task2 - Frees memory from the global buffers. The programmer * "accidentally" frees buf1 again instead of freeing buf2. **/void task2() { free (buf1); free (buf1);}/********************************************************************************* function_totest - Executes one of two branches depending on the value of * arg. **/ void function_totest (int arg) { if (arg <= 100) { printf ("arg <= 100. arg = %d\n", arg); } else { printf ("arg > 100. arg = %d\n", arg); }}/********************************************************************************* test_program - Test function for CodeTEST demo. First calls * function_totest, then calls task1 and task2 in a loop. The * duration of the loop should be five minutes. **/void test_program() { function_totest (100); for (programcount = 0; programcount < 60; programcount++) { taskSpawn("task1", 100, 0, 20000, (FUNCPTR) task1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); taskSpawn("task2", 100, 0, 20000, (FUNCPTR) task2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); /* delay for five seconds */ taskDelay(sysClkRateGet() * 5); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -