Skip to content

Commit

Permalink
Merge pull request ARMmbed#76 from arebert/lpc4088
Browse files Browse the repository at this point in the history
[LPC4088] Merged bugfixes and improvments for LPC1768 target to LPC4088 target
  • Loading branch information
bogdanm committed Sep 23, 2013
2 parents f2f7b21 + bb35d16 commit 4e23b72
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#ifndef __LPC407x_8x_177x_8x_H__
#define __LPC407x_8x_177x_8x_H__

#define CORE_M4
#if defined(__CORTEX_M4) && !defined(CORE_M4)
#define CORE_M4
#endif

// ##################
// Code Red - excluded extern "C" as unrequired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ LR_IROM1 0x00000000 0x00080000 { ; load region size_region
RW_IRAM1 0x100000E8 0x0000FF18 { ; RW data
.ANY (+RW +ZI)
}
RW_IRAM2 0x20000000 0x00008000 {
RW_IRAM2 0x20000000 0x00004000 {
.ANY (AHBSRAM0)
}
RW_IRAM3 0x20004000 0x00004000 {
.ANY (AHBSRAM1)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static const PinMap PinMap_ADC[] = {

void analogin_init(analogin_t *obj, PinName pin) {
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
if (obj->adc == (uint32_t)NC) {
if (obj->adc == (ADCName)NC) {
error("ADC pin mapping failed");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static const PinMap PinMap_DAC[] = {

void analogout_init(dac_t *obj, PinName pin) {
obj->dac = (DACName)pinmap_peripheral(pin, PinMap_DAC);
if (obj->dac == (uint32_t)NC) {
if (obj->dac == (DACName)NC) {
error("DAC pin mapping failed");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void can_irq_set(can_t *obj, CanIrqType type, uint32_t enable) {
obj->dev->MOD &= ~(1);

// Enable NVIC if at least 1 interrupt is active
if((LPC_CAN1->IER | LPC_CAN2->IER) != 0) {
if(((LPC_SC->PCONP & (1 << 13)) && LPC_CAN1->IER) || ((LPC_SC->PCONP & (1 << 14)) && LPC_CAN2->IER)) {
NVIC_SetVector(CAN_IRQn, (uint32_t) &can_irq_n);
NVIC_EnableIRQ(CAN_IRQn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ int ethernet_receive() {
if(receive_idx == -1) {
receive_idx = LPC_EMAC->RxConsumeIndex;
} else {
while(!(rxstat[receive_idx].Info & RINFO_LAST_FLAG) && (receive_idx != LPC_EMAC->RxProduceIndex)) {
while(!(rxstat[receive_idx].Info & RINFO_LAST_FLAG) && ((uint32_t)receive_idx != LPC_EMAC->RxProduceIndex)) {
receive_idx = rinc(receive_idx, NUM_RX_FRAG);
}
unsigned int info = rxstat[receive_idx].Info;
Expand All @@ -738,7 +738,7 @@ int ethernet_receive() {
LPC_EMAC->RxConsumeIndex = receive_idx;
}

if(receive_idx == LPC_EMAC->RxProduceIndex) {
if((uint32_t)receive_idx == LPC_EMAC->RxProduceIndex) {
receive_idx = -1;
return 0;
}
Expand Down Expand Up @@ -787,7 +787,7 @@ int ethernet_read(char *data, int dlen) {
void *pdst, *psrc;
int doff = 0;

if(receive_idx == LPC_EMAC->RxProduceIndex || receive_idx == -1) {
if((uint32_t)receive_idx == LPC_EMAC->RxProduceIndex || receive_idx == -1) {
return 0;
}

Expand Down
94 changes: 58 additions & 36 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/gpio_irq_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,66 @@ static void handle_interrupt_in(void) {
uint32_t fall0 = LPC_GPIOINT->IO0IntStatF;
uint32_t rise2 = LPC_GPIOINT->IO2IntStatR;
uint32_t fall2 = LPC_GPIOINT->IO2IntStatF;
uint32_t mask0 = 0;
uint32_t mask2 = 0;
int i;

// P0.0-0.31
for (i = 0; i < 32; i++) {
uint32_t pmask = (1 << i);
if (rise0 & pmask) {
mask0 |= pmask;
if (channel_ids[i] != 0)
irq_handler(channel_ids[i], IRQ_RISE);
}
if (fall0 & pmask) {
mask0 |= pmask;
if (channel_ids[i] != 0)
irq_handler(channel_ids[i], IRQ_FALL);
}

uint8_t bitloc;

// Continue as long as there are interrupts pending
while(rise0 > 0) {
// CLZ returns number of leading zeros, 31 minus that is location of
// first pending interrupt
bitloc = 31 - __CLZ(rise0);
if (channel_ids[bitloc] != 0)
irq_handler(channel_ids[bitloc], IRQ_RISE); //Run that interrupt

// Both clear the interrupt with clear register, and remove it from
// our local copy of the interrupt pending register
LPC_GPIOINT->IO0IntClr = 1 << bitloc;
rise0 -= 1<<bitloc;
}

// P2.0-2.31
for (i = 0; i < 32; i++) {
uint32_t pmask = (1 << i);
int channel_index = i + 32;
if (rise2 & pmask) {
mask2 |= pmask;
if (channel_ids[channel_index] != 0)
irq_handler(channel_ids[channel_index], IRQ_RISE);
}
if (fall2 & pmask) {
mask2 |= pmask;
if (channel_ids[channel_index] != 0)
irq_handler(channel_ids[channel_index], IRQ_FALL);
}

// Continue as long as there are interrupts pending
while(fall0 > 0) {
// CLZ returns number of leading zeros, 31 minus that is location of
// first pending interrupt
bitloc = 31 - __CLZ(fall0);
if (channel_ids[bitloc] != 0)
irq_handler(channel_ids[bitloc], IRQ_FALL); //Run that interrupt

// Both clear the interrupt with clear register, and remove it from
// our local copy of the interrupt pending register
LPC_GPIOINT->IO0IntClr = 1 << bitloc;
fall0 -= 1<<bitloc;
}

// Same for port 2

// Continue as long as there are interrupts pending
while(rise2 > 0) {
// CLZ returns number of leading zeros, 31 minus that is location of
// first pending interrupt
bitloc = 31 - __CLZ(rise2);
if (channel_ids[bitloc+32] != 0)
irq_handler(channel_ids[bitloc+32], IRQ_RISE); //Run that interrupt

// Both clear the interrupt with clear register, and remove it from
// our local copy of the interrupt pending register
LPC_GPIOINT->IO2IntClr = 1 << bitloc;
rise2 -= 1<<bitloc;
}

// Continue as long as there are interrupts pending
while(fall2 > 0) {
// CLZ returns number of leading zeros, 31 minus that is location of
// first pending interrupt
bitloc = 31 - __CLZ(fall2);
if (channel_ids[bitloc+32] != 0)
irq_handler(channel_ids[bitloc+32], IRQ_FALL); //Run that interrupt

// Both clear the interrupt with clear register, and remove it from
// our local copy of the interrupt pending register
LPC_GPIOINT->IO2IntClr = 1 << bitloc;
fall2 -= 1<<bitloc;
}

// Clear the interrupts we just handled
LPC_GPIOINT->IO0IntClr = mask0;
LPC_GPIOINT->IO2IntClr = mask2;
}

int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/pinmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "error.h"

void pin_function(PinName pin, int function) {
if (pin == (uint32_t)NC) return;
if (pin == (PinName)NC) return;

__IO uint32_t *reg = (__IO uint32_t*) (LPC_IOCON_BASE + 4 * pin);

Expand All @@ -26,7 +26,7 @@ void pin_function(PinName pin, int function) {
}

void pin_mode(PinName pin, PinMode mode) {
if (pin == (uint32_t)NC) { return; }
if (pin == (PinName)NC) { return; }

uint32_t drain = ((uint32_t) mode & (uint32_t) OpenDrain) >> 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static unsigned int pwm_clock_mhz;
void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (uint32_t)NC)
if (pwm == (PWMName)NC)
error("PwmOut pin mapping failed");

obj->channel = pwm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ int serial_writable(serial_t *obj) {
}

void serial_clear(serial_t *obj) {
obj->uart->FCR = 1 << 1 // rx FIFO reset
| 1 << 2 // tx FIFO reset
| 0 << 6; // interrupt depth
obj->uart->FCR = 1 << 0 // FIFO Enable - 0 = Disables, 1 = Enabled
| 1 << 1 // rx FIFO reset
| 1 << 2 // tx FIFO reset
| 0 << 6; // interrupt depth
}

void serial_pinout_tx(PinName tx) {
Expand Down
1 change: 1 addition & 0 deletions workspace_tools/export/uvision4_lpc4088.uvproj.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@
{% for file in object_files %}
{{file}}
{% endfor %}
--any_placement=first_fit
</Misc>
<LinkerInputFile></LinkerInputFile>
<DisabledWarnings></DisabledWarnings>
Expand Down

0 comments on commit 4e23b72

Please sign in to comment.