Custom Channel unload cleanup

We are developing an Asterisk channel to our voice cards.

Almost all job are done, but my voice card library/devide driver needs that the program (the channel in this case) call a shutdown() function. This is a behaviour of my library.

In the channel´s unload_module() routine I was put this shutdown() call. If, in Asterisk console, I call unload the unload_module routine are called and all works well, but when I call stop gracefully/now directly, the unload_module() routine aren´t called.

My question is: How can I do a nice cleanup when the asterisk is stopped. As far I can see, Asterisk didn´t call the unload_module() of all channels , too.