Re: [BLACKBOX] Call GTK from blackbox

From: [at]} <Wojtek>
Date: Sat, 29 Jan 2011 21:08:07 -0500

----boundary-LibPST-iamunique-1006108548_-_-
Content-type: text/plain

On Sat, 29 Jan 2011, Frank Hrebabetzky wrote:

> I want to use GTK with Blackbox. Therefore I must call
>
> void gtk_init (int *argc, char ***argv);
>
> What would be the corresponding interface procedure?
> Where do I get argc, argv from?

Frank:

   I do not know about gtk_init, but typically my Linux programs
start like this:

int main(int argc, char **argv)

The first argument tells the number of command-line arguments. The 2nd
argument is a pointer to array of strings, which are the arguments.

The argument #0 tells the name of the executable. Arguments #1, 2, etc are
the strings which I type at the command prompt. These strings somehow
automagically find their way into the array.

I am attaching one of my very simple command-line programs, and then the
output from the command-line call under embedded Linux running on my
Blackfin board. This is not the simplest demo, but I do not have the "as
simple as possible" version, so I am posting what I have. Hope it will
show the mechanics.

  ================= example program ===============

/* fget.c
  * Reads one 16-bit word from AMS1 memory (automatically added).
  * (C) 2010, Wojtek Skulski skulski{([at]})nowhere.xy
  *
  * Register addresses:
  * Last sample address read-only 0x2400 0002
  *
  * bfin-linux-uclibc-gcc -Wall -mfdpic -g fget.c
  * mv a.out fget
  * cp fget /home/uclinux/uClinux-dist/romfs/bin
  * sudo cp fget /mnt/win
  */
#include <stdio.h>
#include <stdlib.h>
// #include <unistd.h>
#include <string.h>
#include <errno.h>
// #include <signal.h>
// #include <fcntl.h>
// #include <ctype.h>
// #include <termios.h>
// #include <sys/types.h>
// #include <sys/mman.h>

#define FATAL do { fprintf(stderr, \
   "Error at line %d, file %s (%d) [%s]\n", \
   __LINE__, __FILE__, errno, strerror(errno));\
   exit(1); } while(0)

int main(int argc, char **argv) {
         long target; /* long int holds addr, needs a typecast*/
         short value;
         short *virt_saddr; /* typed pointer to 16-bit short */

         if(argc < 2) {
                 fprintf(stderr, "\nUsage:\t%s addr\n"
                         "\taddr : Register address in AMS1\n"
                         "\tregs : 2 = last sample address in FPGA BRAM\n",
                         argv[0]); /* 0 = name of the executable */
                 exit(1);
         }
         target = strtoul(argv[1], 0, 0); /* target address in FPGA*/
         target = target + 0x24000000; /* add AMS1 offset*/
         virt_saddr = (short *) target; /* convert target to pointer*/
         if (virt_saddr == NULL) FATAL;
         value = * virt_saddr; /* read value from address*/
         printf("Read address %p, value = 0x%04X\n", virt_saddr, value);
         return 0;
}

  ========= executing the example program

root:/> fget

Usage: fget addr
         addr : Register address in AMS1
         regs : 2 = last sample address in FPGA BRAM
root:/>
root:/> fget 2
Read address 0x24000002, value = 0x00FF
root:/>


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1006108548_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIE9uIFNhdCwgMjkgSmFuIDIwMTEsIEZyYW5rIEhy
ZWJhYmV0emt5IHdyb3RlOlxwYXINClxwYXINCj4gSSB3YW50IHRvIHVzZSBHVEsgd2l0aCBCbGFj
a2JveC4gVGhlcmVmb3JlIEkgbXVzdCBjYWxsXHBhcg0KPlxwYXINCj4gXHRhYiB2b2lkIGd0a19p
bml0IChpbnQgKmFyZ2MsIGNoYXIgKioqYXJndik7XHBhcg0KPlxwYXINCj4gV2hhdCB3b3VsZCBi
ZSB0aGUgY29ycmVzcG9uZGluZy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QgYWRkcmVzcyAw
eDI0MDAwMDAyLCB2YWx1ZSA9IDB4MDBGRlxwYXINCnJvb3Q6Lz5ccGFyDQpccGFyDQpccGFyDQot
LS0tXHBhcg0KVG8gdW5zdWJzY3JpYmUsIHNlbmQgYSBtZXNzYWdlIHdpdGggYm9keSAiU0lHTk9G
RiBCTEFDS0JPWCIgdG8gTElTVFNFUlZATElTVFMuT0JFUk9OLkNIXHBhcg0KfQ==
----boundary-LibPST-iamunique-1006108548_-_---
Received on Sun Jan 30 2011 - 03:08:07 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:18 UTC