Skip to content

Commit

Permalink
Trim trailing white spaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
gseqBE committed Jan 7, 2025
1 parent 4169c22 commit 6f35c15
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
24 changes: 12 additions & 12 deletions module.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ static struct tty_port port;
static int __init soft_uart_init(void)
{
printk(KERN_INFO "soft_uart: Initializing module...\n");

if (!raspberry_soft_uart_init(gpio_tx, gpio_rx))
{
printk(KERN_ALERT "soft_uart: Failed initialize GPIO.\n");
return -ENOMEM;
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
printk(KERN_INFO "soft_uart: LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0).\n");

Expand Down Expand Up @@ -148,13 +148,13 @@ static int __init soft_uart_init(void)
static void __exit soft_uart_exit(void)
{
printk(KERN_INFO "soft_uart: Finalizing the module...\n");

// Finalizes the soft UART.
if (!raspberry_soft_uart_finalize())
{
printk(KERN_ALERT "soft_uart: Something went wrong whilst finalizing the soft UART.\n");
}

// Unregisters the driver.
tty_unregister_driver(soft_uart_driver);

Expand All @@ -171,7 +171,7 @@ static void __exit soft_uart_exit(void)
static int soft_uart_open(struct tty_struct* tty, struct file* file)
{
int error = NONE;

if (raspberry_soft_uart_open(tty))
{
printk(KERN_INFO "soft_uart: Device opened.\n");
Expand All @@ -181,7 +181,7 @@ static int soft_uart_open(struct tty_struct* tty, struct file* file)
printk(KERN_ALERT "soft_uart: Device busy.\n");
error = -ENODEV;
}

return error;
}

Expand All @@ -200,7 +200,7 @@ static void soft_uart_close(struct tty_struct* tty, struct file* file)
msleep(100);
wait_time += 100;
}

if (raspberry_soft_uart_close())
{
printk(KERN_INFO "soft_uart: Device closed.\n");
Expand Down Expand Up @@ -274,19 +274,19 @@ static void soft_uart_set_termios(struct tty_struct* tty, const struct ktermios*
{
printk(KERN_ALERT "soft_uart: Invalid number of data bits.\n");
}

// Verifies the number of stop bits (it must be 1).
if (cflag & CSTOPB)
{
printk(KERN_ALERT "soft_uart: Invalid number of stop bits.\n");
}

// Verifies the parity (it must be none).
if (cflag & PARENB)
{
printk(KERN_ALERT "soft_uart: Invalid parity.\n");
}

// Configure the baudrate.
if (!raspberry_soft_uart_set_baudrate(baudrate))
{
Expand Down Expand Up @@ -356,11 +356,11 @@ static int soft_uart_ioctl(struct tty_struct* tty, unsigned int command, unsigne
case TIOCMSET:
error = NONE;
break;

case TIOCMGET:
error = NONE;
break;

default:
error = -ENOIOCTLCMD;
break;
Expand Down
44 changes: 22 additions & 22 deletions raspberry_soft_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "raspberry_soft_uart.h"
#include "queue.h"

#include <linux/gpio.h>
#include <linux/gpio.h>
#include <linux/hrtimer.h>
#include <linux/interrupt.h>
#include <linux/ktime.h>
Expand Down Expand Up @@ -37,27 +37,27 @@ static int rx_bit_index = -1;
int raspberry_soft_uart_init(const int _gpio_tx, const int _gpio_rx)
{
bool success = true;

mutex_init(&current_tty_mutex);

// Initializes the TX timer.
hrtimer_init(&timer_tx, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
timer_tx.function = &handle_tx;

// Initializes the RX timer.
hrtimer_init(&timer_rx, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
timer_rx.function = &handle_rx;

// Initializes the GPIO pins.
gpio_tx = _gpio_tx;
gpio_rx = _gpio_rx;

success &= gpio_request(gpio_tx, "soft_uart_tx") == 0;
success &= gpio_direction_output(gpio_tx, 1) == 0;

success &= gpio_request(gpio_rx, "soft_uart_rx") == 0;
success &= gpio_direction_input(gpio_rx) == 0;

// Initializes the interruption.
success &= request_irq(
gpio_to_irq(gpio_rx),
Expand All @@ -66,7 +66,7 @@ int raspberry_soft_uart_init(const int _gpio_tx, const int _gpio_rx)
"soft_uart_irq_handler",
NULL) == 0;
disable_irq(gpio_to_irq(gpio_rx));

return success;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ int raspberry_soft_uart_close(void)
* @param baudrate desired baudrate
* @return 1 if the operation is successful. 0 otherwise.
*/
int raspberry_soft_uart_set_baudrate(const int baudrate)
int raspberry_soft_uart_set_baudrate(const int baudrate)
{
period = ktime_set(0, 1000000000/baudrate);
gpiod_set_debounce(gpio_to_desc(gpio_rx), 1000/baudrate/2);
Expand All @@ -142,13 +142,13 @@ int raspberry_soft_uart_set_baudrate(const int baudrate)
int raspberry_soft_uart_send_string(const unsigned char* string, int string_size)
{
int result = enqueue_string(&queue_tx, string, string_size);

// Starts the TX timer if it is not already running.
if (!hrtimer_active(&timer_tx))
{
hrtimer_start(&timer_tx, period, HRTIMER_MODE_REL);
}

return result;
}

Expand Down Expand Up @@ -198,7 +198,7 @@ static enum hrtimer_restart handle_tx(struct hrtimer* timer)
static int bit_index = -1;
enum hrtimer_restart result = HRTIMER_NORESTART;
bool must_restart_timer = false;

// Start bit.
if (bit_index == -1)
{
Expand All @@ -209,15 +209,15 @@ static enum hrtimer_restart handle_tx(struct hrtimer* timer)
must_restart_timer = true;
}
}

// Data bits.
else if (0 <= bit_index && bit_index < 8)
{
gpio_set_value(gpio_tx, 1 & (character >> bit_index));
bit_index++;
must_restart_timer = true;
}

// Stop bit.
else if (bit_index == 8)
{
Expand All @@ -226,14 +226,14 @@ static enum hrtimer_restart handle_tx(struct hrtimer* timer)
bit_index = -1;
must_restart_timer = get_queue_size(&queue_tx) > 0;
}

// Restarts the TX timer.
if (must_restart_timer)
{
hrtimer_forward(&timer_tx, current_time, period);
result = HRTIMER_RESTART;
}

return result;
}

Expand All @@ -247,15 +247,15 @@ static enum hrtimer_restart handle_rx(struct hrtimer* timer)
int bit_value = gpio_get_value(gpio_rx);
enum hrtimer_restart result = HRTIMER_NORESTART;
bool must_restart_timer = false;

// Start bit.
if (rx_bit_index == -1)
{
rx_bit_index++;
character = 0;
must_restart_timer = true;
}

// Data bits.
else if (0 <= rx_bit_index && rx_bit_index < 8)
{
Expand All @@ -267,26 +267,26 @@ static enum hrtimer_restart handle_rx(struct hrtimer* timer)
{
character |= 0x0100;
}

rx_bit_index++;
character >>= 1;
must_restart_timer = true;
}

// Stop bit.
else if (rx_bit_index == 8)
{
receive_character(character);
rx_bit_index = -1;
}

// Restarts the RX timer.
if (must_restart_timer)
{
hrtimer_forward(&timer_rx, current_time, period);
result = HRTIMER_RESTART;
}

return result;
}

Expand Down

0 comments on commit 6f35c15

Please sign in to comment.