VZTECH / Mbed 2 deprecated main_src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers timeslice.cpp Source File

timeslice.cpp

00001 #include "timeslice.h"
00002 
00003 Timeslice::Timeslice(){                                                                                                                 
00004   for( register int i = 0; i < MAX_TIMESLICES; i++ ) timeslice[ i ] = 0;                                                         
00005 }                                                                                                                                       
00006                                                                                                                                                                                                                                                                               
00007 Timeslice::~Timeslice(){                                                                                                                
00008   // do something here                                                                                                                  
00009 }                                                                                                                                       
00010                                                                                                                                         
00011 uint8_t Timeslice::get_timeslice(){                                                                                                         
00012   for( register uint8_t i = 0; i < MAX_TIMESLICES; i++ )                                                                                
00013     if( timeslice[ i ] == 0 ){                                                                                                       
00014       timeslice[ i ] = 1;                                                                                                            
00015       return( i + 1 );                                                                                                                         
00016     }                                                                                                                                   
00017   return( 0 );                                                                                                                            
00018 }                                                                                                                                       
00019                                                                                                                                         
00020 void Timeslice::return_timeslice( uint8_t ts ){                                                                                             
00021   if( ts <= MAX_TIMESLICES  && ts > 0  ) timeslice[ ts - 1 ] = 0;                                                                                                               
00022 }
00023 
00024 void Timeslice::reset(){
00025     for( register uint8_t i = 0; i < MAX_TIMESLICES; i++ ) 
00026         timeslice[ i ] = 0;       
00027 }
00028 
00029 uint8_t Timeslice::remain_timeslices( void ){
00030     uint8_t sum = 0;
00031     for( register uint8_t i = 0; i < MAX_TIMESLICES; i++ ){
00032         if( timeslice[ i ] == 0 ) sum++;
00033     }
00034     return( sum );
00035 }