Changeset 698
- Timestamp:
- Aug 7, 2015, 5:42:07 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/sys_handler.c
r697 r698 90 90 91 91 __attribute__((section(".kdata"))) 92 unsigned int _tty_channel _allocator = 1;92 unsigned int _tty_channel[NB_TTY_CHANNELS] = {1}; 93 93 94 94 __attribute__((section(".kdata"))) … … 744 744 int _sys_tty_alloc( unsigned int shared ) 745 745 { 746 // get a new TTY terminal index 747 unsigned int channel = _atomic_increment( &_tty_channel_allocator, 1 ); 748 746 unsigned int channel; 747 748 if ( _get_context_slot( CTX_TTY_ID ) < NB_TTY_CHANNELS ) 749 { 750 _printf("\n[GIET_ERROR] in _sys_tty_alloc() : TTY channel already allocated\n"); 751 return 0; 752 } 753 754 // get a new TTY channel 755 for ( channel = 0 ; channel < NB_TTY_CHANNELS ; channel++ ) 756 { 757 if ( !_tty_channel[channel] ) 758 { 759 _tty_channel[channel] = 1; 760 break; 761 } 762 } 749 763 if ( channel >= NB_TTY_CHANNELS ) 750 764 { 751 _atomic_increment( &_tty_channel_allocator , 0xFFFFFFFF ); 752 _printf("\n[GIET_ERROR] in _sys_tty_alloc() : not enough TTY channels\n"); 765 _printf("\n[GIET_ERROR] in _sys_tty_alloc() : no TTY channel available\n"); 753 766 return -1; 754 767 } … … 782 795 unsigned int ltid = task[task_id].ltid; 783 796 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 784 psched->context[ltid][CTX_TTY_ID] = channel; 797 798 // don't overwrite TTY_ID 799 if ( psched->context[ltid][CTX_TTY_ID] >= NB_TTY_CHANNELS ) 800 { 801 psched->context[ltid][CTX_TTY_ID] = channel; 802 } 785 803 } 786 804 } … … 797 815 int _sys_tty_release() 798 816 { 817 unsigned int channel = _get_context_slot( CTX_TTY_ID ); 818 819 if ( channel == -1 ) 820 { 821 _printf("\n[GIET_ERROR] in _sys_tty_alloc() : TTY channel already released\n"); 822 return -1; 823 } 824 799 825 // release WTI mailbox 800 if ( USE_PIC ) _ext_irq_release( ISR_TTY_RX , _get_context_slot( CTX_TTY_ID ) ); 801 802 // release one TTY terminal 803 _atomic_increment( &_tty_channel_allocator , 0xFFFFFFFF ); 826 if ( USE_PIC ) _ext_irq_release( ISR_TTY_RX , channel ); 827 828 // reset CTX_TTY_ID for all tasks in vspace 829 unsigned int vspace_id = _get_context_slot( CTX_VSID_ID ); 830 mapping_header_t *header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; 831 mapping_vspace_t *vspace = _get_vspace_base(header); 832 mapping_task_t *task = _get_task_base(header); 833 834 unsigned int task_id; 835 for (task_id = vspace[vspace_id].task_offset; 836 task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks); 837 task_id++) 838 { 839 unsigned int y_size = header->y_size; 840 unsigned int cid = task[task_id].clusterid; 841 unsigned int x = cid / y_size; 842 unsigned int y = cid % y_size; 843 unsigned int p = task[task_id].proclocid; 844 unsigned int ltid = task[task_id].ltid; 845 static_scheduler_t* psched = (static_scheduler_t*)_schedulers[x][y][p]; 846 847 // only clear matching TTY_ID 848 if ( psched->context[ltid][CTX_TTY_ID] == channel ) 849 { 850 psched->context[ltid][CTX_TTY_ID] = -1; 851 } 852 } 853 854 // release TTY channel 855 _tty_channel[channel] = 0; 804 856 805 857 return 0;
Note: See TracChangeset
for help on using the changeset viewer.