# Shutting down a usrp\_sink\_s

**URL:** <https://www.ruby-forum.com/t/shutting-down-a-usrp-sink-s/163013>\
**Category:** GNU Radio\
**Created:** [March 16, 2009, 3:44pm UTC](https://www.ruby-forum.com/t/shutting-down-a-usrp-sink-s/163013 "2009-03-16T15:44:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattias\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/74df32/32.png) [@mattias\_k](https://www.ruby-forum.com/u/mattias_k)\
**Post date:** [March 16, 2009, 3:44pm UTC](https://www.ruby-forum.com/t/shutting-down-a-usrp-sink-s/163013/1 "2009-03-16T15:44:44Z")

</div>

Hi list,

I have a question regarding the shutdown procedures of c+± flow- graphs  
(using trunk r10527, ubuntu 8.10). As far as I have understood a flow-  
graph will continue until one of the blocks in it either returns -1, or  
ctrl+c is pressed.

However, if I connect a gr\_file\_source(sizeof(short),  
“./data\_to\_usrp.dat”, true) with a usrp\_sink\_s in a gr\_top\_block and do  
top\_block-\>start() the flow- graph exits as if the repeat- flag in  
gr\_file\_source wasn’t set to true.

If I on the other hand use (the same configuration) top\_block-\>start()  
the flow- graph continues until ctrl+c is pressed, but the destructor of  
top-block isn’t run, which I verified with a printf in it.  
t’t  
If I install a signal handler which catches ctrl+c and sets a flag, and  
then use (still the same configuration) uses something like:

top\_block-\>start();  
while(!signaled)  
asm(" nop");  
top\_block-\>stop();

The flow- graph is run as long as ctrl+c isn’t pressed and the  
destructor of top\_block is run as well.

Why is the destructor so important? It’s important because if I don’t  
add the two following statements in there:

d\_tx0-\>write\_io (d\_side, -129, 224);  
d\_tx0-\>write\_io (d\_side, -129, 128);  
(where d\_tx0 is a usrp\_sink\_s\_sptr)

I end up with a pike in the spectrum at the tuned center frequency.

I have basically worked my way from the c++ dial- tone example, which  
imo. is illustrative.

I guess my question is how do I shut down a usrp1 correctly from c++?

Best regards  
//Mattias

---

<div class="post-metadata">

**Author:** ![mattias\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/74df32/32.png) [@mattias\_k](https://www.ruby-forum.com/u/mattias_k)\
**Post date:** [March 16, 2009, 5:11pm UTC](https://www.ruby-forum.com/t/shutting-down-a-usrp-sink-s/163013/2 "2009-03-16T17:11:50Z")

</div>

On Mon, Mar 16, 2009 at 7:43 AM, Mattias K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If I install a signal handler which catches ctrl+c and sets a flag, and then  
> use (still the same configuration) uses something like:
> 
> top\_block-\>start();  
> while(!signaled)  
> asm(" nop");  
> top\_block-\>stop();
> 
> The flow- graph is run as long as ctrl+c isn’t pressed and the destructor of  
> top\_block is run as well.

This is the right way. Unless you call top\_block.run(), you are  
responsible for your own SIGINT handler.

> Why is the destructor so important? It’s important because if I don’t add  
> the two following statements in there:
> 
> d\_tx0-\>write\_io (d\_side, -129, 224);  
> d\_tx0-\>write\_io (d\_side, -129, 128);  
> (where d\_tx0 is a usrp\_sink\_s\_sptr)
> 
> I end up with a pike in the spectrum at the tuned center frequency.

This is an open bug (ticket #348), not your code. It’s not clear yet  
why it happens, but one theory is that we are shutting down the USRP  
transmit pipeline before it has a chance to drain, and leaving a DC  
value as input to the CORDIC, resulting in a carrier tone. Your  
workaround is appropriate.

Johnathan

---

<div class="post-metadata">

**Author:** ![mattias\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/74df32/32.png) [@mattias\_k](https://www.ruby-forum.com/u/mattias_k)\
**Post date:** [March 17, 2009, 1:43am UTC](https://www.ruby-forum.com/t/shutting-down-a-usrp-sink-s/163013/3 "2009-03-17T01:43:49Z")

</div>

On Mon, Mar 16, 2009 at 09:09:57AM -0700, Johnathan C. wrote:

> > The flow- graph is run as long as ctrl+c isn’t pressed and the destructor of  
> > top\_block is run as well.
> 
> This is the right way. Unless you call top\_block.run(), you are  
> responsible for your own SIGINT handler.

Setting up your own signal handler is required, though it would be  
better if you used sigwait instead of burning up cycles in your busy  
loop.

Eric
