Subject Triggers and deadlock

I'm just getting to grips with my first procedures and triggers. I've
written a proc that will insert or update a record in a target table from
a source table depending on whether the record exists in the target table.
I call this from a trigger in the source table.

I've tested it and it works but sometimes I get a deadlock?

I guess I need more info that than provided by the interbase Doc's. Does
anyone know of any good pointers to information about writing triggers and
procedures for firebird?