libedt_timing.c File Reference


Detailed Description

File containing definitions for IRIG-B Timecode library.

Definition in file libedt_timing.c.

#include <time.h>
#include "edtinc.h"

Go to the source code of this file.

Functions

u_char edt_crc16_highbyte (u_char *buf, int len)
u_char edt_crc16_lowbyte (u_char *buf, int len)
void edt_disable_timecode_programmable_year (EdtDev *edt_p)
 Disable the msp430 IRIG-B firmware programmable year mode.
void edt_enable_timecode_programmable_year (EdtDev *edt_p, u_short year)
 Enable the msp430 IRIG-B firmware programmable year mode and set the year.
int edt_get_timecode_version (EdtDev *edt_p)
 Get the msp430 IRIG-B firmware version.
void edt_set_msp430_clock (EdtDev *edt_p, int clock_sel, int clock_hz)
 Select an internal or external clock source for the MSP430 and state the clock rate.
int edt_set_timecode_enable (EdtDev *edt_p, int enable)
 Enable or disable timecode production from the MSP430.
void edt_set_timecode_raw (EdtDev *edt_p, int enable)
 Enable or disable raw BCD timecode production from the MSP430.
void edt_set_timecode_seconds_offset (EdtDev *edt_p, u_int seconds)
 Set a seconds offset for timecode production.
int edt_spi_close (EdtDev *edt_p)
 Closes the SPI master EDT device handle.
void edt_spi_display_time (EdtDev *edt_p, int loops)
 Prints the timecode in ascii once per second for N loops.
int edt_spi_fifo_empty (EdtDev *edt_p)
 Returns true if the SPI fifo is empty.
void edt_spi_flush_fifo (EdtDev *edt_p)
 Flushes the EDT SPI input and output fifos, discarding all data.
int edt_spi_get_binary (EdtDev *edt_p, unsigned char *byte)
 Inputs a single binary byte from the EDT SPI interface.
u_char edt_spi_get_byte (EdtDev *edt_p)
 Polls the EDT SPI master for a single byte.
u_char edt_spi_get_byte_nointr (EdtDev *edt_p)
int edt_spi_get_pkt (EdtDev *edt_p, u_char *pkt)
 After a packet-start byte is received, call this routine to input the packet and check the CRC.
u_char edt_spi_get_stat (EdtDev *edt_p)
 Returns the value of the EDT SPI status register.
uint64_t edt_spi_get_time_pkt (EdtDev *edt_p)
 Obtains a timestamp packet from the timing msp430 via SPI.
int edt_spi_invoke_flash_loader (EdtDev *edt_p)
 Puts the EDT SPI msp430 into flash-loader mode.
EdtDevedt_spi_open (char *edt_interface, int unit, u_int spi_reg_base)
 Opens the EDT SPI master.
u_char edt_spi_put_byte (EdtDev *edt_p, u_char ch)
 Sends one byte to the EDT SPI master.
char * edt_spi_putstr (EdtDev *edt_p, char *str)
 Send a single line of ascii string to the msp430 over the SPI.
u_int edt_spi_reg_read (EdtDev *edt_p, u_int desc)
 Read an SPI access register using the correct register base address.
void edt_spi_reg_write (EdtDev *edt_p, u_int desc, u_int val)
 Write an SPI access register using the correct register base address.
void edt_spi_send_binary (EdtDev *edt_p, u_char val)
void edt_spi_send_packet (EdtDev *edt_p, u_char *cmdbuf)
 Send a command packet to the msp430 via the SPI; wait for output fifo full but not ACK/NAK reply.


Function Documentation

void edt_disable_timecode_programmable_year ( EdtDev edt_p  ) 

Disable the msp430 IRIG-B firmware programmable year mode.

Parameters:
edt_p The EDT open device handle.
Returns:
void
Disable the msp430 IRIG-B firmware programmable year mode. Successive timestamps will obtain the year information from the CONTROL FIELD of the IRIG-B signal.

See the included example program timing_test.c.

Definition at line 1007 of file libedt_timing.c.

void edt_enable_timecode_programmable_year ( EdtDev edt_p,
u_short  year 
)

Enable the msp430 IRIG-B firmware programmable year mode and set the year.

Parameters:
edt_p The EDT open device handle.
year The year >= 2000.
Returns:
void
Enable the msp430 IRIG-B firmware programmable year mode and set the year. The IRIG-B spec does not provide the year of the timestamp. This function enables the user to set the year to be used when computing the timestamp.

By default, the CONTROL FIELD of the IRIG-B signal is assumed to provide the current year since 2000. When this is not the case this function enables the programmed year mode and sets the year to the second argument.

The year argument must be >= 2000. This value is stored in a firmware variable in the MSP430 and included in the timestamps produced by the IRIG-B signal. When the "days" field of the IRIG-B signal rolls over to 1, the year is incremented by 1.

See the included example program timing_test.c.

Definition at line 976 of file libedt_timing.c.

int edt_get_timecode_version ( EdtDev edt_p  ) 

Get the msp430 IRIG-B firmware version.

