void Serial_initialise(void) { static bool initialised = false; if (!initialised) { initialised = true; Vector_initialise(); Event_initialise(); Watchdog_initialise(); Interrupt_type state = Interrupt_disable(); SET_BRTRD(0, CALC_BAUD(PLL_CLK, 1, SERIAL_DIVMD, CONSOLE_BPS)); REG_INT_ESIF01 |= ESRX0 | ESERR0; REG_INT_PLCDC_PSI00 |= SERIAL_CH0_INT_PRI_7; int i; for (i = 0; i < 6; ++i) { // flush FIFO register uint32_t c = REG_EFSIF0_RXD; (void)c; } REG_INT_FSIF01 = FSTX0 | FSRX0 | FSERR0; // clear the interrupt Vector_set(VECTOR_Serial_interface_Ch_0_Receive_error, receive_interrupt); Vector_set(VECTOR_Serial_interface_Ch_0_Receive_buffer_full, receive_interrupt); Interrupt_enable(state); } }
void Direction_init() { double angle = 0.; int id; for (id = 0; id < DIRECTION_POOL_SIZE; ++id) { Vector_set( &DIRECTIONS[id], cos(angle), -sin(angle) ); angle -= 2 * PI / DIRECTION_POOL_SIZE; } }
int DrawPos_new(int body_id, int qw, int qh, float ox, float oy) { int id; for (id = 0; id < DRAWPOS_POOL_SIZE; ++id) { if (!DRAWPOS[id].active) { DRAWPOS[id].phys_id = body_id; DRAWPOS[id].active = true; DRAWPOS[id].pos.w = qw; DRAWPOS[id].pos.h = qh; Vector_set(&DRAWPOS[id].offset, ox, oy); DrawPos_align(id); return id; } } POOL_OVERFLOW(DrawPos); }
// Test your vector here int main() { Vector* temp = Vector_create(); //create a vector Vector_append( temp, "a");//1 Vector_append( temp, "b");//2 Vector_append( temp, "c");//3 Vector_append( temp, "d");//4 Vector_append( temp, NULL);//5 Vector_append( temp, "f");//6 Vector_append( temp, "g");//7 Vector_append( temp, NULL);//8 Vector_append( temp, "");//9 Vector_append( temp, "h");//10 Vector_append( temp, "i");//11 Vector_append( temp, NULL);//12 Vector_resize( temp, 20 ); if( Vector_size(temp) != 20 || strcmp( Vector_get( temp, 10 ), "i" ) || Vector_get( temp, 15 ) != NULL ) perror( "something wrong.\n"); //done for append, resize, get, size Vector_set( temp, 19, "caibi" ); Vector_insert( temp, 20, "niubi" ); Vector_insert( temp, 30, "wori" ); if( Vector_size(temp) != 31 || strcmp( Vector_get( temp, 19 ), "caibi" ) || strcmp( Vector_get( temp, 20 ), "niubi" ) || Vector_get( temp, 15 ) != NULL || strcmp( Vector_get( temp, 30 ), "wori" ) ) perror( "something wrong.\n"); Vector_delete( temp, 11 ); Vector_delete( temp, 27 ); Vector_delete( temp, 1 ); Vector_delete( temp, 18 ); if( Vector_size(temp) != 27 || strcmp( Vector_get( temp, 4 ), "f" ) || strcmp( Vector_get( temp, 26 ), "wori") || Vector_get( temp, 18 ) !=NULL || strcmp( Vector_get( temp, 17 ), "caibi") ) perror( "something wrong.\n"); Vector_destroy( temp ); return 0; }
/** * Push a value to the back of the vector * * @param Vector *v * @param VectorItem value */ void Vector_push(Vector* v, VectorItem value) { return Vector_set(v, v->length, value); }