1
1
/*
2
2
* Pisound Linux kernel module.
3
- * Copyright (C) 2016-2019 Vilniaus Blokas UAB, https://blokas.io/pisound
3
+ * Copyright (C) 2016-2020 Vilniaus Blokas UAB, https://blokas.io/pisound
4
4
*
5
5
* This program is free software; you can redistribute it and/or
6
6
* modify it under the terms of the GNU General Public License
@@ -326,7 +326,7 @@ static void spi_transfer(const uint8_t *txbuf, uint8_t *rxbuf, int len)
326
326
transfer .tx_buf = txbuf ;
327
327
transfer .rx_buf = rxbuf ;
328
328
transfer .len = len ;
329
- transfer .speed_hz = 100000 ;
329
+ transfer .speed_hz = 150000 ;
330
330
transfer .delay_usecs = 10 ;
331
331
spi_message_add_tail (& transfer , & msg );
332
332
@@ -403,9 +403,9 @@ static struct spi_device *pisnd_spi_find_device(void)
403
403
static void pisnd_work_handler (struct work_struct * work )
404
404
{
405
405
enum { TRANSFER_SIZE = 4 };
406
- enum { PISOUND_OUTPUT_BUFFER_SIZE = 128 };
407
- enum { MIDI_BYTES_PER_SECOND = 3125 };
408
- int out_buffer_used = 0 ;
406
+ enum { PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES = 127 * 1000 };
407
+ enum { MIDI_MILLIBYTES_PER_JIFFIE = ( 3125 * 1000 ) / HZ };
408
+ int out_buffer_used_millibytes = 0 ;
409
409
unsigned long now ;
410
410
uint8_t val ;
411
411
uint8_t txbuf [TRANSFER_SIZE ];
@@ -445,7 +445,9 @@ static void pisnd_work_handler(struct work_struct *work)
445
445
had_data = false;
446
446
memset (txbuf , 0 , sizeof (txbuf ));
447
447
for (i = 0 ; i < sizeof (txbuf ) &&
448
- out_buffer_used < PISOUND_OUTPUT_BUFFER_SIZE ;
448
+ ((out_buffer_used_millibytes + 1000 <
449
+ PISOUND_OUTPUT_BUFFER_SIZE_MILLIBYTES ) ||
450
+ g_ledFlashDurationChanged );
449
451
i += 2 ) {
450
452
451
453
val = 0 ;
@@ -458,7 +460,7 @@ static void pisnd_work_handler(struct work_struct *work)
458
460
} else if (kfifo_get (& spi_fifo_out , & val )) {
459
461
txbuf [i + 0 ] = 0x0f ;
460
462
txbuf [i + 1 ] = val ;
461
- ++ out_buffer_used ;
463
+ out_buffer_used_millibytes += 1000 ;
462
464
}
463
465
}
464
466
@@ -469,12 +471,14 @@ static void pisnd_work_handler(struct work_struct *work)
469
471
* rate.
470
472
*/
471
473
now = jiffies ;
472
- out_buffer_used -=
473
- (MIDI_BYTES_PER_SECOND / HZ ) /
474
- (now - last_transfer_at );
475
- if (out_buffer_used < 0 )
476
- out_buffer_used = 0 ;
477
- last_transfer_at = now ;
474
+ if (now != last_transfer_at ) {
475
+ out_buffer_used_millibytes -=
476
+ (now - last_transfer_at ) *
477
+ MIDI_MILLIBYTES_PER_JIFFIE ;
478
+ if (out_buffer_used_millibytes < 0 )
479
+ out_buffer_used_millibytes = 0 ;
480
+ last_transfer_at = now ;
481
+ }
478
482
479
483
for (i = 0 ; i < sizeof (rxbuf ); i += 2 ) {
480
484
if (rxbuf [i ]) {
@@ -489,6 +493,7 @@ static void pisnd_work_handler(struct work_struct *work)
489
493
|| !kfifo_is_empty (& spi_fifo_out )
490
494
|| pisnd_spi_has_more ()
491
495
|| g_ledFlashDurationChanged
496
+ || out_buffer_used_millibytes != 0
492
497
);
493
498
494
499
if (!kfifo_is_empty (& spi_fifo_in ) && g_recvCallback )
0 commit comments