rkapi.h 13.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
#ifndef __TV_rkapi_h_
#define __TV_rkapi_h_

/*
** RiscKernel AS/C/C++ API definitions.
*/

#if defined(mips) || (defined(__i386__) && defined(__GNUC__))
#include "mips.h"
#endif

#include "dbgdefs.h"

/* Manifest constants */
#define TV_FALSE 0
#define TV_TRUE 1
#define TV_NULL 0

/* Error codes */
#define TV_ERROR_NO_ERROR		0
#define TV_ERROR_ILLEGAL_CALL		-1
#define TV_ERROR_INVALID_ID		-2
#define TV_ERROR_INVALID_TYPE		-3
#define TV_ERROR_OP_PROTECTED		-4
#define TV_ERROR_INVALID_ADDRESS	-5
#define TV_ERROR_INVALID_PRIORITY	-6
#define TV_ERROR_INVALID_FLAGS		-7
#define TV_ERROR_INVALID_CAPABILITY	-8
#define TV_ERROR_NO_HANDLER		-9

#define TV_ERROR_NO_MORE_IDS		-10
#define TV_ERROR_NO_MORE_MESSAGES	-11
#define TV_ERROR_NO_MORE_PROCESSES	-12
#define TV_ERROR_NO_MORE_THREADS	-13
#define TV_ERROR_NO_MORE_REGIONS	-14
#define TV_ERROR_NO_MORE_TIMERS		-15
#define TV_ERROR_NO_MORE_LOCKS		-16
#define TV_ERROR_NO_MORE_QUEUES		-17
#define TV_ERROR_NO_MORE_SETS		-18
#define TV_ERROR_NO_MORE_MEMORY		-19

#define TV_ERROR_NOT_LOCKED		-20

#define TV_ERROR_REGION_ALREADY_MAPPED	-30
#define TV_ERROR_ADDRESS_ALREADY_MAPPED	-31
#define TV_ERROR_NOT_MAPPED		-32
#define TV_ERROR_INVALID_SIZE		-33
#define TV_ERROR_INVALID_PADDR		-34

#define TV_ERROR_RESERVED_MESSAGE_TYPE	-40
#define TV_ERROR_QUEUE_FULL		-41

#define TV_ERROR_FULL_SET		-50
#define TV_ERROR_EMPTY_SET		-51

#define TV_ERROR_DEVICE_BUSY		-60
#define TV_ERROR_NOT_NAVIGATOR		-61
#define TV_ERROR_NO_EXECUTABLE		-62
#define	TV_ERROR_DEVICE_INIT		-63
#define	TV_ERROR_DEVICE_NOTOPEN		-64
#define	TV_ERROR_DEVICE_CONFIG		-65
#define	TV_ERROR_INVALID_ARG		-66
#define	TV_ERROR_NOT_READY		-67

#define	TV_ERROR_CM_CHECKSUM		-68
#define	TV_ERROR_CM_BADRSP		-69
#define	TV_ERROR_CM_BADRSPLEN		-70

#define TV_ERROR_ATM_OUT_OF_VCC		-71
#define TV_ERROR_ATM_VCC_INUSE		-72
#define TV_ERROR_ATM_DEVICE_DOWN	-73
#define TV_ERROR_ATM_INVALID_OP		-74
#define TV_ERROR_ATM_VIDEO_INUSE	-75
#define TV_ERROR_ATM_INVALID_SERVICE	-76

#define	TV_ERROR_NV_BAD_NVRAM		-77
#define	TV_ERROR_NV_VAL_TOO_LONG	-78
#define	TV_ERROR_NV_NOT_FOUND		-79
#define	TV_ERROR_NV_FULL		-80

#define TV_ERROR_LOG_BUF_EMPTY		-81

#define __TV_LAST_KERNEL_ERROR		-99

/* error code from -100 to -199 reserved for rk net */

/******************************************/

/* This bit set for messages from the kernel */
#define __TV_MSG_KERNEL               0x8000

/* Message types (from 0x8001 to 0x807F) */
/* Core kernel messages */
#define TV_MSG_DESTROY_PROCESS	0x8001
#define TV_MSG_DESTROY_THREAD	0x8002
#define TV_MSG_TIMER		0x8003
#define TV_MSG_EXCEPTION	0x8004
#define TV_MSG_EXCEPTION_REPLY	0x8005
#define TV_MSG_SHARE		0x8006
#define TV_MSG_BUFFER		0x8007
#define TV_MSG_SOIO		0x8008

