Skip to content

Commit f61d186

Browse files
authored
[LTD mergeup] Merge pull request zephyrproject-rtos#7 from rsalveti/ltd-17.06
Upstream merge 2 Jun 2017
2 parents 0e89ad7 + ee421d3 commit f61d186

File tree

29 files changed

+531
-177
lines changed

29 files changed

+531
-177
lines changed

arch/arm/core/cortex_m/vector_table.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ SECTION_SUBSEC_FUNC(exc_vector_table,_vector_table_section,_vector_table)
4747
.word __reserved
4848
.word __reserved
4949
.word __reserved
50-
.word __reserved /* SVC not used for now (PendSV used instead) */
50+
.word __svc
5151
.word __reserved
5252
#elif defined(CONFIG_ARMV7_M)
5353
.word __mpu_fault

arch/arm/core/cortex_m/vector_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ GTEXT(__reset)
3939
GTEXT(__nmi)
4040
GTEXT(__hard_fault)
4141
#if defined(CONFIG_ARMV6_M)
42+
GTEXT(__svc)
4243
#elif defined(CONFIG_ARMV7_M)
4344
GTEXT(__mpu_fault)
4445
GTEXT(__bus_fault)

arch/arm/core/exc_exit.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, _IntExit)
6161
#ifdef CONFIG_TICKLESS_KERNEL
6262
push {lr}
6363
bl _update_time_slice_before_swap
64+
#if defined(CONFIG_ARMV6_M)
65+
pop {r0}
66+
mov lr, r0
67+
#else
6468
pop {lr}
69+
#endif /* CONFIG_ARMV6_M */
6570
#endif
6671

6772
/**

arch/arm/core/irq_offload.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@ void _irq_do_offload(void)
2222

2323
void irq_offload(irq_offload_routine_t routine, void *parameter)
2424
{
25-
int key;
25+
#if defined(CONFIG_ARMV6_M) && defined(CONFIG_ASSERT)
26+
/* Cortex M0 hardfaults if you make a SVC call with interrupts
27+
* locked.
28+
*/
29+
unsigned int key;
2630

27-
key = irq_lock();
31+
__asm__ volatile("mrs %0, PRIMASK;" : "=r" (key) : : "memory");
32+
__ASSERT(key == 0, "irq_offload called with interrupts locked\n");
33+
#endif
34+
35+
k_sched_lock();
2836
offload_routine = routine;
2937
offload_param = parameter;
3038

@@ -34,6 +42,5 @@ void irq_offload(irq_offload_routine_t routine, void *parameter)
3442
: "memory");
3543

3644
offload_routine = NULL;
37-
38-
irq_unlock(key);
45+
k_sched_unlock();
3946
}

arch/arm/core/swap.S

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
_ASM_FILE_PROLOGUE
2121

2222
GTEXT(__swap)
23-
#if defined(CONFIG_ARMV6_M)
24-
#elif defined(CONFIG_ARMV7_M)
2523
GTEXT(__svc)
26-
#else
27-
#error Unknown ARM architecture
28-
#endif /* CONFIG_ARMV6_M */
2924
GTEXT(__pendsv)
3025
GTEXT(_do_kernel_oops)
3126
GDATA(_k_neg_eagain)
@@ -217,6 +212,52 @@ _thread_irq_disabled:
217212
bx lr
218213

