Bit Fields April 14, 2012 at 11:30 am

Bit Fields allow the packing of data in a structure. This is especially useful when memory or data storage is at a premium. Typical examples:

Packing several objects into a machine word. e.g. 1 bit flags can be compacted — Symbol tables in compilers.
Reading external file formats — non-standard file formats could be read in. E.g. 9 bit integers.

C lets us do this in a structure definition by putting :bit length after the variable. i.e.

struct packed_struct {
unsigned int f1:1;
unsigned int f2:1;
unsigned int f3:1;
unsigned int f4:1;
unsigned int type:4;
unsigned int funny_int:9;
} pack;

Here the packed_struct contains 6 members: Four 1 bit flags f1..f3, a 4 bit type and a 9 bit funny_int.

C automatically packs the above bit fields as compactly as possible, provided that the maximum length of the field is less than or equal to the integer word length of the computer. If this is not the case then some compilers may allow memory overlap for the fields whilst other would store the next field in the next word (see comments on bit fiels portability below).

Access members as usual via:

pack.type = 7;

NOTE:
Only n lower bits will be assigned to an n bit number. So type cannot take values larger than 15 (4 bits long).
Bit fields are always converted to integer type for computation.
You are allowed to mix “normal” types with bit fields.
The unsigned definition is important – ensures that no bits are used as a flag.

Lihtsalt eneseupitamiseks March 10, 2012 at 10:15 am

mdadm how to repair degraded raid device March 6, 2012 at 4:38 pm


