Skip to content

Commit

Permalink
Merge pull request #12 from airspy/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
bvernoux committed Jul 13, 2015
2 parents 378c9a9 + e4d9137 commit 035ff81
Show file tree
Hide file tree
Showing 28 changed files with 197 additions and 333 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#export BOARD ?= AIRSPY_DEMO
#export VERSION_STRING ?= -D'VERSION_STRING="AirSpy DEMO"'

export PACKING ?= NO_PACKING
export BOARD ?= AIRSPY_NOS
export VERSION_STRING ?= -D'VERSION_STRING="AirSpy NOS"'

Expand Down
55 changes: 0 additions & 55 deletions Makefile_packing

This file was deleted.

74 changes: 27 additions & 47 deletions airspy_m0/airspy_m0.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ extern uint32_t cm0_data_share; /* defined in linker script */
volatile unsigned int phase = 0;

volatile uint32_t *usb_bulk_buffer_offset = (&cm4_data_share);
volatile uint32_t *usb_bulk_buffer_length = ((&cm4_data_share)+1);
volatile uint32_t *last_offset_m0 = ((&cm4_data_share)+2);

volatile airspy_mcore_t *start_adchs = (airspy_mcore_t *)(&cm0_data_share);
volatile airspy_mcore_t *set_samplerate = (airspy_mcore_t *)((&cm0_data_share)+1);
volatile airspy_mcore_t *set_packing = (airspy_mcore_t *)((&cm0_data_share)+2);

#define get_usb_buffer_offset() (usb_bulk_buffer_offset[0])
#define get_usb_buffer_length() (usb_bulk_buffer_length[0])

#define MASTER_TXEV_FLAG ((uint32_t *) 0x40043130)
#define MASTER_TXEV_QUIT() { *MASTER_TXEV_FLAG = 0x0; }
Expand Down Expand Up @@ -116,6 +120,20 @@ void set_samplerate_m4(uint8_t conf_num)
}
}

void set_packing_m4(uint8_t state)
{
set_packing->conf = state;
set_packing->cmd = SET_PACKING_CMD;

signal_sev();

while(1)
{
if(set_packing->raw == 0)
break;
}
}

void usb_configuration_changed(usb_device_t* const device)
{
if( device->configuration->number )
Expand Down Expand Up @@ -176,9 +194,9 @@ int main(void)

usb_set_configuration_changed_cb(usb_configuration_changed);
usb_peripheral_reset();

usb_device_init(0, &usb_device);

usb_queue_init(&usb_endpoint_control_out_queue);
usb_queue_init(&usb_endpoint_control_in_queue);
usb_queue_init(&usb_endpoint_bulk_out_queue);
Expand All @@ -191,7 +209,7 @@ int main(void)
iap_cmd_res.cmd_param.command_code = IAP_CMD_READ_SERIAL_NO;
iap_cmd_call(&iap_cmd_res);
if(iap_cmd_res.status_res.status_ret == CMD_SUCCESS)
{
{
/* Only retrieve 2 last 32bits for Serial Number */
serial_number.sn_32b[0] = iap_cmd_res.status_res.iap_result[2];
serial_number.sn_32b[1] = iap_cmd_res.status_res.iap_result[3];
Expand All @@ -208,52 +226,14 @@ int main(void)
while(true)
{
signal_wfe();
#ifdef USE_PACKING
switch(get_usb_buffer_offset())
{
case 0:
if(phase == 0)
{
usb_transfer_schedule_block(&usb_endpoint_bulk_in, &usb_bulk_buffer[0x0000], 0x1800);
phase = 1;
}
break;
case 1:
if(phase == 1)
{
usb_transfer_schedule_block(&usb_endpoint_bulk_in, &usb_bulk_buffer[0x2000], 0x1800);
phase = 2;
}
break;
case 2:
if(phase == 2)
{
usb_transfer_schedule_block(&usb_endpoint_bulk_in, &usb_bulk_buffer[0x4000], 0x1800);
phase = 3;
}
break;
case 3:
if(phase == 3)
{
usb_transfer_schedule_block(&usb_endpoint_bulk_in, &usb_bulk_buffer[0x6000], 0x1800);
phase = 0;
}
break;
}
#else
if( (get_usb_buffer_offset() >= 16384) &&
(phase == 1) )
{
usb_transfer_schedule_block(&usb_endpoint_bulk_in, &usb_bulk_buffer[0x0000], 0x4000);
phase = 0;
}

if( (get_usb_buffer_offset() < 16384) &&
(phase == 0) )
uint32_t offset = get_usb_buffer_offset();
uint32_t length = get_usb_buffer_length();

if(offset != *last_offset_m0)
{
usb_transfer_schedule_block(&usb_endpoint_bulk_in, &usb_bulk_buffer[0x4000], 0x4000);
phase = 1;
usb_transfer_schedule_block(&usb_endpoint_bulk_in, &usb_bulk_buffer[offset], length);
*last_offset_m0 = offset;
}
#endif
}
}
1 change: 1 addition & 0 deletions airspy_m0/airspy_m0.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ void ADCHS_start(uint8_t conf_num);
void ADCHS_stop(uint8_t conf_num);

void set_samplerate_m4(uint8_t conf_num);
void set_packing_m4(uint8_t state);

#endif//__AIRSPY_M0_H__
52 changes: 40 additions & 12 deletions airspy_m0/airspy_usb_req.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,45 @@ usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
return USB_REQUEST_STATUS_OK;
}

usb_request_status_t usb_vendor_request_set_packing_command(
usb_endpoint_t* const endpoint,
const usb_transfer_stage_t stage)
{
receiver_mode_t rx_mode;
uint8_t state;

if( stage == USB_TRANSFER_STAGE_SETUP )
{
if(endpoint->setup.index > (AIRSPY_CONF_NB-1))
{
return USB_REQUEST_STATUS_STALL;
}else
{
state = endpoint->setup.index;
}

rx_mode = get_receiver_mode();
if(rx_mode == RECEIVER_MODE_RX)
{
ADCHS_stop(sample_rate_conf_no);
}

set_packing_m4(state);

if(rx_mode == RECEIVER_MODE_RX)
{
ADCHS_start(sample_rate_conf_no);
}

endpoint->buffer[0] = 1;
usb_transfer_schedule_block(endpoint->in, &endpoint->buffer, 1);
usb_transfer_schedule_ack(endpoint->out);
return USB_REQUEST_STATUS_OK;
}
return USB_REQUEST_STATUS_OK;
}


usb_request_status_t usb_vendor_request_set_samplerate(
usb_endpoint_t* const endpoint,
const usb_transfer_stage_t stage)
Expand Down Expand Up @@ -768,17 +807,6 @@ usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
}
}

