Move M0 offset and tx variables into a state struct.

These variables are already placed together; this commit just groups
them into a struct and declares this in a new header.

This commit should not result in any change to the firmware binary.
Only the names of symbols are changed.
This commit is contained in:
Martin Ling
2021-12-20 10:18:33 +00:00
parent 39c6f3385e
commit 5b2a390728
5 changed files with 49 additions and 16 deletions

View File

@ -34,6 +34,5 @@ MEMORY
}
usb_bulk_buffer = ORIGIN(ram_usb);
usb_bulk_buffer_offset = ORIGIN(ram_shared);
usb_bulk_buffer_tx = ORIGIN(ram_shared)+4;
m0_state = ORIGIN(ram_shared);
PROVIDE(__ram_m0_start__ = ORIGIN(ram_m0));

View File

@ -0,0 +1,36 @@
/*
* Copyright 2022 Great Scott Gadgets
*
* This file is part of HackRF.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef __M0_STATE_H__
#define __M0_STATE_H__
struct m0_state {
uint32_t offset;
uint32_t tx;
};
/* Address of m0_state is set in ldscripts. If you change the name of this
* variable, it won't be where it needs to be in the processor's address space,
* unless you also adjust the ldscripts.
*/
extern volatile struct m0_state m0_state;
#endif/*__M0_STATE_H__*/

View File

@ -25,6 +25,7 @@
#include <hackrf_core.h>
#include "usb_api_transceiver.h"
#include "usb_bulk_buffer.h"
#include "m0_state.h"
#include "tuning.h"
#include "usb_endpoint.h"
#include "streaming.h"
@ -99,7 +100,7 @@ void sweep_mode(void) {
while (TRANSCEIVER_MODE_RX_SWEEP == transceiver_mode()) {
// Set up IN transfer of buffer 0.
if ( usb_bulk_buffer_offset >= 16384 && phase == 1) {
if ( m0_state.offset >= 16384 && phase == 1) {
transfer = true;
buffer = &usb_bulk_buffer[0x0000];
phase = 0;
@ -107,7 +108,7 @@ void sweep_mode(void) {
}
// Set up IN transfer of buffer 1.
if ( usb_bulk_buffer_offset < 16384 && phase == 0) {
if ( m0_state.offset < 16384 && phase == 0) {
transfer = true;
buffer = &usb_bulk_buffer[0x4000];
phase = 1;

View File

@ -27,6 +27,7 @@
#include <libopencm3/cm3/vector.h>
#include "usb_bulk_buffer.h"
#include "m0_state.h"
#include "usb_api_cpld.h" // Remove when CPLD update is handled elsewhere
@ -262,20 +263,20 @@ void set_transceiver_mode(const transceiver_mode_t new_transceiver_mode) {
led_off(LED3);
led_on(LED2);
rf_path_set_direction(&rf_path, RF_PATH_DIRECTION_RX);
usb_bulk_buffer_tx = false;
m0_state.tx = false;
break;
case TRANSCEIVER_MODE_TX:
led_off(LED2);
led_on(LED3);
rf_path_set_direction(&rf_path, RF_PATH_DIRECTION_TX);
usb_bulk_buffer_tx = true;
m0_state.tx = true;
break;
case TRANSCEIVER_MODE_OFF:
default:
led_off(LED2);
led_off(LED3);
rf_path_set_direction(&rf_path, RF_PATH_DIRECTION_OFF);
usb_bulk_buffer_tx = false;
m0_state.tx = false;
}
@ -284,7 +285,7 @@ void set_transceiver_mode(const transceiver_mode_t new_transceiver_mode) {
hw_sync_enable(_hw_sync_mode);
usb_bulk_buffer_offset = 0;
m0_state.offset = 0;
}
}
@ -330,7 +331,7 @@ void rx_mode(void) {
while (TRANSCEIVER_MODE_RX == _transceiver_mode) {
// Set up IN transfer of buffer 0.
if (16384 <= usb_bulk_buffer_offset && 1 == phase) {
if (16384 <= m0_state.offset && 1 == phase) {
usb_transfer_schedule_block(
&usb_endpoint_bulk_in,
&usb_bulk_buffer[0x0000],
@ -340,7 +341,7 @@ void rx_mode(void) {
phase = 0;
}
// Set up IN transfer of buffer 1.
if (16384 > usb_bulk_buffer_offset && 0 == phase) {
if (16384 > m0_state.offset && 0 == phase) {
usb_transfer_schedule_block(
&usb_endpoint_bulk_in,
&usb_bulk_buffer[0x4000],
@ -368,7 +369,7 @@ void tx_mode(void) {
while (TRANSCEIVER_MODE_TX == _transceiver_mode) {
// Set up OUT transfer of buffer 0.
if (16384 <= usb_bulk_buffer_offset && 1 == phase) {
if (16384 <= m0_state.offset && 1 == phase) {
usb_transfer_schedule_block(
&usb_endpoint_bulk_out,
&usb_bulk_buffer[0x0000],
@ -378,7 +379,7 @@ void tx_mode(void) {
phase = 0;
}
// Set up OUT transfer of buffer 1.
if (16384 > usb_bulk_buffer_offset && 0 == phase) {
if (16384 > m0_state.offset && 0 == phase) {
usb_transfer_schedule_block(
&usb_endpoint_bulk_out,
&usb_bulk_buffer[0x4000],

View File

@ -32,8 +32,4 @@
*/
extern uint8_t usb_bulk_buffer[32768];
extern volatile uint32_t usb_bulk_buffer_offset;
extern bool usb_bulk_buffer_tx;
#endif/*__USB_BULK_BUFFER_H__*/