#include "config.h"
#include "conf_usb.h"
#include "cdc_rf_task.h"
#include "lib_mcu/usb/usb_drv.h"
#include "usb_descriptors.h"
#include "modules/usb/device_chap9/usb_standard_request.h"
#include "usb_specific_request.h"
#include "lib_mcu/spi/spi_lib.h"
#include "lib_board/nrf24l01/nRF_API.h"
Include dependency graph for cdc_rf_task.c:
Go to the source code of this file.
Defines | |
#define | Flash_tx_led() (led_tx_flash=0,Led1_on()) |
#define | Flash_rx_led() (led_rx_flash=0,Led0_on()) |
Functions | |
void | cdc_rf_task_init (void) |
This function initializes the hardware ressources required for CDC demo. | |
void | cdc_rf_task (void) |
Entry point of the uart cdc management. | |
void | sof_action () |
sof_action | |
bit | usb_test_hit (void) |
This function checks if a character has been received on the USB bus. | |
char | usb_getchar (void) |
This function reads one byte from the USB bus. | |
bit | usb_tx_ready (void) |
This function checks if the USB emission buffer is ready to accept at at least 1 byte. | |
int | usb_putchar (int data_to_send) |
This function fills the USB transmit buffer with the new data. | |
void | usb_flush (void) |
This function sends the data stored in the USB transmit buffer. | |
Variables | |
volatile U8 | cpt_sof |
volatile U8 | led_tx_flash = 0 |
volatile U8 | led_rx_flash = 0 |
volatile U16 | cpt_sof_led |
S_line_coding | line_coding |
U8 | rx_buffer [RF_BUFFER_SIZE] |
U8 | tx_buffer [RF_BUFFER_SIZE] |
U8 | tx_counter |
U8 | rx_counter |
Definition in file cdc_rf_task.c.
#define Flash_tx_led | ( | ) | (led_tx_flash=0,Led1_on()) |
#define Flash_rx_led | ( | ) | (led_rx_flash=0,Led0_on()) |
void cdc_rf_task_init | ( | void | ) |
This function initializes the hardware ressources required for CDC demo.
none |
Definition at line 96 of file cdc_rf_task.c.
References FOSC, Leds_init, NRF_disable, NRF_enable, NRF_init_rx, NRF_port_init, NRF_set_payload, RF_BUFFER_SIZE, rx_counter, spi_init(), SPI_MASTER, tx_counter, and Usb_enable_sof_interrupt.
00097 { 00098 volatile U32 tempo; 00099 00100 Leds_init(); 00101 //Init nr24L01 driver 00102 NRF_port_init(); 00103 spi_init(SPI_MASTER); 00104 NRF_enable(); // Enable receiver 00105 NRF_disable(); // Enable receiver 00106 for(tempo=0;tempo<FOSC/10;tempo++); 00107 NRF_init_rx(); // Set nRf primary receiver 00108 00109 NRF_set_payload(0,RF_BUFFER_SIZE); // Pipe 0 receiver is 32 bytes 00110 NRF_enable(); // Enable receiver 00111 00112 tx_counter = 0; 00113 rx_counter = 0; 00114 Usb_enable_sof_interrupt(); 00115 }
Here is the call graph for this function:
void cdc_rf_task | ( | void | ) |
Entry point of the uart cdc management.
This function links the uart and the USB bus.
none |
Definition at line 128 of file cdc_rf_task.c.
References cpt_sof, Flash_rx_led, Flash_tx_led, Is_device_enumerated, Is_not_NRF_IRQ, Is_NRF_IRQ, Is_NRF_received, Is_NRF_timeout, Is_NRF_transmit, NB_MS_BEFORE_FLUSH, NRF_ack_received, NRF_ack_timeout, NRF_ack_transmit, NRF_init_rx, NRF_init_tx, NRF_rx_buffer, NRF_tx_buffer, RF_BUFFER_SIZE, rx_buffer, rx_counter, tx_buffer, tx_counter, usb_flush(), usb_getchar(), usb_putchar(), and usb_test_hit().
00129 { 00130 U8 i,j; 00131 00132 if(Is_device_enumerated()) //Enumeration processs OK ? 00133 { 00134 if(cpt_sof>=NB_MS_BEFORE_FLUSH && tx_counter!=0 ) //Flush buffer in Timeout 00135 { 00136 cpt_sof=0; 00137 usb_flush(); 00138 } 00139 00140 if(Is_NRF_IRQ()) 00141 { 00142 if (Is_NRF_received()) //Something on RF ? 00143 { 00144 NRF_rx_buffer(rx_buffer,RF_BUFFER_SIZE); //Read data buffer from Rf 00145 i=rx_buffer[0]; // Get number of data byte 00146 for(j=1;j<=i;j++) 00147 { 00148 usb_putchar(rx_buffer[j]); 00149 } 00150 Flash_rx_led(); 00151 NRF_ack_received(); 00152 } 00153 } 00154 00155 00156 if(usb_test_hit()) 00157 { 00158 tx_buffer[0]=rx_counter; 00159 for(j=1;j<=tx_buffer[0];j++) 00160 { 00161 tx_buffer[j]=usb_getchar(); 00162 } 00163 NRF_init_tx(); // RF is Tx mode 00164 NRF_tx_buffer(tx_buffer,RF_BUFFER_SIZE); // Send data to Rf 00165 while(Is_not_NRF_IRQ()); // Wait event from Rf 00166 if(Is_NRF_transmit()) // Data sent ? 00167 { 00168 NRF_ack_transmit(); 00169 Flash_tx_led(); 00170 } 00171 else if (Is_NRF_timeout()) 00172 { 00173 NRF_ack_timeout(); 00174 } 00175 NRF_init_rx(); 00176 } 00177 } 00178 }
Here is the call graph for this function:
bit usb_test_hit | ( | void | ) |
This function checks if a character has been received on the USB bus.
Definition at line 232 of file cdc_rf_task.c.
References Is_usb_receive_out, rx_counter, TX_EP, Usb_ack_receive_out, Usb_byte_counter, and Usb_select_endpoint.
Referenced by cdc_rf_task(), and usb_getchar().
00233 { 00234 if (!rx_counter) 00235 { 00236 Usb_select_endpoint(TX_EP); 00237 if (Is_usb_receive_out()) 00238 { 00239 rx_counter = Usb_byte_counter(); 00240 if (!rx_counter) 00241 { 00242 Usb_ack_receive_out(); 00243 } 00244 } 00245 } 00246 return (rx_counter!=0); 00247 }
Here is the caller graph for this function:
char usb_getchar | ( | void | ) |
This function reads one byte from the USB bus.
If one byte is present in the USB fifo, this byte is returned. If no data is present in the USB fifo, this function waits for USB data.
Definition at line 257 of file cdc_rf_task.c.
References rx_counter, TX_EP, Usb_ack_receive_out, Usb_read_byte, Usb_select_endpoint, and usb_test_hit().
Referenced by cdc_rf_task().
00258 { 00259 register Uchar data_rx; 00260 00261 Usb_select_endpoint(TX_EP); 00262 if (!rx_counter) while (!usb_test_hit()); 00263 data_rx=Usb_read_byte(); 00264 rx_counter--; 00265 if (!rx_counter) Usb_ack_receive_out(); 00266 return data_rx; 00267 }
Here is the call graph for this function:
Here is the caller graph for this function:
bit usb_tx_ready | ( | void | ) |
This function checks if the USB emission buffer is ready to accept at at least 1 byte.
Definition at line 276 of file cdc_rf_task.c.
References FALSE, Is_usb_write_enabled, and TRUE.
Referenced by usb_putchar().
00277 { 00278 if (!Is_usb_write_enabled()) 00279 { 00280 return FALSE; 00281 } 00282 return TRUE; 00283 }
Here is the caller graph for this function:
int usb_putchar | ( | int | data_to_send | ) |
This function fills the USB transmit buffer with the new data.
This buffer is sent if complete. To flush this buffer before waiting full, launch the rf_usb_flush() function.
data_to_send |
Definition at line 294 of file cdc_rf_task.c.
References Is_usb_write_enabled, RX_EP, tx_counter, usb_flush(), Usb_select_endpoint, usb_tx_ready(), and Usb_write_byte.
Referenced by cdc_rf_task().
00295 { 00296 Usb_select_endpoint(RX_EP); 00297 while(!usb_tx_ready()); // Wait Endpoint ready 00298 Usb_write_byte(data_to_send); 00299 tx_counter++; 00300 if(!Is_usb_write_enabled()) //If Endpoint full -> flush 00301 { 00302 usb_flush(); 00303 } 00304 return data_to_send; 00305 }
Here is the call graph for this function:
Here is the caller graph for this function:
void usb_flush | ( | void | ) |
This function sends the data stored in the USB transmit buffer.
This function does nothing if there is no data in the buffer.
Definition at line 312 of file cdc_rf_task.c.
References RX_EP, tx_counter, Usb_select_endpoint, and Usb_send_in.
Referenced by cdc_rf_task(), and usb_putchar().
00313 { 00314 Usb_select_endpoint(RX_EP); 00315 Usb_send_in(); 00316 tx_counter = 0; 00317 }
Here is the caller graph for this function:
volatile U8 led_tx_flash = 0 |
volatile U8 led_rx_flash = 0 |
volatile U16 cpt_sof_led |
Definition at line 75 of file cdc_rf_task.c.
Referenced by cdc_get_line_coding(), and cdc_set_line_coding().
Definition at line 81 of file cdc_rf_task.c.
Referenced by cdc_rf_task(), cdc_rf_task_init(), usb_flush(), and usb_putchar().
Definition at line 82 of file cdc_rf_task.c.
Referenced by cdc_rf_task(), cdc_rf_task_init(), usb_getchar(), and usb_test_hit().