/* Driver messages */
#define TV_MSG_CONTROL_PANEL	0x8020
#define TV_MSG_VIDEO_INPUT	0x8021
#define TV_MSG_NG1_RETRACE	0x8022
#define TV_MSG_SERIAL		0x8023
#define TV_MSG_AUDIO		0x8024
#define TV_MSG_DEBUG		0x8025
#define TV_MSG_KERNEL_NMTRAP	0x8026
#define TV_MSG_NETISR		0x8027
#define	TV_MSG_ADEC		0x8028
#define	TV_MSG_CLOSEDCAP	0x8029
#define TV_MSG_CENT		0x802a
#define	TV_MSG_VDEC		0x802b
#define	TV_MSG_SA		0x802c
#define	TV_MSG_BTSC		0x802d
#define	TV_MSG_TXL_CTRL		0x802e
/* last message			0x807f */

/* Send flags */
#define TV_SM_WAIT		0x1

/******************************************/

/* Capabilities */
#define TV_SHARE		1
#define TV_SEND			2
#define TV_RECEIVE		3
#define TV_SET_QUEUE_LIMIT	4
#define TV_CHANGE_SET		5
#define TV_KILL_PROCESS		6
#define TV_CHANGE_THREAD	7
#define TV_REAL_TIME		8
#define TV_PHYS_REGION		9
#define TV_DRIVER		10
#define TV_MAP_REGION		11
#define TV_CHANGE_REGION	12
#define TV_CHANGE_TIMER		13
#define TV_SET_TIME		14
#define TV_LOCK			15
#define TV_COPY_BUFFER		16
#define TV_SYSTEM		17

#define __TV_LAST_CAPABILITY_NUM	18

/******************************************/

#define TV_MAX_PROCESS_NAME_LENGTH	256

/* tvCreateThread flags */
#define TV_CT_PRIORITY_MASK	0x0000000f
#define TV_CT_REAL_TIME		0x00000010
#define TV_CT_STOP_CALLER	0x00000020
#define TV_CT_STOP_NEW_THREAD	0x00000040

/* tvGetThreadState return value when not an error */
#define TV_GTS_STOPPED		1
#define TV_GTS_RUNNABLE		2
#define TV_GTS_RUNNING		3
#define TV_GTS_WAITING		4

/* DestroyThreadMsg cause field values */
#define TV_DT_EXCEPTION		1
#define TV_DT_EXIT		2

/******************************************/

/* Exception causes */
#define TV_EXC_MEMORY_ALIGNMENT		0
#define TV_EXC_MEMORY_BOUNDS		1
#define TV_EXC_MEMORY_ACCESS		2
#define TV_EXC_ILLEGAL_INSTRUCTION	3
#define TV_EXC_TRACE_INSTRUCTION	4
#define TV_EXC_PRIV_INSTRUCTION		5
#define TV_EXC_BREAKPOINT_INSTRUCTION	6
#define TV_EXC_FLOATING_POINT		7

/* Exception responses */
#define TV_EXC_RETRY			0
#define TV_EXC_ABORT			1
#define TV_EXC_SET_PC			2

/******************************************/

/* Region flags */
#define TV_CR_RO		0x0000
#define TV_CR_RW		0x0001
#define TV_CR_EXEC		0x0002
#define TV_CR_PHYS		0x0004

/******************************************/

/* tvCreateTimer flags */
#define TV_CT_ONE_SHOT		0x0001
#define TV_CT_NO_STOP_MSG	0x0002

/* TimerMsg "why" values */
#define TV_TM_TICKED	1
#define TV_TM_STOPPED	2

/******************************************/

/* BufferMsg "why" values */
#define TV_BUF_READY	1
#define TV_BUF_DONE	2

/******************************************/

/* TVSoioMsg "why" values */
#define TV_SO_EXCP	1
#define TV_SO_RCV	2
#define TV_SO_SND	3

/******************************************/

