Skip to content

Commit

Permalink
Misc code cleaning
Browse files Browse the repository at this point in the history
* Remove empty lines
* Remove dead code
* Update copyright notice
  • Loading branch information
jeanthom committed Dec 13, 2022
1 parent 75be2c3 commit bef4f6e
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 61 deletions.
20 changes: 9 additions & 11 deletions src/cmd.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2017 Jean THOMAS.
Copyright (c) 2017-2022 The DirtyJTAG authors.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
Expand All @@ -9,7 +9,7 @@
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Expand Down Expand Up @@ -98,7 +98,7 @@ static void cmd_setsig(const uint8_t *commands);
* @brief Handle CMD_GETSIG command
*
* CMD_GETSIG gets the current signal state.
*
*
* @param usbd_dev USB device
*/
static void cmd_getsig(usbd_device *usbd_dev);
Expand All @@ -115,13 +115,13 @@ static void cmd_clk(const uint8_t *commands);

uint8_t cmd_handle(usbd_device *usbd_dev, const usbd_transfer *transfer) {
uint8_t *commands= (uint8_t*)transfer->buffer;

while (*commands != CMD_STOP) {
switch ((*commands)&0x0F) {
case CMD_INFO:
cmd_info(usbd_dev);
break;

case CMD_FREQ:
cmd_freq(commands);
commands += 2;
Expand Down Expand Up @@ -171,7 +171,7 @@ static void cmd_freq(const uint8_t *commands) {
static void cmd_xfer(usbd_device *usbd_dev, const uint8_t *commands, bool extend_length, bool no_read) {
uint16_t transferred_bits;
uint8_t output_buffer[64];

/* Fill the output buffer with zeroes */
if (!no_read) {
memset(output_buffer, 0, sizeof(output_buffer));
Expand All @@ -194,8 +194,6 @@ static void cmd_xfer(usbd_device *usbd_dev, const uint8_t *commands, bool extend
}
}



static void cmd_setsig(const uint8_t *commands) {
uint8_t signal_mask, signal_status;

Expand All @@ -213,7 +211,7 @@ static void cmd_setsig(const uint8_t *commands) {
if (signal_mask & SIG_TMS) {
jtag_set_tms(signal_status & SIG_TMS);
}

if (signal_mask & SIG_TRST) {
jtag_set_trst(signal_status & SIG_TRST);
}
Expand All @@ -225,7 +223,7 @@ static void cmd_setsig(const uint8_t *commands) {

static void cmd_getsig(usbd_device *usbd_dev) {
uint8_t signal_status = 0;

if (jtag_get_tdo()) {
signal_status |= SIG_TDO;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cmd.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2017 Jean THOMAS.
Copyright (c) 2017-2022 The DirtyJTAG authors.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
Expand All @@ -9,7 +9,7 @@
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Expand Down
2 changes: 1 addition & 1 deletion src/delay.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2017 Jean THOMAS.
Copyright (c) 2017-2022 The DirtyJTAG authors.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
Expand Down
8 changes: 4 additions & 4 deletions src/delay.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2017 Jean THOMAS.
Copyright (c) 2017-2022 The DirtyJTAG authors.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
Expand All @@ -9,7 +9,7 @@
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Expand All @@ -22,7 +22,7 @@
#define _DELAY_F_CPU 72000000ULL

/**
* @brief Initialises
* @brief Initialises delay peripheral
*
* Halts code execution for a specified amount of time
* expressed in microseconds. The function was copied
Expand Down
12 changes: 6 additions & 6 deletions src/dirtyjtag.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2017 Jean THOMAS.
Copyright (c) 2017-2022 The DirtyJTAG authors.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
Expand All @@ -9,7 +9,7 @@
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Expand Down Expand Up @@ -62,7 +62,7 @@ int main(void) {
#endif

delay_init();

/* Peripherals reset/init */
rcc_periph_clock_enable(RCC_GPIOA);
rcc_periph_clock_enable(RCC_GPIOB);
Expand Down Expand Up @@ -103,9 +103,9 @@ int main(void) {
GPIO_CNF_OUTPUT_PUSHPULL, GPIO9);
gpio_clear(GPIOA, GPIO9);
#endif

jtag_init();
usb_init();

return 0;
}
42 changes: 26 additions & 16 deletions src/jtag.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
Copyright (c) 2017-2022 The DirtyJTAG authors.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <stdint.h>
#include <string.h>
#include <unicore-mx/stm32/gpio.h>
Expand Down Expand Up @@ -245,10 +266,6 @@ void jtag_set_srst(uint8_t value) {
#endif
}





void jtag_transfer_internal(uint16_t length, const uint8_t *in, uint8_t *out) {
uint32_t xfer_length, xfer_i;
const uint8_t *xfer_in;
Expand Down Expand Up @@ -285,10 +302,9 @@ void jtag_transfer_internal(uint16_t length, const uint8_t *in, uint8_t *out) {


GPIO_BSRR(JTAG_PORT_TCK) = JTAG_PIN_TCK << 16;

}
}
else
else
{
timer_set_counter(TIM2,0);
TIM_SR(TIM2) = ~TIM_SR_UIF;
Expand Down Expand Up @@ -320,11 +336,6 @@ void jtag_transfer_internal(uint16_t length, const uint8_t *in, uint8_t *out) {
xfer_i++;

GPIO_BSRR(JTAG_PORT_TCK) = JTAG_PIN_TCK << 16;





}
}

Expand Down Expand Up @@ -378,12 +389,11 @@ void jtag_transfer(uint16_t length, const uint8_t *in, uint8_t *out) {
GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_ALTFN_PUSHPULL,
JTAG_PIN_TCK | JTAG_PIN_TDI);

while (xfer_out_i < byte_length)
{

/* if the transmit reg is empty, push a byte */
/* this should make the transfer continuous */
/* this should make the transfer continuous */
if ((SPI_SR(SPI1) & SPI_SR_TXE) && (xfer_in_i < byte_length))
{
SPI_DR(SPI1) = in[xfer_in_i++];
Expand All @@ -396,16 +406,16 @@ void jtag_transfer(uint16_t length, const uint8_t *in, uint8_t *out) {
}

}

//set pins in GPIO mode
gpio_set_mode(JTAG_PORT_TCK,
GPIO_MODE_OUTPUT_50_MHZ,
GPIO_CNF_OUTPUT_PUSHPULL,
JTAG_PIN_TCK | JTAG_PIN_TDI);
}
if (remaining_length)

if (remaining_length) {
jtag_transfer_internal(remaining_length, &in[byte_length], &out[byte_length]);
}
}

#else
Expand Down
8 changes: 4 additions & 4 deletions src/jtag.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2017 Jean THOMAS.
Copyright (c) 2017-2022 The DirtyJTAG authors.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
Expand All @@ -9,7 +9,7 @@
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Expand All @@ -21,7 +21,7 @@

/**
* @brief Initialize JTAG
*
*
* Set GPIO in correct state for JTAG operation
*/
void jtag_init(void);
Expand Down
26 changes: 13 additions & 13 deletions src/usb.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2017 Jean THOMAS.
Copyright (c) 2017-2022 The DirtyJTAG authors.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
Expand All @@ -9,7 +9,7 @@
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Expand All @@ -33,7 +33,7 @@

/**
* @brief Registers the callback for incomming USB packet
*
*
* This function registers the callback which be called when
* an incomming USB packet arrives. It must be called each time
* you want to receive a USB packet.
Expand Down Expand Up @@ -136,7 +136,7 @@ const struct __attribute__((packed)) {
.bmAttributes = 0x80,
.bMaxPower = 0x32, /* 100mA current consumption */
},

.iface = {
.bLength = USB_DT_INTERFACE_SIZE,
.bDescriptorType = USB_DT_INTERFACE,
Expand All @@ -148,7 +148,7 @@ const struct __attribute__((packed)) {
.bInterfaceProtocol = 0,
.iInterface = 0,
},

.endp = {
{
.bLength = USB_DT_ENDPOINT_SIZE,
Expand Down Expand Up @@ -216,7 +216,7 @@ void usb_read_serial(void) {
static void usb_set_config(usbd_device *usbd_dev,
const struct usb_config_descriptor *cfg) {
(void)cfg;

usbd_ep_prepare(usbd_dev, DIRTYJTAG_READ_ENDPOINT, USBD_EP_BULK, 64,
USBD_INTERVAL_NA, USBD_EP_NONE);
usbd_ep_prepare(usbd_dev, DIRTYJTAG_WRITE_ENDPOINT, USBD_EP_BULK, 64,
Expand All @@ -231,7 +231,7 @@ static void usb_control_request(usbd_device *usbd_dev, uint8_t ep,

const uint8_t bmReqMask = USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT;
const uint8_t bmReqVal = USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE;

if ((setup_data->bmRequestType & bmReqMask) != bmReqVal) {
/* Pass on to usb stack internal */
usbd_ep0_setup(usbd_dev, setup_data);
Expand All @@ -250,7 +250,7 @@ void usb_init(void) {
usbd_dev = usbd_init(USBD_STM32_FSDEV, NULL, &info);
usbd_register_set_config_callback(usbd_dev, usb_set_config);
usbd_register_setup_callback(usbd_dev, usb_control_request);

while (1) {
usbd_poll(usbd_dev, 0);
}
Expand All @@ -260,7 +260,7 @@ void usb_reenumerate(void) {
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
GPIO_CNF_OUTPUT_OPENDRAIN, GPIO12);
gpio_clear(GPIOA, GPIO12);

delay_us(20000);
}

Expand All @@ -280,11 +280,11 @@ void usb_send(usbd_device *usbd_dev, uint8_t *sent_buffer, uint8_t sent_size) {
/* Packets are copied into a buffer because the operation
is done asynchronously */
memcpy(tx_usb_buffer, sent_buffer, sent_size);

usbd_transfer_submit(usbd_dev, &transfer);
}

static uint8_t submit_buffer_index = 0;
static uint8_t submit_buffer_index = 0;

static void usb_prepare_rx(usbd_device *usbd_dev) {
const usbd_transfer transfer = {
Expand All @@ -306,7 +306,7 @@ static void usb_prepare_rx(usbd_device *usbd_dev) {
static void usb_rx_callback(usbd_device *usbd_dev, const usbd_transfer *transfer,
usbd_transfer_status status, usbd_urb_id urb_id) {
(void)urb_id;

if (status == USBD_SUCCESS) {
if (transfer->transferred) {
usb_prepare_rx(usbd_dev);
Expand Down
Loading

0 comments on commit bef4f6e

Please sign in to comment.