Пример #1
0
uint16_t BspReadEepromSerialAddress(void)
{
	uint16_t tmp = 0;
	uint16_t offset = BSP_IO_SERIAL_ADDR_OFFSET;
	NutNvMemLoad(offset,&tmp,sizeof(tmp)); //内部串口地址,不管是否配置模式
	return tmp;
}
Пример #2
0
char BspReadFactoryOut(void)
{
	char ch;
	uint16_t offset = BSP_FACTORY_OUT_OFFSET;
	NutNvMemLoad(offset,&ch,sizeof(char));
	return ch;
}
Пример #3
0
int BspReadIoTimingInfo(timint_info * info)
{
	int ret;
	uint16_t offset = BSP_IO_TIMING_OFFSET;
	uint8_t  buffer[sizeof(timint_info)+2];
	memset(info,0,sizeof(timint_info));
	memset(buffer,0,sizeof(buffer));
	ret = NutNvMemLoad(offset,buffer,sizeof(buffer));
	if(!ret) {
#if THISINFO
		int i;
		printf("read timing info:");
		for(i=0;i<sizeof(buffer);i++) {
			printf("0x%x,",buffer[i]);
		}
		printf("\r\n");
		printf("buffer[0]=0x%x,buffer[%d]=0x%x\r\n",buffer[0],sizeof(buffer)-1,buffer[sizeof(buffer)-1]);
#endif
		ret = -1;
		if(buffer[0] == 0x55 && buffer[sizeof(timint_info)+1] == 0xAA) {
			memcpy(info,&buffer[1],sizeof(timint_info));
			ret = 0;
		} else {
			if(THISERROR)printf("ERROR:read timing info data value not valid!\r\n");
		}
	} else {
		if(THISERROR)printf("ERROR:Nv Mem load failed!\r\n");
	}
	return ret;
}
Пример #4
0
int BspReadControlMode(unsigned char index,CmdInputControl * pm)
{
	int ret = -1;
	uint16_t offset = BSP_MODE_CTL_OFFSET + index * sizeof(CmdInputControl);
	if(index >= INPUT_CHANNEL_NUM) {
		return ret;
	}
	ret = NutNvMemLoad(offset,pm,sizeof(CmdInputControl));
	if(ret == 0) {
		unsigned int tmp;
		input_trig_mode[index] = pm->mode;

		tmp = pm->input_filter_time_hi;
		tmp <<= 8;
		tmp += pm->input_filter_time_lo;
		input_filter_hold_time_max[index] = tmp;

		tmp = pm->input_trig_front_time_hi;
		tmp <<= 8;
		tmp += pm->input_trig_front_time_lo;
		input_trig_before_delay_max[index] = tmp;

		tmp = pm->input_trig_after_time_hi;
		tmp <<= 8;
		tmp += pm->input_trig_after_time_lo;
		input_trig_after_delay_max[index] = tmp;

		input_trig_to_witch_io_out[index] = pm->input_trig_io_number;
	}
	return ret;
}
Пример #5
0
void NtpCheckValidTime(void){

    Eeprom_tm eeprom_tm_struct;

    NutNvMemLoad(256, &eeprom_tm_struct, sizeof(eeprom_tm_struct));

    if (eeprom_tm_struct.len != sizeof(eeprom_tm_struct)){
        // Size mismatch: There is no valid configuration present.
        puts("NtpCheckValidTime(): Size mismatch \n");
        validTime = false;
        return;
    }

    // Valid configuration available.
    puts("NtpCheckValidTime(): Valid config available \n");
    tm stored_tm = eeprom_tm_struct.tm_struct;

    // Check time is valid;
    tm current_tm;
    X12RtcGetClock(&current_tm);

    validTime = compareTime(current_tm, stored_tm);
    if (validTime){
        puts("NtpCheckValidTime(): Time was valid \n");
    }else {
        puts("NtpCheckValidTime(): Invalid time! \n");
    }
}
Пример #6
0
int BspReadIoTiming(uint16_t index,timing_node_eeprom * time)
{
	uint16_t offset = BSP_IO_TIMING_OFFSET+1+sizeof(timint_info)+1;
	if(index >= SYS_TIMING_COUNT_MAX) {
		return -1;
	}
	offset += sizeof(timing_node_eeprom)*index;
	return NutNvMemLoad(offset,time,sizeof(timing_node_eeprom));
}
Пример #7
0
int BspTimingStartWrite(void)
{
	uint16_t offset = BSP_IO_TIMING_OFFSET;
	uint8_t  buffer[sizeof(timint_info)+2];
	memset(buffer,0,sizeof(buffer));
	buffer[0] = 0x55;
	NutNvMemLoad(offset,time_last_head,sizeof(time_last_head));
	return NutNvMemSave(offset,buffer,sizeof(buffer));
}
Пример #8
0
int BspReadManualCtlModeIndex(unsigned char index,unsigned char * mode)
{
	int ret  = 0;
	if(index >= INPUT_CHANNEL_NUM) {
		return -1;
	}
	ret = NutNvMemLoad(BSP_MODE_INDEX_OFFSET+index,&input_trig_mode[index],1);
	*mode = input_trig_mode[index];
	return ret;
}
Пример #9
0
void BspWriteEepromSerialAddress(uint16_t address)
{
	uint16_t offset = BSP_IO_SERIAL_ADDR_OFFSET;
	if(IoGetConfig()&(1<<0)) {  //配置为1的时候,才能写数据
		uint16_t tmp;
		NutNvMemLoad(offset,&tmp,sizeof(tmp));
		if(tmp != address) {
			NutNvMemSave(offset,&address,sizeof(address));
		}
	}
}
Пример #10
0
int BspReadIoName(uint8_t addr[2],CmdIoName * io)
{
	uint16_t offset = BSP_IO_NAME_OFFSET;
	if(addr[1] == 0) {
		offset += addr[0]*sizeof(CmdIoName);
	} else if(addr[1] == 1) {
		offset += OUTPUT_NUM*sizeof(CmdIoName) + addr[0]*sizeof(CmdIoName);
	} else {
		memset(io->io_name,0,sizeof(io->io_name));
		return -1;
	}
	return NutNvMemLoad(offset,io,sizeof(CmdIoName));
}
Пример #11
0
int BspReadManualCtlModeIndex(unsigned char index,unsigned char * mode)
{
	int ret = -1;
	CmdInputControl ctl;
	uint16_t offset = BSP_MODE_CTL_OFFSET + index * sizeof(CmdInputControl);
	if(index >= INPUT_CHANNEL_NUM) {
		return ret;
	}
	ret = NutNvMemLoad(offset,&ctl,sizeof(CmdInputControl));
	if(ret == 0) {
		*mode = ctl.mode;
	}
	return ret;
}
Пример #12
0
int BspWriteManualCtlModeIndex(unsigned char index,unsigned char mode)
{
	int ret = -1;
	CmdInputControl ctl;
	uint16_t offset = BSP_MODE_CTL_OFFSET + index * sizeof(CmdInputControl);
	if(index >= INPUT_CHANNEL_NUM) {
		return ret;
	}
	ret = NutNvMemLoad(offset,&ctl,sizeof(CmdInputControl));
	ctl.mode = mode;
	ret = NutNvMemSave(offset,&ctl,sizeof(CmdInputControl));
	if(ret == 0) {
		input_trig_mode[index] = mode;
	}
	return ret;
}
Пример #13
0
/*!
 * \brief Load Nut/OS configuration from non-volatile memory.
 *
 * This routine is automatically called during system initialization.
 * It tries to read the OS configuration structure \ref CONFOS from
 * non-volatile memory, starting at /ref CONFOS_EE_OFFSET.
 *
 * The routine may fail, if 
 * - non-volatile memory is not supported,
 * - non-volatile memory contains invalid data,
 * - the configuration structure has changed.
 *
 * \return 0 if OK, -1 on failures, in which case the hostname will
 *         be set to \ref CONFOS_VIRGIN_HOSTNAME.
 */
int NutLoadConfig(void)
{
    /* Sanity check. */
    NUTASSERT(sizeof(CONFOS) <= 255);

    if (NutNvMemLoad(CONFOS_EE_OFFSET, &confos, sizeof(CONFOS)) == 0 /* If loaded... */
        && confos.size == sizeof(CONFOS) /* ...check magic size and cookie. */
        && memcmp(confos.magic, CONFOS_EE_MAGIC, sizeof(CONFOS_EE_MAGIC) - 1) == 0) {
            return 0;
    }

    /* No valid configuration, set virgin hostname. */
    NUTASSERT(sizeof(confos.hostname) > strlen(CONFOS_VIRGIN_HOSTNAME));
    strcpy(confos.hostname, CONFOS_VIRGIN_HOSTNAME);

    return -1;
}
Пример #14
0
//读写网页密码
int BspReadWebPassword(char *password)
{
	int ret;
	if(IoGetConfig()&(1<<0)) {
		gpassword[0] = 'a';
		gpassword[1] = 'd';
		gpassword[2] = 'm';
		gpassword[3] = 'i';
		gpassword[4] = 'n';
		gpassword[5] = 0;
		ret = 0;
	} else {
	    ret = NutNvMemLoad(BSP_KEY_OFFSET,password,sizeof(gpassword));
	    gpassword[31] = 0;
	}
	return ret;
}
Пример #15
0
/*!
 * \brief Load network configuration from non-volatile memory.
 *
 * If no configuration is available in EEPROM, all configuration
 * parameters are cleared to zero. Except the MAC address, which
 * is set to the Ethernet broadcast address.
 *
 * \param name Name of the device.
 *
 * \return 0 if configuration has been read. Otherwise the
 *         return value is -1.
 */
