Project

General

Profile

Revision 318

Analog out of bounds memory access error fixed.

View differences:

branches/analog/trunk/code/projects/libdragonfly/dragonfly_lib.c
64 64
 **/
65 65
void dragonfly_init(int config) 
66 66
{
67
		sei();
67
	sei();
68 68

  
69 69
	// Set directionality of various IO pins
70 70
	DDRG &= ~(_BV(PING0)|_BV(PING1));
......
108 108
	_delay_ms(1);
109 109
}
110 110

  
111
/**
112
 * Malloc for colony. Disables analog loop and then restarts it
113
 * to avoid problems with malloc.
114
 *
115
 * @param size the number of bytes to allocate
116
 * @return a pointer to size bytes of allocated memory
117
 **/
118
inline void* colony_malloc(int size)
119
{
120
	void* ret = NULL;
121
	analog_stop_loop();
122
	delay_ms(1000);
123
	cli();
124
	usb_puts("Calling malloc!\n");
125
	ret = malloc(size);
126
	usb_puts("Malloc returned!\n");
127
	sei();
128
	analog_start_loop();
129
	return ret;
130
}
111 131

  
132

  
112 133
/** @} **/ //end defgroup
113 134

  
branches/analog/trunk/code/projects/libdragonfly/dragonfly_lib.h
66 66

  
67 67
/** @brief Initialize the board **/
68 68
void dragonfly_init(int config);
69
/** @brief Special malloc to prevent errors from analog **/
70
void* colony_malloc(int size);
69 71

  
70 72
/** @} **/ //end addtogroup
71 73

  
branches/analog/trunk/code/projects/libdragonfly/analog.c
40 40
// Internal Function Prototypes
41 41
void set_adc_mux(int which);
42 42

  
43
/** @brief Struct to hold the value of a particular analog port */
44
typedef struct {
45
	uint8_t adc8;
46
	uint16_t adc10;
47
} adc_t;
48

  
43 49
/**
44 50
 * @defgroup analog Analog
45 51
 * Functions for manipulation the ADC on the dragonfly board.
......
50 56

  
51 57
int adc_loop_running = 0;
52 58
int adc_current_port = 0;
53
adc_t an_val[10];
59
adc_t an_val[11];
54 60

  
55 61
/**
56 62
 * Initializes the ADC.
......
60 66
 **/
61 67
void analog_init(int start_conversion)
62 68
{
63
	for (int i = 0; i < 10; i++) {
69
	for (int i = 0; i < 11; i++) {
64 70
		an_val[i].adc10 = 0;
65 71
		an_val[i].adc8 = 0;
66 72
	}
......
246 252
	int adc_l = 0;
247 253

  
248 254
	//usb_putc('p');
249
	//usb_puti(adc_current_port);
250 255
	//usb_putc('r');
251 256
	//usb_puti(adc_loop_running);
252 257
	//usb_puts("\n\r");
branches/analog/trunk/code/projects/libdragonfly/analog.h
96 96

  
97 97
#define ADMUX_OPT 0x60
98 98

  
99
/** @brief Struct to hold the value of a particular analog port */
100
typedef struct {
101
	uint8_t adc8;
102
	uint16_t adc10;
103
} adc_t;
104 99

  
105

  
106 100
/** @brief Initialize analog ports. Will start running a loop
107 101
	 if start_conversion is ADC_START.**/
108 102
void analog_init(int start_conversion);
branches/analog/trunk/code/projects/libdragonfly/bom.c
108 108
 *
109 109
 * @see analog_init
110 110
 **/
111
int get_max_bom(void) {
111
int get_max_bom(void)
112
{
112 113
	int max_bom_temp = 0;
113
	int a, i, j, h;
114
    h = 255;
114
	int a, i, j, h = 255;
115 115

  
116 116
	//Turn off the loop so that we can actually use analog8 correctly
117 117
	analog_stop_loop();
118 118

  
119 119
	//Iterate through through each LED
120
    for (j = 0; j < 16; j++)
121
    {
122
      i = lookup[j];
120
	for (j = 0; j < 16; j++)
121
	{
122
		i = lookup[j];
123
	
124
		if (i&8)
125
			output_high(MONK3);
126
		else
127
			output_low(MONK3);
128
	
129
		if (i&4)
130
			output_high(MONK2);
131
		else
132
			output_low(MONK2);
133
	
134
		if (i&2)
135
			output_high(MONK1);
136
		else
137
			output_low(MONK1);
138
	
139
		if (i&1)
140
			output_high(MONK0);
141
		else
142
			output_low(MONK0);
143
		
144
		a = analog8(MONKI);
145
	          
146
		if (a < h)
147
		{
148
			h = a;
149
			max_bom_temp = j;
150
		}
123 151

  
124
      if (i&8)
125
        output_high(MONK3);
126
      else
127
        output_low(MONK3);
128

  
129
      if (i&4)
130
        output_high(MONK2);
131
      else
132
        output_low(MONK2);
133

  
134
      if (i&2)
135
        output_high(MONK1);
136
      else
137
        output_low(MONK1);
138

  
139
      if (i&1)
140
        output_high(MONK0);
141
      else
142
        output_low(MONK0);
143

  
144
      a = analog8(MONKI);
145
              
146
      if (a < h)
147
      {
148
        h = a;
149
        max_bom_temp = j;
150
      }
151

  
152
    }
152
	}
153 153
	
154 154
	//Restart loop now that we are done using analog8
155 155
	analog_start_loop();

Also available in: Unified diff