voltando a versao de n aberturas e fechamentos de sockets data 19/09

Dependencies:   EthernetInterface NTPClient mbed-rtos mbed EALib

Fork of header_main_publish by VZTECH

timeslice.cpp

Committer:
klauss
Date:
2014-09-20
Revision:
19:ab2088e0dec6
Parent:
0:4d17cd9c8f9d

File content as of revision 19:ab2088e0dec6:

#include "timeslice.h"

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

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

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