[tuxdroid-svn] r678 - in firmware/fuxusb/tags: . 0.3.1 0.3.1/lib_board 0.3.1/lib_c 0.3.1/lib_mcu 0
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-11-09 16:50:43
|
Author: jaguarondi Date: 2007-11-09 17:11:44 +0100 (Fri, 09 Nov 2007) New Revision: 678 Added: firmware/fuxusb/tags/0.3.1/ firmware/fuxusb/tags/0.3.1/bootloading.c firmware/fuxusb/tags/0.3.1/bootloading.h firmware/fuxusb/tags/0.3.1/config.h firmware/fuxusb/tags/0.3.1/global.c firmware/fuxusb/tags/0.3.1/global.h firmware/fuxusb/tags/0.3.1/i2c.c firmware/fuxusb/tags/0.3.1/i2c.h firmware/fuxusb/tags/0.3.1/lib_board/ firmware/fuxusb/tags/0.3.1/lib_board/c5131_evab.h firmware/fuxusb/tags/0.3.1/lib_board/kbd_drv.c firmware/fuxusb/tags/0.3.1/lib_board/kbd_drv.h firmware/fuxusb/tags/0.3.1/lib_c/ firmware/fuxusb/tags/0.3.1/lib_c/stdint.h firmware/fuxusb/tags/0.3.1/lib_mcu/ firmware/fuxusb/tags/0.3.1/lib_mcu/5131_drv.h firmware/fuxusb/tags/0.3.1/lib_mcu/c51_drv.h firmware/fuxusb/tags/0.3.1/lib_mcu/compiler.h firmware/fuxusb/tags/0.3.1/lib_mcu/ext_5131.h firmware/fuxusb/tags/0.3.1/lib_mcu/fa-usb/ firmware/fuxusb/tags/0.3.1/lib_mcu/fa-usb/fa-usb.html firmware/fuxusb/tags/0.3.1/lib_mcu/fa-usb/flash_api.bak firmware/fuxusb/tags/0.3.1/lib_mcu/fa-usb/flash_api.c firmware/fuxusb/tags/0.3.1/lib_mcu/fa-usb/flash_api.h firmware/fuxusb/tags/0.3.1/lib_mcu/mcu.h firmware/fuxusb/tags/0.3.1/lib_mcu/mcu_drv.h firmware/fuxusb/tags/0.3.1/lib_mcu/reg_5131.h firmware/fuxusb/tags/0.3.1/lib_mcu/spi/ firmware/fuxusb/tags/0.3.1/lib_mcu/spi/spi_lib.c firmware/fuxusb/tags/0.3.1/lib_mcu/spi/spi_lib.h firmware/fuxusb/tags/0.3.1/lib_mcu/twi/ firmware/fuxusb/tags/0.3.1/lib_mcu/twi/twi.h firmware/fuxusb/tags/0.3.1/lib_mcu/uart/ firmware/fuxusb/tags/0.3.1/lib_mcu/uart/tools/ firmware/fuxusb/tags/0.3.1/lib_mcu/uart/tools/c51_bdr.c firmware/fuxusb/tags/0.3.1/lib_mcu/uart/uart_bdr.h firmware/fuxusb/tags/0.3.1/lib_mcu/uart/uart_lib.c firmware/fuxusb/tags/0.3.1/lib_mcu/uart/uart_lib.h firmware/fuxusb/tags/0.3.1/lib_mcu/usb/ firmware/fuxusb/tags/0.3.1/lib_mcu/usb/uart_usb_lib.c firmware/fuxusb/tags/0.3.1/lib_mcu/usb/uart_usb_lib.h firmware/fuxusb/tags/0.3.1/lib_mcu/usb/usb_drv.c firmware/fuxusb/tags/0.3.1/lib_mcu/usb/usb_drv.h firmware/fuxusb/tags/0.3.1/main.c firmware/fuxusb/tags/0.3.1/modules/ firmware/fuxusb/tags/0.3.1/modules/fifo/ firmware/fuxusb/tags/0.3.1/modules/fifo/fifo.c firmware/fuxusb/tags/0.3.1/modules/fifo/fifo.h firmware/fuxusb/tags/0.3.1/modules/fifo/fifo_mic.c firmware/fuxusb/tags/0.3.1/modules/fifo/fifo_mic.h firmware/fuxusb/tags/0.3.1/modules/fifo/fifo_spk.c firmware/fuxusb/tags/0.3.1/modules/fifo/fifo_spk.h firmware/fuxusb/tags/0.3.1/modules/fifo_stt/ firmware/fuxusb/tags/0.3.1/modules/fifo_stt/fifo_stt.bak firmware/fuxusb/tags/0.3.1/modules/fifo_stt/fifo_stt.c firmware/fuxusb/tags/0.3.1/modules/fifo_stt/fifo_stt.h firmware/fuxusb/tags/0.3.1/modules/scheduler/ firmware/fuxusb/tags/0.3.1/modules/scheduler/scheduler.c firmware/fuxusb/tags/0.3.1/modules/scheduler/scheduler.h firmware/fuxusb/tags/0.3.1/modules/spi/ firmware/fuxusb/tags/0.3.1/modules/spi/spi_task.c firmware/fuxusb/tags/0.3.1/modules/spi/spi_task.h firmware/fuxusb/tags/0.3.1/modules/timer_soft/ firmware/fuxusb/tags/0.3.1/modules/timer_soft/timer_soft.c firmware/fuxusb/tags/0.3.1/modules/timer_soft/timer_soft.gif firmware/fuxusb/tags/0.3.1/modules/timer_soft/timer_soft.h firmware/fuxusb/tags/0.3.1/modules/usb/ firmware/fuxusb/tags/0.3.1/modules/usb/usb_task.c firmware/fuxusb/tags/0.3.1/modules/usb/usb_task.h firmware/fuxusb/tags/0.3.1/modules/usb_enum/ firmware/fuxusb/tags/0.3.1/modules/usb_enum/USB_ENUM.H firmware/fuxusb/tags/0.3.1/modules/usb_enum/usb_enum.c firmware/fuxusb/tags/0.3.1/usb_RFDongle.Uv2 firmware/fuxusb/tags/0.3.1/version.h Log: * Version 0.3.1 of fuxusb added directly as a tag as this code wasn't in SVN yet. It's the stable USB code released on production early 2007. This update adds versioning through standard tux commands. Property changes on: firmware/fuxusb/tags/0.3.1 ___________________________________________________________________ Name: svn:externals + common -r 677 http://svn.tuxisalive.com/firmware/tuxdefs Added: firmware/fuxusb/tags/0.3.1/bootloading.c =================================================================== --- firmware/fuxusb/tags/0.3.1/bootloading.c (rev 0) +++ firmware/fuxusb/tags/0.3.1/bootloading.c 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,49 @@ +/* KySoH iTux agent + * + * Behavioural source code + * created on 2005/10/19 David Bourgeois + * -------------------------------------------------------- + * $Id: main.c 28 2006-01-12 16:51:01Z david $ + */ + +//#include "lib_mcu/twi/twi.h" +#include "bootloading.h" + +uint8_t Command_FromUSB_bootload_cmd; +uint8_t cpu_address; +uint8_t page_size; +uint8_t page_address; +uint8_t packets_per_page; +uint8_t address_idx; +uint8_t packet_idx; + +blHeader_t blHeader; /* header for bootloading */ + +/* + * Initialize i2c interface + */ +void blInit(void) +{ + i2cSetBitrate(); /* set TWI bitrate */ + i2cInit(); /* initialize TWI interface */ + blHeader.blData = &i2cSendData[2]; +} + +/* + * Sends the data stored in i2cSendData array. Only the + * 'dataLength' first bytes are sent. + * + * Prepare the i2c communication and store the page address in the + * i2c buffer. Status can be followed with i2cFlags.i2c_busy which + * is set when the communication is in progress and cleared when + * done. i2cFlags.s_val is set when the bootload has succeded. + */ +void blSendData(blHeader_t blHeader, uint8_t dataLength) +{ + i2cFlags.s_val = 0; + i2cDeviceAddrRW = blHeader.slave_address; + i2cSendData[0] = blHeader.page_address >> 8; /* the first 2 bytes of the i2c frame are the page address */ + i2cSendData[1] = blHeader.page_address; + i2cSendDataLength = dataLength + 2; + i2cMasterStart(); +} Added: firmware/fuxusb/tags/0.3.1/bootloading.h =================================================================== --- firmware/fuxusb/tags/0.3.1/bootloading.h (rev 0) +++ firmware/fuxusb/tags/0.3.1/bootloading.h 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2006, C2ME S.A. + * All rights reserved. + * + * $Id:$ + */ + +#ifndef _BOOTLOADING_H_ +#define _BOOTLOADING_H_ + +#include "lib_c/stdint.h" +#include "i2c.h" +#include "config.h" + +/** USB bootloader commands */ +#define BOOT_INIT 1 +#define BOOT_FILLPAGE 2 +#define BOOT_EXIT 3 + +#define BOOTLOADER_CMD (uint8_t)0xF0 /* Bootloader status command */ + +/** + * \brief Bootloading header structure which holds all information to initiate + * a bootloading communication + */ +typedef struct blHeader_s { + /* 7 bits slave address aligned left + rw bit */ + uint8_t slave_address; + /* 16 bits address of the first byte of the page to write */ + uint16_t page_address; + /* page length in multiple of 64 bytes */ + uint8_t page_length; + /* pointer to the bootloader data */ + uint8_t xdata *blData; +} blHeader_t; + +extern blHeader_t blHeader; + +/* + * Extern declarations + */ + +void blInit(void); +void blSendData(blHeader_t blHeader, uint8_t dataLength); + +extern uint8_t Command_FromUSB_bootload_cmd; +extern uint8_t cpu_address; +extern uint8_t page_size; +extern uint8_t page_address; +extern uint8_t packets_per_page; +extern uint8_t address_idx; +extern uint8_t packet_idx; + +#endif /* _BOOTLOADING_H_ */ Added: firmware/fuxusb/tags/0.3.1/config.h =================================================================== --- firmware/fuxusb/tags/0.3.1/config.h (rev 0) +++ firmware/fuxusb/tags/0.3.1/config.h 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,130 @@ +/*H************************************************************************** +* NAME: config.h +*---------------------------------------------------------------------------- +* Copyright (c) 2004 Atmel. +*---------------------------------------------------------------------------- +* PURPOSE: +* Describes the system dependant software configuration. +* This file is included by all source files in order to access to system wide +* configuration. +*---------------------------------------------------------------------------- +* $Id: config.h 482 2007-03-16 15:02:58Z david $ +*****************************************************************************/ + +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + +/*_____ I N C L U D E S ____________________________________________________*/ +#include "version.h" +#include "lib_c/stdint.h" +#include "lib_mcu/compiler.h" +#include "lib_mcu/reg_5131.h" +#include "lib_mcu/ext_5131.h" +#include "lib_mcu/5131_drv.h" +#include <stdio.h> + +/*_____ M A C R O S ________________________________________________________*/ + + +//#define USB_ENUM_DEBUG +//#define MAIN_DEBUG +//#define USB_TASK_DEBUG +//#define BOOTLOAD_DEBUG + +#define DEBUG_1 P3_6 +#define DEBUG_2 P4_0 + +/*_____ D E F I N I T I O N ________________________________________________*/ + +// Board config +#define FOSC 24000 +#define CPUB_VERSION //#define FILE_BOARD_H "lib_board/c5131_evab.h" 0x0102 +#define X2_MODE // Allow use of c51 x2 mode feature + +#define SPI_Clock_Div8 + + +#define BAUDRATE 115200 // in bps +#define BDR_GENERATOR BRG_TIMER2 // Available value: BRG_INTERNAL, BRG_TIMER1, BRG_TIMER2 + + + +/*_____ D E F I N I T I O N ________________________________________________*/ + +/* USB Configuration */ + /* DEVICE DESCRIPTOR */ + + +#define EP_AUDIO_IN 1 +#define EP_AUDIO_OUT 2 +#define EP_AUDIO_OUT_TTS 3 +#define EP_CMD_IN 4 +#define EP_CMD_OUT 5 + + + +#define USB_SPECIFICATION 0x1001 +#define DEVICE_CLASS 0x00 +#define DEVICE_SUB_CLASS 0 +#define DEVICE_PROTOCOL 0 +#define EP_CONTROL_LENGTH 32 + +#define VENDOR_ID 0xEB03 /* Atmel vendor ID = 03EBh */ +#define PRODUCT_ID 0x07FF /* Product ID: FF07h*/ +#define RELEASE_NUMBER (0x0100*VER_UPDATE)+(0x1000*VER_MINOR)+(0x0001*VER_MAJOR) // 0x2021 //(VER_MAJOR)//((0x0000)|(VER_MAJOR<<24)|(VER_MINOR<<8)|(VER_UPDATE)) +#define NB_CONFIGURATION 1 + + + /* CONFIGURATION DESCRIPTOR */ +#define CONF_LENGTH 0xE800 // 232 +#define NB_INTERFACE 6 +#define CONF_NB 1 +#define CONF_ATTRIBUTES USB_CONFIG_BUSPOWERED +#define MAX_POWER 50 /* 100 mA */ + +#define LANG_ID 0x00 +#define LANGUAGE_ID 0x0904 + +#define EP_CONTROL 0x00 +#define EP_IN 0x01 +#define EP_KBD_IN EP_IN +#define EP_IN_LENGTH 64 +#define ENDPOINT_0 0x00 +#define ENDPOINT_1 0x81 + +#define RX_EP 2 +#define TX_EP 1 +#define TX_EP_SIZE 32 + + +/* STRING INDEX */ +/*******************************************/ + +#define MAN_STRING_INDEX 1 +#define PROD_STRING_INDEX 2 +#define SN_STRING_INDEX 3 +#define CONFIG_STRING_INDEX 4 + + +#define USB_MANUFACTURER_NAME {'K'<<8, 'y'<<8, 's'<<8, 'o'<<8, 'h'<<8} +#define USB_MN_LENGTH 5 + +#define USB_PRODUCT_NAME {'T'<<8, 'u'<<8, 'x'<<8, ' '<<8, 'D'<<8, \ + 'r'<<8, 'o'<<8, 'i'<<8, 'd'<<8} +#define USB_PN_LENGTH 9 + +#define USB_SERIAL_NUMBER {'1'<<8, '0'<<8, '0'<<8, '0'<<8, '1'<<8} +#define USB_SN_LENGTH 5 + + +#define USB_CONFIG_NAME {'T'<<8, 'u'<<8, 'x'<<8, ' '<<8, 'D'<<8, \ + 'r'<<8, 'o'<<8, 'i'<<8, 'd'<<8} +#define USB_CONFIG_LENGTH 9 + +#define LANG_ID 0x00 +#define LANGUAGE_ID 0x0904 + +/*_____ D E C L A R A T I O N ______________________________________________*/ + + +#endif /* _CONFIG_H_ */ Added: firmware/fuxusb/tags/0.3.1/global.c =================================================================== --- firmware/fuxusb/tags/0.3.1/global.c (rev 0) +++ firmware/fuxusb/tags/0.3.1/global.c 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,95 @@ +/*C************************************************************************** +* NAME: global.c +*---------------------------------------------------------------------------- +* Copyright (c) 2006 C2me. +*---------------------------------------------------------------------------- +* RELEASE: c5131-usb-RF Dongle +* REVISION: 1.3 +*---------------------------------------------------------------------------- +* PURPOSE: +*---------------------------------------------------------------------------- +* $Id: global.c 481 2007-03-09 14:36:33Z raphael $ +*****************************************************************************/ + +#include "global.h" + +#include "version.h" + + + + +/*_____ M A C R O S ________________________________________________________*/ + +/*_____ D E F I N I T I O N ________________________________________________*/ + +/*_____ D E C L A R A T I O N ______________________________________________*/ + + + +//------------------------------------------------------- +// SPI Controler +//------------------------------------------------------- +bit spi_task_on_Flag; // = 1; // to turn ON the RF Task + // = 0; // to turn OFF the RF Task +//------------------------------------------------------- +// USB Controler +//------------------------------------------------------- +unsigned int usb_sof_counter; +unsigned char usb_configuration_nb; +bit usb_connected_Flag; + +bit CMD_OUT_usb_Bank; // To store the number of the Bank used for the CMD_OUT Endpoint +char CMD_IN_Bank_Nb; + +bit USB_ParserProcess_Permit_Flag; +bit USB_StatusProcess_Permit_Flag; +bit USB_Status_NewCmd_Flag; +//------------------------------------------------------- +// I2C Controler +//------------------------------------------------------- + +unsigned char i2c_wait_counter = 0; +bit i2c_task_on_Flag; + +//------------------------------------------------------- +// RF Controler +//------------------------------------------------------- +// RF Header +//------------------------------------------------------- + +#define RF_2FRAMES_HDR 0x80 +#define RF_AUDIO_HDR 0x02 +#define RF_CMD_HDR 0x08 + +//------------------------------------------------------- + +bit RF_OFFLine_Back; +unsigned char RF_Status; +unsigned char RF_Status_Temp; + +unsigned int spi_watchdog_ctr; + +//------------------------------------------------------- +// Tux Command and Status +//------------------------------------------------------- + + // From USB + //------------------------------------------------------- +unsigned char USBCommand_ForDongle[65]; // For Dongle +unsigned char USBCommand_ForRF[65]; // For RF +unsigned char USBCommand_Ctr; // Store the number of byte sent by the LIBUSB +bit USBCommand_NewRequest_Flag; +unsigned char USBCommand_Header; // Needed to analyze the LIBUSB command : to RF or to I2C + + #define LIBUSB_TUX_CMD_HDR 0 + #define LIBUSB_DONGLE_CMD_HDR 1 + #define LIBUSB_BOOTLOADER_CMD_HDR 2 + +//------------------------------------------------------- +// Dongle Info +//------------------------------------------------------- + +code version_t info_version ={VERSION_CMD, CPU_VER_JOIN(FUXUSB_CPU_NUM, VER_MAJOR), VER_MINOR, VER_UPDATE}; +code revision_t info_revision={REVISION_CMD, REVISION_NUMBER, RELEASE_TYPE}; +code author_t info_author={AUTHOR_CMD, AUTHOR_ID, VARIATION}; + Added: firmware/fuxusb/tags/0.3.1/global.h =================================================================== --- firmware/fuxusb/tags/0.3.1/global.h (rev 0) +++ firmware/fuxusb/tags/0.3.1/global.h 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,110 @@ +/*C************************************************************************** +* NAME: global.h +*---------------------------------------------------------------------------- +* Copyright (c) 2006 C2me. +*---------------------------------------------------------------------------- +* RELEASE: c5131-usb-RF Dongle +* REVISION: 1.3 +*---------------------------------------------------------------------------- +* PURPOSE: +* +*****************************************************************************/ + + + +#ifndef _GLOBAL_H_ +#define _GLOBAL_H_ + +#include "common\api.h" +#include "common\defines.h" +#include "common\commands.h" + +/*_____ M A C R O S ________________________________________________________*/ + +/*_____ D E F I N I T I O N ________________________________________________*/ + +// Hardware +#define rf_reset_signal P0_1 +#define RF_OFFLINE P2_3 + + +/*_____ D E C L A R A T I O N ______________________________________________*/ + +extern unsigned int Sleep_Ctr; +//------------------------------------------------------- +// SPI Controler +//------------------------------------------------------- +extern bit spi_task_on_Flag; // = 1; // to turn ON the RF Task + // = 0; // to turn OFF the RF Task +extern unsigned int spi_watchdog_ctr; +#define SPI_WATCHDOG_MAX (6000) + + +//------------------------------------------------------- +// USB Controler +//------------------------------------------------------- +extern unsigned int usb_sof_counter; +extern unsigned char usb_configuration_nb; +extern bit usb_connected_Flag; + +extern bit CMD_OUT_usb_Bank; // To store the number of the Bank used for the CMD_OUT Endpoint +extern char CMD_IN_Bank_Nb; + +extern bit USB_ParserProcess_Permit_Flag; +extern bit USB_StatusProcess_Permit_Flag; +extern bit USB_Status_NewCmd_Flag; + +//------------------------------------------------------- +// I2C Controler +//------------------------------------------------------- + +extern unsigned char i2c_wait_counter; +extern bit i2c_task_on_Flag; + +//------------------------------------------------------- +// RF Controler +//------------------------------------------------------- +// RF Header +//------------------------------------------------------- + +#define RF_2FRAMES_HDR 0x80 +#define RF_AUDIO_HDR 0x02 +#define RF_CMD_HDR 0x08 + +//------------------------------------------------------- + +extern bit RF_OFFLine_Back; +extern unsigned char RF_Status; +extern unsigned char RF_Status_Temp; + +//------------------------------------------------------- +// Tux Command and Status +//------------------------------------------------------- + + + + // From USB + //------------------------------------------------------- +extern unsigned char USBCommand_ForRF[]; // Store the USB Command +extern unsigned char USBCommand_ForDongle[]; // For Dongle +extern unsigned char USBCommand_Ctr; // Store the number of byte sent by the LIBUSB + +extern bit USBCommand_NewRequest_Flag; +extern unsigned char USBCommand_Header; // Needed to analyze the LIBUSB command : to RF or to I2C + + + #define LIBUSB_TUX_CMD_HDR 0 + #define LIBUSB_DONGLE_CMD_HDR 1 + #define LIBUSB_BOOTLOADER_CMD_HDR 2 + + + +//------------------------------------------------------- +// Dongle Info +//------------------------------------------------------- + +extern code version_t info_version; +extern code revision_t info_revision; +extern code author_t info_author; + +#endif /* _GLOBAL_H_ */ Added: firmware/fuxusb/tags/0.3.1/i2c.c =================================================================== --- firmware/fuxusb/tags/0.3.1/i2c.c (rev 0) +++ firmware/fuxusb/tags/0.3.1/i2c.c 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,301 @@ +#include "i2c.h" + +#define I2C_DEBUG 0 + +/* + * DEBUG + */ +//#define __debug__ + +/* I2C status and address variables */ +uint8_t i2cDeviceAddrRW; +volatile I2C_FLAGS i2cFlags; +/* send/transmit buffer (outgoing data) */ +uint8_t xdata i2cSendData[I2C_SEND_DATA_BUFFER_SIZE]; +uint8_t *i2cDataToSend; +uint8_t i2cSendDataIndex; +uint8_t i2cSendDataLength; +/* receive buffer (incoming data) */ +uint8_t xdata i2cReceiveData[I2C_RECEIVE_DATA_BUFFER_SIZE]; +uint8_t i2cReceiveDataIndex; +uint8_t i2cReceiveDataLength; + +/* function pointer to i2c receive routine */ +/* I2cSlaveReceive is called when this processor is addressed as a slave for + * writing */ +static void (*i2cSlaveReceive)(uint8_t receiveDataLength, uint8_t* recieveData); +/* I2cSlaveTransmit is called when this processor is addressed as a slave for + * reading */ +static uint8_t (*i2cSlaveTransmit)(uint8_t transmitDataLengthMax, uint8_t* transmitData); + +/* functions */ + +/* + * Set the TWI transaction bitrate + */ +void i2cSetBitrate(void) +{ + /* Setting SSCON based on TWI_SCAL defined in i2c.h */ + SSCON = TWI_SCAL_VALUE; /* twi intialisation */ +} + +/* + * This function initializes the TWI interface for i2c communication. You + * should use the definitions in i2c.h to select the mode you want. + * + * Note that you should set the i2cSlaveReceive and i2cSlaveTransmit handlers + * after this initialization otherwise they'll be cleared. + */ +void i2cInit(void) +{ + /* Set up twi */ + SSCON = TWI_SSIE | TWI_SCAL_VALUE; /* enable TWI */ +#ifdef TWI_INT_ENABLED + Enable_twi_interrupt(); +#endif + +#ifdef TWI_SLA_ENABLED /* If Slave mode: */ + /* Set local device address (used in slave mode only) */ + SSADR = I2C_SLA_ADD; + + /* Enabling Slave mode */ + TWI_SET_AA(); /* enable TWI ACK */ + i2cSlaveReceive = 0; /* XXX do we need those 2 lines? clear SlaveReceive and SlaveTransmit handler to null */ + i2cSlaveTransmit = 0; +#endif + +#ifdef TWI_M_ENABLED +#endif +} + +/* Set the user function which handles receiving (incoming) data as a slave */ +void i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func)(uint8_t receiveDataLength, uint8_t* recieveData)) +{ + i2cSlaveReceive = i2cSlaveRx_func; +} + +/* Set the user function which handles transmitting (outgoing) data as a slave */ +void i2cSetSlaveTransmitHandler(uint8_t (*i2cSlaveTx_func)(uint8_t transmitDataLengthMax, uint8_t* transmitData)) +{ + i2cSlaveTransmit = i2cSlaveTx_func; +} + +void i2cSendStart(void); +/* Start a Master transmission, i2cSendDataIndex is reset automatically here */ +void i2cMasterStart(void) +{ + i2cFlags.i2c_busy = 1; + i2cSendDataIndex = 0; /* don't forget to reset the index */ + i2cSendStart(); +} + +void i2cSendStart(void) +{ + TWI_SET_START(); +} + +void i2cSendStop(void) +{ + TWI_SET_STOP(); + i2cFlags.i2c_busy = 0; +} + +void i2cSendByte(uint8_t _data) +{ + SSDAT = _data; +} + +void i2cAckReceiveByte(void) +{ + TWI_SET_AA(); +} + +void i2cNackReceiveByte(void) +{ + TWI_CLEAR_AA(); +} + +#define TW_DATA SSDAT +uint8_t i2cGetReceivedByte(void) +{ + return SSDAT; +} + +uint8_t i2cGetStatus(void) +{ + return TW_STATUS; +} + +#ifdef __debug__ +uint8_t i2cStatus[20]; /* debug only */ +uint8_t i2cStatusIdx = 0; +#endif + +/* TWI interrupt service routine */ +#ifdef TWI_INT_ENABLED +void it_TWI(void) interrupt IRQ_TWI using 1 +{ +#ifdef __debug__ + i2cStatus[i2cStatusIdx++] = TW_STATUS; + if (i2cStatusIdx == 20) i2cStatusIdx = 0; +#endif + + + switch (TW_STATUS) + { + /* * * Master General * * */ + case TW_START: // 0x08: Sent start condition + case TW_REP_START: // 0x10: Sent repeated start condition +#if I2C_DEBUG +#endif + // send device address + TWI_CLEAR_START(); /* clear start condition */ + i2cSendByte(i2cDeviceAddrRW); + break; + + + /* * * Master Transmitter & Receiver status codes * * */ + + case TW_MT_SLA_ACK: // 0x18: Slave address acknowledged + case TW_MT_DATA_ACK: // 0x28: Data acknowledged +#if I2C_DEBUG +#endif + if(i2cSendDataIndex < i2cSendDataLength) + { + + i2cSendByte( i2cSendData[i2cSendDataIndex++] ); /* send data */ + } + else + { + i2cSendStop(); /* End of data stream */ + i2cFlags.s_val = 1; + } + break; + case TW_MR_DATA_NACK: // 0x58: Data received, NACK reply issued +#if I2C_DEBUG +#endif + i2cReceiveData[i2cReceiveDataIndex++] = TW_DATA; // store final received data byte + /* no break, continue to transmit STOP condition */ + case TW_MR_SLA_NACK: // 0x48: Slave address not acknowledged + case TW_MT_SLA_NACK: // 0x20: Slave address not acknowledged + case TW_MT_DATA_NACK: // 0x30: Data not acknowledged +#if I2C_DEBUG +#endif + i2cFlags.mt_nack = 1; + i2cSendStop(); + break; + case TW_MT_ARB_LOST: // 0x38: Bus arbitration lost + //case TW_MR_ARB_LOST: // 0x38: Bus arbitration lost +#if I2C_DEBUG +#endif + i2cInit(); + break; + case TW_MR_DATA_ACK: // 0x50: Data acknowledged +#if I2C_DEBUG +#endif + // store received data byte + i2cReceiveData[i2cReceiveDataIndex++] = TW_DATA; + // fall-through to see if more bytes will be received + case TW_MR_SLA_ACK: // 0x40: Slave address acknowledged +#if I2C_DEBUG +#endif + if(i2cReceiveDataIndex < (i2cReceiveDataLength-1)) + i2cAckReceiveByte(); /* receive more bytes */ + else + i2cNackReceiveByte(); /* receive the last byte */ + break; + + + /* * * Slave Receiver status codes * * */ + + case TW_SR_SLA_ACK: // 0x60: own SLA+W has been received, ACK has been returned + case TW_SR_ARB_LOST_SLA_ACK: // 0x68: own SLA+W has been received, ACK has been returned + case TW_SR_GCALL_ACK: // 0x70: GCA+W has been received, ACK has been returned + case TW_SR_ARB_LOST_GCALL_ACK: // 0x78: GCA+W has been received, ACK has been returned +#if I2C_DEBUG +#endif + /* we are being addressed as slave for writing (data will be received from master) */ + i2cFlags.i2c_busy = 1; + i2cReceiveDataIndex = 0; + i2cFlags.s_nack = 0; /* reset nack flag here, not in user app */ + i2cAckReceiveByte(); /* accept data */ + break; + case TW_SR_DATA_ACK: // 0x80: data byte has been received, ACK has been returned + case TW_SR_GCALL_DATA_ACK: // 0x90: data byte has been received, ACK has been returned +#if I2C_DEBUG +#endif + i2cReceiveData[i2cReceiveDataIndex++] = TW_DATA; /* get received data byte */ + /* check receive buffer status */ + if(i2cReceiveDataIndex < I2C_RECEIVE_DATA_BUFFER_SIZE) + { + i2cAckReceiveByte(); /* accept more data */ + } + else + { + i2cNackReceiveByte(); /* refuse more data */ + } + break; + case TW_SR_DATA_NACK: // 0x88: data byte has been received, NACK has been returned + case TW_SR_GCALL_DATA_NACK: // 0x98: data byte has been received, NACK has been returned +#if I2C_DEBUG +#endif + //i2cReceiveData[i2cReceiveDataIndex++] = TW_DATA; /* receive last byte XXX check if this is right */ + //i2cNackReceiveByte(); //XXX bug here? // receive data byte and return NACK + //i2cAckReceiveByte(); [> I should clear the interrupt and enable acknoledge for slave mode (disabled during previous nack) <] + i2cFlags.s_nack = 1; /* XXX check if this flag is reset in all possible conditions */ + //break; + /* pass along to restart slave mode */ + case TW_SR_STOP: // 0xA0: STOP or REPEATED START has been received while addressed as slave +#if I2C_DEBUG +#endif + i2cInit(); /* enable TWI ACK */ + if(i2cSlaveReceive) i2cSlaveReceive(i2cReceiveDataIndex, i2cReceiveData); /* i2c receive is complete, call i2cSlaveReceive */ + i2cFlags.i2c_busy = 0; /* XXX check if this flag is reset in all possible conditions */ + break; + + + /* * * Slave Transmitter * * */ + + case TW_ST_SLA_ACK: // 0xA8: own SLA+R has been received, ACK has been returned + case TW_ST_ARB_LOST_SLA_ACK: // 0xB0: GCA+R has been received, ACK has been returned +#if I2C_DEBUG +#endif + // we are being addressed as slave for reading (data must be transmitted back to master) + // request data from application + if(i2cSlaveTransmit) i2cSendDataLength = i2cSlaveTransmit(I2C_SEND_DATA_BUFFER_SIZE, i2cSendData); + i2cSendDataIndex = 0; /* reset data index */ + /* fall-through to transmit first data byte */ + case TW_ST_DATA_ACK: // 0xB8: data byte has been transmitted, ACK has been received +#if I2C_DEBUG +#endif + TW_DATA = i2cSendData[i2cSendDataIndex++]; /* transmit data byte */ + if(i2cSendDataIndex < i2cSendDataLength) + i2cAckReceiveByte(); /* expect ACK to data byte */ + else + i2cNackReceiveByte(); /* expect NACK to data byte */ + break; + case TW_ST_DATA_NACK: // 0xC0: data byte has been transmitted, NACK has been received + case TW_ST_LAST_DATA: // 0xC8: last data byte transmitted, ACK received +#if I2C_DEBUG +#endif + /* all done, switch to open slave */ + i2cInit(); /* enable TWI ACK */ + break; + + + /* * * Misc * * */ + + case TW_NO_INFO: // 0xF8: No relevant state information + /* do nothing */ +#if I2C_DEBUG +#endif + break; + case TW_BUS_ERROR: // 0x00: Bus error due to illegal start or stop condition +#if I2C_DEBUG +#endif + i2cSendStop(); /* reset internal hardware and release bus */ + break; + } + TWI_CLEAR_SI(); +} +#endif Added: firmware/fuxusb/tags/0.3.1/i2c.h =================================================================== --- firmware/fuxusb/tags/0.3.1/i2c.h (rev 0) +++ firmware/fuxusb/tags/0.3.1/i2c.h 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2006, C2ME S.A. + * All rights reserved. + * + * $Id:$ + */ + +#ifndef _I2C_H_ +#define _I2C_H_ + +#include "lib_c/stdint.h" +#include "lib_mcu/twi/twi.h" +#include "config.h" + +#ifdef __debug__ +extern uint8_t i2cStatus[20]; /* XXX debug only */ +extern uint8_t i2cStatusIdx; +#endif + +/* * * include custom configuration here * * */ + +#define I2C_SEND_DATA_BUFFER_SIZE 130 +#define I2C_RECEIVE_DATA_BUFFER_SIZE 8 + +/* + * Choose operation mode, comment/uncomment lines + * For Slave only operation, choose Master and Slave + */ +#define TWI_INT_ENABLED /* comment if you don't want twi interrupts */ +#define TWI_M_ENABLED /* comment if you don't want twi master mode */ +//#define TWI_SLA_ENABLED /* comment if you don't want twi slave mode */ + +/* SSADR: TWI (Slave) Address Register + * Bits 7..1 : TWI (Slave) Address Register + * Bit 0 : TWI General Call Recognition Enable Bit */ +#define I2C_SLA_ADD ((0X55<<1) | 0x01) /* Only necessary in slave mode */ + +/* + * Initialise TWI clock + * + * Here we set SCL frequency in Master mode by defining TWI_SCAL: + * SCL_freq = F_CPU/TWI_SCAL + * + * TWI_SCAL value should be one of: 256 224 192 160 960 120 60 + */ + +//#define TWI_SCAL 160 /* TWI_SCAL value should be: 256 224 192 160 960 120 60 */ +#define TWI_SCAL 960 /* TWI_SCAL value should be: 256 224 192 160 960 120 60 */ + +/* * * END of code customisation * * */ + +#if TWI_SCAL == 256 +#define TWI_SCAL_VALUE TWI_RATIO_256 +#elif TWI_SCAL == 224 +#define TWI_SCAL_VALUE TWI_RATIO_224 +#elif TWI_SCAL == 192 +#define TWI_SCAL_VALUE TWI_RATIO_192 +#elif TWI_SCAL == 160 +#define TWI_SCAL_VALUE TWI_RATIO_160 +#elif TWI_SCAL == 960 +#define TWI_SCAL_VALUE TWI_RATIO_960 +#elif TWI_SCAL == 120 +#define TWI_SCAL_VALUE TWI_RATIO_120 +#elif TWI_SCAL == 60 +#define TWI_SCAL_VALUE TWI_RATIO_60 +#else +#error Incorrect TWI_SCAL value, should be: 256 224 192 160 960 120 60 +#define TWI_SCAL_VALUE +#endif + +/*! defines and constants */ +#define TWCR_CMD_MASK 0x0F + +/* + * Bits that are set inside interrupt routines, and watched outside in + * the program's main loop. + */ +typedef struct +{ + uint8_t i2c_busy: 1; /* set when twi hardware is busy, cleared after an i2c stop */ + uint8_t mt_nack: 1; /* error due to a nack received by the master transmitter */ + uint8_t s_nack: 1; /* error due to a nack replied by the slave */ + uint8_t sr_end: 1; /* set at the end of a receiver slave transmission if i2cSlaveReceive has not been defined */ + uint8_t st_end: 1; /* set at the end of a transmitter slave transmission if i2cSlaveTransmit has not been defined */ + uint8_t i2c_idx: 1; /* application side - can be used for data indexes status */ + uint8_t s_val: 1; /* application side - can be used for data validation */ +} +I2C_FLAGS; +extern volatile I2C_FLAGS i2cFlags; + +/*! types */ +typedef enum +{ + I2C_IDLE = 0, I2C_BUSY = 1, + I2C_MASTER_TX = 2, I2C_MASTER_RX = 3, + I2C_SLAVE_TX = 4, I2C_SLAVE_RX = 5 +} eI2cStateType; + +/* I2C state and address variables */ +extern uint8_t i2cDeviceAddrRW; +/* send/transmit buffer (outgoing data) */ +extern uint8_t xdata i2cSendData[]; +extern uint8_t i2cSendDataIndex; +extern uint8_t i2cSendDataLength; +/* receive buffer (incoming data) */ +extern uint8_t xdata i2cReceiveData[]; +extern uint8_t i2cReceiveDataIndex; +extern uint8_t i2cReceiveDataLength; + +/* Functions */ +void i2cSetBitrate(void); +void i2cInit(void); +void i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func)(uint8_t receiveDataLength, uint8_t* recieveData)); +void i2cSetSlaveTransmitHandler(uint8_t (*i2cSlaveTx_func)(uint8_t transmitDataLengthMax, uint8_t* transmitData)); +void i2cMasterStart(void); + +#endif + Added: firmware/fuxusb/tags/0.3.1/lib_board/c5131_evab.h =================================================================== --- firmware/fuxusb/tags/0.3.1/lib_board/c5131_evab.h (rev 0) +++ firmware/fuxusb/tags/0.3.1/lib_board/c5131_evab.h 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,51 @@ +/*H************************************************************************** +* NAME: c5131_evab.h +*---------------------------------------------------------------------------- +* Copyright (c) 2004 Atmel. +*---------------------------------------------------------------------------- +* RELEASE: c5131-usb-cdc-1_0_2 +* REVISION: 1.8 +*---------------------------------------------------------------------------- +* PURPOSE: +* Configuration file. Selection of the device. +*****************************************************************************/ +#ifndef _C5131_EVAB_H +#define _C5131_EVAB_H + +/*_____ D E F I N I T I O N S ______________________________________________*/ +#define GENEB_BUZZER P1_5 // CPU I/O Port connected to GENEB Buzzer Pin or mute +#define GENEB_BP1 P3_2 // CPU I/O Port connected to GENEB BP1 + +#define GENEB_TWI_IT P3_2 // Port I/O IT pin of CPU connected to GENEB TWI_IT Pin +#define GENEB_SDA P1_1 +#define GENEB_SCL P1_0 + +#define GENEB_A16 P3_4 // CPU I/O Port connected to GENEB A16 +#define GENEB_CS_RAM P1_2 +#define GENEB_CS_FLASH P1_3 +#define GENEB_ISP_FLASH P1_4 + +#define RST_ETH P1_5 +#define CS_ETH P3_5 + +#define CPUb_enable_all_leds() (AUXR&=~1,P3_0=0,P3_1=0,P4_0=0,P4_1=0,P1_5=0) +#define CPUb_disable_all_leds() (AUXR|=1,P3_0=1,P3_1=1,P4_0=1,P4_1=1,P1_5=1) +#define Geneb_enable_ram() (GENEB_ISP_FLASH=1,CS_ETH=1,GENEB_CS_RAM=0) +#define Geneb_disable_ram() (GENEB_CS_RAM=1) +#define Geneb_enable_isp() (GENEB_ISP_FLASH=0,GENEB_CS_FLASH=1) +#define Geneb_disable_isp() (GENEB_ISP_FLASH=1) + +/*_____ I N C L U D E S ____________________________________________________*/ +#ifdef GENEB_VERSION +#include "lib_board/geneb.h" +#endif + + +/*_____ M A C R O S ________________________________________________________*/ + +/*_____ D E C L A R A T I O N S ____________________________________________*/ + +#endif /* _C5131_EVAB_H */ + + + Added: firmware/fuxusb/tags/0.3.1/lib_board/kbd_drv.c =================================================================== --- firmware/fuxusb/tags/0.3.1/lib_board/kbd_drv.c (rev 0) +++ firmware/fuxusb/tags/0.3.1/lib_board/kbd_drv.c 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,68 @@ +/*C************************************************************************** +* NAME: kbd_drv.c +*---------------------------------------------------------------------------- +* Copyright (c) 2004 Atmel. +*---------------------------------------------------------------------------- +* RELEASE: c5131-usb-cdc-1_0_2 +* REVISION: 1.1 +*---------------------------------------------------------------------------- +* PURPOSE: +* This file contains C functions to control: +* SWITCHES +*****************************************************************************/ + +/*_____ I N C L U D E S ____________________________________________________*/ +#include "config.h" +#include "kbd_drv.h" + +/*_____ M A C R O S ________________________________________________________*/ + +/*_____ D E F I N I T I O N S ______________________________________________*/ +#define KBD_COL_MASK 0x0F +#define KBD_COL0 0x08 +#define KBD_COL1 0x04 +#define KBD_COL2 0x02 +#define KBD_COL3 0x01 +#define KBD_ROW_MASK 0xF0 +#define KBD_ROW0 0x10 +#define KBD_ROW1 0x20 +#define KBD_ROW2 0x40 +#define KBD_ROW3 0x80 + +#define DEFAULT_SWITCHES_VALUE 0xFF +#define DEFAULT_SCAN_KEY_VALUE 0 +/*_____ D E C L A R A T I O N S ____________________________________________*/ + + +/*V************************************************************************** +* NAME: scan_key +*---------------------------------------------------------------------------- +* PURPOSE: +* scan_key is a structure allowing easy byte/word access (Union16). +* 16 keys on keypad in a 16-bit variable => all cases supported +* Ex. for geneb: +* MSb LSb +* 9 5 1 < * 6 2 > 0 7 3 V # 8 4 C +*****************************************************************************/ +volatile Union16 idata scan_key; +Byte code geneb_keys[]= { 'C', '4', '8', '#', + 'V', '3', '7', '0', + '>', '2', '6', '*', + '<', '1', '5', '9' }; +void kbd_test_hit (void) +{ + + +} + + +bit kbd_init (void) +{ + return 0; +} + + + + + + Added: firmware/fuxusb/tags/0.3.1/lib_board/kbd_drv.h =================================================================== --- firmware/fuxusb/tags/0.3.1/lib_board/kbd_drv.h (rev 0) +++ firmware/fuxusb/tags/0.3.1/lib_board/kbd_drv.h 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,49 @@ +/*H************************************************************************** +* NAME: kbd_drv.h +*---------------------------------------------------------------------------- +* Copyright (c) 2004 Atmel. +*---------------------------------------------------------------------------- +* RELEASE: c5131-usb-cdc-1_0_2 +* REVISION: 1.1 +*---------------------------------------------------------------------------- +* PURPOSE: +* Include file of twi_common.c file +*****************************************************************************/ +#ifndef _KBD_DRV_H +#define _KBD_DRV_H + +/*_____ I N C L U D E S ____________________________________________________*/ +#include FILE_BOARD_H + +/*_____ M A C R O S ________________________________________________________*/ +//#ifdef USE_TWI_INTERRUPT + +/*F************************************************************************** +* NAME: get_switches +*---------------------------------------------------------------------------- +* PARAMS: none +* return: Uchar: switches value +*---------------------------------------------------------------------------- +* PURPOSE: +* 0=SWITCH ON, 1= SWITCH OFF, MSB =SWITCH 8, LSB = SWITCH 1 +*---------------------------------------------------------------------------- +* EXAMPLE: +*---------------------------------------------------------------------------- +* NOTE: +*---------------------------------------------------------------------------- +* REQUIREMENTS: +*****************************************************************************/ + + +/*_____ D E C L A R A T I O N S ____________________________________________*/ + +#define ROW_PORT KBF +#define ROW_ALL ((KBF & 0xF0)>>4) + +#define SELECT_COLUMN 0 /*the active level is 0*/ +#define FREE_COLUMN 1 + +/*FUNCTION PROTOTYPES*/ + +#endif /* _KBD_DRV_H */ + Added: firmware/fuxusb/tags/0.3.1/lib_c/stdint.h =================================================================== --- firmware/fuxusb/tags/0.3.1/lib_c/stdint.h (rev 0) +++ firmware/fuxusb/tags/0.3.1/lib_c/stdint.h 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,560 @@ +/* + * ISO/IEC 9899:1999 7.18 Integer types <stdint.h> + */ + +#ifndef __STDINT_H_ +#define __STDINT_H_ + +/** \defgroup avr_stdint <stdint.h>: Standard Integer Types + \code #include <stdint.h> \endcode + + Use [u]intN_t if you need exactly N bits. + + Since these typedefs are mandated by the C99 standard, they are preferred + over rolling your own typedefs. */ + +/* Integer types */ + +/** \name Exact-width integer types + Integer types having exactly the specified width */ + +/*@{*/ + +/** \ingroup avr_stdint + 8-bit signed type. */ + +typedef signed char int8_t; + +/** \ingroup avr_stdint + 8-bit unsigned type. */ + +typedef unsigned char uint8_t; + +/** \ingroup avr_stdint + 16-bit signed type. */ + +typedef signed int int16_t; + +/** \ingroup avr_stdint + 16-bit unsigned type. */ + +typedef unsigned int uint16_t; + +/** \ingroup avr_stdint + 32-bit signed type. */ + +typedef signed long int int32_t; + +/** \ingroup avr_stdint + 32-bit unsigned type. */ + +typedef unsigned long int uint32_t; + +/** \ingroup avr_stdint + 64-bit signed type. */ + +// typedef signed long long int int64_t; + +/** \ingroup avr_stdint + 64-bit unsigned type. */ + +// typedef unsigned long long int uint64_t; + +/*@}*/ + +/** \name Integer types capable of holding object pointers + These allow you to declare variables of the same size as a pointer. */ + +/*@{*/ + +/** \ingroup avr_stdint + Signed pointer compatible type. */ + +typedef int16_t intptr_t; + +/** \ingroup avr_stdint + Unsigned pointer compatible type. */ + +typedef uint16_t uintptr_t; + +/*@}*/ + +/** \name Minimum-width integer types + Integer types having at least the specified width */ + +/*@{*/ + +/** \ingroup avr_stdint + signed int with at least 8 bits. */ + +typedef int8_t int_least8_t; + +/** \ingroup avr_stdint + unsigned int with at least 8 bits. */ + +typedef uint8_t uint_least8_t; + +/** \ingroup avr_stdint + signed int with at least 16 bits. */ + +typedef int16_t int_least16_t; + +/** \ingroup avr_stdint + unsigned int with at least 16 bits. */ + +typedef uint16_t uint_least16_t; + +/** \ingroup avr_stdint + signed int with at least 32 bits. */ + +typedef int32_t int_least32_t; + +/** \ingroup avr_stdint + unsigned int with at least 32 bits. */ + +typedef uint32_t uint_least32_t; + +/** \ingroup avr_stdint + signed int with at least 64 bits. */ + +// typedef int64_t int_least64_t; + +/** \ingroup avr_stdint + unsigned int with at least 64 bits. */ + +// typedef uint64_t uint_least64_t; + +/*@}*/ + + +/** \name Fastest minimum-width integer types + Integer types being usually fastest having at least the specified width */ + +/*@{*/ + +/** \ingroup avr_stdint + fastest signed int with at least 8 bits. */ + +typedef int8_t int_fast8_t; + +/** \ingroup avr_stdint + fastest unsigned int with at least 8 bits. */ + +typedef uint8_t uint_fast8_t; + +/** \ingroup avr_stdint + fastest signed int with at least 16 bits. */ + +typedef int16_t int_fast16_t; + +/** \ingroup avr_stdint + fastest unsigned int with at least 16 bits. */ + +typedef uint16_t uint_fast16_t; + +/** \ingroup avr_stdint + fastest signed int with at least 32 bits. */ + +typedef int32_t int_fast32_t; + +/** \ingroup avr_stdint + fastest unsigned int with at least 32 bits. */ + +typedef uint32_t uint_fast32_t; + +/** \ingroup avr_stdint + fastest signed int with at least 64 bits. */ + +// typedef int64_t int_fast64_t; + +/** \ingroup avr_stdint + fastest unsigned int with at least 64 bits. */ + +// typedef uint64_t uint_fast64_t; + +/*@}*/ + + +/** \name Greatest-width integer types + Types designating integer data capable of representing any value of + any integer type in the corresponding signed or unsigned category */ + +/*@{*/ + +/** \ingroup avr_stdint + largest signed int available. */ + +// typedef int64_t intmax_t; + +/** \ingroup avr_stdint + largest unsigned int available. */ + +// typedef uint64_t uintmax_t; + +/*@}*/ + +/* Helping macro */ +#ifndef __CONCAT +#define __CONCATenate(left, right) left ## right +#define __CONCAT(left, right) __CONCATenate(left, right) +#endif + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) + +/** \name Limits of specified-width integer types + C++ implementations should define these macros only when + __STDC_LIMIT_MACROS is defined before <stdint.h> is included */ + +/*@{*/ + +/** \ingroup avr_stdint + largest positive value an int8_t can hold. */ + +#define INT8_MAX 0x7f + +/** \ingroup avr_stdint + smallest negative value an int8_t can hold. */ + +#define INT8_MIN (-INT8_MAX - 1) + +/** \ingroup avr_stdint + largest value an uint8_t can hold. */ + +#define UINT8_MAX (__CONCAT(INT8_MAX, U) * 2U + 1U) + +/** \ingroup avr_stdint + largest positive value an int16_t can hold. */ + +#define INT16_MAX 0x7fff + +/** \ingroup avr_stdint + smallest negative value an int16_t can hold. */ + +#define INT16_MIN (-INT16_MAX - 1) + +/** \ingroup avr_stdint + largest value an uint16_t can hold. */ + +#define UINT16_MAX (__CONCAT(INT16_MAX, U) * 2U + 1U) + +/** \ingroup avr_stdint + largest positive value an int32_t can hold. */ + +#define INT32_MAX 0x7fffffffL + +/** \ingroup avr_stdint + smallest negative value an int32_t can hold. */ + +#define INT32_MIN (-INT32_MAX - 1L) + +/** \ingroup avr_stdint + largest value an uint32_t can hold. */ + +#define UINT32_MAX (__CONCAT(INT32_MAX, U) * 2UL + 1UL) + +/** \ingroup avr_stdint + largest positive value an int64_t can hold. */ + +#define INT64_MAX 0x7fffffffffffffffLL + +/** \ingroup avr_stdint + smallest negative value an int64_t can hold. */ + +#define INT64_MIN (-INT64_MAX - 1LL) + +/** \ingroup avr_stdint + largest value an uint64_t can hold. */ + +#define UINT64_MAX (__CONCAT(INT64_MAX, U) * 2ULL + 1ULL) + +/*@}*/ + +/** \name Limits of minimum-width integer types */ +/*@{*/ + +/** \ingroup avr_stdint + largest positive value an int_least8_t can hold. */ + +#define INT_LEAST8_MAX INT8_MAX + +/** \ingroup avr_stdint + smallest negative value an int_least8_t can hold. */ + +#define INT_LEAST8_MIN INT8_MIN + +/** \ingroup avr_stdint + largest value an uint_least8_t can hold. */ + +#define UINT_LEAST8_MAX UINT8_MAX + +/** \ingroup avr_stdint + largest positive value an int_least16_t can hold. */ + +#define INT_LEAST16_MAX INT16_MAX + +/** \ingroup avr_stdint + smallest negative value an int_least16_t can hold. */ + +#define INT_LEAST16_MIN INT16_MIN + +/** \ingroup avr_stdint + largest value an uint_least16_t can hold. */ + +#define UINT_LEAST16_MAX UINT16_MAX + +/** \ingroup avr_stdint + largest positive value an int_least32_t can hold. */ + +#define INT_LEAST32_MAX INT32_MAX + +/** \ingroup avr_stdint + smallest negative value an int_least32_t can hold. */ + +#define INT_LEAST32_MIN INT32_MIN + +/** \ingroup avr_stdint + largest value an uint_least32_t can hold. */ + +#define UINT_LEAST32_MAX UINT32_MAX + +/** \ingroup avr_stdint + largest positive value an int_least64_t can hold. */ + +#define INT_LEAST64_MAX INT64_MAX + +/** \ingroup avr_stdint + smallest negative value an int_least64_t can hold. */ + +#define INT_LEAST64_MIN INT64_MIN + +/** \ingroup avr_stdint + largest value an uint_least64_t can hold. */ + +#define UINT_LEAST64_MAX UINT64_MAX + +/*@}*/ + +/** \name Limits of fastest minimum-width integer types */ + +/*@{*/ + +/** \ingroup avr_stdint + largest positive value an int_fast8_t can hold. */ + +#define INT_FAST8_MAX INT8_MAX + +/** \ingroup avr_stdint + smallest negative value an int_fast8_t can hold. */ + +#define INT_FAST8_MIN INT8_MIN + +/** \ingroup avr_stdint + largest value an uint_fast8_t can hold. */ + +#define UINT_FAST8_MAX UINT8_MAX + +/** \ingroup avr_stdint + largest positive value an int_fast16_t can hold. */ + +#define INT_FAST16_MAX INT16_MAX + +/** \ingroup avr_stdint + smallest negative value an int_fast16_t can hold. */ + +#define INT_FAST16_MIN INT16_MIN + +/** \ingroup avr_stdint + largest value an uint_fast16_t can hold. */ + +#define UINT_FAST16_MAX UINT16_MAX + +/** \ingroup avr_stdint + largest positive value an int_fast32_t can hold. */ + +#define INT_FAST32_MAX INT32_MAX + +/** \ingroup avr_stdint + smallest negative value an int_fast32_t can hold. */ + +#define INT_FAST32_MIN INT32_MIN + +/** \ingroup avr_stdint + largest value an uint_fast32_t can hold. */ + +#define UINT_FAST32_MAX UINT32_MAX + +/** \ingroup avr_stdint + largest positive value an int_fast64_t can hold. */ + +#define INT_FAST64_MAX INT64_MAX + +/** \ingroup avr_stdint + smallest negative value an int_fast64_t can hold. */ + +#define INT_FAST64_MIN INT64_MIN + +/** \ingroup avr_stdint + largest value an uint_fast64_t can hold. */ + +#define UINT_FAST64_MAX UINT64_MAX + +/*@}*/ + +/** \name Limits of integer types capable of holding object pointers */ + +/*@{*/ + +/** \ingroup avr_stdint + largest positive value an intptr_t can hold. */ + +#define INTPTR_MAX INT16_MAX + +/** \ingroup avr_stdint + smallest negative value an intptr_t can hold. */ + +#define INTPTR_MIN INT16_MIN + +/** \ingroup avr_stdint + largest value an uintptr_t can hold. */ + +#define UINTPTR_MAX UINT16_MAX + +/*@}*/ + +/** \name Limits of greatest-width integer types */ + +/*@{*/ + +/** \ingroup avr_stdint + largest positive value an intmax_t can hold. */ + +#define INTMAX_MAX INT64_MAX + +/** \ingroup avr_stdint + smallest negative value an intmax_t can hold. */ + +#define INTMAX_MIN INT64_MIN + +/** \ingroup avr_stdint + largest value an uintmax_t can hold. */ + +#define UINTMAX_MAX UINT64_MAX + +/*@}*/ + +/** \name Limits of other integer types + C++ implementations should define these macros only when + __STDC_LIMIT_MACROS is defined before <stdint.h> is included */ + +/*@{*/ + +/** \ingroup avr_stdint + largest positive value a ptrdiff_t can hold. */ + +#define PTRDIFF_MAX INT16_MAX + +/** \ingroup avr_stdint + smallest negative value a ptrdiff_t can hold. */ + +#define PTRDIFF_MIN INT16_MIN + + +/* Limits of sig_atomic_t */ +/* signal.h is currently not implemented (not avr/signal.h) */ + +/** \ingroup avr_stdint + largest positive value a sig_atomic_t can hold. */ + +#define SIG_ATOMIC_MAX INT8_MAX + +/** \ingroup avr_stdint + smallest negative value a sig_atomic_t can hold. */ + +#define SIG_ATOMIC_MIN INT8_MIN + + +/** \ingroup avr_stdint + largest value a size_t can hold. */ + +#define SIZE_MAX (__CONCAT(INT16_MAX, U)) + + +/* Limits of wchar_t */ +/* wchar.h is currently not implemented */ +/* #define WCHAR_MAX */ +/* #define WCHAR_MIN */ + + +/* Limits of wint_t */ +/* wchar.h is currently not implemented */ +/* #define WINT_MAX */ +/* #define WINT_MIN */ + + +#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */ + +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) + +/** \name Macros for integer constants + C++ implementations should define these macros only when + __STDC_CONSTANT_MACROS is defined before <stdint.h> is included. + + These definitions are valid for integer constants without suffix and + for macros defined as integer constant without suffix */ + +/** \ingroup avr_stdint + define a constant of type int8_t */ + +#define INT8_C(value) ((int8_t) value) + +/** \ingroup avr_stdint + define a constant of type uint8_t */ + +#define UINT8_C(value) ((uint8_t) __CONCAT(value, U)) + +/** \ingroup avr_stdint + define a constant of type int16_t */ + +#define INT16_C(value) value + +/** \ingroup avr_stdint + define a constant of type uint16_t */ + +#define UINT16_C(value) __CONCAT(value, U) + +/** \ingroup avr_stdint + define a constant of type int32_t */ + +#define INT32_C(value) __CONCAT(value, L) + +/** \ingroup avr_stdint + define a constant of type uint32_t */ + +#define UINT32_C(value) __CONCAT(value, UL) + +/** \ingroup avr_stdint + define a constant of type int64_t */ + +#define INT64_C(value) __CONCAT(value, LL) + +/** \ingroup avr_stdint + define a constant of type uint64_t */ + +#define UINT64_C(value) __CONCAT(value, ULL) + +/** \ingroup avr_stdint + define a constant of type intmax_t */ + +#define INTMAX_C(value) __CONCAT(value, LL) + +/** \ingroup avr_stdint + define a constant of type uintmax_t */ + +#define UINTMAX_C(value) __CONCAT(value, ULL) + +/*@}*/ + +#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */ + + +#endif /* _STDINT_H_ */ Added: firmware/fuxusb/tags/0.3.1/lib_mcu/5131_drv.h =================================================================== --- firmware/fuxusb/tags/0.3.1/lib_mcu/5131_drv.h (rev 0) +++ firmware/fuxusb/tags/0.3.1/lib_mcu/5131_drv.h 2007-11-09 16:11:44 UTC (rev 678) @@ -0,0 +1,248 @@ +/*H************************************************************************** +* NAME: 5131_drv.h +*---------------------------------------------------------------------------- +* Copyright (c) 2004 Atmel. +*---------------------------------------------------------------------------- +* RELEASE: c5131-usb-cdc-1_0_2 +* REVISION: 1.7 +*---------------------------------------------------------------------------- +* PURPOSE: +* This file contains the C51 driver definition +*****************************************************************************/ + +#ifndef _5131_DRV_H_ +#define _5131_DRV_H_ + +/*_____ I N C L U D E S ____________________________________________________*/ + + +/*_____ M A C R O S ________________________________________________________*/ + + +/*_____ D E F I N I T I O N ________________________________________________*/ +/* SYSTEM MANAGEMENT */ +#define MSK_SMOD1 0x80 /* PCON */ +#define MSK_SMOD0 0x40 +#define MSK_GF1 0x08 +#define MSK_GF0 0x04 +#define MSK_PD 0x02 +#define MSK_IDL 0x01 + +#define MSK_EXT16 0x40 /* AUXR */ +#define MSK_M0 0x20 +#define MSK_DPHDIS 0x10 +#define MSK_XRS 0x0C +#define MSK_EXTRAM 0x02 +#define MSK_AO 0x01 +#define ERAM_256 0x00 +#define ERAM_512 0x04 +#define ERAM_1024 0x08 +#define ERAM_2048 0x0C + + +/* PLL & CLOCK */ +#define MSK_X2 0x01 /* CKCON */ +#define MSK_T0X2 0x02 +#define MSK_T1X2 0x04 +#define MSK_WDX2 0x40 + + +/* TIMERS */ +#define MSK_GATE1 0x80 /* TMOD */ +#define MSK_C_T1 0x40 +#define MSK_MO1 0x30 +#define MSK_GATE0 0x08 +#define MSK_C_T0 0x04 +#define MSK_MO0 0x03 + + +/* WATCHDOG */ +#define MSK_WTO 0x07 /* WDTPRG*/ + +/*_____ D E C L A R A T I O N ______________________________________________*/ + +#define Set_x2_mode() (CKCON0 |= MSK_X2) +#define Set_x1_mode() (CKCON0 &= ~MSK_X2) +#define Mode_x2() ((CKCON0 & MSK_X2) == MSK_X2) + +#define Set_timer0_x1_mode() (CKCON0 |= MSK_T0X2) +#define Set_timer0_x2_mode() (CKCON0 &=~MSK_T0X2) +#define Set_timer1_x1_mode() (CKCON0 |= MSK_T1X2) +#define Set_timer1_x2_mode() (CKCON0 &=~MSK_T1X2) +#define Set_timer2_x1_mode() (CKCON0 |= MSK_T2X2) +#define Set_timer2_x2_mode() (CKCON0 &=~MSK_T2X2) +#define Set_uart_x1_mode() (CKCON0 |= MSK_UARTX2) +#define Set_uart_x2_mode() (CKCON0 &=~MSK_UARTX2) +#define Set_pca_x1_mode() (CKCON0 |= MSK_PCAX2) +#define Set_pca_x2_mode() (CKCON0 &=~MSK_PCAX2) + +#define Set_spi_x1_mode() (CKCON1 |= MSK_SPIX2) +#define Set_spi_x2_mode() (CKCON1 &=~MSK_SPIX2) + +#define Set_idle_mode() (PCON |= MSK_IDLE) +#define Set_power_down_mode() (PCON |= MSK_PD) + +#define Enable_eram() (AUXR &= ~MSK_EXTRAM) +#define Disable_eram() (AUXR |= MSK_EXTRAM) +#define Set_eram_size(s) ((AUXR &= ~MSK_XRS),(AUXR |= s)) + +#define Enable_interrupt() (EA = 1) +#define Disable_interrupt() (EA = 0) + +#define Enable_twi_interrupt() (IEN1 |= 0x02) +#define Disable_twi_interrupt() (IEN1 &= 0xFD) + +#define Enable_spi_interrupt() (IEN1 |= 0x04) +#define Disable_spi_interrupt() (IEN1 &= ~0x04) + +#define Disable_ale() (AUXR |= MSK_AO) +#define Enable_ale() (AUXR &= ~MSK_AO) +#define Switch_ale() (AUXR ^= MSK_AO) + +#define STANDARD_PORT 0 +#define LED_PORT_2MA 1 +#define LED_PORT_4MA 2 +#define LED_PORT_10MA 3 + +#define Configure_led(num,type) {LEDCON &= (0xFF & ~(0x03 << (num*2))); \ + LEDCON |= (type << (num*2));} + +#define Led_0_on() (P3_3 = 0) +#define Led_0_off() (P3_3 = 1) +#define Led_0_toggle() (P3_3 = ~P3_3) +#define Led_0_status() (P3_3) +#define Led_0_write(x) (P3_3 = x) +#define Led_1_on() (P3_5 = 0) +#define Led_1_off() (P3_5 = 1) +#define Led_1_toggle() (P3_5 = ~P3_5) +#define Led_1_status() (P3_5) +#define Led_1_write(x) (P3_5 = x) +#define Led_2_on() (P3_6 = 0) +#define Led_2_off() (P3_6 = 1) +#define Led_2_toggle() (P3_6 = ~P3_6) +#define Led_2_status() (P3_6) +#define Led_2_write(x) (P3_6 = x) +#define Led_3_on() (P3_7 = 0) +#define Led_3_off() (P3_7 = 1) +#define Led_3_toggle() (P3_7 = ~P3_7) +#define Led_3_status() (P3_7) +#define Led_3_write(x) (P3_7 = x) + + +#define Led_all_on() (P3 &= 0x17) +#define Led_all_off() (P3 |= ~0x17) + +/*C************************************************************************** +* NAME: PLL_3MHz +*---------------------------------------------------------------------------- +* PURPOSE: +* PLLDIV value for an oscillator frequency of 3MHz +*****************************************************************************/ +#define PLL_3MHz 0xF0 + +/*C************************************************************************** +* NAME: PLL_4MHz +*---------------------------------------------------------------------------- +* PURPOSE: +* PLLDIV value for an oscillator frequency of 4MHz +*****************************************************************************/ +#define PLL_4MHz 0xC0 + +/*C************************************************************************** +* NAME: PLL_6MHz +*---------------------------------------------------------------------------- +* PURPOSE: +* PLLDIV value for an oscillator frequency of 6MHz +*****************************************************************************/ +#define PLL_6MHz 0x70 + +/*C************************************************************************** +* NAME: PLL_8MHz +*---------------------------------------------------------------------------- +* PURPOSE: +* PLLDIV value for an oscillator frequency of 8MHz +**********************************... [truncated message content] |