/* Debug Message reasons */
#define TV_DEBUG_PACKET 	1
#define TV_DEBUG_EVENT  	2
#define TV_DEBUG_SETLOG  	3
#define TV_DEBUG_CLEARLOG  	4
#define TV_DEBUG_LISTLOG  	5
#define TV_DEBUG_FLUSHLOG  	6

/******************************************/

/* Type code for using trap instructions */
#define TV_TRAP_LOG_EVENT0	0
#define TV_TRAP_LOG_EVENT1	1
#define TV_TRAP_LOG_EVENT2	2
#define TV_TRAP_LOG_EVENT3	3
#define TV_TRAP_LOG_KDATA1	4
#define TV_TRAP_LOG_KDATA2	5
#define TV_TRAP_LOG_KDATA3	6

/* These are codes for slow traps */
#define TV_TRAP_CODE_SLOW	7

#define TV_TRAP_LOG_DATA	7
#define TV_TRAP_LOG_FLUSH	8

/* Total number of trap code */
#define	TV_TRAP_CODE_LAST	9

/******************************************/

#ifndef _LANGUAGE_ASSEMBLY

#ifdef __cplusplus
extern "C" {
#endif

typedef short TVshort;
typedef long TVlong;
typedef unsigned long TVulong;

typedef struct {
    unsigned long sec;			/* seconds */
    unsigned long nsec;			/* nano-seconds */
} TVTime;

/************************************************************************/

/*
** Kernel messages
*/

/* Generic message struct */
typedef struct {
    TVushort type;
    TVuchar opaqueData[32 - sizeof(TVushort)];
} TVMessage;

/*
** Message sent to process object when a share is done. The message is
** sent to the process that is gaining an id. shareID is the id that
** can now be used while processID is the id of the process that did
** the share (processID can also be used).
*/
typedef union {
    struct {
	TVushort type;
	TVushort reserved;
	TVid shareID;
	TVid processID;
    } msg;
    TVMessage notused;
} TVShareMsg;

/*
** The DestroyProcess message is sent to the creator of the process that
** is being destroyed.
*/
typedef union {
    struct {
	TVushort type;
	TVushort reserved;
	TVid pid;
    } msg;
    TVMessage notused;
} TVDestroyProcessMsg;

/*
** The DestroyThread message is sent to the the process that owns the
** thread when the thread is being destroyed.
*/
typedef union {
    struct {
	TVushort type;
	TVushort why;
	TVushort cause;
	TVushort reserved;
	TVid tid;
	void* address;
	void* pc;
	void* sp;
    } msg;
    TVMessage notused;
} TVDestroyThreadMsg;

/*
** The Exception message is sent when a thread takes an exception.
*/
typedef union {
    struct {
	TVushort type;
	TVushort cause;
	TVid threadID;
	TVid processID;
	void* address;
	void* pc;
	void* sp;
    } msg;
    TVMessage notused;
} TVExceptionMsg;

/*
** The ExceptionReply message is sent by the threads exception handler
** in response to an Exception message.
*/
typedef union {
    struct {
	TVushort type;
	TVushort response;
	TVid threadID;
	void* pc;
    } msg;
    TVMessage notused;
} TVExceptionReplyMsg;

/*
** The Timer message is sent when a timer ticks or is stopped.
*/
typedef union {
    struct {
	TVushort type;
	TVushort why;
	TVid timer;
	TVTime time;
    } msg;
    TVMessage notused;
} TVTimerMsg;

/*
** The Buffer message is sent when a buffer is ready for usage or when
** the buffer is done being used.
*/
typedef union {
    struct {
	TVushort type;
	TVushort why;
	TVid buffer;
	int len;
    } msg;
    TVMessage generic;
} TVBufferMsg;

/*
** The Socket IO message is sent when data are ready to be received.
** sockID is the socket id where the data are available.
*/
typedef union {
    struct {
	TVushort type;
	TVushort why;
	TVid sockID;
    } msg;
    TVMessage notused;
} TVSoioMsg;

/*
** This message is for the ATMMisc thread to do Tx Level Ctrl which
** may require a message to be sent to the ctrl micro and the ATMMain
** cannot do this because it may be put to sleep by the io_sa driver.
*/
typedef union {
    struct {
	TVushort type;
	TVushort why;
	TVuchar measuredLevel;
    } msg;
    TVMessage generic;
} TVTxLevelCtrlMsg;

/************************************************************************/

/*
** Id's
*/
extern int tvDestroyID(TVid ppid);
extern TVid tvShare(TVid obj, TVid withProcess, const short* caps,
		    const TVShareMsg* msg);
extern int tvGetNumCapabilities(TVid object);
extern int tvGetCapabilities(TVid object, short* caps, int numCaps);

/************************************************************************/

/*
** ID set's
*/
extern TVid tvCreateSet(int maxsize);
extern int tvAddElement(TVid set, TVid add);
extern int tvRemoveElement(TVid set, TVid remove);
extern int tvGetSetSize(TVid set);
extern int tvGetSetElements(TVid set, TVid* buf, int numids);

/************************************************************************/

/*
** Queue's
*/
extern TVid tvCreateQueue(int limit);
extern int tvGetQueueLimit(TVid id);
extern int tvSetQueueLimit(TVid id, int newLimit);

/************************************************************************/

/*
** Lock's
*/
extern TVid tvCreateLock(int startLocked);
extern int tvLock(TVid lock);
extern int tvUnlock(TVid lock);
extern int tvTryLock(TVid lock);
extern int tvTestLock(TVid lock);

/************************************************************************/

extern int tvSend(TVid to, const TVMessage* msg, TVid replyTo, int flags);
extern int tvReceive(TVid from, TVMessage* msg, TVid* replyID);
extern int tvPoll(TVid from);

/************************************************************************/

/*
** Processes
*/
extern TVid tvCreateProcess(const char *processName,
			    const short* newProcessCapabilities,
			    void (*startAddress)(void* arg), void* arg,
			    double* sp, int flags);
extern int tvKillProcess(TVid process);
extern int tvStartProcess(TVid process);
extern int tvStopProcess(TVid process);
extern TVid tvGetProcessID(void);
extern TVid tvGetThreadSet(void);
extern TVid tvGetRegionSet(void);
extern int tvGetRegionVirtualAddress(TVid process, TVid region, void** addr);
extern int tvGetProcessName(TVid process, char *buf, int buflen);

/************************************************************************/

/*
** Threads
*/
extern TVid tvCreateThread(void (*startAddress)(void* arg), void* arg,
			   double* sp, int flags);
extern TVid tvGetThreadID(void);
extern int tvStartThread(TVid thread);
extern int tvStopThread(TVid thread);
extern int tvGetThreadState(TVid thread);
extern int tvSetPriority(TVid thread, int priorityFlags);
extern int tvGetPriority(TVid thread);
extern void tvYield(void);
extern int tvSetHandler(TVid proc, TVid handler);
extern TVid tvGetHandler(TVid proc);
extern int tvSetTLSAddr(TVid tid, void *vaddr);
extern void *tvGetTLSAddr(void);

/************************************************************************/

/*
** Regions
*/
extern TVid tvCreateRegion(int size, int flags, void* paddr);
extern int tvMapRegion(TVid process, TVid region, void* vaddr);
extern int tvUnmapRegion(TVid process, TVid region);
extern int tvChangeRegion(TVid region, int flags);
extern int tvGetRegionFlags(TVid region);
extern int tvResizeRegion(TVid region, int newSize);
extern int tvGetRegionSize(TVid region);
extern int tvGetRegionPhysicalAddress(TVid region, void **addr);

/************************************************************************/

/*
** Timers
*/
extern TVid tvCreateTimer(const TVTime* duration, int flags);
extern int tvStartTimer(TVid timer, TVid destination);
extern int tvStopTimer(TVid timer);
extern int tvSetDuration(TVid timer, const TVTime* newDuration);
extern int tvGetDuration(TVid timer, TVTime* result);
extern int tvChangeTimer(TVid timer, int newFlags);
extern int tvGetTimerFlags(TVid timer);
extern int tvGetCurrentTime(TVTime* tv);
extern int tvSetCurrentTime(const TVTime* newTime);

/************************************************************************/

/*
** Buffers
*/
extern TVid tvCreateBuffer(TVid region, int offset, int len);
extern int tvGetBufferLength(TVid id);
extern int tvCopyBuffer(TVid id, int offset, void* dest, int len);

/************************************************************************/

#ifdef __cplusplus
}
#endif

#endif /* _LANGUAGE_ASSEMBLY */

#endif /* __TV_rkapi_h_ */