mtkernel_3/lib/libtm/libtm.c | bare source | permlink (0.02 seconds) |
1: /* 2: *---------------------------------------------------------------------- 3: * micro T-Kernel 3.00.03 4: * 5: * Copyright (C) 2006-2021 by Ken Sakamura. 6: * This software is distributed under the T-License 2.2. 7: *---------------------------------------------------------------------- 8: * 9: * Released by TRON Forum(http://www.tron.org) at 2021/03/31. 10: * 11: *---------------------------------------------------------------------- 12: */ 13: 14: /* 15: * libtm.c 16: * T-Monitor compatible calls library 17: */ 18: #include <tk/tkernel.h> 19: #include <tm/tmonitor.h> 20: 21: #if USE_TMONITOR 22: #include "libtm.h" 23: 24: /* 25: * libtm_init() - libtm Initialize 26: * supported only on wait != 0 (polling not supported) 27: */ 28: EXPORT void libtm_init(void) 29: { 30: tm_com_init(); 31: } 32: 33: /* 34: * tm_getchar() - Get Character 35: * supported only on wait != 0 (polling not supported) 36: */ 37: EXPORT INT tm_getchar( INT wait ) 38: { 39: UB p; 40: UINT imask; 41: 42: DI(imask); 43: tm_rcv_dat(&p, 1); 44: EI(imask); 45: 46: return (INT)p; 47: } 48: 49: /* 50: * tm_getline() - Get Line 51: * special key is not supported 52: */ 53: EXPORT INT tm_getline( UB *buff ) 54: { 55: UB* p = buff; 56: int len = 0; 57: static const char LF = CHR_LF; 58: INT imask; 59: 60: DI(imask); 61: while (1) { 62: tm_rcv_dat(p, 1); 63: tm_snd_dat(p, 1); /* echo back */ 64: if (*p == CHR_CR) { 65: tm_snd_dat((const UB*)&LF, 1); 66: break; 67: } else if (*p == CHR_ETX) { 68: len = -1; 69: break; 70: } 71: p++; len++; 72: } 73: *p = 0x00; 74: EI(imask); 75: 76: return len; 77: } 78: 79: /* 80: * tm_putchar() 81: * Ctrl-C is not supported 82: */ 83: EXPORT INT tm_putchar( INT c ) 84: { 85: static const char CR = CHR_CR; 86: UB buf = (UB)c; 87: INT imask; 88: 89: DI(imask); 90: if (buf == CHR_LF) { 91: tm_snd_dat((const UB*)&CR, 1); 92: } 93: tm_snd_dat(&buf, 1); 94: EI(imask); 95: 96: return 0; 97: } 98: 99: /* 100: * tm_putstring() - Put String 101: * Ctrl-C is not supported 102: */ 103: EXPORT INT tm_putstring( const UB *buff ) 104: { 105: const UB* p = buff; 106: INT imask; 107: 108: DI(imask); 109: while ( *p != (UB)'\0' ) { 110: tm_putchar(*p++); 111: } 112: EI(imask); 113: 114: return 0; 115: } 116: 117: #endif /* USE_TMONITOR */