Parameters:
edt_p The EDT open device handle.
Returns:
An integer containing the firmware version number
Obtain the version of the IRIG-B firmware running on the msp430.

See the included example program timing_test.c.

Definition at line 758 of file libedt_timing.c.

void edt_set_msp430_clock ( EdtDev edt_p,
int  clock_sel,
int  clock_hz 
)

Select an internal or external clock source for the MSP430 and state the clock rate.

Parameters:
edt_p The EDT open device handle.
clock_sel An integer containing 0 for internal clock and 1 for external clock select.
clock_hz An integer stating the number of Hertz for the selected clock.
Returns:
void
The MSP430 normally uses an internal 16 Mhz system clock. This clock can be set to 1 Mhz, 4 Mhz, 8 Mhz, 12 Mhz or 16 Mhz by using the third argument. An external clock can also be specified along with its stated clock rate.

When an external clock is selected and no clock signal is available on XIN (P26), a clock fault condition is triggered which resets the system clock back to the default internal 16 Mhz clock.

See the included example program timing_test.c.

Definition at line 906 of file libedt_timing.c.

int edt_set_timecode_enable ( EdtDev edt_p,
int  enable 
)

Enable or disable timecode production from the MSP430.

Parameters:
edt_p The EDT open device handle.
enable An integer containing 1 to enable timestamp production, 0 to disable it.
Returns:
0 for success, -1 for failure.
Packet communication with the MSP430 requires the timestamp production must be disabled before the packets, then reenabled when packet communication is complete.

See the included example program timing_test.c.

Definition at line 789 of file libedt_timing.c.

void edt_set_timecode_raw ( EdtDev edt_p,
int  enable 
)

Enable or disable raw BCD timecode production from the MSP430.

Parameters:
edt_p The EDT open device handle.
enable An integer containing 1 to enable BCD timestamp production, 0 to disable it.
Returns:
0 for success, -1 for failure.
The timecodes produced by the MSP430 are normally UNIX time; i.e. the number of seconds since January 1, 1970. By enabling raw BCD timecode production, the raw numbers from the IRIG-B timecode signal are produced instead. The numbers are sent in a struct ts_raw_t defined in libedt_timing.h.

See the included example program timing_test.c.

Definition at line 834 of file libedt_timing.c.

void edt_set_timecode_seconds_offset ( EdtDev edt_p,
u_int  seconds 
)

Set a seconds offset for timecode production.

Parameters:
edt_p The EDT open device handle.
seconds An integer containing the number of seconds to add to the timecode.
Returns:
void
The timecodes produced by the MSP430 are normally one to two seconds later than the PPS signal due to timestamp decoding and datpath transmission. This function sets a firmware variable to the number of seconds to add to the timestamp to align it with the current PPS.

See the included example program timing_test.c.

Definition at line 870 of file libedt_timing.c.

int edt_spi_close ( EdtDev edt_p  ) 

Closes the SPI master EDT device handle.

Parameters:
edt_p The EDT open device handle.
Returns:
The value from edt_close().

Definition at line 151 of file libedt_timing.c.

void edt_spi_display_time ( EdtDev edt_p,
int  loops 
)

Prints the timecode in ascii once per second for N loops.

Parameters:
edt_p The EDT open device handle.
loops The number of seconds to print.
Returns:
No return value.
This function is mostly used for testing and debugging as the timestamp is normally inserted into the DMA data stream by the board FPGA firmware.

See the included example program timing_test.c.

Definition at line 429 of file libedt_timing.c.

int edt_spi_fifo_empty ( EdtDev edt_p  ) 

Returns true if the SPI fifo is empty.

Parameters:
edt_p The EDT open device handle.
Returns:
Nonzero if the SPI fifo is empty, zero otherwise.

Definition at line 241 of file libedt_timing.c.

void edt_spi_flush_fifo ( EdtDev edt_p  ) 

Flushes the EDT SPI input and output fifos, discarding all data.

Parameters:
edt_p The EDT open device handle.
Returns:
No return value.

Definition at line 289 of file libedt_timing.c.

int edt_spi_get_binary ( EdtDev edt_p,
unsigned char *  byte 
)

Inputs a single binary byte from the EDT SPI interface.

Parameters:
edt_p The EDT open device handle.
byte Pointer to an unsigned char.
Returns:
0 on success; -1 on timeout or other failure.

Definition at line 202 of file libedt_timing.c.

u_char edt_spi_get_byte ( EdtDev edt_p  ) 

Polls the EDT SPI master for a single byte.

Parameters:
edt_p The EDT open device handle.
Returns:
The byte obtained from the SPI interface.

Definition at line 165 of file libedt_timing.c.

int edt_spi_get_pkt ( EdtDev edt_p,
u_char *  pkt 
)

After a packet-start byte is received, call this routine to input the packet and check the CRC.

Parameters:
edt_p The EDT open device handle.
byte Pointer to an unsigned char array of 64-bytes which will contain the packet on success.
Returns:
packet data length on success; -1 on timeout or other failure.

Definition at line 328 of file libedt_timing.c.

u_char edt_spi_get_stat ( EdtDev edt_p  ) 

