From: zer0 Date: Wed, 20 Jan 2010 22:53:19 +0000 (+0100) Subject: compilation on host X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=5ded7a62fc884aa9025cb0bc9da7fd4b75814797;p=aversive.git compilation on host --- diff --git a/include/aversive/eeprom.h b/include/aversive/eeprom.h new file mode 100644 index 0000000..0b165c2 --- /dev/null +++ b/include/aversive/eeprom.h @@ -0,0 +1,41 @@ +/* + * Copyright Droids Corporation, Microb Technology, Eirbot (2005) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: eeprom.h,v 1.1.2.4 2007-11-21 21:54:38 zer0 Exp $ + * + */ + +/** + * This file is used for compatibility between host and avr : with + * this we can emulate eeprom on a host. + */ + +#ifndef _AVERSIVE_EEPROM_H_ +#define _AVERSIVE_EEPROM_H_ + +#ifndef HOST_VERSION + +#include + +#else + +/* XXX */ + +#endif /* HOST_VERSION */ +#endif /* _AVERSIVE_EEPROM_H_ */ + + diff --git a/modules/comm/spi/spi_host.c b/modules/comm/spi/spi_host.c new file mode 100644 index 0000000..9ccf87d --- /dev/null +++ b/modules/comm/spi/spi_host.c @@ -0,0 +1,159 @@ +/* + * Copyright Droids Corporation (2008) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + * Host wrapper for SPI + */ + +#include +#include +#include + +#include +#include + +#include +#include + +/* global vars */ +static volatile uint8_t g_ss_number; +static volatile spi_mode_t g_spi_mode; +static volatile uint8_t g_slave_selected; +static volatile uint8_t g_spi_order; +static volatile spi_format_t g_spi_format; +static volatile spi_mode_t g_spi_mode; +static volatile spi_clk_rate_t g_spi_clk_rate; + +/* + * Register a pin as SS line + * Returns a unique identifier, or -1 on error + * There is always the physical SS line registered as 0 + */ +int8_t spi_register_ss_line(volatile uint8_t *port, uint8_t bitnum) +{ + DEBUG(E_SPI, "Trying to register new SS line: port 0x%x, bitnum %d", port, bitnum); + /* too much SS lines (try to change SPI_MAX_SLAVES) */ + if (g_ss_number >= SPI_MAX_SLAVES+1) + return -1; + + NOTICE(E_SPI, "New Slave Line registered: %d", g_ss_number); + return g_ss_number++; +} + + +/* + * Set data order (default: MSB first) + */ +inline void spi_set_data_order(uint8_t order) +{ + g_spi_order = order; +} + +/* + * Get data order + */ +inline uint8_t spi_get_data_order(void) +{ + return g_spi_order; +} + + +/* + * Initialize SPI + */ +void spi_init(spi_mode_t mode, spi_format_t format, spi_clk_rate_t clk_rate) +{ + NOTICE(E_SPI, "Init SPI: mode %d, format %d, clk_rate %d", + mode, format, clk_rate); + + /* SS pin is not driven by SPI hardware + * This is taken care of by spi_register_ss_line() + * EVEN for the "default" SS line */ + g_ss_number = 0; + g_spi_format = format; + g_spi_clk_rate = clk_rate; + g_slave_selected = FALSE; + g_spi_mode = SPI_MODE_MASTER; + NOTICE(E_SPI, "Init done"); +} + +/* + * Returns the state of SPI + */ +inline spi_mode_t spi_get_mode(void) +{ + return g_spi_mode; +} + +/* + * Send a byte (and receive one) + * Returns the received byte + */ +uint8_t spi_send_and_receive_byte(uint8_t byte) +{ + /* XXX */ + return 0; +} + +/* + * Send a byte, discard the result + */ +inline void spi_send_byte(uint8_t byte) +{ + spi_send_and_receive_byte(byte); +} + +/* + * Receives a byte (sends a NULL) + */ +uint8_t spi_receive_byte(void) +{ + return spi_send_and_receive_byte(0x00); +} + +/* + * Activates the selected SS line + */ +uint8_t spi_slave_select(uint8_t slave) +{ + if (g_slave_selected) { + ERROR(E_SPI, "A slave is already selected !"); + return EBUSY; + } + + /* XXX */ + g_slave_selected = TRUE; + return ESUCCESS; +} + +/* + * Desactivates the selected SS line + */ +void spi_slave_deselect(uint8_t slave) +{ + /* XXX */ + g_slave_selected = FALSE; +} + +/* + * Display SS lines + */ +void spi_display_ss_lines(void) +{ +}