[16:55:57 root@xen1 ~ :/root]# mdadm --detail /dev/md2
/dev/md2:
Version : 0.90
Creation Time : Wed Apr 13 13:26:33 2011
Raid Level : raid1
Array Size : 9213120 (8.79 GiB 9.43 GB)
Used Dev Size : 9213120 (8.79 GiB 9.43 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 2
Persistence : Superblock is persistent

Update Time : Tue Mar 6 16:55:41 2012
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 1
Spare Devices : 0

UUID : c19b28c1:ecbdf4f8:1a597600:a2292b4d
Events : 0.55948

Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 0 0 1 removed

2 8 17 - faulty spare /dev/sdb1

[16:56:01 root@xen1 ~ :/root]# mdadm --remove /dev/md2 /dev/sdb1
mdadm: hot removed /dev/sdb1
[16:56:37 root@xen1 ~ :/root]# mdadm --detail /dev/md2
/dev/md2:
Version : 0.90
Creation Time : Wed Apr 13 13:26:33 2011
Raid Level : raid1
Array Size : 9213120 (8.79 GiB 9.43 GB)
Used Dev Size : 9213120 (8.79 GiB 9.43 GB)
Raid Devices : 2
Total Devices : 1
Preferred Minor : 2
Persistence : Superblock is persistent

Update Time : Tue Mar 6 16:56:37 2012
State : clean, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 0
Spare Devices : 0

UUID : c19b28c1:ecbdf4f8:1a597600:a2292b4d
Events : 0.55948

Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 0 0 1 removed

[16:56:40 root@xen1 ~ :/root]# mdadm --add /dev/md2 /dev/sdb1
mdadm: re-added /dev/sdb1
[16:57:08 root@xen1 ~ :/root]# mdadm --detail /dev/md2
/dev/md2:
Version : 0.90
Creation Time : Wed Apr 13 13:26:33 2011
Raid Level : raid1
Array Size : 9213120 (8.79 GiB 9.43 GB)
Used Dev Size : 9213120 (8.79 GiB 9.43 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 2
Persistence : Superblock is persistent

Update Time : Tue Mar 6 16:57:06 2012
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 0
Spare Devices : 1

Rebuild Status : 2% complete

UUID : c19b28c1:ecbdf4f8:1a597600:a2292b4d
Events : 0.55948

Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 8 17 1 spare rebuilding /dev/sdb1

vim and tags March 5, 2012 at 4:03 pm

Taagid on vim puhul hämmastavad asjad. Oleme näinud samalaatset asja suurte, kallite ja tööjaama koormavate IDE’e puhul. Põhimõtteliselt on tegu süsteemiga, kus sa saad suvalises failis olles otsida ja liikuda kiirelt, kas samas falis või mõnes teises failis oleva koha peale.

Kiire demo.

Loome kaks faili: fail.c ja fail2.c
fail1.c on sisuga:

void kala(void) {
// sisu
}

fail2.c on sisuga:

void maja(void) {
// sisu
}

nüüd teeme ctags *.c

Avame faili vim fail1.c ja teeme :tag maja. Ja voila! Me oleme kenasti failis fail2 funktsiooni maja juures. Tehes nüüd :tag kala satume tagasi faili1 funktsiooni kala juurde.

Rauda tagumas March 4, 2012 at 9:46 pm

Infotehnoloogiat poleks ilma raudvarata. Raud on vahel kallis, eriti pisikesed pudinad. Lahendueks on vajaliku rauajubina ise tegemine.
Plaan on valmis taguda temperatuuri ja niiskusandur, mis saadab andmed kodus asuvasse kesksesse vastuvõtjasse (wireless), mis omakorda saadav andmed internetti monitooringuserverisse. Alustasime Ulluga täna peale. Paar pilti ka lisaks. Kui kokku saab siis ka tehnilisi parameetred juurde

 

Trükiplaat (by dbweb design), raadio (RFM12B HopeRF wireless module – 868 MHz), mikorokontroller (Atmel ATmega328), temperatuuri- ja niiskuseandur (SHT11), resonaator(keraamiline) ja kaks kontentsaatorit sisendpinge silusmiseks,  kuna jubin hakkab istuma vooluvõrgus.

 





Arvamusliider February 16, 2012 at 12:28 pm

Seoses sotsiaalmeedia integreeritusele ja laiale levikule on jõudu kogumas väliend “Arvamusliider” oma uues tähenduses. Positiivne on see, et on olemas sellised tehnilised vahendid. Negatiivne see, et suurem osa nn arvamusliidreid, keda mina tean , on lihtsalt virisejad igas eluvaldkonnas, mille taustast neil õrna aimugi ei ole.

See on minu tervitus “Arvamusliidritele”

ERROR: Date::Manip unable to determine TimeZone. February 10, 2012 at 7:42 am

CentOS release 6.2 (Final)

logwatch gave me:

ERROR: Date::Manip unable to determine TimeZone. Execute the following command in a shell prompt: perldoc Date::Manip The section titled TIMEZONES describes valid TimeZones and where they can be defined.

Temporary solution was in me case:

export DATE_MANIP=DM5

 

 

MSP430G2231 and USI SPI January 31, 2012 at 10:44 pm

Veetsin mõnegi õhtu, et saada toimivat, minu kontrolli all olevat, USI SPI clock ja data signaali. Nüüd on esimene pääsuke olemas.

Selle tõestuseks, kollane on clock ja sinine minu test data (10000010)


23
24 #include
25
26
27 void main(void)
28 {
29 WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
30 P1OUT = 0;
31 P1DIR |= 0x03;
32 USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI master
33 USICTL1 |= USIIE; // Counter interrupt, flag remains set
34 USICKCTL = USIDIV_2 + USISSEL_2; // /4 SMCLK
35 P1OUT |= BIT6; // set cs
36 USICTL0 &= ~USISWRST; // USI released for operation
37 USICNT = 8; // init-load counter
38 _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
39 }
40
41 // USI interrupt service routine
42 //#pragma vector=USI_VECTOR
43 //__interrupt void universal_serial_interface(void)
44 void universal_serial_interface(void) __attribute__((interrupt(USI_VECTOR)));
45 void universal_serial_interface(void) {
46 USISRL = 0b10000010; // test output data
47 USICNT = 8; // re-load counter
48 }

msp430g2231 timer output modes sheet January 20, 2012 at 10:33 am

Palju rõõmus stringist “He” January 14, 2012 at 9:43 pm

Kui arvasin, et ei saa sügavamale minna, siis eksisin. Nüüd on mul lõbutsemiseks veel kola :) Antud juhul toimub UART kaudu stringi “Se” avastamine ka “ossiga”