Create launcher

Cool way to make application launcher:

1) download Ubuntu-Tweak from ubuntu-tweak.com site – you will get DEB file
2) sudo dpkg -i (DEB-file-path)
3) installation will break, don’t worry, be happy
4) sudo apt-get install -f
5) sudo apt-get install gnome-panel
6) start ubuntu-tweak from Dash
7) go to Admins > Scripts and drag Create Launcher script to left panel ( see picture )
ubuntu-tweak

Bind QUdpSocket to localhost

Well, that’s what you want ? Is it ? Maybe not.

In fact – that is what Qt document suggest – QUdpSocket Class Reference have an example of UDP Server:

udpSocket = new QUdpSocket(this);
udpSocket->bind(QHostAddress::LocalHost, 7755);
connect(udpSocket, SIGNAL(readyRead()), 
        this, SLOT(receiveDatagrams()));

I try this example with two PC – one for UDP Server and other as UDP client. Datagrams are sending correctly as I can view in WireShark utility. But Server receive nothing !

I try to open firewall, and google for few hours. Nothing. Then I look closer in WireShark – what we are receiving – we receive datagrams at IP address from local network – 192.168.1.104 and 192.168.1.112 ( my example ).

And what is LocalHost indeed ?
It is name for IP address 127.0.0.1 – everybody knows that !
So, what is the problem ?

It took one more scratch-your-head duty cycle to find out what is going on. Nobody told Qt and QUdpSocket to listen ( bind ) to IP address 192.168.1.104 or 192.168.1.112 or whatever…

That example is useless !
Do you realy want to build server that listen only to LocalHost ?
Think once again … :-)

Ubuntu RT kernel

There is LOW-LATENCY kernel avaliable via Synaptic.
It is cool if you are ok with 1 kHz rates, and can afford latency time cca. 400 micro.

If you need faster rate – up to 10 kHz – and latency time bellow 100 micro – you have to use RT kernel. Unfortunately – it can’t be find in official repos – via Synaptic. This can be problem for dummy like me.

But there is something called PPA. Sorry linux guys – I am too old to learn all variations of your repos.

Nevermind, this is procedure to install RT kernel from PPA:


sudo add-apt-repository ppa:abogani/realtime
sudo apt-get update
sudo apt-get install linux-realtime

You will need one more utility: it is called grub-customizer
So, you can switch kernel at boot.

AVR32 interrupt latency time

Atmel made great ASF framework powered by linux GCC compiler. Everything works out-of-box. No matter what IDE you use: Eclipse based ( ver 2.6 ) or VS based ( ver 6.0 ).

I have one project with EVK 1100 board as industrial PLC. It drive seven PWM output at 25 kHz rate. This frequency give 40 microseconds clock for main loop task. Main loop itself tooks about 15 microseconds. There is 25 microseconds left for interrupts. It is pretty short period.

First thing that I had to optimize is ISR routine for PWM module: I rewrite code in pure assembly. That is cool, but did not approve interrupt latency time. I had to change exception.x file that came in ASF framework for handling interrupts.

Originaly, Atmel ASF work this way:

.balign 4
.irp priority,0,1,2,3
_int\priority:
  mov r12, \priority
  call _get_interrupt_handler
  cp.w r12, 0
  movne pc, r12
  rete
.endr

I did not know this assembly directive, until I look in debuger, what you realy get with this code:

_int0:
  mov r12, 0
  call _get_interrupt_handler
  cp.w r12, 0
  movne pc, r12
  rete
_int1:
  mov r12, 1
  call _get_interrupt_handler
  cp.w r12, 0
  movne pc, r12
  rete
_int2:
  mov r12, 2
  call _get_interrupt_handler
  cp.w r12, 0
  movne pc, r12
  rete
_int3:
  mov r12, 3
  call _get_interrupt_handler
  cp.w r12, 0
  movne pc, r12
  rete

Now it make sense ! You have one block for every priority level. COOL !
Here comes possibility for hacking. Lets give PWM ISR routine highest priority LEVEL_3 and then you have to change only block for LEVEL_3
You dont mind at all for lower priority level, it can stay as is. Now we can write this:

.balign 4
.irp priority,0,1,2
_int\priority:
  mov r12, \priority
  call _get_interrupt_handler
  cp.w r12, 0
  movne pc, r12
  rete
.endr
.balign 4
_int3:
  mov r12, _lo_pwm_isr_handler
  orh r12, _hi_pwm_isr_handler
  mov pc, r12

You see – first three priority levels are same – only LEVEL_3 is changed ! There is no call to _get_interrupt_handler routine at all ! Just use one and only handler we need !

Bad news – avr-gcc compiler have no complain about global variable defined in C. But I did not get correct value. Very strange ! Never mind – I skip that part and put immidiate values in r12 register, for lo and hi part of ISR handler pointer. It is clumsy little bit – but it works !

We got FAST interrupt response, as we wanted !

EDIT ( two days later ):

ok – now I understand what is going on.

I can use C variables in assembly. but I have to know some basic. First of all, MOV command is for load IMMIDIATE values only. So – this one will not work:

mov r12, _lo_pwm_isr_handler

Here is solution:

    mov     r12, 0
    ld.w    r12, r12[_pwm_isr_handler]
    cp.w    r12, 0          
    movne   pc, r12       
    rete  

one more thing. This one is not trivial at all. If I don’t have mkII debuger I will never find what is going on. This command fire _handle_Data_Address_Read exception

    ld.w    r12, r12[_pwm_isr_handler]

and default handler for all exceptions are infinite loop – bad luck !
so – I have to change default behaviour, like this:

     .org  0x034
        // Data Address (Read).
_handle_Data_Address_Read:
		rete
        // rjmp $
  

and that’s it !
regards to all – merry hacking !

Reinstall Grub

Today I reinstall windoze on first partition of my laptop. After that I can only boot to windoze. Don’t panic. Boot from Ubuntu live CD and repair GRUB.

On first screen, when live CD boot choose TRY UBUNTU and not Install Ubuntu. After few seconds you get Ubuntu desktop. Click on Dash and type TERMINAL ( in fact you need to type only T – terminal icon will show immediately ).

Add boot-repair from ppa: repository and install it:
$ sudo add-apt-repository ppa:yannubuntu/boot-repair
$ sudo apt-get update
$ sudo apt-get install -y boot-repair
$ boot-repair
boot-repair
Boot-repair is GUI application, so you just have to click few more times.

When finished – restart PC – and that’s it !

Ubuntu and Fedora side by side

One of my clients has Ubuntu, so I have to install it – side by side with Fedora 17.

First, this is screen from GParted:
gparted

SDA1 is primary XP partition ( shame on me ).
SDA2 is extended partition where I install Ubuntu 12.04, I use help from dedo_i_medo blog
And finaly – I let Fedora use free space. Feedora made two primary partition SDA3, SDA4 for herself.
EDIT: ubuntu can’t see LVM partition, next time I will not use LVM in fedora

Making GTK3 themes

World of Gnome has serial with same name, writen by satya. First part is on this link, and second part is on this link. I think there will be more – or better to say – I hope there will be more.

Today I clone GNOME Themes from GIT. I made some changes in CSS files, compile it and replace resource file in GTK-3.0 data directory ( /usr/share/themes ). It works !

Sorry, but have no time to play with these. Maybe some other day.
Stay cool !