Returns the value of the EDT SPI status register.

Parameters:
edt_p The EDT open device handle.
Returns:
The value of the EDT SPI status register.

Definition at line 275 of file libedt_timing.c.

uint64_t edt_spi_get_time_pkt ( EdtDev edt_p  ) 

Obtains a timestamp packet from the timing msp430 via SPI.

Parameters:
edt_p The EDT open device handle.
Returns:
unsigned 64-bit unix based time (seconds since Jan 1, 1970)

Definition at line 385 of file libedt_timing.c.

int edt_spi_invoke_flash_loader ( EdtDev edt_p  ) 

Puts the EDT SPI msp430 into flash-loader mode.

Parameters:
edt_p The EDT open device handle.
Returns:
Zero on success, -1 on fault.
Puts the EDT SPI msp430 into flash-loader mode, which accepts commands via ascii string to erase and reprogram the msp430 flash memory. Culminates in rebooting the msp430.

See the included utility program msp430_load.c.

Definition at line 546 of file libedt_timing.c.

EdtDev* edt_spi_open ( char *  edt_interface,
int  unit,
u_int  spi_reg_base 
)

Opens the EDT SPI master.

Parameters:
edt_interface string containing the type of board; "pcd", "pdv", "pe53b", etc.
unit Board unit number
spi_reg_base Selects an alternative spi register base address (0 selects default 0x60)
Returns:
A pointer to the EdtDev structure if successful or NULL if the open fails or the device is not attached to the SPI master on the timing board.
This EDT device handle should be used with edt_spi_ prefixed subroutines.

See the included example program timing_test.c.

Definition at line 121 of file libedt_timing.c.

u_char edt_spi_put_byte ( EdtDev edt_p,
u_char  ch 
)

Sends one byte to the EDT SPI master.

Parameters:
edt_p The EDT open device handle.
ch The byte to send to the SPI master.
Returns:
The byte sent to the SPI interface.

Definition at line 260 of file libedt_timing.c.

char* edt_spi_putstr ( EdtDev edt_p,
char *  str 
)

Send a single line of ascii string to the msp430 over the SPI.

Parameters:
edt_p The EDT open device handle.
str The string to send to the EDT SPI interface.
Returns:
A pointer to the argument string.

Definition at line 614 of file libedt_timing.c.

u_int edt_spi_reg_read ( EdtDev edt_p,
u_int  desc 
)

Read an SPI access register using the correct register base address.

Parameters:
edt_p The EDT open device handle.
desc One of the SPI_ access macros from libedt_timing.h
Returns:
The value returned from the register read.

Definition at line 70 of file libedt_timing.c.

void edt_spi_reg_write ( EdtDev edt_p,
u_int  desc,
u_int  val 
)

Write an SPI access register using the correct register base address.

Parameters:
edt_p The EDT open device handle.
desc One of the SPI_ access macros from libedt_timing.h
val Value to write to the SPI register.

Definition at line 93 of file libedt_timing.c.

void edt_spi_send_packet ( EdtDev edt_p,
u_char *  cmdbuf 
)

Send a command packet to the msp430 via the SPI; wait for output fifo full but not ACK/NAK reply.

Parameters:
edt_p The EDT open device handle.
str The formatted command buffer to send as a packet.
Packets to and from the msp430 microcontroller over the SPI bus always start with

define SPI_PKT_START 0x82 Start of packet byte.

followed by a command buffer, followed by a two-byte command buffer CRC check.

The command buffer consists of the following:

byte 0: Command byte byte 1: Number of data bytes 0 - 60 bytes 2 - 62: Command specific data bytes

Currently supported commands are:

define SPI_PACKET_LOOP 0 Loop back packet; send back the packet. Data size 0-60 bytes; no ACK/NAK response.

define SPI_TIMECODE_EN 1 Enable (1) or disable (0) the 1 Hz ascii-hex timestamp. Data size 1 byte. ACK/NAK response.

define SPI_CLK_SELECT 2 Select msp430 clock source as internal DCO (0) or external XIN (1) plus clock rate. ACK/NAK response. Data size 5 bytes; first byte selects internal/external, last 4 bytes is an integer specifying the clock rate in Hz; LS byte first; MS byte last. Currently supported clock rates for DCO (0) are 1, 8, 12 and 16 Mhz. Currently supported clock rate for XIN (1) is 10 Mhz.

define SPI_TIMECODE_PKT 3 Sent from msp430 to FPGA. Data consists of 4-8 bytes of timecode LSByte first, extended UNIX seconds time format.

The CRC check bytes apply to the command buffer (command, length and data bytes), and is computed as follows where CKL is the low CRC byte, CKH is the high CRC byte, B1 is the Command byte and Bn is the last data byte (derived from Texas Instruments Application Report SLAA089D "Features of the MSP430 Bootstrap Loader"):

CKL = INV [ B1 XOR B3 XOR ... XOR Bn–1 ] CKH = INV [ B2 XOR B4 XOR ... XOR Bn ]

Definition at line 728 of file libedt_timing.c.


Generated on 19 Jun 2015 by  doxygen 1.4.7