summaryrefslogtreecommitdiff
path: root/software
diff options
context:
space:
mode:
authorChristian Pointner <equinox@mur.at>2013-02-05 21:06:18 +0000
committerChristian Pointner <equinox@mur.at>2013-02-05 21:06:18 +0000
commitd4b95678b1e35f407afeabe6b0f7f85b36d9bce4 (patch)
tree4d5069c1cd8de215ddce45f774572c2fb55069ad /software
parentbeacon is now continous (diff)
using stdio
git-svn-id: https://svn.spreadspace.org/mur.sat@666 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software')
-rw-r--r--software/hhd70dongle/c1101lib.c34
-rw-r--r--software/hhd70dongle/hhd70dongle.c121
2 files changed, 84 insertions, 71 deletions
diff --git a/software/hhd70dongle/c1101lib.c b/software/hhd70dongle/c1101lib.c
index cdc1270..d943048 100644
--- a/software/hhd70dongle/c1101lib.c
+++ b/software/hhd70dongle/c1101lib.c
@@ -57,14 +57,6 @@
//static RingBuffer_t SPItoUSB_Buffer;
//static uint8_t SPItoUSB_Buffer_Data[8];
-/** LUFA CDC Class driver interface configuration and state information. This structure is
- * passed to all CDC Class driver functions, so that multiple instances of the same class
- * within a device can be differentiated from one another.
- */
-extern USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface;
-/* ###### end LUFA CDC-ACM specific definitions ###### */
-
-
int16_t c1101_spi_write_byte_ok_get_status(char data)
{
@@ -141,12 +133,12 @@ void c1101_spi_dump_registers_to_usb(void)
hhd70_c1101_wait_chip_rdy();
if (c1101_spi_write_byte_ok_get_status(0xC0) < 0)
return;
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"dump all 46 registers:\r\n");
+ printf("dump all 46 registers:\r\n");
for (c=0; c<47; c++)
{
debug_sprint_int16hex(debug_sb, hhd70_spi_read_byte());
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, debug_sb);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, "\r\n");
+ printf("%s", debug_sb);
+ printf("\r\n");
}
hhd70_spi_cs_disable();
}
@@ -456,13 +448,13 @@ void c1101_handleMARCStatusByte(char sb)
if (sb == 0x11)
{
c1101_spi_strobe_command(SPIC1101_ADDR_SFRX);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"RX fifo flushed\r\n");
+ printf("RX fifo flushed\r\n");
}
//on TXFifo Overflow, Flush TX Fifo
else if (sb == 0x16)
{
c1101_spi_strobe_command(SPIC1101_ADDR_SFTX);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"TX fifo flushed\r\n");
+ printf("TX fifo flushed\r\n");
}
}
@@ -472,13 +464,13 @@ void c1101_handleStatusByte(char sb)
if (SPIC1101_SB_RXFIFO_OVERFLOW(sb))
{
c1101_spi_strobe_command(SPIC1101_ADDR_SFRX);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"RX fifo flushed\r\n");
+ printf("RX fifo flushed\r\n");
}
//on TXFifo Overflow, Flush TX Fifo
if (SPIC1101_SB_TXFIFO_OVERFLOW(sb))
{
c1101_spi_strobe_command(SPIC1101_ADDR_SFTX);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"TX fifo flushed\r\n");
+ printf("TX fifo flushed\r\n");
}
}
@@ -500,10 +492,10 @@ char c1101_getMARCState(void)
sb &= 0x1F;
//debug start
char debug_sb[6];
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"c1101 MARCSate:\r\n");
+ printf("c1101 MARCSate:\r\n");
debug_sprint_int16hex(debug_sb, sb);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,debug_sb);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"\r\n");
+ printf("%s", debug_sb);
+ printf("\r\n");
//debug end
return sb;
}
@@ -736,9 +728,9 @@ void c1101_recieveData(void)
num_leave_in_fifo = (recv_data[0] - num_recv_total < 64)? 0 : 1;
} while (num_recv > 0);
recv_data[num_recv_total]=0;
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"RX: Data Recieved: ");
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,recv_data);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"\r\n");
+ printf("RX: Data Recieved: ");
+ printf("%s", recv_data);
+ printf("\r\n");
c1101_getStatus(); // get status and handle possiblble RX Fifo Overflow
}
diff --git a/software/hhd70dongle/hhd70dongle.c b/software/hhd70dongle/hhd70dongle.c
index ff85ab8..be66baf 100644
--- a/software/hhd70dongle/hhd70dongle.c
+++ b/software/hhd70dongle/hhd70dongle.c
@@ -116,21 +116,33 @@ void EVENT_USB_Device_ControlRequest(void)
}
/* ###### end LUFA CDC-ACM specific definitions ###### */
+FILE usb_stream;
+
+/* this creates an non-blocking IO Stream which can be used by printf and scanf */
+void stdio_init(void)
+{
+ CDC_Device_CreateStream(&VirtualSerial_CDC_Interface,&usb_stream);
+ stdin = &usb_stream;
+ stdout = &usb_stream;
+ stderr = &usb_stream;
+}
+
+
bool enable_tx_part=false;
bool enable_rx_part=false;
bool enable_beacon_part=false;
void print_part_status(void)
{
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, "OOK Beacon: ");
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, ((enable_beacon_part)? "Enabled": "Disabled") );
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, "\r\n");
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, "RX-Part: ");
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, ((enable_rx_part)? "Enabled": "Disabled") );
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, "\r\n");
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, "TX-Part: ");
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, ((enable_tx_part)? "Enabled": "Disabled") );
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, "\r\n");
+ printf("OOK Beacon: ");
+ printf(((enable_beacon_part)? "Enabled": "Disabled") );
+ printf("\r\n");
+ printf("RX-Part: ");
+ printf(((enable_rx_part)? "Enabled": "Disabled") );
+ printf("\r\n");
+ printf("TX-Part: ");
+ printf(((enable_tx_part)? "Enabled": "Disabled") );
+ printf("\r\n");
}
//void generate_morse_code_sequence(char *msg, *cw_buffer, uint16_t buffer_len)
@@ -142,9 +154,14 @@ void print_part_status(void)
//char cw_wordspace[2] = {0, 7};
//}
-void beacon_on(void)
+void beacon_enable(void)
{
+ c1101_spi_strobe_command(SPIC1101_ADDR_STX);
hhd70_palna_txmode();
+}
+
+void beacon_on(void)
+{
hhd70_set_OOK_GDO0_high();
led_on();
}
@@ -153,7 +170,12 @@ void beacon_off(void)
{
led_off();
hhd70_set_OOK_GDO0_low();
+}
+
+void beacon_disable(void)
+{
hhd70_palna_rxmode();
+ c1101_spi_strobe_command(SPIC1101_ADDR_SIDLE);
}
int main(void)
@@ -164,11 +186,13 @@ int main(void)
led_init();
USB_Init();
+ stdio_init();
+
hhd70_init();
DDRB &= ~(1<<DDB5); // set PB5/ADC12 to INPUT (c1101 temp sensor)
sei(); //set enable global interrupt
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"hhd70dongle ready\r\n");
+ printf("hhd70dongle ready\r\n");
_delay_ms(500);
c1101_spi_strobe_command(SPIC1101_ADDR_SRES); // reset c1101
@@ -193,13 +217,13 @@ int main(void)
int16_t num_bytes_received = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface);
while(num_bytes_received > 0)
{
- int16_t recv_byte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
+ int16_t recv_byte = fgetc(stdin);
num_bytes_received--;
- if (recv_byte < 0)
+ if (recv_byte == EOF)
continue;
if ((char) recv_byte == '!')
{
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, "resetting\r\n");
+ printf("resetting\r\n");
wdt_enable(WDTO_500MS);
reset();
}
@@ -212,7 +236,7 @@ int main(void)
enable_tx_part=false;
c1101_init_ook_beacon();
- c1101_spi_strobe_command(SPIC1101_ADDR_STX);
+ beacon_enable();
beacon_on();
}
print_part_status();
@@ -244,8 +268,7 @@ int main(void)
}
else if ((char) recv_byte == 'D' || (char) recv_byte == 'd')
{
- sprintf(write_buffer,"FSK Freq Deviation Now: %u0 Hz\r\n", c1101_setFSKDeviationFromCarrier(fdev_m, fdev_e));
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, write_buffer);
+ printf("FSK Freq Deviation Now: %u0 Hz\r\n", c1101_setFSKDeviationFromCarrier(fdev_m, fdev_e));
if ((char) recv_byte == 'd')
{
fdev_m--;
@@ -290,7 +313,7 @@ int main(void)
change_freq = -100000;
break;
case 'f':
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, "Setting Frequency to previously adjusted value.\r\n");
+ printf("Setting Frequency to previously adjusted value.\r\n");
c1101_setFrequency(prev_ook_freq);
break;
case '?':
@@ -300,21 +323,19 @@ int main(void)
if (change_freq != 0)
{
beacon_off();
- c1101_spi_strobe_command(SPIC1101_ADDR_SIDLE);
+ beacon_disable();
- sprintf(write_buffer,"Frequency %s by %lu KHz - ", (change_freq > 0 ? "up" : "down"), (change_freq > 0 ? 1 : -1) * change_freq / 1000);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, write_buffer);
+ printf("Frequency %s by %lu KHz - ", (change_freq > 0 ? "up" : "down"), (change_freq > 0 ? 1 : -1) * change_freq / 1000);
c1101_changeFrequencyByRelativeValue(change_freq);
prev_ook_freq = c1101_getCurrentCarrierFrequencyHz();
- c1101_spi_strobe_command(SPIC1101_ADDR_STX);
+ beacon_enable();
beacon_on();
}
uint32_t hz = c1101_getCurrentCarrierFrequencyHz();
uint16_t mhz = hz / 1000000;
uint16_t khz = (hz % 1000000)/1000;
- sprintf(write_buffer,"Frequency is now: %d.%03d MHz\r\n", mhz, khz);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, write_buffer);
+ printf("Frequency is now: %d.%03d MHz\r\n", mhz, khz);
}
}
@@ -330,42 +351,42 @@ int main(void)
if (hhd70_rx_data_available())
{
led_on();
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"RX: GDO2 pin HIGH\r\n");
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"c1101 rx bytes:");
+ printf("RX: GDO2 pin HIGH\r\n");
+ printf("c1101 rx bytes:");
debug_sprint_int16hex(write_buffer, c1101_spi_read_register(SPIC1101_ADDR_RXBYTES));
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,write_buffer);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"\r\n");
+ printf("%s", write_buffer);
+ printf("\r\n");
c1101_recieveData();
led_off();
}
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"c1101 rssi: ");
+ printf("c1101 rssi: ");
debug_sprint_int16hex(write_buffer, c1101_spi_read_register(SPIC1101_ADDR_RSSI));
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,write_buffer);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"\r\n");
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"c1101 tx bytes: ");
+ printf("%s", write_buffer);
+ printf("\r\n");
+ printf("c1101 tx bytes: ");
debug_sprint_int16hex(write_buffer, c1101_spi_read_register(SPIC1101_ADDR_TXBYTES));
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,write_buffer);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"\r\n");
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"c1101 rx bytes: ");
+ printf("%s", write_buffer);
+ printf("\r\n");
+ printf("c1101 rx bytes: ");
int16_t num_rx_bytes = c1101_spi_read_register(SPIC1101_ADDR_RXBYTES);
debug_sprint_int16hex(write_buffer, num_rx_bytes);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,write_buffer);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"\r\n");
+ printf("%s", write_buffer);
+ printf("\r\n");
//~ if (num_rx_bytes > 0)
//~ {
//~ led_on();
- //~ CDC_Device_SendString(&VirtualSerial_CDC_Interface,"RX Buffer Non-Empty\r\n");
+ //~ printf("RX Buffer Non-Empty\r\n");
//~ c1101_recieveData();
//~ led_off();
//~ }
-// CDC_Device_SendString(&VirtualSerial_CDC_Interface,"c1101 status byte: ");
+// printf("c1101 status byte: ");
// debug_sprint_int16hex(write_buffer, c1101_getStatus());
-// CDC_Device_SendString(&VirtualSerial_CDC_Interface,write_buffer);
-// CDC_Device_SendString(&VirtualSerial_CDC_Interface,"\r\n");
+// printf("%s", write_buffer);
+// printf("\r\n");
}
@@ -379,24 +400,24 @@ int main(void)
write_buffer[5]=':';
adc_on();
_delay_ms(250);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"temp c1101: ");
+ printf("temp c1101: ");
debug_sprint_int16hex(write_buffer+6, c1101_measureTemp());
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,write_buffer+6);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"\r\n");
+ printf("%s", write_buffer+6);
+ printf("\r\n");
_delay_ms(250);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"temp atmega: ");
+ printf("temp atmega: ");
debug_sprint_int16hex(write_buffer+10, adc_read(ADCMUX_ADC12));
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,write_buffer+10);
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"\r\n");
+ printf("%s", write_buffer+10);
+ printf("\r\n");
adc_off();
_delay_ms(250);
led_on();
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"TX Data: String\r\n");
+ printf("TX Data: String\r\n");
c1101_transmitData_infPktMode("OE6EOF test mur.sat GFSK r:9k6 fdev:11kHz 1234567890123456789012345678901234567890 End of Test",93);
led_off();
_delay_ms(100);
led_on();
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"TX Data: Temps\r\n");
+ printf("TX Data: Temps\r\n");
c1101_transmitData_infPktMode((char*) write_buffer,14);
led_off();
}
@@ -404,7 +425,7 @@ int main(void)
/* if (enable_beacon_part)
{
//char mursat_beacon[8] = {0b11101110, 0b11100010, 0b00111010, 0b10101000, 0b10001110, 0b11101110, 0b00101011, 0b10100000}; //OE6EOF
- CDC_Device_SendString(&VirtualSerial_CDC_Interface,"OOK Sending Beacon\r\n");
+ printf("OOK Sending Beacon\r\n");
led_on();
//c1101_transmitData_infPktMode(mursat_beacon,sizeof(mursat_beacon));
hhd70_palna_txmode();