static ssize_t lirc_write(struct file * file, const char * buf, size_t n, loff_t * pos) { int i; int retval; if(n%sizeof(lirc_t) || (n/sizeof(lirc_t)) > WBUF_LEN) return(-EINVAL); retval = verify_area(VERIFY_READ, buf, n); if (retval) return retval; copy_from_user(tx_buf, buf, n); i = 0; n/=sizeof(lirc_t); init_send(); while (1) { if (i >= n) break; if (tx_buf[i]) send_pulse(tx_buf[i]); i++; if (i >= n) break; if (tx_buf[i]) send_space(tx_buf[i]); i++; } terminate_send(tx_buf[i-1]); return n; }
/* lirc to tx */ static ssize_t lirc_write(struct file *file, const char *buf, size_t n, loff_t *ppos) { int i, count; unsigned long flags; long delta = 0; int *wbuf; if (!gpio_out_pin) { return -ENODEV; } count = n / sizeof(int); if (n % sizeof(int) || count % 2 == 0) return -EINVAL; wbuf = memdup_user(buf, n); if (IS_ERR(wbuf)) return PTR_ERR(wbuf); spin_lock_irqsave(&lock, flags); dprintk("lirc_write called, offset %d",TX_OFFSET_GPIOCHIP); for (i = 0; i < count; i++) { if (i%2) send_space(wbuf[i] - delta); else delta = send_pulse(wbuf[i]); } gpiochip->set(gpiochip, TX_OFFSET_GPIOCHIP, invert); spin_unlock_irqrestore(&lock, flags); if (count>11) { dprintk("lirc_write sent %d pulses: no10: %d, no11: %d\n",count,wbuf[10],wbuf[11]); } kfree(wbuf); return n; }
inline void send_header(struct ir_remote *remote) { if (has_header(remote)) { send_pulse(remote->phead); send_space(remote->shead); } }
static int lirc_write(struct inode *node, struct file *file, const char *buf, int n) #endif { #ifdef LIRC_SERIAL_TRANSMITTER int retval,i,count; unsigned long flags; if(n%sizeof(lirc_t)) return(-EINVAL); retval=verify_area(VERIFY_READ,buf,n); if(retval) return(retval); count=n/sizeof(lirc_t); if(count>WBUF_LEN || count%2==0) return(-EINVAL); # ifdef KERNEL_2_1 copy_from_user(wbuf,buf,n); # else memcpy_fromfs(wbuf,buf,n); # endif save_flags(flags);cli(); # ifdef LIRC_SERIAL_IRDEO /* DTR, RTS down */ on(); # endif for(i=0;i<count;i++) { if(i%2) send_space(wbuf[i]); else send_pulse(wbuf[i]); } off(); restore_flags(flags); return(n); #else return(-EBADF); #endif }
inline void send_foot(struct ir_remote *remote) { if (has_foot(remote)) { send_space(remote->sfoot); send_pulse(remote->pfoot); } }
inline void send_repeat(struct ir_remote *remote) { send_lead(remote); send_pulse(remote->prepeat); send_space(remote->srepeat); send_trail(remote); }
static ssize_t lirc_write(struct file *file, const char *buf, size_t n, loff_t *ppos) { int i, count; unsigned long flags; long delta = 0; int *wbuf; count = n / sizeof(int); if (n % sizeof(int) || count % 2 == 0) return -EINVAL; wbuf = memdup_user(buf, n); if (IS_ERR(wbuf)) return PTR_ERR(wbuf); spin_lock_irqsave(&lock, flags); for (i = 0; i < count; i++) { if (i%2) send_space(wbuf[i] - delta); else delta = send_pulse(wbuf[i]); } gpiochip->set(gpiochip, gpio_out_pin, invert); spin_unlock_irqrestore(&lock, flags); kfree(wbuf); return n; }
void send_data(struct ir_remote *remote,ir_code data,int bits,int done) { int i; int all_bits = bit_count(remote); int toggle_bit_mask_bits = bits_set(remote->toggle_bit_mask); ir_code mask; data=reverse(data,bits); if(is_rcmm(remote)) { mask=(ir_code)1<<(all_bits-1-done); if(bits%2 || done%2) { return; } for(i=0;i<bits;i+=2,mask>>=2) { switch(data&3) { case 0: send_pulse(remote->pzero); send_space(remote->szero); break; /* 2 and 1 swapped due to reverse() */ case 2: send_pulse(remote->pone); send_space(remote->sone); break; case 1: send_pulse(remote->ptwo); send_space(remote->stwo); break; case 3: send_pulse(remote->pthree); send_space(remote->sthree); break; } data=data>>2; } return; } else if(is_xmp(remote))
inline void send_pre(struct ir_remote *remote) { if(has_pre(remote)) { send_data(remote,remote->pre_data,remote->pre_data_bits,0); if(remote->pre_p>0 && remote->pre_s>0) { send_pulse(remote->pre_p); send_space(remote->pre_s); } } }
inline void send_post(struct ir_remote *remote) { if(has_post(remote)) { if(remote->post_p>0 && remote->post_s>0) { send_pulse(remote->post_p); send_space(remote->post_s); } send_data(remote,remote->post_data,remote->post_data_bits, remote->pre_data_bits+remote->bits); } }
static void send_char (const unsigned char c) { int offset; offset = toupper (c) - 'A'; if (offset < 26) { do_send_morse_char (&(morse_alphabet[offset])); } else { DBG (DBG_LEVEL_ERROR, "Invalid character '%c'", c); send_space (); } }
static void send_digit (const unsigned char c) { if (c == '0') { do_send_morse_char (&(morse_number[9])); } else { int offset; offset = c - '0'; if (offset < 9) { do_send_morse_char (&(morse_number[offset - 1])); } else { DBG (DBG_LEVEL_ERROR, "Invalid digit '%c'", c); send_space (); } } }
static void terminate_send(unsigned long len) { unsigned long flags; unsigned long last = 0; last = it87_send_counter; /* make sure all necessary data has been sent */ while (last == it87_send_counter) send_space(len); /* wait until all data sent */ while ((inb(io + IT87_CIR_TSR) & IT87_CIR_TSR_TXFBC) != 0); /* then reenable receiver */ spin_lock_irqsave(&hardware_lock, flags); it87_RXEN_mask = IT87_CIR_RCR_RXEN; outb(inb(io + IT87_CIR_RCR) | IT87_CIR_RCR_RXEN, io + IT87_CIR_RCR); spin_unlock_irqrestore(&hardware_lock, flags); }
void morse_send (const char * msg, size_t msg_len) { int i; for (i = 0; i < msg_len; i++) { const unsigned char c = msg[i]; if (isalpha (c)) { send_char (c); } else if (isdigit (c)) { send_digit (c); } else { send_space (); } send_pause (); } }
static void do_send_morse_char (const morse_char_t * c) { int pos; if ((c->length == 0) || (c->length > 8)) { DBG (DBG_LEVEL_ERROR, "Invalid morse character length"); send_space (); return; } for (pos = c->length; pos > 0; pos--) { if (c->code & (1 << (pos - 1))) { tone_enable (MORSE_LONG_DURATION_MS); } else { tone_enable (MORSE_SHORT_DURATION_MS); } do_pause (MORSE_SHORT_DURATION_MS); } }
/* SECTION: Communication with user-space */ static int sir_tx_ir(struct rc_dev *dev, unsigned int *tx_buf, unsigned int count) { unsigned long flags; int i; local_irq_save(flags); for (i = 0; i < count;) { if (tx_buf[i]) send_pulse(tx_buf[i]); i++; if (i >= count) break; if (tx_buf[i]) send_space(tx_buf[i]); i++; } local_irq_restore(flags); return count; }
inline void send_data(struct ir_remote *remote,ir_code data,int bits,int done) { int i; int all_bits = bit_count(remote); ir_code mask; if(is_rcmm(remote)) { data=reverse(data,bits); mask=1<<(all_bits-1-done); if(bits%2 || done%2) { logprintf(LOG_ERR,"invalid bit number."); return; } for(i=0;i<bits;i+=2,mask>>=2) { switch(data&3) { case 0: send_pulse(remote->pzero); send_space(remote->szero); break; /* 2 and 1 swapped due to reverse() */ case 2: send_pulse(remote->pone); send_space(remote->sone); break; case 1: send_pulse(remote->ptwo); send_space(remote->stwo); break; case 3: send_pulse(remote->pthree); send_space(remote->sthree); break; } data=data>>2; } return; } data=reverse(data,bits); mask=((ir_code) 1)<<(all_bits-1-done); for(i=0;i<bits;i++,mask>>=1) { if(has_toggle_bit_mask(remote) && mask&remote->toggle_bit_mask) { data &= ~((ir_code) 1); if(remote->toggle_bit_mask_state&mask) { data |= (ir_code) 1; } } if(has_toggle_mask(remote) && mask&remote->toggle_mask && remote->toggle_mask_state%2) { data ^= 1; } if(data&1) { if(is_biphase(remote)) { if(mask&remote->rc6_mask) { send_space(2*remote->sone); send_pulse(2*remote->pone); } else { send_space(remote->sone); send_pulse(remote->pone); } } else if(is_space_first(remote)) { send_space(remote->sone); send_pulse(remote->pone); } else { send_pulse(remote->pone); send_space(remote->sone); } } else { if(mask&remote->rc6_mask) { send_pulse(2*remote->pzero); send_space(2*remote->szero); } else if(is_space_first(remote)) { send_space(remote->szero); send_pulse(remote->pzero); } else { send_pulse(remote->pzero); send_space(remote->szero); } } data=data>>1; } }
int init_send(struct ir_remote *remote,struct ir_ncode *code) { int i, repeat=0; if(is_grundig(remote) || is_goldstar(remote) || is_serial(remote) || is_bo(remote)) { logprintf(LOG_ERR,"sorry, can't send this protocol yet"); return(0); } clear_send_buffer(); if(is_biphase(remote)) { send_buffer.is_biphase=1; } if(repeat_remote==NULL) { remote->repeat_countdown=remote->min_repeat; } else { repeat = 1; } init_send_loop: if(repeat && has_repeat(remote)) { if(remote->flags&REPEAT_HEADER && has_header(remote)) { send_header(remote); } send_repeat(remote); } else { if(!is_raw(remote)) { ir_code next_code; if(code->transmit_state == NULL) { next_code = code->code; } else { next_code = code->transmit_state->code; } send_code(remote, next_code, repeat); if(has_toggle_mask(remote)) { remote->toggle_mask_state++; if(remote->toggle_mask_state==4) { remote->toggle_mask_state=2; } } send_buffer.data=send_buffer._data; } else { if(code->signals==NULL) { logprintf(LOG_ERR, "no signals for raw send"); return 0; } if(send_buffer.wptr>0) { send_signals(code->signals, code->length); } else { send_buffer.data=code->signals; send_buffer.wptr=code->length; for(i=0; i<code->length; i++) { send_buffer.sum+=code->signals[i]; } } } } sync_send_buffer(); if(bad_send_buffer()) { logprintf(LOG_ERR,"buffer too small"); return(0); } if(has_repeat_gap(remote) && repeat && has_repeat(remote)) { remote->min_remaining_gap=remote->repeat_gap; remote->max_remaining_gap=remote->repeat_gap; } else if(is_const(remote)) { if(min_gap(remote)>send_buffer.sum) { remote->min_remaining_gap=min_gap(remote)-send_buffer.sum; remote->max_remaining_gap=max_gap(remote)-send_buffer.sum; } else { logprintf(LOG_ERR,"too short gap: %u",remote->gap); remote->min_remaining_gap=min_gap(remote); remote->max_remaining_gap=max_gap(remote); return(0); } } else { remote->min_remaining_gap=min_gap(remote); remote->max_remaining_gap=max_gap(remote); } /* update transmit state */ if(code->next != NULL) { if(code->transmit_state == NULL) { code->transmit_state = code->next; } else { code->transmit_state = code->transmit_state->next; } } if((remote->repeat_countdown>0 || code->transmit_state != NULL) && remote->min_remaining_gap<LIRCD_EXACT_GAP_THRESHOLD) { if(send_buffer.data!=send_buffer._data) { lirc_t *signals; int n; LOGPRINTF(1, "unrolling raw signal optimisation"); signals=send_buffer.data; n=send_buffer.wptr; send_buffer.data=send_buffer._data; send_buffer.wptr=0; send_signals(signals, n); } LOGPRINTF(1, "concatenating low gap signals"); if(code->next == NULL || code->transmit_state == NULL) { remote->repeat_countdown--; } send_space(remote->min_remaining_gap); flush_send_buffer(); send_buffer.sum=0; repeat = 1; goto init_send_loop; } LOGPRINTF(3, "transmit buffer ready"); return(1); }