219214
#if defined(CONFIG_ARMV6_M)
215+
SECTION_FUNC(TEXT, __svc)
216+
/* Use EXC_RETURN state to find out if stack frame is on the
217+
* MSP or PSP
218+
*/
219+
ldr r0, =0x4
220+
mov r1, lr
221+
tst r1, r0
222+
beq _stack_frame_msp
223+
mrs r0, PSP
224+
bne _stack_frame_endif
225+
_stack_frame_msp:
226+
mrs r0, MSP
227+
_stack_frame_endif:
228+
229+
/* Figure out what SVC call number was invoked */
230+
ldr r1, [r0, #24] /* grab address of PC from stack frame */
231+
/* SVC is a two-byte instruction, point to it and read encoding */
232+
subs r1, r1, #2
233+
ldrb r1, [r1, #0]
234+
235+
/*
236+
* grab service call number:
237+
* 1: irq_offload (if configured)
238+
* 2: kernel panic or oops (software generated fatal exception)
239+
* Planned implementation of system calls for memory protection will
240+
* expand this case.
241+
*/
242+
243+
cmp r1, #2
244+
beq _oops
245+
246+
#if CONFIG_IRQ_OFFLOAD
247+
push {lr}
248+
blx _irq_do_offload /* call C routine which executes the offload */
249+
pop {r3}
250+
mov lr, r3
251+
#endif
252+
253+
/* exception return is done in _IntExit() */
254+
b _IntExit
255+
256+
_oops:
257+
push {lr}
258+
blx _do_kernel_oops
259+
pop {pc}
260+
220261
#elif defined(CONFIG_ARMV7_M)
221262
/**
222263
*

arch/x86/Makefile.idt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ else
55
endif
66

77
ifeq ($(PREBUILT_HOST_TOOLS),)
8-
GENIDT := $(ZEPHYR_BASE)/scripts/gen_idt/gen_idt
8+
GENIDT := scripts/gen_idt/gen_idt
99
else
1010
GENIDT := $(PREBUILT_HOST_TOOLS)/gen_idt
1111
endif
@@ -29,7 +29,7 @@ quiet_cmd_gen_idt = SIDT $@
2929
)
3030

3131
$(GENIDT):
32-
$(Q)$(MAKE) $(build)=$(ZEPHYR_BASE)/scripts/gen_idt
32+
$(Q)$(MAKE) $(build)=scripts/gen_idt
3333

3434
staticIdt.o: $(PREBUILT_KERNEL) $(GENIDT)
3535
$(call cmd,gen_idt)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
PYOCD_TARGET = nrf51
22
FLASH_SCRIPT=pyocd.sh
3-
3+
DEBUG_SCRIPT=pyocd.sh
44
export PYOCD_TARGET FLASH_SCRIPT

boards/x86/quark_d2000_crb/quark_d2000_crb_defconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ CONFIG_SERIAL=y
1212
CONFIG_SERIAL_HAS_DRIVER=y
1313
CONFIG_PRINTK=y
1414
CONFIG_ISR_STACK_SIZE=256
15-
CONFIG_MAIN_STACK_SIZE=512
15+
CONFIG_MAIN_STACK_SIZE=1024
1616
CONFIG_PINMUX=y

drivers/spi/spi_context.h

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ struct spi_context {
2929
struct k_poll_signal *signal;
3030
bool asynchronous;
3131
#endif
32-
const struct spi_buf **current_tx;
33-
struct spi_buf **current_rx;
32+
const struct spi_buf *current_tx;
33+
size_t tx_count;
34+
struct spi_buf *current_rx;
35+
size_t rx_count;
3436

3537
void *tx_buf;
36-
u32_t tx_len;
38+
size_t tx_len;
3739
void *rx_buf;
38-
u32_t rx_len;
40+
size_t rx_len;
3941
};
4042

4143
#define SPI_CONTEXT_INIT_LOCK(_data, _ctx_name) \
@@ -144,36 +146,40 @@ static inline void spi_context_cs_control(struct spi_context *ctx, bool on)
144146
}
145147

146148
static inline void spi_context_buffers_setup(struct spi_context *ctx,
147-
const struct spi_buf **tx_bufs,
148-
struct spi_buf **rx_bufs,
149+
const struct spi_buf *tx_bufs,
150+
size_t tx_count,
151+
struct spi_buf *rx_bufs,
152+
size_t rx_count,
149153
uint8_t dfs)
150154
{
151-
SYS_LOG_DBG("tx_bufs %p (%p) - rx_bufs %p (%p) - %u",
152-
tx_bufs, tx_bufs ? *tx_bufs : NULL,
153-
rx_bufs, rx_bufs ? *rx_bufs : NULL, dfs);
155+
SYS_LOG_DBG("tx_bufs %p (%zu) - rx_bufs %p (%zu) - %u",
156+
tx_bufs, tx_count, rx_bufs, rx_count, dfs);
154157

155158
ctx->current_tx = tx_bufs;
159+
ctx->tx_count = tx_count;
156160
ctx->current_rx = rx_bufs;
161+
ctx->rx_count = rx_count;
157162

158-
if (*tx_bufs) {
159-
ctx->tx_buf = (*tx_bufs)->buf;
160-
ctx->tx_len = (*tx_bufs)->len/dfs;
163+
if (tx_bufs) {
164+
ctx->tx_buf = tx_bufs->buf;
165+
ctx->tx_len = tx_bufs->len / dfs;
161166
} else {
162167
ctx->tx_buf = NULL;
163168
ctx->tx_len = 0;
164169
}
165170

166-
if (*rx_bufs) {
167-
ctx->rx_buf = (*rx_bufs)->buf;
168-
ctx->rx_len = (*rx_bufs)->len/dfs;
171+
if (rx_bufs) {
172+
ctx->rx_buf = rx_bufs->buf;
173+
ctx->rx_len = rx_bufs->len / dfs;
169174
} else {
170175
ctx->rx_buf = NULL;
171176
ctx->rx_len = 0;
172177
}
173178

174-
SYS_LOG_DBG("current_tx %p, current_rx %p,"
175-
" tx buf/len %p/%u, rx buf/len %p/%u",
176-
ctx->current_tx, ctx->current_rx,
179+
SYS_LOG_DBG("current_tx %p (%zu), current_rx %p (%zu),"
180+
" tx buf/len %p/%zu, rx buf/len %p/%zu",
181+
ctx->current_tx, ctx->tx_count,
182+
ctx->current_rx, ctx->rx_count,
177183
ctx->tx_buf, ctx->tx_len, ctx->rx_buf, ctx->rx_len);
178184
}
179185

@@ -187,17 +193,19 @@ void spi_context_update_tx(struct spi_context *ctx, uint8_t dfs)
187193
ctx->tx_len--;
188194
if (!ctx->tx_len) {
189195
ctx->current_tx++;
190-
if (*ctx->current_tx) {
191-
ctx->tx_buf = (*ctx->current_tx)->buf;
192-
ctx->tx_len = (*ctx->current_tx)->len/dfs;
196+
ctx->tx_count--;
197+
198+
if (ctx->tx_count) {
199+
ctx->tx_buf = ctx->current_tx->buf;
200+
ctx->tx_len = ctx->current_tx->len / dfs;
193201
} else {
194202
ctx->tx_buf = NULL;
195203
}
196204
} else if (ctx->tx_buf) {
197205
ctx->tx_buf += dfs;
198206
}
199207

200-
SYS_LOG_DBG("tx buf/len %p/%u", ctx->tx_buf, ctx->tx_len);
208+
SYS_LOG_DBG("tx buf/len %p/%zu", ctx->tx_buf, ctx->tx_len);
201209
}
202210

203211
static ALWAYS_INLINE
@@ -216,17 +224,19 @@ void spi_context_update_rx(struct spi_context *ctx, uint8_t dfs)
216224
ctx->rx_len--;
217225
if (!ctx->rx_len) {
218226
ctx->current_rx++;
219-
if (*ctx->current_rx) {
220-
ctx->rx_buf = (*ctx->current_rx)->buf;
221-
ctx->rx_len = (*ctx->current_rx)->len/dfs;
227+
ctx->rx_count--;
228+
229+
if (ctx->rx_count) {
230+
ctx->rx_buf = ctx->current_rx->buf;
231+
ctx->rx_len = ctx->current_rx->len / dfs;
222232
} else {
223233
ctx->rx_buf = NULL;
224234
}
225235
} else if (ctx->rx_buf) {
226236
ctx->rx_buf += dfs;
227237
}
228238

229-
SYS_LOG_DBG("rx buf/len %p/%u", ctx->rx_buf, ctx->rx_len);
239+
SYS_LOG_DBG("rx buf/len %p/%zu", ctx->rx_buf, ctx->rx_len);
230240
}
231241

232242
static ALWAYS_INLINE

drivers/spi/spi_dw.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,10 @@ static int spi_dw_configure(const struct spi_dw_config *info,
251251
}
252252

253253
static int transceive(struct spi_config *config,
254-
const struct spi_buf **tx_bufs,
255-
struct spi_buf **rx_bufs,
254+
const struct spi_buf *tx_bufs,
255+
size_t tx_count,
256+
struct spi_buf *rx_bufs,
257+
size_t rx_count,
256258
bool asynchronous,
257259
struct k_poll_signal *signal)
258260
{
@@ -277,7 +279,8 @@ static int transceive(struct spi_config *config,
277279
}
278280

279281
/* Set buffers info */
280-
spi_context_buffers_setup(&spi->ctx, tx_bufs, rx_bufs, spi->dfs);
282+
spi_context_buffers_setup(&spi->ctx, tx_bufs, tx_count,
283+
rx_bufs, rx_count, spi->dfs);
281284

282285
spi->fifo_diff = 0;
283286

@@ -317,23 +320,31 @@ static int transceive(struct spi_config *config,
317320
}
318321

319322
static int spi_dw_transceive(struct spi_config *config,
320-
const struct spi_buf **tx_bufs,
321-
struct spi_buf **rx_bufs)
323+
const struct spi_buf *tx_bufs,
324+
size_t tx_count,
325+
struct spi_buf *rx_bufs,
326+
size_t rx_count)
322327
{
323-
SYS_LOG_DBG("%p, %p, %p", config->dev, tx_bufs, rx_bufs);
328+
SYS_LOG_DBG("%p, %p (%zu), %p (%zu)",
329+
config->dev, tx_bufs, tx_count, rx_bufs, rx_count);
324330

325-
return transceive(config, tx_bufs, rx_bufs, false, NULL);
331+
return transceive(config, tx_bufs, tx_count,
332+
rx_bufs, rx_count, false, NULL);
326333
}
327334

328335
#ifdef CONFIG_POLL
329336
static int spi_dw_transceive_async(struct spi_config *config,
330-
const struct spi_buf **tx_bufs,
331-
struct spi_buf **rx_bufs,
337+
const struct spi_buf *tx_bufs,
338+
size_t tx_count,
339+
struct spi_buf *rx_bufs,
340+
size_t rx_count,
332341
struct k_poll_signal *async)
333342
{
334-
SYS_LOG_DBG("%p, %p, %p, %p", config->dev, tx_bufs, rx_bufs, async);
343+
SYS_LOG_DBG("%p, %p (%zu), %p (%zu), %p",
344+
config->dev, tx_bufs, tx_count, rx_bufs, rx_count, async);
335345

336-
return transceive(config, tx_bufs, rx_bufs, true, async);
346+
return transceive(config, tx_bufs, tx_count,
347+
rx_bufs, rx_count, true, async);
337348
}
338349
#endif /* CONFIG_POLL */
339350

0 commit comments

Comments
 (0)