Skip to content

Commit 28c26a4

Browse files
committed
Merge branch 'imageproc2.5-testing' into biomimetics-imageproc2.5-integration
2 parents ddaa53a + c061850 commit 28c26a4

23 files changed

+172
-124
lines changed

adc_pid.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "adc_pid.h"
4949
#include "p33Fxxxx.h"
5050
#include "ports.h"
51+
#include "utils.h"
5152

5253

5354
//Functions
@@ -250,6 +251,7 @@ static void initDma0(void) {
250251
void __attribute__((interrupt, no_auto_psv)) _DMA0Interrupt(void) {
251252
//This should really be done in an elegant way by selecting a pointer, and
252253
// not repeating code below.
254+
LED_3 = 1;
253255
if (DmaBuffer == 0) {
254256
adc_AN0 = BufferA[0][0]; //AN0
255257
adc_AN8 = BufferA[1][0]; //AN8
@@ -272,6 +274,7 @@ void __attribute__((interrupt, no_auto_psv)) _DMA0Interrupt(void) {
272274
adc_MotorD = adc_AN11;
273275

274276
DmaBuffer ^= 1; //Toggle between buffers
277+
LED_3 = 0;
275278
IFS0bits.DMA0IF = 0; //Clear the DMA0 Interrupt Flag
276279
}
277280
// End DMA section

ams-enc.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ EncObj encPos[NUM_ENC];
7373

7474
#define AMS_ENC_ANGLE_REG 0xFE
7575

76+
#define AMS_ENC_OFFSET_0 5758
77+
#define AMS_ENC_OFFSET_1 7706
78+
7679
volatile unsigned char state = AMS_ENC_IDLE;
7780
volatile unsigned char encoder_number = 0;
7881
volatile unsigned int encoder_new_pos;
@@ -86,8 +89,10 @@ static inline void encoderSetupPeripheral(void);
8689
* Public functions
8790
-----------------------------------------------------------------------------*/
8891

89-
void amsEncoderSetup(void)
90-
{
92+
void amsEncoderSetup(void) {
93+
// Need delay for encoders to be ready
94+
delay_ms(100);
95+
9196
// LSB = R/W* .
9297
// 1. send slave <a2:a1>, a0=W (write reg address)
9398
// 2. send slave register address <a7:a0>,
@@ -119,11 +124,13 @@ void amsEncoderResetPos(void) {
119124
// initialize structure
120125
int i;
121126
for(i = 0; i< NUM_ENC; i++) {
122-
amsEncoderBlockingRead(i); // get initial values w/o setting oticks
123-
encPos[i].offset = encPos[i].pos; // initialize encoder
127+
//amsEncoderBlockingRead(i); // get initial values w/o setting oticks
128+
//encPos[i].offset = encPos[i].pos; // initialize encoder
124129
encPos[i].calibPos = 0;
125130
encPos[i].oticks = 0; // set revolution counter to 0
126131
}
132+
encPos[0].offset = AMS_ENC_OFFSET_0;
133+
encPos[1].offset = AMS_ENC_OFFSET_1;
127134
}
128135

129136
/*****************************************************************************
@@ -139,11 +146,12 @@ static inline void encoderSetupPeripheral(void) { //same setup as ITG3200 for co
139146
I2C1_SM_DIS & I2C1_GCALL_DIS & I2C1_STR_DIS &
140147
I2C1_NACK & I2C1_ACK_DIS & I2C1_RCV_DIS &
141148
I2C1_STOP_DIS & I2C1_RESTART_DIS & I2C1_START_DIS &
142-
MI2C1_INT_PRI_5;
149+
MI2C1_INT_PRI_6;
143150

144151
// BRG = Fcy(1/Fscl - 1/10000000)-1, Fscl = 909KHz
145152
I2C1BRGvalue = 40;
146153
OpenI2C1(I2C1CONvalue, I2C1BRGvalue);
154+
SetPriorityIntMI2C1(6);
147155
_MI2C1IF = 0;
148156
EnableIntMI2C1;
149157
}
@@ -185,7 +193,6 @@ unsigned char amsEncoderStartAsyncRead(void) {
185193
void __attribute__((interrupt, no_auto_psv)) _MI2C1Interrupt(void) {
186194
LED_3 = 1;
187195

188-
CRITICAL_SECTION_START
189196
switch(state) {
190197
case AMS_ENC_WRITE_START:
191198
I2C1TRN = encAddr[2*encoder_number+1];
@@ -196,11 +203,7 @@ void __attribute__((interrupt, no_auto_psv)) _MI2C1Interrupt(void) {
196203
state = AMS_ENC_WRITE_REG;
197204
break;
198205
case AMS_ENC_WRITE_REG:
199-
I2C1CONbits.PEN = 1;
200-
state = AMS_ENC_WRITE_STOP;
201-
break;
202-
case AMS_ENC_WRITE_STOP:
203-
I2C1CONbits.SEN = 1;
206+
I2C1CONbits.RSEN = 1;
204207
state = AMS_ENC_READ_START;
205208
break;
206209
case AMS_ENC_READ_START:
@@ -212,7 +215,7 @@ void __attribute__((interrupt, no_auto_psv)) _MI2C1Interrupt(void) {
212215
state = AMS_ENC_READ_0;
213216
break;
214217
case AMS_ENC_READ_0:
215-
encoder_new_pos = I2C1RCV & 0x3F;
218+
encoder_new_pos = I2C1RCV <<6;
216219
I2C1CONbits.ACKDT = 0;
217220
I2C1CONbits.ACKEN = 1;
218221
state = AMS_ENC_READ_0_ACK;
@@ -222,7 +225,7 @@ void __attribute__((interrupt, no_auto_psv)) _MI2C1Interrupt(void) {
222225
state = AMS_ENC_READ_1;
223226
break;
224227
case AMS_ENC_READ_1:
225-
encoder_new_pos = I2C1RCV<<6;
228+
encoder_new_pos |= (I2C1RCV & 0x3F);
226229
I2C1CONbits.ACKDT = 1;
227230
I2C1CONbits.ACKEN = 1;
228231
state = AMS_ENC_READ_1_NACK;
@@ -247,7 +250,6 @@ void __attribute__((interrupt, no_auto_psv)) _MI2C1Interrupt(void) {
247250
}
248251
LED_3 = 0;
249252
_MI2C1IF = 0;
250-
CRITICAL_SECTION_END
251253
}
252254

253255
inline void amsEncoderUpdatePos(unsigned char encoder_number, unsigned int new_pos) {

at86rf231_driver.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@
5353

5454
#include <string.h>
5555

56-
#define SPI_CON1bits (SPI1CON1bits)
57-
#define SPI_CON2 (SPI1CON2)
58-
#define SPI_STATbits (SPI1STATbits)
59-
#define SLPTR (_LATB15) // Sleep/Transmit Pin
60-
6156
// Basic commands
6257
#define TRX_CMD_RW (0xC0) // Register Write
6358
#define TRX_CMD_RR (0x80) // Register Read
@@ -100,15 +95,13 @@ static TrxIrqHandler irqCallback;
10095
static tal_trx_status_t trx_state;
10196
static unsigned char frame_buffer[FRAME_BUFFER_SIZE];
10297
static unsigned char last_rssi;
103-
static unsigned char spi_cs;
10498
static unsigned char last_ackd = 0;
10599

106100

107101
// =========== Public functions ===============================================
108102

109103
void trxSetup(unsigned char cs)
110104
{
111-
spi_cs = cs;
112105

113106
// SPI setup
114107
setupSPI(); // Set up SPI com port
@@ -241,7 +234,7 @@ void trxWriteFrameBuffer(MacPacket packet) {
241234

242235
memcpy(frame_buffer + i, payToString(pld), payGetPayloadLength(pld));
243236

244-
spic1BeginTransaction(spi_cs);
237+
spic1BeginTransaction(TRX_CS);
245238
spic1Transmit(TRX_CMD_FW);
246239
spic1MassTransmit(phy_len, frame_buffer, phy_len*3); // 3*length microseconds timeout seems to work well
247240

@@ -346,7 +339,7 @@ void trxSetStateOff(void) {
346339
*/
347340
static void trxWriteReg(unsigned char addr, unsigned char val) {
348341

349-
spic1BeginTransaction(spi_cs);
342+
spic1BeginTransaction(TRX_CS);
350343
spic1Transmit(TRX_CMD_RW | addr);
351344
spic1Transmit(val);
352345
spic1EndTransaction();
@@ -362,7 +355,7 @@ static void trxWriteReg(unsigned char addr, unsigned char val) {
362355
static unsigned char trxReadReg(unsigned char addr) {
363356

364357
unsigned char c;
365-
spic1BeginTransaction(spi_cs);
358+
spic1BeginTransaction(TRX_CS);
366359
spic1Transmit(TRX_CMD_RR | addr);
367360
c = spic1Receive();
368361
spic1EndTransaction();
@@ -495,7 +488,7 @@ static void trxSpiCallback(unsigned int interrupt_code) {
495488
*/
496489
static void trxFillBuffer(void) {
497490

498-
spic1BeginTransaction(spi_cs);
491+
spic1BeginTransaction(TRX_CS);
499492
last_rssi = spic1Transmit(TRX_CMD_FR); // Begin write (returns RSSI because of SPI_CMD_MODE)
500493
//current_phy_len = spic1Receive(); // Read physical frame size
501494
//spic1MassTransmit(current_phy_len, NULL, current_phy_len*3); // DMA rest into buffer
@@ -514,7 +507,7 @@ static void trxReadBuffer(void) {
514507

515508
static void setupSPI(void)
516509
{
517-
spicSetupChannel1(spi_cs,
510+
spicSetupChannel1(TRX_CS,
518511
ENABLE_SCK_PIN &
519512
ENABLE_SDO_PIN &
520513
SPI_MODE16_OFF &

battery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void __attribute__((interrupt, no_auto_psv)) _INT0Interrupt(void) {
124124
_INT0IF = 0; // Clear the interrupt flag
125125

126126
}
127-
#elif defined(__IMAGEPROC2)
127+
#elif defined(__IMAGEPROC24) || defined(__IMAGEPROC25)
128128
void __attribute__((interrupt, no_auto_psv)) _INT2Interrupt(void) {
129129

130130
batHandleISR();

bsp-ip25.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* File: bsp-ip25.h
3+
* Author: apullin
4+
*
5+
* Created on January 15, 2014, 5:05 PM
6+
*/
7+
8+
#ifndef BSP_IP25_H
9+
#define BSP_IP25_H
10+
11+
//SPI setup registers; possible should be in a chip support include
12+
// SPIx Registers
13+
#define SPI_BUF SPI2BUF
14+
#define SPI_CON1 SPI2CON1
15+
#define SPI_CON2 SPI2CON2
16+
#define SPI_STAT SPI2STAT
17+
#define SPI_STATbits SPI2STATbits
18+
#define SPI_CON1bits SPI2CON1bits
19+
#define SLPTR (_LATB15) // Radio Sleep/Transmit Pin
20+
21+
//TRX defines
22+
#define TRX_CS 0 //On SPI channel 1
23+
//DFMEM defines
24+
#define DFMEM_CS 0 //On SPI channel 2
25+
//MPU defines
26+
#define MPU_CS 1 //On SPI channel 2
27+
28+
//These should probably be in a chip support package include, rather than BSP
29+
#define SPI1_CS (_LATB2) // Radio Chip Select
30+
#define SPI2_CS1 (_LATG9) // Flash Chip Select
31+
#define SPI2_CS2 (_LATC15) // MPU6000 Chip Select
32+
33+
//LED colors
34+
//TODO (): Should this be here? Since any color LED could end up installed
35+
// on the board, which could be very misleading
36+
#define LED_1 _LATB12
37+
#define LED_2 _LATB13
38+
#define LED_3 _LATB14
39+
40+
#define LED_RED LED_1
41+
#define LED_GREEN LED_2
42+
#define LED_YELLOW LED_3
43+
44+
#endif /* BSP_IP25_H */
45+

dfmem.c

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@
6363
#include "spi_controller.h" // For DMA
6464
#include "utils.h"
6565

66-
// TODO (humhu) : Consolidate into some BSP header
67-
#if (defined(__IMAGEPROC1) || defined(__IMAGEPROC2) || defined(__MIKRO) || defined(__EXP16DEV))
68-
// MIKRO & EXP16DEV has no FLASHMEM, but needs this for compile
69-
70-
// SPIx pins
71-
#define SPI_CS _LATG9
72-
73-
// SPIx Registers
74-
#define SPI_BUF SPI2BUF
75-
#define SPI_CON1 SPI2CON1
76-
#define SPI_CON2 SPI2CON2
77-
#define SPI_STAT SPI2STAT
78-
#define SPI_STATbits SPI2STATbits
79-
#define SPI_CON1bits SPI2CON1bits
80-
81-
#endif
82-
8366
// Flash geometry
8467
// 8 Mbit
8568
#define FLASH_8MBIT_MAX_SECTOR 16
@@ -152,9 +135,6 @@ static unsigned int currentBuffer = 0;
152135
static unsigned int currentBufferOffset = 0;
153136
static unsigned int nextPage = 0;
154137

155-
// Chip select
156-
static unsigned char spi_cs;
157-
158138
enum FlashSizeType {
159139
DFMEM_8MBIT = 0b00101,
160140
DFMEM_16MBIT = 0b00110,
@@ -188,11 +168,10 @@ static void spiCallback(unsigned int irq_source);
188168
* Public functions
189169
-----------------------------------------------------------------------------*/
190170

191-
void dfmemSetup(unsigned char cs)
171+
void dfmemSetup(void)
192172
{
193-
spi_cs = cs;
194173
dfmemSetupPeripheral();
195-
spic2SetCallback(cs, &spiCallback);
174+
spic2SetCallback(DFMEM_CS, &spiCallback);
196175
while(!dfmemIsReady());
197176

198177
dfmemGeometrySetup();
@@ -571,7 +550,7 @@ static inline unsigned char dfmemReadByte (void)
571550
}
572551

573552
// Selects the memory chip.
574-
static inline void dfmemSelectChip(void) { spic2BeginTransaction(spi_cs); }
553+
static inline void dfmemSelectChip(void) { spic2BeginTransaction(DFMEM_CS); }
575554

576555
// De-selects the memory chip.
577556
static inline void dfmemDeselectChip(void) { spic2EndTransaction(); }
@@ -581,7 +560,7 @@ static inline void dfmemDeselectChip(void) { spic2EndTransaction(); }
581560
// The MCU is the SPI master and the clock isn't continuous.
582561
static void dfmemSetupPeripheral(void)
583562
{
584-
spicSetupChannel2(spi_cs,
563+
spicSetupChannel2(DFMEM_CS,
585564
ENABLE_SCK_PIN &
586565
ENABLE_SDO_PIN &
587566
SPI_MODE16_OFF &
@@ -669,4 +648,4 @@ static void dfmemReadSecurityRegister(void){
669648
}
670649
dfmemDeselectChip();
671650

672-
}
651+
}

dfmem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ typedef struct {
7171
typedef DfmemGeometryStruct* DfmemGeometry;
7272

7373
// Handles initialization of communication peripherals and makes sure the
74-
// memory is initially deselected. Must pass in chip select pin index.
75-
void dfmemSetup (unsigned char cs);
74+
// memory is initially deselected. Chip select defined in BSP header.
75+
void dfmemSetup (void);
7676

7777
// Writes the contents of a data array to memory.
7878
//

init_default.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void SetupPorts(void)
150150
TRISE = 0b00000000;
151151

152152

153-
#elif defined(__IMAGEPROC2)
153+
#elif defined(__IMAGEPROC24) || defined(__IMAGEPROC25)
154154

155155
// LEDs: RB12-14 are outputs
156156
// SPI1 Slave Select is an output (RB2)

0 commit comments

Comments
 (0)