Changeset 4019


Ignore:
Timestamp:
11/29/10 21:40:55 (10 years ago)
Author:
dingo35
Message:

ifd_smartreader.c: reverse 4015 seems to give problems on different platforms

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/csctapi/ifd_smartreader.c

    r4015 r4019  
    2525#define NUM_TXFERS 2
    2626
    27 static int number_of_smartreaders_running=0; //counts how many smartreaders are running, if 0 no libusbeventhandler needs to be called
    28 static pthread_t libusb_thread;
     27typedef struct s_reader S_READER;
    2928
    3029static bool smartreader_check_endpoint(libusb_device *usb_dev, uint8_t out_endpoint);
    3130static struct libusb_device *find_smartreader(const char*busname,const char *devname, uint8_t out_endpoint);
    32 static void smartreader_init(struct s_reader *reader, uint8_t out_endpoint);
    33 static unsigned int smartreader_determine_max_packet_size(struct s_reader *reader);
    34 static int smartreader_usb_close_internal (struct s_reader *reader);
    35 static int smartreader_usb_reset(struct s_reader *reader);
    36 static int smartreader_usb_open_dev(struct s_reader *reader);
    37 static int smartreader_usb_purge_rx_buffer(struct s_reader *reader);
    38 static int smartreader_usb_purge_tx_buffer(struct s_reader *reader);
    39 static int smartreader_usb_purge_buffers(struct s_reader *reader);
    40 static int smartreader_convert_baudrate(int baudrate, struct s_reader *reader, unsigned short *value, unsigned short *index);
    41 static int smartreader_set_baudrate(struct s_reader *reader, int baudrate);
    42 static int smartreader_setdtr_rts(struct s_reader *reader, int dtr, int rts);
    43 static int smartreader_setflowctrl(struct s_reader *reader, int flowctrl);
    44 static int smartreader_set_line_property2(struct s_reader *reader, enum smartreader_bits_type bits,
     31static void smartreader_init(S_READER *reader, uint8_t out_endpoint);
     32static unsigned int smartreader_determine_max_packet_size(S_READER *reader);
     33static int smartreader_usb_close_internal (S_READER *reader);
     34static int smartreader_usb_reset(S_READER *reader);
     35static int smartreader_usb_open_dev(S_READER *reader);
     36static int smartreader_usb_purge_rx_buffer(S_READER *reader);
     37static int smartreader_usb_purge_tx_buffer(S_READER *reader);
     38static int smartreader_usb_purge_buffers(S_READER *reader);
     39static int smartreader_convert_baudrate(int baudrate, S_READER *reader, unsigned short *value, unsigned short *index);
     40static int smartreader_set_baudrate(S_READER *reader, int baudrate);
     41static int smartreader_setdtr_rts(S_READER *reader, int dtr, int rts);
     42static int smartreader_setflowctrl(S_READER *reader, int flowctrl);
     43static int smartreader_set_line_property2(S_READER *reader, enum smartreader_bits_type bits,
    4544                            enum smartreader_stopbits_type sbit, enum smartreader_parity_type parity,
    4645                            enum smartreader_break_type break_type);
    47 static int smartreader_set_line_property(struct s_reader *reader, enum smartreader_bits_type bits,
     46static int smartreader_set_line_property(S_READER *reader, enum smartreader_bits_type bits,
    4847                           enum smartreader_stopbits_type sbit, enum smartreader_parity_type parity);
    49 static void smart_flush(struct s_reader *reader);
    50 static int smartreader_set_latency_timer(struct s_reader *reader, unsigned short latency);
    51 static void EnableSmartReader(struct s_reader *reader, int clock, unsigned short Fi, unsigned char Di, unsigned char Ni, unsigned char T,unsigned char inv, int parity);
     48static void smart_flush(S_READER *reader);
     49static int smartreader_set_latency_timer(S_READER *reader, unsigned short latency);
     50static void EnableSmartReader(S_READER *reader, int clock, unsigned short Fi, unsigned char Di, unsigned char Ni, unsigned char T,unsigned char inv, int parity);
    5251static void *ReaderThread(void *p);
    5352
     
    7574    cs_debug_mask (D_IFD,"IO:SR: Looking for device %s on bus %s",devname,busname);
    7675
    77     ret = libusb_init(NULL); //FIXME should we really init for every smartreader or only for first one?
    78     if (ret < 0) {
     76    ret = libusb_init(NULL);
     77    if (ret < 0) {
    7978        cs_log("Libusb init error : %d",ret);
    8079        return ret;
     
    128127    pthread_mutex_init(&reader->sr_config->g_read_mutex,NULL);
    129128    pthread_mutex_init(&reader->sr_config->g_usb_mutex,NULL);
    130     if (number_of_smartreaders_running++ <= 1) { //first smartreader starting needs to start readerthread
    131       ret = pthread_create(&libusb_thread, NULL, ReaderThread, (void *)(reader));
    132       if (ret) {
     129    ret = pthread_create(&reader->sr_config->rt, NULL, ReaderThread, (void *)(reader));
     130    if (ret) {
    133131        cs_log("ERROR; return code from pthread_create() is %d", ret);
    134132        return ERROR;
    135       }
    136     }
    137     return OK;
     133    }
     134
     135    return OK;
    138136}
    139137
     
    157155}
    158156
    159 static int smart_read(struct s_reader *reader, unsigned char* buff, unsigned int size, int timeout_sec)
     157static int smart_read(S_READER *reader, unsigned char* buff, unsigned int size, int timeout_sec)
    160158{
    161159
     
    285283}
    286284
    287 static int smart_write(struct s_reader *reader, unsigned char* buff, unsigned int size)
     285static int smart_write(S_READER *reader, unsigned char* buff, unsigned int size)
    288286{
    289287
     
    392390{
    393391
    394     cs_debug_mask(D_IFD,"IO:SR: Closing smarteader\n");
    395 
     392    cs_debug_mask(D_IFD,"IO:SR: Closing smarteader\n");
     393
     394    reader->sr_config->running=FALSE;
     395    pthread_join(reader->sr_config->rt,NULL);
    396396    libusb_close(reader->sr_config->usb_dev_handle);
    397     if (number_of_smartreaders_running-- <= 0) {//last reader is closed, thread must be closed also
    398       pthread_join(libusb_thread,NULL);
    399       libusb_exit(NULL);
    400     }
     397    libusb_exit(NULL);
    401398    free(reader->sr_config);
    402399    return OK;
     
    425422}
    426423
    427 static void EnableSmartReader(struct s_reader *reader, int clock, unsigned short Fi, unsigned char Di, unsigned char Ni, unsigned char T, unsigned char inv,int parity) {
     424static void EnableSmartReader(S_READER *reader, int clock, unsigned short Fi, unsigned char Di, unsigned char Ni, unsigned char T, unsigned char inv,int parity) {
    428425
    429426    int ret = 0;
     
    618615}
    619616
    620 void smartreader_init(struct s_reader *reader,uint8_t out_endpoint)
     617void smartreader_init(S_READER *reader,uint8_t out_endpoint)
    621618{
    622619    reader->sr_config->usb_dev = NULL;
     
    639636
    640637
    641 static unsigned int smartreader_determine_max_packet_size(struct s_reader *reader)
     638static unsigned int smartreader_determine_max_packet_size(S_READER *reader)
    642639{
    643640    unsigned int packet_size;
     
    687684
    688685
    689 static int smartreader_usb_close_internal (struct s_reader *reader)
     686static int smartreader_usb_close_internal (S_READER *reader)
    690687{
    691688    int ret = 0;
     
    701698
    702699
    703 int smartreader_usb_reset(struct s_reader *reader)
     700int smartreader_usb_reset(S_READER *reader)
    704701{
    705702    if (libusb_control_transfer(reader->sr_config->usb_dev_handle,
     
    720717
    721718
    722 int smartreader_usb_open_dev(struct s_reader *reader)
     719int smartreader_usb_open_dev(S_READER *reader)
    723720{
    724721    int detach_errno = 0;
     
    854851
    855852
    856 int smartreader_usb_purge_rx_buffer(struct s_reader *reader)
     853int smartreader_usb_purge_rx_buffer(S_READER *reader)
    857854{
    858855    if (libusb_control_transfer(reader->sr_config->usb_dev_handle,
     
    872869}
    873870
    874 int smartreader_usb_purge_tx_buffer(struct s_reader *reader)
     871int smartreader_usb_purge_tx_buffer(S_READER *reader)
    875872{
    876873    if (libusb_control_transfer(reader->sr_config->usb_dev_handle,
     
    889886}
    890887
    891 int smartreader_usb_purge_buffers(struct s_reader *reader)
     888int smartreader_usb_purge_buffers(S_READER *reader)
    892889{
    893890    int result;
     
    904901}
    905902
    906 static int smartreader_convert_baudrate(int baudrate, struct s_reader *reader, unsigned short *value, unsigned short *index)
     903static int smartreader_convert_baudrate(int baudrate, S_READER *reader, unsigned short *value, unsigned short *index)
    907904{
    908905    static const char am_adjust_up[8] = {0, 0, 0, 1, 0, 3, 2, 1};
     
    10241021}
    10251022
    1026 int smartreader_set_baudrate(struct s_reader *reader, int baudrate)
     1023int smartreader_set_baudrate(S_READER *reader, int baudrate)
    10271024{
    10281025    unsigned short value, index;
     
    10651062}
    10661063
    1067 int smartreader_setdtr_rts(struct s_reader *reader, int dtr, int rts)
     1064int smartreader_setdtr_rts(S_READER *reader, int dtr, int rts)
    10681065{
    10691066    unsigned short usb_val;
     
    10941091}
    10951092
    1096 int smartreader_setflowctrl(struct s_reader *reader, int flowctrl)
     1093int smartreader_setflowctrl(S_READER *reader, int flowctrl)
    10971094{
    10981095    if (libusb_control_transfer(reader->sr_config->usb_dev_handle,
     
    11111108}
    11121109
    1113 int smartreader_set_line_property2(struct s_reader *reader, enum smartreader_bits_type bits,
     1110int smartreader_set_line_property2(S_READER *reader, enum smartreader_bits_type bits,
    11141111                            enum smartreader_stopbits_type sbit, enum smartreader_parity_type parity,
    11151112                            enum smartreader_break_type break_type)
     
    11751172
    11761173
    1177 int smartreader_set_line_property(struct s_reader *reader, enum smartreader_bits_type bits,
     1174int smartreader_set_line_property(S_READER *reader, enum smartreader_bits_type bits,
    11781175                           enum smartreader_stopbits_type sbit, enum smartreader_parity_type parity)
    11791176{
     
    11831180
    11841181
    1185 void smart_flush(struct s_reader *reader)
     1182void smart_flush(S_READER *reader)
    11861183{
    11871184
     
    11941191}
    11951192
    1196 static int smartreader_set_latency_timer(struct s_reader *reader, unsigned short latency)
     1193static int smartreader_set_latency_timer(S_READER *reader, unsigned short latency)
    11971194{
    11981195    unsigned short usb_val;
     
    12801277   
    12811278    reader = (struct s_reader *)p;
     1279    reader->sr_config->running=TRUE;
    12821280
    12831281    for(idx=0; idx<NUM_TXFERS; idx++) {
     
    12961294    }
    12971295
    1298     while(number_of_smartreaders_running > 0) {
     1296    while(reader->sr_config->running) {
    12991297        ret = libusb_handle_events(NULL);
    13001298        if(ret!=0)
  • trunk/globals.h

    r4015 r4019  
    415415    int parity;
    416416    int irdeto;
     417    int running;
    417418    libusb_device *usb_dev;
    418419    libusb_device_handle *usb_dev_handle;
     
    435436    pthread_mutex_t g_read_mutex;
    436437    pthread_mutex_t g_usb_mutex;
     438    pthread_t rt;
    437439    unsigned char modem_status;
    438440} SR_CONFIG;
Note: See TracChangeset for help on using the changeset viewer.