Posts

Showing posts with the label Embedec C

Bit manipulation

a |= 0x4; /* Set bit 2 */ b &= ˜0x4; /* Clear bit 2 */ c &= ˜(1 << 3); /* Clear bit 3 */ d ˆ= (1 << 5); /* Toggle bit 5 */ e >>= 2; /* Divide e by 4 */ f <<= 2; /* Multiplay f by power 2 of 2 = 4 */

Copy array from round buffer with memcopy()

Since I started to work with embedded systems I had to start thing about pointers... A subject foreign in my previews Java development. Bellow is a small spinet of my code to copy arrays with pointers. Also the use of some Microblaze functions use are shown... void BufferMemoryCopy ( void * dest , GPS_BUFFER * buff , u16 buff_offset , u32 size ) { // Microblaze -- typedef Xuint16 u16; u16 pos = ( buff -> Tail16 + buff_offset ) & GPS_FIFO_MASK ; // Fifo mast is used in roun buffer         if ( ( pos + size ) <= GPS_FIFO_SIZE ) {         memcpy ( dest , & buff -> Buffer [ pos ] , size ) ; } else { memcpy ( dest , & buff -> Buffer [ pos ] , GPS_FIFO_SIZE - pos ) ; memcpy ( dest   + ( GPS_FIFO_SIZE - pos ) , & buff -> Buffer [ 0 ] , size - ( GPS_FIFO_SIZE - pos ) ) ;