usb_request_status_t usb_vendor_request_get_packing_command(
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
{
if (stage == USB_TRANSFER_STAGE_SETUP) {
endpoint->buffer[0] = AIRSPY_PACKING;
usb_transfer_schedule_block(endpoint->in, &endpoint->buffer, 1);
usb_transfer_schedule_ack(endpoint->out);
}
return USB_REQUEST_STATUS_OK;
}

/* ID 1 to X corresponds to user endpoint->setup.request */
usb_request_handler_fn vendor_request_handler[AIRSPY_CMD_MAX+1];

Expand Down Expand Up @@ -831,7 +859,7 @@ void airspy_usb_req_init(void)
vendor_request_handler[AIRSPY_GPIODIR_READ] = usb_vendor_request_gpiodir_read_command;

vendor_request_handler[AIRSPY_GET_SAMPLERATES] = usb_vendor_request_get_samplerates_command;
vendor_request_handler[AIRSPY_GET_PACKING] = usb_vendor_request_get_packing_command;
vendor_request_handler[AIRSPY_SET_PACKING] = usb_vendor_request_set_packing_command;
}

usb_request_status_t usb_vendor_request(usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
Expand Down
22 changes: 13 additions & 9 deletions airspy_m4/adchs.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void ADCHS_DMA_init_stop(void)
LPC_GPDMA->CONFIG = 0x00; /* Disable DMA channels, little endian */
}

void ADCHS_DMA_init(uint32_t dest_addr)
void ADCHS_DMA_init(uint32_t dest_addr, uint8_t packed)
{
uint32_t nb_dma_transfer;
int i;
Expand Down Expand Up @@ -97,17 +97,21 @@ void ADCHS_DMA_init(uint32_t dest_addr)
(0x1 << 25) |
(0x0 << 26) |
(0x1 << 27) |
#ifdef USE_PACKING
(0x1UL << 31);
#else
(0x0UL << 31);
#endif
}

#ifndef USE_PACKING
adchs_dma_lli[(ADCHS_DMA_NUM_LLI/2)-1].control |= (0x1UL << 31);
adchs_dma_lli[i-1].control |= (0x1UL << 31);
#endif
if(packed)
{
for(i=0; i<ADCHS_DMA_NUM_LLI; i++)
{
adchs_dma_lli[i].control |= (0x1UL << 31);
}
}
else
{
adchs_dma_lli[(ADCHS_DMA_NUM_LLI/2)-1].control |= (0x1UL << 31);
adchs_dma_lli[i-1].control |= (0x1UL << 31);
}

LPC_GPDMA->C0SRCADDR = adchs_dma_lli[0].src_addr;
LPC_GPDMA->C0DESTADDR = adchs_dma_lli[0].dst_addr;
Expand Down
2 changes: 1 addition & 1 deletion airspy_m4/adchs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern "C"

void ADCHS_deinit(void);
void ADCHS_init(void);
void ADCHS_DMA_init(uint32_t dest_addr);
void ADCHS_DMA_init(uint32_t dest_addr, uint8_t packed);
void ADCHS_desc_init(uint8_t chan_num);
void ADCHS_stop(uint8_t conf_num);

Expand Down
Loading

0 comments on commit 035ff81

Please sign in to comment.