component mesa_pktgyro_test "PktUART simple test with Microstrain 3DM-GX3-15 gyro"; description """This component is written in order to test the PktUART driver for Mesa. It resembles partly Andy Pugh's mesa_uart.comp . This module uses the names= mode of loadrt declaration to specify which PktUART instances to enable. A check is included to ensure that the count= option is not used instead. For simplicity we test only one PktUART instance, therefore load the component like this: \\fB loadrt mesa_uart names=hm2_5i25.0.pktuart.0\\fR The PktUART instance names are printed to the dmesg buffer during the Hostmot2 setup sequence, one for each PktUART instance included in the bitfile loaded to each installed card during the Hostmot2 setup sequence. Type "dmesg" at the terminal prompt to view the output. If you want to work with more than one PktUART instance, consult Andy Pugh's mesa_uart.comp In order to compile and install do: \\fB halcompile --install src/hal/drivers/mesa_pktgyro_test.comp\\fR The component exports only one function, namely receive, which needs to be added to a realtime thread. To test this component set DEBUG=5 before and execute this HAL script: \\fB loadrt hostmot2\\fR \\fB loadrt hm2_pci\\fR \\fB loadrt mesa_pktgyro_test names=hm2_5i25.0.pktuart.0\\fR \\fB loadrt threads name1=test1 period1=10000000\\fR \\fB addf hm2_5i25.0.pktuart.0.receive test1\\fR \\fB start\\fR Check linuxcnc.log for debug output. """; author "Boris Skegin"; license "GPL"; include "hal/drivers/mesa-hostmot2/hostmot2.h"; pin out s32 rxbytes "Number of Bytes received or negative Error code"; variable char *name; // PktUART name option extra_setup yes; function receive; ;; #define BAUDRATE (115200) /* This uses the RTAPI_MP_ARRAY_STRING macro to load the list of PktUART channels into an array. This is copied into the *name string of each */ char *pktuart_chans[4] = {0,}; RTAPI_MP_ARRAY_STRING(pktuart_chans, 2, "PktUART Channel names"); static hostmot2_t* hm2=NULL; FUNCTION(receive){ rtapi_u16 max_frame_length = 20; rtapi_u8 num_frames = 20; unsigned char Replyd3[num_frames*max_frame_length]; rtapi_u16 frame_sizes3[20]; rxbytes=hm2_pktuart_read(name, Replyd3, &num_frames, &max_frame_length, frame_sizes3); rtapi_print_msg(RTAPI_MSG_INFO, "PktUART receive: got %d bytes, %d frames\n", rxbytes, num_frames); //Print out the actual frame sizes int i; for(i=0;iclock_freq); Bitrate is (RXBitrate_Register_Value/1048576)*ClockLow */ /* http://freeby.mesanet.com/regmap The PktUARTxMode register is used for setting and checking the PktUARTx's operation mode, timing and status: Bit 21 FrameBuffer Has Data Bits 20..16 Frames to send Bits 15..8 InterFrame delay in bit times Bit 7 Tr Logic active (not an error) Bit 6 Drive Enable bit (enables external RS-422/485 Driver when set) Bit 5 Drive enable Auto (Automatic external drive enable) Bit 4 unused Bits 3..0 Drive enable delay (delay from asserting drive enable to start of data transmit. In CLock Low periods */ /* http://freeby.mesanet.com/regmap The PktUARTrMode register is used for setting and checking the PktUARTr's operation mode, timing, and status Bit 21 FrameBuffer has data Bits 20..16 Frames received Bits 15..8 InterFrame delay in bit times Bit 7 Rx Logic active ( not an error) Bit 6 RXMask Bit 5 Unused Bit 4 RCFIFO Error Bit 3 RXEnable (must be set to receive packets) Bit 2 RXMask Enable (enables input data masking when transmitting) Bit 1 Overrun error (no stop bit when expected) (sticky) Bit 0 False Start bit error (sticky) */ /* In case our device is streaming data from the very beginning, at first we do not set RXEnable but clear Rx and Tx registers. Then we read out whatever is in the buffer, send the DISABLE STREAM datagram and only then set RXEnable bit. */ int retval=hm2_pktuart_setup(name, BAUDRATE , 0x0ff20, 0x007f00,1,1); if (retval<0) { rtapi_print_msg(1, "PktUART for gyro setup problem: %d\n", retval); return -1; } /* We expect the max frame length to be 58 byte if the gyro is streaming data from the beginning, but in case the InterFrame delay is not appropriate, the frame size can be longer. Anyway as long as the array size we pass to hm2_pktuart_read is big enough, we can read everything which is in the Rx buffer. */ rtapi_u16 max_frame_length = 58*2; rtapi_u8 num_frames = 20; // If Rx buffer <= 1024 bytes, than 2*58*20 bytes of read1 array are enough unsigned char read1[num_frames*max_frame_length]; rtapi_u16 read1_sizes[num_frames]; // read out as many frames as possible retval=hm2_pktuart_read(name, read1, &num_frames, &max_frame_length, read1_sizes); rtapi_print_msg(RTAPI_MSG_INFO, "PktUART after first read: got %d bytes\n", retval); //Print out the actual frame sizes int i; for(i=0;i