Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

timeslice.cpp

Committer:
klauss
Date:
2015-11-24
Revision:
137:32dd35a6dbc9
Parent:
121:ee02790d00b7

File content as of revision 137:32dd35a6dbc9:

#include "timeslice.h"

Timeslice::Timeslice(){                                                                                                                 
  for( register int i = 0; i < MAX_TIMESLICES; i++ ) timeslice[ i ] = 0;                                                         
}                                                                                                                                       
                                                                                                                                                                                                                                                                              
Timeslice::~Timeslice(){                                                                                                                
  // do something here                                                                                                                  
}                                                                                                                                       
                                                                                                                                        
uint8_t Timeslice::get_timeslice(){                                                                                                         
  for( register uint8_t i = 0; i < MAX_TIMESLICES; i++ )                                                                                
    if( timeslice[ i ] == 0 ){                                                                                                       
      timeslice[ i ] = 1;                                                                                                            
      return( i + 1 );                                                                                                                         
    }                                                                                                                                   
  return( 0 );                                                                                                                            
}                                                                                                                                       
                                                                                                                                        
void Timeslice::return_timeslice( uint8_t ts ){                                                                                             
  if( ts <= MAX_TIMESLICES  && ts > 0  ) timeslice[ ts - 1 ] = 0;                                                                                                               
}

void Timeslice::reset(){
    for( register uint8_t i = 0; i < MAX_TIMESLICES; i++ ) 
        timeslice[ i ] = 0;       
}

uint8_t Timeslice::remain_timeslices( void ){
    uint8_t sum = 0;
    for( register uint8_t i = 0; i < MAX_TIMESLICES; i++ ){
        if( timeslice[ i ] == 0 ) sum++;
    }
    return( sum );
}