/* This file is part of MANTIS OS, Operating System for Nymph. See http://mantis.cs.colorado.edu/ Copyright (C) 2003 University of Colorado, Boulder */ /** * @File: i2c_support.c * @Brief: Taken from mos/src/test/weatherboard_test.c * A file to test the weather-sensor board. */ #include "mos.h" #include "command_daemon.h" #include "printf.h" #include "com.h" #include "led.h" #include "dev.h" #include "avr-i2c.h" #include "avr-eeprom.h" //devines the DEV_AVR_EEPROM_SEEK ioctl #include "avr-adc.h" #include "adc.h" #undef HAVE_ME_START /* REMEMBER * to include the following declarations if the load file * follows the main routine where the references are void i2c_write(); void i2c_read(); void i2c_dest(); void i2c_setbrr(); void i2c_slave(); void i2c_enable_ack(); void i2c_disable_ack(); void i2c_report(); */ //---------------------------------------- #ifdef HAVE_ME_START void start (void) { mos_thread_new (mos_command_daemon, MOS_COMMANDER_STACK_SIZE + 60, PRIORITY_NORMAL); printf ("AVR-I2C Test\n"); mos_register_function ("i2c_write", i2c_write); mos_register_function ("i2c_read", i2c_read); mos_register_function ("i2c_setbrr",i2c_setbrr); mos_register_function ("i2c_setbrr",i2c_setbrr); mos_register_function ("i2c_dest",i2c_dest); mos_register_function ("i2c_slave",i2c_slave); mos_register_function ("i2c_enable_ack",i2c_enable_ack); mos_register_function ("i2c_disable_ack",i2c_disable_ack); mos_register_function ("setup",setup); /* printf ("AVR-I2C Test\n"); printf( "1 = Set I2C Addr\n2 = write\n3=read\n4=enable_ack\n5=disable_ack\n6=setup\n"); ix = prompt_uint8("Enter Option:"); printf( "You Entered: %d = 0x%x",ix,ix); dev_write(DEV_AVR_I2C, i, sizeof(i)); printf("Wrote: %C\n",i); */ } #endif //---------------------------------------- void i2c_write () { uint8_t i = prompt_uint8("#:"); dev_write(DEV_AVR_I2C, &i, 1); printf("Wrote: %C\n",i); mos_thread_sleep(50); // pause awhile before returning com_flush(IFACE_SERIAL); // and flush the serial buffer } void i2c_read () { uint8_t i; dev_read(DEV_AVR_I2C, &i, 1); printf("i2c Value: %C\n",i); mos_thread_sleep(50); // pause awhile before returning com_flush(IFACE_SERIAL); // and flush the serial buffer } void i2c_setbrr () { uint8_t i = prompt_uint8("#:"); dev_ioctl(DEV_AVR_I2C, I2C_SET_BRR, i); printf("BRR: %C\n",i); mos_thread_sleep(50); // pause awhile before returning com_flush(IFACE_SERIAL); // and flush the serial buffer } void i2c_dest () { uint8_t i = prompt_uint8("#:"); dev_ioctl(DEV_AVR_I2C, I2C_DEST_ADDR, i); } void i2c_slave () { uint8_t i = prompt_char("#:"); dev_ioctl(DEV_AVR_I2C, I2C_SLAVE_ADDR, i); } void i2c_enable_ack () { dev_ioctl(DEV_AVR_I2C, I2C_ENABLE_ACK); printf("Auto-Ack enabled.\n"); mos_thread_sleep(50); // pause awhile before returning com_flush(IFACE_SERIAL); // and flush the serial buffer } void i2c_disable_ack () { dev_ioctl(DEV_AVR_I2C, I2C_DISABLE_ACK); printf("Auto-Ack disabled.\n"); mos_thread_sleep(50); // pause awhile before returning com_flush(IFACE_SERIAL); // and flush the serial buffer } void i2c_report () { printf("Status = %x",avr_i2c_get_status()); mos_thread_sleep(50); // pause awhile before returning com_flush(IFACE_SERIAL); // and flush the serial buffer }