[tuxdroid-svn] r576 - firmware/fuxusb/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-10-02 21:03:15
|
Author: jaguarondi Date: 2007-10-02 23:03:04 +0200 (Tue, 02 Oct 2007) New Revision: 576 Modified: firmware/fuxusb/trunk/bootloading.c firmware/fuxusb/trunk/bootloading.h firmware/fuxusb/trunk/config.h firmware/fuxusb/trunk/global.c firmware/fuxusb/trunk/global.h firmware/fuxusb/trunk/i2c.c firmware/fuxusb/trunk/i2c.h firmware/fuxusb/trunk/main.c firmware/fuxusb/trunk/version.h Log: * Indented on all source files with: indent *.[ch] -nut -i4 -bad -bap -bbb -sob -sc -bl -bli0 -cli0 -cbi4 -nce -ncdw -ss -bls -npsl -ncs -npcs -nprs -saf -sai -saw -nbfda -nhnl -l80 Modified: firmware/fuxusb/trunk/bootloading.c =================================================================== --- firmware/fuxusb/trunk/bootloading.c 2007-10-02 18:09:47 UTC (rev 575) +++ firmware/fuxusb/trunk/bootloading.c 2007-10-02 21:03:04 UTC (rev 576) @@ -1,3 +1,4 @@ + /* KySoH iTux agent * * Behavioural source code @@ -17,15 +18,15 @@ uint8_t address_idx; uint8_t packet_idx; -blHeader_t blHeader; /* header for bootloading */ +blHeader_t blHeader; /* header for bootloading */ /* * Initialize i2c interface */ void blInit(void) { - i2cSetBitrate(); /* set TWI bitrate */ - i2cInit(); /* initialize TWI interface */ + i2cSetBitrate(); /* set TWI bitrate */ + i2cInit(); /* initialize TWI interface */ blHeader.blData = &i2cSendData[2]; } @@ -42,7 +43,7 @@ { 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[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(); Modified: firmware/fuxusb/trunk/bootloading.h =================================================================== --- firmware/fuxusb/trunk/bootloading.h 2007-10-02 18:09:47 UTC (rev 575) +++ firmware/fuxusb/trunk/bootloading.h 2007-10-02 21:03:04 UTC (rev 576) @@ -1,3 +1,4 @@ + /* * Copyright (c) 2006, C2ME S.A. * All rights reserved. @@ -2,3 +3,3 @@ * - * $Id:$ + * $Id$ */ @@ -17,13 +18,14 @@ #define BOOT_FILLPAGE 2 #define BOOT_EXIT 3 -#define BOOTLOADER_CMD (uint8_t)0xF0 /* Bootloader status command */ +#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 { +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 */ Modified: firmware/fuxusb/trunk/config.h =================================================================== --- firmware/fuxusb/trunk/config.h 2007-10-02 18:09:47 UTC (rev 575) +++ firmware/fuxusb/trunk/config.h 2007-10-02 21:03:04 UTC (rev 576) @@ -1,3 +1,4 @@ + /*H************************************************************************** * NAME: config.h *---------------------------------------------------------------------------- @@ -21,11 +22,10 @@ #include "lib_mcu/reg_5131.h" #include "lib_mcu/ext_5131.h" #include "lib_mcu/5131_drv.h" -#include <stdio.h> +#include <stdio.h> /*_____ M A C R O S ________________________________________________________*/ - /* * Debugging configuration */ @@ -42,49 +42,42 @@ // 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 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 -#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 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 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 MAX_POWER 50 /* 100 mA */ #define LANG_ID 0x00 #define LANGUAGE_ID 0x0904 @@ -100,8 +93,8 @@ #define TX_EP 1 #define TX_EP_SIZE 32 +/* STRING INDEX */ -/* STRING INDEX */ /*******************************************/ #define MAN_STRING_INDEX 1 @@ -109,7 +102,6 @@ #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 @@ -120,7 +112,6 @@ #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 @@ -130,5 +121,4 @@ /*_____ D E C L A R A T I O N ______________________________________________*/ - #endif /* _CONFIG_H_ */ Modified: firmware/fuxusb/trunk/global.c =================================================================== --- firmware/fuxusb/trunk/global.c 2007-10-02 18:09:47 UTC (rev 575) +++ firmware/fuxusb/trunk/global.c 2007-10-02 21:03:04 UTC (rev 576) @@ -1,3 +1,4 @@ + /*C************************************************************************** * NAME: global.c *---------------------------------------------------------------------------- @@ -11,7 +12,7 @@ * $Id$ *****************************************************************************/ -#include "global.h" +#include "global.h" #include "version.h" @@ -21,31 +22,31 @@ /*_____ 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 +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; +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 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_ParserProcess_Permit_Flag; //------------------------------------------------------- // I2C Controler //------------------------------------------------------- -unsigned char i2c_wait_counter = 0; -bit i2c_task_on_Flag; +unsigned char i2c_wait_counter = 0; +bit i2c_task_on_Flag; //------------------------------------------------------- // RF Controler @@ -60,14 +61,14 @@ //------------------------------------------------------- -bit RF_OFFLine_Back; +bit RF_OFFLine_Back; unsigned char RF_Status; -unsigned char RF_Status_Temp; +unsigned char RF_Status_Temp; -bit RF_ToConnect_Flag; -unsigned char RF_Connection_Status; -unsigned char RF_InitFrame[22]; -unsigned int spi_watchdog_ctr; +bit RF_ToConnect_Flag; +unsigned char RF_Connection_Status; +unsigned char RF_InitFrame[22]; +unsigned int spi_watchdog_ctr; //------------------------------------------------------- // Tux Command and Status @@ -75,25 +76,21 @@ unsigned char Tux_ID[2]; unsigned char Tux_NewID[2]; -bit Tux_RequestingID_Flag; -bit Tux_ChangingID_Flag; +bit Tux_RequestingID_Flag; +bit Tux_ChangingID_Flag; + // 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 - - // 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 - - //------------------------------------------------------- // Dongle Info //------------------------------------------------------- -code version_t info_version ={VERSION_CMD,VER_MAJOR,VER_MINOR,VER_UPDATE}; -code revision_t info_revision={REVISION_CMD,REVISION_NUMBER,0}; -code author_t info_author={AUTHOR_CMD,AUTHOR_ID,0}; - +code version_t info_version = { VERSION_CMD, VER_MAJOR, VER_MINOR, VER_UPDATE }; +code revision_t info_revision = { REVISION_CMD, REVISION_NUMBER, 0 }; +code author_t info_author = { AUTHOR_CMD, AUTHOR_ID, 0 }; Modified: firmware/fuxusb/trunk/global.h =================================================================== --- firmware/fuxusb/trunk/global.h 2007-10-02 18:09:47 UTC (rev 575) +++ firmware/fuxusb/trunk/global.h 2007-10-02 21:03:04 UTC (rev 576) @@ -1,3 +1,4 @@ + /*C************************************************************************** * NAME: global.h *---------------------------------------------------------------------------- @@ -10,8 +11,6 @@ * *****************************************************************************/ - - #ifndef _GLOBAL_H_ #define _GLOBAL_H_ @@ -25,37 +24,38 @@ #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; +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) +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 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 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_ParserProcess_Permit_Flag; //------------------------------------------------------- // I2C Controler //------------------------------------------------------- extern unsigned char i2c_wait_counter; -extern bit i2c_task_on_Flag; +extern bit i2c_task_on_Flag; //------------------------------------------------------- // RF Controler @@ -70,50 +70,46 @@ //------------------------------------------------------- -extern bit RF_OFFLine_Back; +extern bit RF_OFFLine_Back; extern unsigned char RF_Status; -extern unsigned char RF_Status_Temp; -extern bit RF_ToConnect_Flag; -extern unsigned char RF_InitFrame[]; -extern unsigned char RF_Connection_Status; +extern unsigned char RF_Status_Temp; +extern bit RF_ToConnect_Flag; +extern unsigned char RF_InitFrame[]; +extern unsigned char RF_Connection_Status; - #define RF_DISCONNECTED 0 - #define RF_TO_CONNECT 1 - #define RF_REQUEST_ID 2 - #define RF_CHANGE_ID 3 - #define RF_CONNECTED 4 +#define RF_DISCONNECTED 0 +#define RF_TO_CONNECT 1 +#define RF_REQUEST_ID 2 +#define RF_CHANGE_ID 3 +#define RF_CONNECTED 4 //------------------------------------------------------- // Tux Command and Status //------------------------------------------------------- extern unsigned char Tux_ID[]; extern unsigned char Tux_NewID[]; -extern bit Tux_RequestingID_Flag; -extern bit Tux_ChangingID_Flag; +extern bit Tux_RequestingID_Flag; +extern bit Tux_ChangingID_Flag; - - // 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 + // 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 +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 +#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; +extern code version_t info_version; +extern code revision_t info_revision; +extern code author_t info_author; #endif /* _GLOBAL_H_ */ Modified: firmware/fuxusb/trunk/i2c.c =================================================================== --- firmware/fuxusb/trunk/i2c.c 2007-10-02 18:09:47 UTC (rev 575) +++ firmware/fuxusb/trunk/i2c.c 2007-10-02 21:03:04 UTC (rev 576) @@ -10,23 +10,29 @@ /* 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); +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); +static uint8_t(*i2cSlaveTransmit) (uint8_t transmitDataLengthMax, + uint8_t * transmitData); /* functions */ @@ -36,7 +42,7 @@ void i2cSetBitrate(void) { /* Setting SSCON based on TWI_SCAL defined in i2c.h */ - SSCON = TWI_SCAL_VALUE; /* twi intialisation */ + SSCON = TWI_SCAL_VALUE; /* twi intialisation */ } /* @@ -49,18 +55,18 @@ void i2cInit(void) { /* Set up twi */ - SSCON = TWI_SSIE | TWI_SCAL_VALUE; /* enable TWI */ + SSCON = TWI_SSIE | TWI_SCAL_VALUE; /* enable TWI */ #ifdef TWI_INT_ENABLED Enable_twi_interrupt(); #endif -#ifdef TWI_SLA_ENABLED /* If Slave mode: */ +#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 */ + 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 @@ -69,23 +75,29 @@ } /* Set the user function which handles receiving (incoming) data as a slave */ -void i2cSetSlaveReceiveHandler(void (*i2cSlaveRx_func)(uint8_t receiveDataLength, uint8_t* recieveData)) +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)) +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 */ + i2cSendDataIndex = 0; /* don't forget to reset the index */ i2cSendStart(); } @@ -127,175 +139,175 @@ } #ifdef __debug__ -uint8_t i2cStatus[20]; /* debug only */ +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 -{ +void it_TWI(void) + interrupt IRQ_TWI using 1 + { #ifdef __debug__ - i2cStatus[i2cStatusIdx++] = TW_STATUS; - if (i2cStatusIdx == 20) i2cStatusIdx = 0; + 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 + 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; + // send device address + TWI_CLEAR_START(); /* clear start condition */ + i2cSendByte(i2cDeviceAddrRW); + break; + /* * * Master Transmitter & Receiver status codes * * */ - /* * * Master Transmitter & Receiver status codes * * */ - - case TW_MT_SLA_ACK: // 0x18: Slave address acknowledged - case TW_MT_DATA_ACK: // 0x28: Data acknowledged + case TW_MT_SLA_ACK: // 0x18: Slave address acknowledged + case TW_MT_DATA_ACK: // 0x28: Data acknowledged #if I2C_DEBUG #endif - if(i2cSendDataIndex < i2cSendDataLength) - { + 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 + 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 + 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 + 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 + 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 + // 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; + if (i2cReceiveDataIndex < (i2cReceiveDataLength - 1)) + i2cAckReceiveByte(); /* receive more bytes */ + else + i2cNackReceiveByte(); /* receive the last byte */ + break; + /* * * Slave Receiver status codes * * */ - /* * * 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 + 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 + /* 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 + 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 + //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; + 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 * * */ - /* * * 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 + 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 + // 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 + 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; + /* all done, switch to open slave */ + i2cInit(); /* enable TWI ACK */ + break; + /* * * Misc * * */ - /* * * Misc * * */ - - case TW_NO_INFO: // 0xF8: No relevant state information - /* do nothing */ + 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 + 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(); -} + i2cSendStop(); /* reset internal hardware and release bus */ + break; + } + TWI_CLEAR_SI(); + } #endif Modified: firmware/fuxusb/trunk/i2c.h =================================================================== --- firmware/fuxusb/trunk/i2c.h 2007-10-02 18:09:47 UTC (rev 575) +++ firmware/fuxusb/trunk/i2c.h 2007-10-02 21:03:04 UTC (rev 576) @@ -1,3 +1,4 @@ + /* * Copyright (c) 2006, C2ME S.A. * All rights reserved. @@ -2,3 +3,3 @@ * - * $Id:$ + * $Id$ */ @@ -13,7 +14,7 @@ #include "config.h" #ifdef __debug__ -extern uint8_t i2cStatus[20]; /* XXX debug only */ +extern uint8_t i2cStatus[20]; /* XXX debug only */ extern uint8_t i2cStatusIdx; #endif @@ -26,14 +27,14 @@ * 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_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 */ +#define I2C_SLA_ADD ((0X55<<1) | 0x01) /* Only necessary in slave mode */ /* * Initialise TWI clock @@ -45,7 +46,7 @@ */ //#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 */ +#define TWI_SCAL 960 /* TWI_SCAL value should be: 256 224 192 160 960 120 60 */ /* * * END of code customisation * * */ @@ -77,13 +78,13 @@ */ 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 */ + 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; @@ -98,10 +99,12 @@ /* 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; @@ -110,9 +113,13 @@ /* 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 +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 - Modified: firmware/fuxusb/trunk/main.c =================================================================== --- firmware/fuxusb/trunk/main.c 2007-10-02 18:09:47 UTC (rev 575) +++ firmware/fuxusb/trunk/main.c 2007-10-02 21:03:04 UTC (rev 576) @@ -1,3 +1,4 @@ + /*C************************************************************************** * NAME: main.c *---------------------------------------------------------------------------- @@ -13,7 +14,6 @@ /*_____ I N C L U D E S ____________________________________________________*/ - #include "config.h" #include "lib_c/stdint.h" #include "global.h" @@ -24,9 +24,8 @@ #include "modules\fifo\fifo_mic.h" #include "modules\fifo_stt\fifo_stt.h" -char code reserve [3] _at_ 0x23; /* for Monitor-51 serial interrupt */ +char code reserve[3] _at_ 0x23; /* for Monitor-51 serial interrupt */ - /*_____ G L O B A L S ________________________________________________________*/ /*_____ M A C R O S ________________________________________________________*/ @@ -49,7 +48,7 @@ *---------------------------------------------------------------------------- * REQUIREMENTS: *****************************************************************************/ -void main (void) +void main(void) { /* RF is disabled when this signal is low and is reset when going from * 0 to 1. @@ -57,21 +56,20 @@ * It is set when USB receives SET_CONGIGURATION command during * enumeration. RF is also disabled during bootload. */ rf_reset_signal = 0; // Maintains the RF in RESET STATE until the USB has received the Command to connect RF - // Go to 0 in usb_set_configuration() + // Go to 0 in usb_set_configuration() // Stay Low During the I2C communication - RF_OFFLINE = 1; // Set Port to able to Read the Input Signal + RF_OFFLINE = 1; // Set Port to able to Read the Input Signal - Set_x2_mode(); Enable_interrupt(); - usb_task_init(); + usb_task_init(); #ifdef MAIN_DEBUG - uart_init(); + uart_init(); printf("= TUX started ==\n"); #endif - while(1) + while (1) usb_task(); } Modified: firmware/fuxusb/trunk/version.h =================================================================== --- firmware/fuxusb/trunk/version.h 2007-10-02 18:09:47 UTC (rev 575) +++ firmware/fuxusb/trunk/version.h 2007-10-02 21:03:04 UTC (rev 576) @@ -1,3 +1,4 @@ + /* KySoH iTux agent * * Behavioural source code @@ -17,9 +18,7 @@ #define VER_MINOR 2 #define VER_UPDATE 0 -#define AUTHOR_ID 0 /* official release */ -#define REVISION_NUMBER 0xFFEE /* XXX find a way to define this automatically in the Makefile from SVN */ +#define AUTHOR_ID 0 /* official release */ +#define REVISION_NUMBER 0xFFEE /* XXX find a way to define this automatically in the Makefile from SVN */ #endif /* _VERSION_H_ */ - - |