![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: ring_buffer.cpp
- Revision:
- 114:472502b31a12
- Parent:
- 113:db67ae00550e
- Child:
- 116:39a41ebb675c
diff -r db67ae00550e -r 472502b31a12 ring_buffer.cpp --- a/ring_buffer.cpp Thu Apr 16 12:57:13 2015 +0000 +++ b/ring_buffer.cpp Mon Apr 20 14:40:09 2015 +0000 @@ -6,7 +6,7 @@ rb->begin = 0; rb->end = 0; rb->size = 0; - rb->data = ( uint8_t * )malloc( sizeof( uint8_t ) * CB_BUFFER_SIZE * RING_BUFFER_SIZE ); + rb->data = ( uint8_t * )malloc( sizeof( uint8_t ) * __CB_BUFFER_SIZE__ * RING_BUFFER_SIZE ); return( rb ); }else return( rb ); } @@ -28,7 +28,7 @@ if( rb->size >= RING_BUFFER_SIZE ) return 0x01; else{ - rb_xmemcpy( rb->data + ( CB_BUFFER_SIZE * rb->end ), data, CB_BUFFER_SIZE ); + rb_xmemcpy( rb->data + ( __CB_BUFFER_SIZE__ * rb->end ), data, __CB_BUFFER_SIZE__ ); if( ++( rb->end ) >= RING_BUFFER_SIZE ) rb->end = 0; rb->size++; } @@ -41,7 +41,7 @@ if( rb->size == 0 ) return( NULL ); - uint8_t * ret = rb->data + ( rb->begin * CB_BUFFER_SIZE ); + uint8_t * ret = rb->data + ( rb->begin * __CB_BUFFER_SIZE__ ); if( ++( rb->begin ) >= RING_BUFFER_SIZE ) rb->begin = 0; @@ -76,9 +76,9 @@ /* add 1 next 4 */ ring_buffer * rb = ring_buffer_init( NULL ); - uint8_t data_buff[ CB_BUFFER_SIZE ], *data = NULL; + uint8_t data_buff[ __CB_BUFFER_SIZE__ ], *data = NULL; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xab; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xab; ring_buffer_add( rb, data_buff ); assert( rb->size == 1 ); @@ -112,11 +112,11 @@ ring_buffer * rb = ring_buffer_init( NULL ); - uint8_t data_buff[ CB_BUFFER_SIZE ], *data = NULL; + uint8_t data_buff[ __CB_BUFFER_SIZE__ ], *data = NULL; bool flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xab; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xab; ring_buffer_add( rb, data_buff ); assert( rb->size == 1 ); @@ -124,14 +124,14 @@ assert( data != NULL ); assert( rb->size == 0 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0xab ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0xab ) flag = false; assert( flag == true ); - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xcc; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xcc; ring_buffer_add( rb, data_buff ); assert( rb->size == 1 ); - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xdb; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xdb; ring_buffer_add( rb, data_buff ); assert( rb->size == 2 ); @@ -139,14 +139,14 @@ assert( data != NULL ); assert( rb->size == 1 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0xcc ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0xcc ) flag = false; assert( flag == true ); data = ring_buffer_get_next( rb ); assert( data != NULL ); assert( rb->size == 0 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0xdb ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0xdb ) flag = false; assert( flag == true ); data = ring_buffer_get_next( rb ); @@ -163,11 +163,11 @@ ring_buffer * rb = ring_buffer_init( NULL ); - uint8_t data_buff[ CB_BUFFER_SIZE ], *data = NULL; + uint8_t data_buff[ __CB_BUFFER_SIZE__ ], *data = NULL; bool flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xab; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xab; ring_buffer_add( rb, data_buff ); assert( rb->size == 1 ); @@ -175,14 +175,14 @@ assert( data != NULL ); assert( rb->size == 0 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0xab ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0xab ) flag = false; assert( flag == true ); - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xcc; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xcc; ring_buffer_add( rb, data_buff ); assert( rb->size == 1 ); - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xdb; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xdb; ring_buffer_add( rb, data_buff ); assert( rb->size == 2 ); @@ -190,10 +190,10 @@ assert( data != NULL ); assert( rb->size == 1 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0xcc ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0xcc ) flag = false; assert( flag == true ); - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xdd; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xdd; ring_buffer_add( rb, data_buff ); assert( rb->size == 2 ); @@ -201,25 +201,25 @@ assert( data != NULL ); assert( rb->size == 1 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0xdb ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0xdb ) flag = false; assert( flag == true ); data = ring_buffer_get_next( rb ); assert( data != NULL ); assert( rb->size == 0 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0xdd ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0xdd ) flag = false; assert( flag == true ); - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xaa; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xaa; ring_buffer_add( rb, data_buff ); assert( rb->size == 1 ); - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xab; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xab; ring_buffer_add( rb, data_buff ); assert( rb->size == 2 ); - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xac; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xac; ring_buffer_add( rb, data_buff ); assert( rb->size == 3 ); @@ -228,24 +228,24 @@ assert( rb->size == 2 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0xaa ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0xaa ) flag = false; assert( flag == true ); data = ring_buffer_get_next( rb ); assert( data != NULL ); assert( rb->size == 1 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0xab ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0xab ) flag = false; assert( flag == true ); data = ring_buffer_get_next( rb ); assert( data != NULL ); assert( rb->size == 0 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0xac ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0xac ) flag = false; assert( flag == true ); - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ){ + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ data = ring_buffer_get_next( rb ); assert( data == NULL ); assert( rb->size == 0 ); @@ -260,20 +260,20 @@ /* add 3 add 300, next 1, add 301, next 300, add 300, next 300 */ ring_buffer * rb = ring_buffer_init( NULL ); - uint8_t data_buff[ CB_BUFFER_SIZE ], *data = NULL; + uint8_t data_buff[ __CB_BUFFER_SIZE__ ], *data = NULL; bool flag = true; // add 3 uint8_t value = 0x00; for( uint8_t count = 0; count < 3; count++ ){ - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = value; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = value; ring_buffer_add( rb, data_buff ); assert( rb->size == ( count + 1 ) ); value++; } // add 300 - for( uint16_t count = 0; count < CB_BUFFER_SIZE; count++ ){ - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = value; + for( uint16_t count = 0; count < __CB_BUFFER_SIZE__; count++ ){ + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = value; assert( ring_buffer_add( rb, data_buff ) == 0x01 ) ; assert( rb->size == RING_BUFFER_SIZE ); value++; @@ -283,17 +283,17 @@ assert( data != NULL ); assert( rb->size == 2 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0x00 ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0x00 ) flag = false; assert( flag == true ); // add 1 - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = 0xff; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = 0xff; assert( ring_buffer_add( rb, data_buff ) == 0x00 ); // add 300 value = 0xee; - for( uint16_t count = 0; count < CB_BUFFER_SIZE; count++ ){ - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = value; + for( uint16_t count = 0; count < __CB_BUFFER_SIZE__; count++ ){ + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = value; assert( ring_buffer_add( rb, data_buff ) == 0x01 ); assert( rb->size == RING_BUFFER_SIZE ); value++; @@ -304,7 +304,7 @@ assert( data != NULL ); assert( rb->size == 2 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0x01 ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0x01 ) flag = false; assert( flag == true ); //next 1 @@ -312,7 +312,7 @@ assert( data != NULL ); assert( rb->size == 1 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0x02 ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0x02 ) flag = false; assert( flag == true ); //next 1 @@ -320,19 +320,19 @@ assert( data != NULL ); assert( rb->size == 0 ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != 0xff ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != 0xff ) flag = false; assert( flag == true ); // next 300 - 3 - for( uint16_t count = 0; count < CB_BUFFER_SIZE - 3; count++ ){ + for( uint16_t count = 0; count < __CB_BUFFER_SIZE__ - 3; count++ ){ data = ring_buffer_get_next( rb ); assert( data == NULL ); } // add 300 value = 0xbb; - for( uint16_t count = 0; count < CB_BUFFER_SIZE; count++ ){ - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) data_buff[ i ] = value; + for( uint16_t count = 0; count < __CB_BUFFER_SIZE__; count++ ){ + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) data_buff[ i ] = value; if( rb->size != RING_BUFFER_SIZE ) assert( ring_buffer_add( rb, data_buff ) == 0x00 ); @@ -347,12 +347,12 @@ assert( data != NULL ); assert( rb->size == ( RING_BUFFER_SIZE - 1 - count ) ); flag = true; - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) if( data[ i ] != value ) flag = false; + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) if( data[ i ] != value ) flag = false; assert( flag == true ); value++; } - for( uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ){ + for( uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ data = ring_buffer_get_next( rb ); assert( data == NULL ); assert( rb->size == 0 );