Commit 1ecc871b authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

shell: time/sfp commands, added missing makefiles

parent 0870173d
OBJS_DEV = dev/dna.o \
dev/eeprom.o \
dev/endpoint.o \
dev/ep_pfilter.o \
dev/i2c.o \
dev/minic.o \
dev/onewire.o \
dev/pps_gen.o \
dev/syscon.o \
dev/uart.o \
dev/sfp.o
/* SFP Detection / managenent functions */
#include <stdio.h>
#include <inttypes.h>
#include "syscon.h"
#include "i2c.h"
#include "sfp.h"
int sfp_present()
{
return !gpio_in(GPIO_SFP_DET);
}
int sfp_read_part_id(char *part_id)
{
int i;
uint8_t data, sum;
mi2c_init(WRPC_SFP_I2C);
mi2c_start(WRPC_SFP_I2C);
mi2c_put_byte(WRPC_SFP_I2C, 0xA0);
mi2c_put_byte(WRPC_SFP_I2C, 0x00);
mi2c_repeat_start(WRPC_SFP_I2C);
mi2c_put_byte(WRPC_SFP_I2C, 0xA1);
mi2c_get_byte(WRPC_SFP_I2C, &data, 1);
mi2c_stop(WRPC_SFP_I2C);
sum = data;
mi2c_start(WRPC_SFP_I2C);
mi2c_put_byte(WRPC_SFP_I2C, 0xA1);
for(i=1; i<63; ++i)
{
mi2c_get_byte(WRPC_SFP_I2C, &data, 0);
sum = (uint8_t) ((uint16_t)sum + data) & 0xff;
if(i>=40 && i<=55) //Part Number
part_id[i-40] = data;
}
mi2c_get_byte(WRPC_SFP_I2C, &data, 1); //final word, checksum
mi2c_stop(WRPC_SFP_I2C);
if(sum == data)
return 0;
return -1;
}
/* SFP Detection / management functions */
#ifndef __SFP_H
#define __SFP_H
#include <stdint.h>
struct sfp_info {
char part_no[16];
int32_t delta_tx, delta_rx, alpha;
};
/* Returns 1 if there's a SFP transceiver inserted in the socket. */
int sfp_present();
/* Reads the part ID of the SFP from its configuration EEPROM */
int sfp_read_part_id(char *part_id);
/* SFP Database functions */
/* Adds an SFP to the DB */
int sfp_db_add(struct sfp_info *sinfo);
/* Searches for an SFP matching its' part_id */
struct sfp_info *sfp_db_lookup(const char *part_id);
struct sfp_info *sfp_db_get(int i);
void sfp_db_clear();
#endif
#ifndef __UTIL_H
#define __UTIL_H
/* Color codes for cprintf()/pcprintf() */
#define C_DIM 0x80
#define C_WHITE 7
#define C_GREY (C_WHITE | C_DIM)
#define C_RED 1
#define C_GREEN 2
#define C_BLUE 4
/* Return TAI date/time in human-readable form. Non-reentrant. */
char *format_time(uint32_t utc);
/* Color printf() variant. */
void cprintf(int color, const char *fmt, ...);
/* Color printf() variant, sets curspor position to (row, col) before printing. */
void pcprintf(int row, int col, int color, const char *fmt, ...);
/* Clears the terminal scree. */
void term_clear();
#endif
......@@ -11,9 +11,25 @@
#include "shell.h"
#include "sfp.h"
int cmd_sfp(const char *args[])
{
if(args[0] && !strcasecmp(args[0], "detect"))
{
char pn[17];
if(!sfp_present())
mprintf("No SFP.\n");
else
sfp_read_part_id(pn);
pn[16]=0;
mprintf("%s\n",pn);
return 0;
} else if (args[3] && !strcasecmp(args[0], "add"))
{
}
return 0;
}
\ No newline at end of file
/* Command: time
Arguments:
set UTC NSEC - sets time
raw - dumps raw time
<none> - dumps pretty time
Description: (re)starts/stops the PTP session. */
#include <errno.h>
#include <string.h>
#include "shell.h"
#include "wrc_ptp.h"
#include "pps_gen.h"
extern char *format_time(uint32_t utc);
int cmd_time(const char *args[])
{
uint32_t utc, nsec;
pps_gen_get_time(&utc, &nsec);
if(args[2] && !strcasecmp(args[0], "set")) {
if(wrc_ptp_get_mode() != WRC_MODE_SLAVE)
{
pps_gen_set_time(atoi(args[1]), atoi(args[2]) / 8);
return 0;
} else
return -EBUSY;
} else if(args[0] && !strcasecmp(args[0], "raw"))
{
mprintf("%d %d\n", utc, nsec);
return 0;
}
mprintf("%s +%d nanoseconds.\n", format_time(utc), nsec*8); /* fixme: clock freq is not always 125 MHz */
return 0;
}
\ No newline at end of file
......@@ -44,6 +44,7 @@ static const struct shell_cmd cmds_list[] = {
{ "env", cmd_env },
{ "saveenv", cmd_saveenv },
{ "time", cmd_time },
{ "sfp", cmd_sfp },
{ NULL, NULL }
};
......
......@@ -3,6 +3,7 @@
int cmd_gui(const char *args[]);
int cmd_pll(const char *args[]);
int cmd_sfp(const char *args[]);
int cmd_version(const char *args[]);
int cmd_stat(const char *args[]);
int cmd_ptp(const char *args[]);
......
......@@ -2,6 +2,7 @@ OBJS_SHELL = shell/shell.o \
shell/environ.o \
shell/cmd_version.o \
shell/cmd_pll.o \
shell/cmd_sfp.o \
shell/cmd_stat.o \
shell/cmd_ptp.o \
shell/cmd_mode.o \
......
OBJS_SOFTPLL = softpll/softpll_ng.o
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment