Exemple #1
0
// Programs a page of data.
static void page_program(uint32_t offset, const char* buf, uint16_t size) {
  start_command(COMMAND_PAGE_PROGRAM);
  write_address(offset);
  if (size > PAGE_SIZE) {
    size = PAGE_SIZE;
  }

  // The file data bit order is reversed.
  spi_set_bit_order(SPI_LSB_FIRST);
  for (; size > 0; --size, ++buf) {
    spi_tx(*buf);
  }
  spi_set_bit_order(SPI_MSB_FIRST);

  end_command();
}
Exemple #2
0
static int address_to_data(entry_ptr_t ent)
{
	int length;
	int offset;

	int son = get_digits(*(ent->data->number))+1;
	int soz = get_digits(*(ent->data->zipcode))+1;

	char nr[son];
	char zip[soz];

	offset = 5*(strlen(DATA_SEPARATOR)) + strlen(DATA_END);
	length = get_entry_length(ent) + offset;

	char line[length];
	_dbgmsg("reserved %i characters for the line", length);

	strcpy(line, ent->data->firstname);
	strcat(line, DATA_SEPARATOR);
	strcat(line, ent->data->lastname);
	strcat(line, DATA_SEPARATOR);
	strcat(line, ent->data->street);
	strcat(line, DATA_SEPARATOR);
	sprintf(nr, "%i", *(ent->data->number));
	strcat(line, nr);
	strcat(line, DATA_SEPARATOR);
	sprintf(zip, "%i", *(ent->data->zipcode));
	strcat(line, zip);
	strcat(line, DATA_SEPARATOR);
	strcat(line, ent->data->city);
	strcat(line, DATA_END);

	_dbgmsg("created line \"%s\"", line);
	write_address(line);

	return 0;
}
Exemple #3
0
void isapnp_write_byte(unsigned char idx, unsigned char val)
{
	write_address(idx);
	write_data(val);
}
Exemple #4
0
unsigned char isapnp_read_byte(unsigned char idx)
{
	write_address(idx);
	return read_data();
}
void Dynamixel::set_baud_rate(baud_rate_t baud) {
	write_address(_BAUD_RATE, baud);
}
void Dynamixel::write_id(uint8_t id) {
	write_address(_ID, id);
	m_id = id;
}
Exemple #7
0
		void write_endpoint(Endpoint const& e, OutIt& out)
		{
			write_address(e.address(), out);
			write_uint16(e.port(), out);
		}
Exemple #8
0
void
ntb_save_message(time_t timestamp,
                 struct ntb_key *from_key,
                 const char *from_address,
                 struct ntb_key *to_key,
                 struct ntb_blob *blob,
                 FILE *out)
{
        char to_address[NTB_ADDRESS_MAX_LENGTH + 1];
        struct ntb_proto_decrypted_msg msg;
        const uint8_t *eol;
        static const char *day_names[] = {
                "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
        };
        static const char *month_names[] = {
                "Jan", "Feb", "Mar", "Apr", "May", "Jun",
                "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
        };
        struct tm tm;

        ntb_address_encode(&to_key->address, to_address);

        localtime_r(&timestamp, &tm);

        fputs("From: ", out);
        write_address(from_key, from_address, out);
        fputs("\nTo: ", out);
        write_address(to_key, to_address, out);

        fprintf(out,
                "\n"
                "Date: %s, %i %s %i %02i:%02i:%02i %c%02li%02li\n"
                "Content-Type: text/plain; charset=UTF-8\n"
                "Content-Transfer-Encoding: 8bit\n",
                day_names[tm.tm_wday],
                tm.tm_mday,
                month_names[tm.tm_mon],
                tm.tm_year + 1900,
                tm.tm_hour,
                tm.tm_min,
                tm.tm_sec,
                tm.tm_gmtoff < 0 ? '-' : '+',
                labs(tm.tm_gmtoff) / 3600,
                labs(tm.tm_gmtoff) % 3600 / 60);

        ntb_proto_get_decrypted_msg(blob->data, blob->size, &msg);

        if (msg.encoding == 2 &&
            msg.message_length >= 9 &&
            !memcmp(msg.message, "Subject:", 8) &&
            (eol = memchr(msg.message, '\n', msg.message_length))) {
                fputs("Subject: ", out);
                write_subject(msg.message + 8, eol - msg.message - 8, out);
                fputc('\n', out);

                msg.message_length -= eol - msg.message + 1;
                msg.message = eol + 1;

                if (msg.message_length >= 5 &&
                    !memcmp(msg.message, "Body:", 5)) {
                        msg.message += 5;
                        msg.message_length -= 5;
                }
        }

        fputc('\n', out);
        fwrite(msg.message, 1, msg.message_length, out);
}
Exemple #9
0
/*---------------------------------------------------------------------------*/
int main(void)
{
    uint8_t rv;
    uint8_t i = 0;
    uint8_t mcp3421_addr;
    uint8_t mcp9800_addr;
    uint8_t tmpReadout[4];

    /* Variables for cold junction moving average filter */
    int16_t movAvg_read;
    int8_t movAvg_ind = 0;
    int32_t movAvg_sum = 0;
    uint8_t movAvg_stabil = 0;
    int16_t movAvg_mem[8] = {0,0,0,0,0,0,0,0};    

    gainSetting = 0;
    timer0_counter = 0;

    initSerialNumber();
    usb_init();  
    I2C_Init();  
    timer_init();

    pinMode(B,1,OUTPUT);

    /*-----------------------------------------------------------------------*/
    /* Search for viable MCP3421 address options */
    /*-----------------------------------------------------------------------*/
    for(i=0x68;i<0x70;i++)
    {
        I2C_Start();
        rv = I2C_Write(write_address(i));
        I2C_Stop();

        if(rv == 0)
        {
            mcp3421_addr = i;
        }
    }

    /*-----------------------------------------------------------------------*/
    /* Search for viable MCP9800 address options */
    /*-----------------------------------------------------------------------*/
    I2C_Start();
    rv = I2C_Write(write_address(0x48));
    I2C_Stop();

    if(rv == 0)
    {
        mcp9800_addr = 0x48;
    }
    else
    {
        mcp9800_addr = 0x4D;
    }

    /*-----------------------------------------------------------------------*/
    /* Set MCP9800 to 12 bit resolution */
    /*-----------------------------------------------------------------------*/
    I2C_Start();
    I2C_Write(write_address(mcp9800_addr));    
    I2C_Write(0x01);
    I2C_Write((1<<7)|(1<<6)|(1<<5));
    I2C_Stop();

    /*-----------------------------------------------------------------------*/
    /* Set MCP9800 Register Pointer to Ambient Temperature */
    /*-----------------------------------------------------------------------*/
    I2C_Start();
    I2C_Write(write_address(mcp9800_addr));
    I2C_Write(0x00);
    I2C_Stop();
    
    while(1)
    {                
        /*-------------------------------------------------------------------*/
        /* MCP9800: Cold junction channel */
        /*-------------------------------------------------------------------*/
        usbPoll();
        I2C_Start();
        debug[0] = I2C_Write(read_address(mcp9800_addr));
        tmpReadout[0] = I2C_Read(ACK);
        tmpReadout[1] = I2C_Read(NO_ACK);        
        I2C_Stop();

        movAvg_read = ((int16_t)tmpReadout[0] << 8) + ((int16_t)tmpReadout[1]);                
        movAvg_sum -= movAvg_mem[movAvg_ind];
        movAvg_sum += movAvg_read;        
        movAvg_mem[movAvg_ind] = movAvg_read;
        
        if(movAvg_ind == 7)
        {
            movAvg_ind = 0;
            movAvg_stabil = 1;
        }
        else
        {
            movAvg_ind++;
        }

        if(movAvg_stabil == 1)
        {
            movAvg_read = movAvg_sum >> 3;    
        }        

        usbPoll();
        cli();                                
            coldJunctionReadout[0] = movAvg_read >> 8;            
            coldJunctionReadout[1] = movAvg_read & 0xFF;          
        sei();

        /*-------------------------------------------------------------------*/
        /* MCP3421: 3.75 SPS + 18 Bits + Initiate new conversion
        /*-------------------------------------------------------------------*/
        usbPoll();
        I2C_Start();
        I2C_Write(write_address(mcp3421_addr));
        I2C_Write((1<<7)|(1<<3)|(1<<2)|gainSetting);
        I2C_Stop();

        /*-------------------------------------------------------------------*/
        /* Small delay ...
        /*-------------------------------------------------------------------*/
        timer0_counter = 250;
        while(timer0_counter)
        {
            usbPoll();            
        }

        /*-------------------------------------------------------------------*/
        /* MCP3421
        /*-------------------------------------------------------------------*/
        usbPoll();
        I2C_Start();
        I2C_Write(read_address(mcp3421_addr));
        tmpReadout[0] = I2C_Read(ACK);
        tmpReadout[1] = I2C_Read(ACK);
        tmpReadout[2] = I2C_Read(ACK);
        tmpReadout[3] = I2C_Read(NO_ACK);
        I2C_Stop();

        usbPoll();
        cli();
            thermocoupleReadout[0] = tmpReadout[0];
            thermocoupleReadout[1] = tmpReadout[1];
            thermocoupleReadout[2] = tmpReadout[2];
            thermocoupleReadout[3] = tmpReadout[3];
        sei();
    }
Exemple #10
0
// Initiates block erase.
static void block_erase(uint32_t offset) {
  start_command(COMMAND_BLOCK_ERASE);
  write_address(offset);
  end_command();
}