int NutNetLoadConfig(CONST char *name)
{
#ifndef __NUT_EMULATION__	
    if (NutNvMemLoad(CONFNET_EE_OFFSET, &confnet, sizeof(CONFNET))) {
        return -1;
    }
    if (confnet.cd_size == sizeof(CONFNET) && strcmp(confnet.cd_name, name) == 0) {
        return 0;
    }
#endif
    memset(&confnet, 0, sizeof(confnet));

    /*
     * Set initial MAC address to broadcast. Thanks to Tomohiro
     * Haraikawa, who pointed out that all zeroes is occupied by
     * Xerox and should not be used.
     */
    memset(confnet.cdn_mac, 0xFF, sizeof(confnet.cdn_mac));

    return -1;
}
Пример #16
0
int main(void)
{
    struct _tm timeCheck;

    WatchDogDisable();

    NutDelay(100);

    SysInitIO();

	SPIinit();

	LedInit();

	LcdLowLevelInit();

    Uart0DriverInit();
    Uart0DriverStart();
	LogInit();

    X12Init();

    VsPlayerInit();

    NtpInit();

    NutThreadCreate("BackgroundThread", StartupInit, NULL, 1024);
    NutThreadCreate("BackgroundThread", AlarmSync, NULL, 2500);
    NutThreadCreate("BackgroundThread", AlarmCheck, NULL, 256);

	KbInit();

    SysControlMainBeat(ON);             // enable 4.4 msecs heartbeat interrupt

    /*
     * Increase our priority so we can feed the watchdog.
     */
    NutThreadSetPriority(1);

	/* Enable global interrupts */
	sei();
	
	LcdBackLight(LCD_BACKLIGHT_ON);
    setCurrentDisplay(DISPLAY_DateTime, 5);

    X12RtcGetClock(&timeCheck);
    int hours;
    int mins;
    int secs;
    if(!NutNvMemLoad(100, &hours, sizeof(hours)))
    {
        printf("uren: %d", hours);
    }
    if(!NutNvMemLoad(105, &mins, sizeof(mins)))
    {
        printf(" minuten: %d", mins);
    }
    if(!NutNvMemLoad(110, &secs, sizeof(secs)))
    {
        printf(" seconden %d", secs);
    }
    printf("Welcome to Saltyradio.\nI'm using mac address:  %s\n\n\n", getMacAdress());

    for (;;)
    {
        //Key detecten
        if(KbGetKey() == KEY_01){
            setCurrentDisplay(DISPLAY_DateTime, 5);
        }
        else if(KbGetKey() == KEY_OK)
        {
            if(getCurrentDisplay() == DISPLAY_MainMenu)
            {
                clickOk();
            }
            else if(getCurrentDisplay() == DISPLAY_SettingsMenu)
            {
                clickOkSettings();
            }
            else if(getCurrentDisplay() == DISPLAY_Play || getCurrentDisplay() == DISPLAY_Song)
            {
                clickOkPlay();
            }
            else
            {
                setCurrentDisplay(DISPLAY_MainMenu, 10000);
            }
        }
        else if(KbGetKey() == KEY_LEFT)
        {
            switchLeft();
        }
        else if(KbGetKey() == KEY_RIGHT)
        {
            switchItem();
        }
        else if(KbGetKey() == KEY_DOWN){
            setCurrentDisplay(DISPLAY_Volume, 5);
            volumeDown();
        }else if(KbGetKey() == KEY_UP) {
            setCurrentDisplay(DISPLAY_Volume, 5);
            volumeUp();
        }
        refreshScreen();
        WatchDogRestart();
        NutSleep(100);
    }
    return(0);
}
Пример #17
0
int BspManualCtlModeInit(void)
{
	return NutNvMemLoad(BSP_MODE_INDEX_OFFSET,input_trig_mode,INPUT_CHANNEL_NUM);
}
Пример #18
0
int load_relay_info(ethernet_relay_info * info)
{
	uint16_t offset = BSP_HTTP_CLIENT_INFO_OFFSET;
	NutNvMemLoad(offset,info,sizeof(ethernet_relay_info));
}
Пример #19
0
void BspLoadmultimgr_info(device_info_st * info)
{
	uint16_t offset = BSP_MULTI_MANGER_DATA_OFFSET;
	NutNvMemLoad(offset,info,sizeof(device_info_st));
}
Пример #20
0
int BspReadIpConfig(CmdIpConfigData * cid)
{
	return NutNvMemLoad(BSP_IP_ADDR_OFFSET,cid,sizeof(CmdIpConfigData));
}
Пример #21
0
int BspReadHostAddress(host_address * info)
{
	return NutNvMemLoad(HOST_ADDRESS_CONFIG,info,sizeof(host_address));
}
Пример #22
0
int BspReadBoardInfo(CmdBoardInfo * info)
{
	return NutNvMemLoad(BSP_BOARD_INFO_OFFSET,info,sizeof(CmdBoardInfo));
}