From 6f52ce5838146abec6717b10d83abf7d6f33982b Mon Sep 17 00:00:00 2001
From: tslewe <tslewe@ubuntu.ubuntu-domain>
Date: Sun, 28 Nov 2010 14:14:48 +0100
Subject: [PATCH] Added 'volatile' to the global vars that are written in the interrupt sevice routine, and read in the rest of the source code.

---
 src/target/firmware/calypso/sim.c |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/target/firmware/calypso/sim.c b/src/target/firmware/calypso/sim.c
index 610f968..1f7e254 100755
--- a/src/target/firmware/calypso/sim.c
+++ b/src/target/firmware/calypso/sim.c
@@ -29,11 +29,11 @@
 #include <calypso/sim.h>
 #include <calypso/irq.h>
 
-static int sim_rx_character_count = 0;	/* How many bytes have been received by calypso_sim_receive() */
-static int sim_tx_character_count = 0;	/* How many bytes have been transmitted by calypso_sim_transmit() */
-static int sim_tx_character_length = 0;	/* How many bytes have to be transmitted by calypso_sim_transmit() */
-static uint8_t *rx_buffer = 0;		/* RX-Buffer that is issued by calypso_sim_receive() */
-static uint8_t *tx_buffer = 0;		/* TX-Buffer that is issued by calypso_sim_transmit() */
+static volatile int sim_rx_character_count = 0;	/* How many bytes have been received by calypso_sim_receive() */
+static volatile int sim_tx_character_count = 0;	/* How many bytes have been transmitted by calypso_sim_transmit() */
+static volatile int sim_tx_character_length = 0;	/* How many bytes have to be transmitted by calypso_sim_transmit() */
+static volatile uint8_t *rx_buffer = 0;		/* RX-Buffer that is issued by calypso_sim_receive() */
+static volatile uint8_t *tx_buffer = 0;		/* TX-Buffer that is issued by calypso_sim_transmit() */
 volatile static int rxDoneFlag = 0;	/* Used for rx syncronization instead of a semaphore in calypso_sim_receive() */
 volatile static int txDoneFlag = 0;	/* Used for rx syncronization instead of a semaphore in calypso_sim_transmit() */
 
@@ -403,15 +403,17 @@ int calypso_sim_receive(uint8_t *data)
 	writew(~(REG_SIM_MASKIT_MASK_SIM_RX | REG_SIM_MASKIT_MASK_SIM_WT), REG_SIM_MASKIT);
 
 	/* Wait till rxDoneFlag is set */
-	while(rxDoneFlag == 0);
+	while (rxDoneFlag == 0);
 
 	/* Disable all interrupt driven functions by masking all interrupts */
 	writew(0xFF, REG_SIM_MASKIT);
 
+#if (SIM_DEBUG == 1)
+        printf("Received %d bytes\n", sim_rx_character_count);
+#endif
+
 	/* Hand back the number of bytes received */
 	return sim_rx_character_count;
-	
-	return;
 }
 
 /* Transmit raw data through the sim interface */
@@ -434,7 +436,7 @@ int calypso_sim_transmit(uint8_t *data, int length)
 	tx_buffer++;
 	sim_tx_character_count++;
 
-	/* Wait till rxDoneFlag is set */
+	/* Wait till txDoneFlag is set */
 	while(txDoneFlag == 0);
 
 	/* Disable all interrupt driven functions by masking all interrupts */
@@ -504,6 +506,9 @@ void sim_irq_handler(enum irq_nr irq)
 
 		/* Read byte from rx-fifo and write it to the issued buffer */
 		*rx_buffer = (uint8_t) (readw(REG_SIM_DRX) & 0xFF);
+#if (SIM_DEBUG == 1)
+                printf("received: %02x (total count: %d)\n" , *rx_buffer, sim_rx_character_count);
+#endif
 		rx_buffer++;
 	}
 }
-- 
1.7.0.4

