Arm the devp-pccard server
#include <sys/pccard.h> int pccard_arm( pccard_t handle, int devtype, unsigned event, int coid );
libpccard
Use the -l pccard option to qcc to link against this library.
The pccard_arm() function call is used to request that the devp-pccard server notify the user application, via a pulse, when the specified event occurs.
/* * Ask to be informed when a Network card is inserted */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys/neutrino.h> #include <sys/pccard.h> int main (void) { pccard_t handle; int chid, coid; char buf [10]; struct _pccard_info io; if ((handle = pccard_attach (0)) == -1) { printf ("Unable to attach to PCCARD\n"); exit (EXIT_FAILURE); } if ((chid = ChannelCreate (_NTO_CHF_FIXED_PRIORITY)) == -1) { printf ("Unable to create channel\n"); exit (EXIT_FAILURE); } if ((coid = ConnectAttach (0, 0, chid, _NTO_SIDE_CHANNEL, 0)) == -1) { printf ("Unable to ConnectAttach\n"); exit (EXIT_FAILURE); } if (pccard_arm (handle, _PCCARD_DEV_NETWORK, _PCCARD_ARM_INSERT_REMOVE, coid) == -1) { perror ("Arm failed"); exit (EXIT_FAILURE); } /* To be informed about any card insertion/removal event, * change _PCCARD_DEV_NETWORK to _PCCARD_DEV_ALL. */ /* * MsgReceive (chid, ....); * Other user logic... */ /* Get information from socket 0 - function 0 */ if (pccard_info (handle, 0, &io, sizeof (io)) == -1) { perror ("Info failed"); exit (EXIT_FAILURE); } if (io.flags & _PCCARD_FLAG_CARD) { printf ("Card inserted in socket 1 - Type %x\n", io.window [0].device & 0xff00); /* Now lock the card in socket 1 with exclusive access */ if (pccard_lock (handle, 0, 0, O_RDWR | O_EXCL) == -1) { perror ("Lock failed"); exit (EXIT_FAILURE); } /* Read 2 bytes of the CIS from offset 0 in attribute memory */ if (pccard_raw_read (handle, 0, _PCCARD_MEMTYPE_ATTRIBUTE, 0, 2, buf) == -1) { perror ("Raw read"); exit (EXIT_FAILURE); } /* More user logic... */ } pccard_unlock (handle, 0, 0); pccard_detach (handle); return (EXIT_SUCCESS); }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
pccard_attach(), pccard_detach(), pccard_info(), pccard_lock(), pccard_raw_read(), pccard_unlock()