You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/02/19 00:39:06 UTC
[2/3] incubator-mynewt-tadpole git commit: hatch tadpole from master
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/include/os/os_sanity.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_sanity.h b/libs/os/include/os/os_sanity.h
index 4824c5d..e399749 100644
--- a/libs/os/include/os/os_sanity.h
+++ b/libs/os/include/os/os_sanity.h
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#ifndef _OS_SANITY_H
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/include/os/os_sched.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_sched.h b/libs/os/include/os/os_sched.h
index a34c5e3..ebd7eb5 100644
--- a/libs/os/include/os/os_sched.h
+++ b/libs/os/include/os/os_sched.h
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#ifndef _OS_SCHED_H
@@ -19,9 +22,6 @@
#include "os/os_task.h"
-typedef int (*os_sched_walk_func_t)(struct os_task *, void *arg);
-
-int os_sched_walk(os_sched_walk_func_t walk_func, void *arg);
void os_sched_ctx_sw_hook(struct os_task *);
struct os_task *os_sched_get_current_task(void);
void os_sched_set_current_task(struct os_task *);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/include/os/os_sem.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_sem.h b/libs/os/include/os/os_sem.h
index b0eb8bf..0396e96 100644
--- a/libs/os/include/os/os_sem.h
+++ b/libs/os/include/os/os_sem.h
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#ifndef _OS_SEM_H_
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/include/os/os_task.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_task.h b/libs/os/include/os/os_task.h
index ae44a73..25845e7 100644
--- a/libs/os/include/os/os_task.h
+++ b/libs/os/include/os/os_task.h
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#ifndef _OS_TASK_H
@@ -53,8 +56,12 @@ typedef enum os_task_state {
typedef void (*os_task_func_t)(void *);
+#define OS_TASK_MAX_NAME_LEN (32)
+
struct os_task {
os_stack_t *t_stackptr;
+ os_stack_t *t_stacktop;
+
uint16_t t_stacksize;
uint16_t t_flags;
@@ -74,7 +81,10 @@ struct os_task {
os_time_t t_next_wakeup;
os_time_t t_run_time;
uint32_t t_ctx_sw_cnt;
-
+
+ /* Global list of all tasks, irrespective of run or sleep lists */
+ STAILQ_ENTRY(os_task) t_os_task_list;
+
/* Used to chain task to either the run or sleep list */
TAILQ_ENTRY(os_task) t_os_list;
@@ -88,5 +98,24 @@ int os_task_init(struct os_task *, char *, os_task_func_t, void *, uint8_t,
int os_task_sanity_checkin(struct os_task *);
uint8_t os_task_count(void);
+struct os_task_info {
+ uint8_t oti_prio;
+ uint8_t oti_taskid;
+ uint8_t oti_state;
+ uint8_t oti_pad1;
+ uint8_t oti_pad2;
+ uint16_t oti_flags;
+ uint16_t oti_stkusage;
+ uint16_t oti_stksize;
+ uint32_t oti_cswcnt;
+ uint32_t oti_runtime;
+ os_time_t oti_last_checkin;
+ os_time_t oti_next_checkin;
+
+ char oti_name[OS_TASK_MAX_NAME_LEN];
+};
+struct os_task *os_task_info_get_next(const struct os_task *,
+ struct os_task_info *);
+
#endif /* _OS_TASK_H */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/include/os/os_test.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_test.h b/libs/os/include/os/os_test.h
index 8f4bece..6701315 100644
--- a/libs/os/include/os/os_test.h
+++ b/libs/os/include/os/os_test.h
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#ifndef H_OS_TEST_
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/include/os/os_time.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_time.h b/libs/os/include/os/os_time.h
index 9c2bc23..b3c95b3 100644
--- a/libs/os/include/os/os_time.h
+++ b/libs/os/include/os/os_time.h
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#ifndef _OS_TIME_H
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/os/pkg.yml b/libs/os/pkg.yml
new file mode 100644
index 0000000..332fc28
--- /dev/null
+++ b/libs/os/pkg.yml
@@ -0,0 +1,33 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: libs/os
+pkg.vers: 0.1
+pkg.deps:
+ - libs/testutil
+pkg.req_caps:
+ - console
+
+pkg.deps.SHELL:
+ - libs/shell
+pkg.cflags.SHELL: -DSHELL_PRESENT
+pkg.reqs.SHELL:
+ - console
+# Satisfy capability dependencies for the self-contained test executable.
+pkg.deps.selftest: libs/console/stub
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/arch/cortex_m0/m0/HAL_CM0.s
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/m0/HAL_CM0.s b/libs/os/src/arch/cortex_m0/m0/HAL_CM0.s
new file mode 100644
index 0000000..1a01c11
--- /dev/null
+++ b/libs/os/src/arch/cortex_m0/m0/HAL_CM0.s
@@ -0,0 +1,277 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*----------------------------------------------------------------------------
+ * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * - Neither the name of ARM nor the names of its contributors may be used
+ * to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *---------------------------------------------------------------------------*/
+
+ .file "HAL_CM0.S"
+ .syntax unified
+
+/*----------------------------------------------------------------------------
+ * Functions
+ *---------------------------------------------------------------------------*/
+
+ .thumb
+
+ .section ".text"
+ .align 2
+
+/*--------------------------- os_set_env ------------------------------------*/
+# void os_set_env (void);
+#
+# Called to switch to privileged or unprivileged thread mode. The variable
+# 'os_flags' contains the CONTROL bit LSB to set the device into the
+# proper mode. We also use PSP so we set bit 1 (the SPSEL bit) to 1.
+#
+
+ .thumb_func
+ .type os_set_env, %function
+ .global os_set_env
+os_set_env:
+ .fnstart
+ .cantunwind
+
+ MOV R0,SP /* Copy MSP to PSP */
+ MSR PSP,R0
+ LDR R0,=os_flags
+ LDRB R0,[R0]
+ ADDS R0, R0, #2
+ MSR CONTROL,R0
+ ISB
+ BX LR
+
+ .fnend
+ .size os_set_env, .-os_set_env
+/*--------------------------- os_set_env ------------------------------------*/
+
+
+/*--------------------------- os_arch_init_task_stack------------------------*/
+# void os_arch_init_task_stack(os_stack_t *sf);
+# NOTE: This function only stores R4 through R11 on stack. The reason we do
+# this is that the application may have stored some values in some of the
+# registers and we want to preserve those values (position independent code
+# is a good example). The other registers are handled in the C startup code.
+ .thumb_func
+ .type os_arch_init_task_stack, %function
+ .global os_arch_init_task_stack
+os_arch_init_task_stack:
+ .fnstart
+
+ MOV R3,R0
+ STMIA R0!,{R4-R7}
+ MOV R4,R8
+ MOV R5,R9
+ MOV R6,R10
+ MOV R7,R11
+ STMIA R0!,{R4-R7}
+ LDM R3!,{R4-R7}
+ BX LR
+
+ .fnend
+ .size os_arch_init_task_stack, .-os_arch_init_task_stack
+/*--------------------------- os_set_env ------------------------------------*/
+
+
+/*-------------------------- SVC_Handler ------------------------------------*/
+# void SVC_Handler (void);
+ .thumb_func
+ .type SVC_Handler, %function
+ .global SVC_Handler
+SVC_Handler:
+ .fnstart
+ .cantunwind
+ MRS R0,PSP /* Read PSP */
+ LDR R1,[R0,#24] /* Read Saved PC from Stack */
+ SUBS R1,R1,#2 /* Point to SVC Instruction */
+ LDRB R1,[R1] /* Load SVC Number */
+ CMP R1,#0
+ BNE SVC_User /* User SVC Number > 0 */
+ LDR R1,[R0,#16] /* Read saved R12 from Stack */
+ MOV R12, R1 /* Store in R12 */
+ LDMIA R0,{R0-R3} /* Read R0-R3 from stack */
+ PUSH {LR} /* Save LR */
+ BLX R12 /* Call SVC Function */
+ MRS R3,PSP /* Read PSP */
+ STMIA R3!,{R0-R2} /* Store return values */
+ POP {PC} /* RETI */
+
+ /*------------------- User SVC ------------------------------*/
+SVC_User:
+ PUSH {R4,LR} /* Save Registers */
+ LDR R2,=SVC_Count
+ LDR R2,[R2]
+ CMP R1,R2
+ BHI SVC_Done /* Overflow */
+ LDR R4,=SVC_Table-4
+ LSLS R1,R1,#2
+ LDR R4,[R4,R1] /* Load SVC Function Address */
+ MOV LR,R4
+ LDMIA R0,{R0-R3,R4} /* Read R0-R3,R12 from stack */
+ MOV R12,R4
+ BLX LR /* Call SVC Function */
+ MRS R4,PSP /* Read PSP */
+ STMIA R4!,{R0-R3} /* Function return values */
+SVC_Done:
+ POP {R4,PC} /* RETI */
+ .fnend
+ .size SVC_Handler, .-SVC_Handler
+/*-------------------------- PendSV_Handler ---------------------------------*/
+# void PendSV_Handler (void);
+ .thumb_func
+ .type PendSV_Handler, %function
+ .global PendSV_Handler
+PendSV_Handler:
+ .fnstart
+ .cantunwind
+
+ LDR R3,=g_os_run_list /* Get highest priority task ready to run */
+ LDR R2,[R3] /* Store in R2 */
+ LDR R3,=g_current_task /* Get current task */
+ LDR R1,[R3] /* Current task in R1 */
+ CMP R1,R2
+ BNE context_switch
+ BX LR /* RETI, no task switch */
+context_switch:
+ MRS R0,PSP /* Read PSP */
+ SUBS R0,R0,#32
+ STMIA R0!,{R4-R7} /* Save Old context */
+ MOV R4,R8
+ MOV R5,R9
+ MOV R6,R10
+ MOV R7,R11
+ STMIA R0!,{R4-R7} /* Save Old context */
+ SUBS R0,R0,#32
+
+ STR R0,[R1,#0] /* Update stack pointer in current task */
+ STR R2,[R3] /* g_current_task = highest ready */
+
+ LDR R0,[R2,#0] /* get stack pointer of task we will start */
+ ADDS R0,R0, #16
+ LDMIA R0!,{R4-R7} /* Restore New Context */
+ MOV R8,R4
+ MOV R9,R5
+ MOV R10,R6
+ MOV R11,R7
+ MSR PSP,R0 /* Write PSP */
+ SUBS R0,R0,#32
+ LDMIA R0!,{R4-R7} /* Restore New Context */
+ BX LR /* Return to Thread Mode */
+
+ .fnend
+ .size PendSV_Handler, .-PendSV_Handler
+
+
+
+/*-------------------------- SysTick_Handler --------------------------------*/
+
+# void SysTick_Handler (void);
+ .thumb_func
+ .type SysTick_Handler, %function
+ .global SysTick_Handler
+SysTick_Handler:
+ .fnstart
+ .cantunwind
+
+ PUSH {R4,LR} /* Save EXC_RETURN */
+ BL timer_handler
+ POP {R4,PC} /* Restore EXC_RETURN */
+
+ .fnend
+ .size SysTick_Handler, .-SysTick_Handler
+
+/*-------------------------- Defalt IRQ --------------------------------*/
+ .thumb_func
+ .type os_default_irq_asm, %function
+ .global os_default_irq_asm
+os_default_irq_asm:
+ .fnstart
+ .cantunwind
+
+ /*
+ * LR = 0xfffffff9 if we were using MSP as SP
+ * LR = 0xfffffffd if we were using PSP as SP
+ */
+ MOV R0,LR
+ MOVS R1,#4
+ TST R0,R1
+ MRS R12,MSP
+ BEQ using_msp_as_sp
+ MRS R12,PSP
+using_msp_as_sp:
+ /*
+ * Push the "trap frame" structure onto stack by moving R8-R11 into
+ * R0-R3 and then pushing R0-R3. LR gets pushed as well with LR
+ * residing at higher memory, R8 at the lower memory address.
+ */
+ MOV R0,R8
+ MOV R1,R9
+ MOV R2,R10
+ MOV R3,R11
+ PUSH {R0-R3, LR}
+ /* Now push r3 - r7. R3 is the lowest memory address. */
+ MOV R3,R12
+ PUSH {R3-R7}
+ MOV R0, SP
+ BL os_default_irq
+ POP {R3-R7}
+ POP {R0-R3}
+ MOV R8,R0
+ MOV R9,R1
+ MOV R10,R2
+ MOV R11,R3
+ POP {PC} /* Restore EXC_RETURN */
+
+ .fnend
+ .size os_default_irq_asm, .-os_default_irq_asm
+
+ /*
+ * Prevent libgcc unwind stuff from getting pulled in.
+ */
+ .section ".data"
+ .global __aeabi_unwind_cpp_pr0
+__aeabi_unwind_cpp_pr0:
+ .end
+
+/*----------------------------------------------------------------------------
+ * end of file
+ *---------------------------------------------------------------------------*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/arch/cortex_m0/m0/SVC_Table.s
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/m0/SVC_Table.s b/libs/os/src/arch/cortex_m0/m0/SVC_Table.s
new file mode 100755
index 0000000..5f58657
--- /dev/null
+++ b/libs/os/src/arch/cortex_m0/m0/SVC_Table.s
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+;
+;/*----------------------------------------------------------------------------
+; * RL-ARM - RTX
+; *----------------------------------------------------------------------------
+; * Name: SVC_TABLE.S
+; * Purpose: Pre-defined SVC Table for Cortex-M
+; * Rev.: V4.70
+; *----------------------------------------------------------------------------
+; *
+; * Copyright (c) 1999-2009 KEIL, 2009-2013 ARM Germany GmbH
+; * All rights reserved.
+; * Redistribution and use in source and binary forms, with or without
+; * modification, are permitted provided that the following conditions are met:
+; * - Redistributions of source code must retain the above copyright
+; * notice, this list of conditions and the following disclaimer.
+; * - Redistributions in binary form must reproduce the above copyright
+; * notice, this list of conditions and the following disclaimer in the
+; * documentation and/or other materials provided with the distribution.
+; * - Neither the name of ARM nor the names of its contributors may be used
+; * to endorse or promote products derived from this software without
+; * specific prior written permission.
+; *
+; * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+; * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+; * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+; * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+; * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+; * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+; * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+; * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+; * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+; * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+; * POSSIBILITY OF SUCH DAMAGE.
+; *---------------------------------------------------------------------------*/
+
+
+ .file "SVC_Table.S"
+
+
+ .section ".svc_table"
+
+ .global SVC_Table
+SVC_Table:
+/* Insert user SVC functions here. SVC 0 used by RTL Kernel. */
+# .long __SVC_1 /* user SVC function */
+SVC_End:
+
+ .global SVC_Count
+SVC_Count:
+ .long (SVC_End-SVC_Table)/4
+
+
+ .end
+
+/*----------------------------------------------------------------------------
+ * end of file
+ *---------------------------------------------------------------------------*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/arch/cortex_m0/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/os_arch_arm.c b/libs/os/src/arch/cortex_m0/os_arch_arm.c
new file mode 100755
index 0000000..1fd719b
--- /dev/null
+++ b/libs/os/src/arch/cortex_m0/os_arch_arm.c
@@ -0,0 +1,338 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "os/os.h"
+#include "os/os_arch.h"
+
+#include <bsp/cmsis_nvic.h>
+
+/* XXX*/
+extern void system_os_tick_init(uint32_t os_ticks_per_sec);
+
+/*
+ * From HAL_CM0.s
+ */
+extern void SVC_Handler(void);
+extern void PendSV_Handler(void);
+extern void SysTick_Handler(void);
+/* XXX */
+
+/* Initial program status register */
+#define INITIAL_xPSR 0x01000000
+
+/*
+ * Exception priorities. The higher the number, the lower the priority. A
+ * higher priority exception will interrupt a lower priority exception.
+ */
+#define PEND_SV_PRIO ((1 << __NVIC_PRIO_BITS) - 1)
+#define SYSTICK_PRIO (PEND_SV_PRIO - 1)
+
+/* Make the SVC instruction highest priority */
+#define SVC_PRIO (1)
+
+/* Stack frame structure */
+struct stack_frame {
+ uint32_t r4;
+ uint32_t r5;
+ uint32_t r6;
+ uint32_t r7;
+ uint32_t r8;
+ uint32_t r9;
+ uint32_t r10;
+ uint32_t r11;
+ uint32_t r0;
+ uint32_t r1;
+ uint32_t r2;
+ uint32_t r3;
+ uint32_t r12;
+ uint32_t lr;
+ uint32_t pc;
+ uint32_t xpsr;
+};
+
+#define SVC_ArgN(n) \
+ register int __r##n __asm("r"#n);
+
+#define SVC_Arg0() \
+ SVC_ArgN(0) \
+ SVC_ArgN(1) \
+ SVC_ArgN(2) \
+ SVC_ArgN(3)
+
+#if (defined (__MCU_CORTEX_M0_H__)) || defined (__CORTEX_M0PLUS)
+#define SVC_Call(f) \
+ __asm volatile \
+ ( \
+ "ldr r7,="#f"\n\t" \
+ "mov r12,r7\n\t" \
+ "svc 0" \
+ : "=r" (__r0), "=r" (__r1), "=r" (__r2), "=r" (__r3) \
+ : "r" (__r0), "r" (__r1), "r" (__r2), "r" (__r3) \
+ : "r7", "r12", "lr", "cc" \
+ );
+#else
+#define SVC_Call(f) \
+ __asm volatile \
+ ( \
+ "ldr r12,="#f"\n\t" \
+ "svc 0" \
+ : "=r" (__r0), "=r" (__r1), "=r" (__r2), "=r" (__r3) \
+ : "r" (__r0), "r" (__r1), "r" (__r2), "r" (__r3) \
+ : "r12", "lr", "cc" \
+ );
+#endif
+
+/* XXX: determine how we will deal with running un-privileged */
+uint32_t os_flags = OS_RUN_PRIV;
+
+void
+timer_handler(void)
+{
+ os_time_tick();
+ os_callout_tick();
+ os_sched_os_timer_exp();
+ os_sched(NULL, 1);
+}
+
+void
+os_arch_ctx_sw(struct os_task *t)
+{
+ os_sched_ctx_sw_hook(t);
+
+ /* Set PendSV interrupt pending bit to force context switch */
+ SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
+}
+
+void
+os_arch_ctx_sw_isr(struct os_task *t)
+{
+ os_sched_ctx_sw_hook(t);
+
+ /* Set PendSV interrupt pending bit to force context switch */
+ SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
+}
+
+os_sr_t
+os_arch_save_sr(void)
+{
+ uint32_t isr_ctx;
+
+ isr_ctx = __get_PRIMASK();
+ __disable_irq();
+ return (isr_ctx & 1);
+}
+
+void
+os_arch_restore_sr(os_sr_t isr_ctx)
+{
+ if (!isr_ctx) {
+ __enable_irq();
+ }
+}
+
+os_stack_t *
+os_arch_task_stack_init(struct os_task *t, os_stack_t *stack_top, int size)
+{
+ int i;
+ os_stack_t *s;
+ struct stack_frame *sf;
+
+ /* Get stack frame pointer */
+ s = (os_stack_t *) ((uint8_t *) stack_top - sizeof(*sf));
+
+ /* Zero out R1-R3, R12, LR */
+ for (i = 9; i < 14; ++i) {
+ s[i] = 0;
+ }
+
+ /* Set registers R4 - R11 on stack. */
+ os_arch_init_task_stack(s);
+
+ /* Set remaining portions of stack frame */
+ sf = (struct stack_frame *) s;
+ sf->xpsr = INITIAL_xPSR;
+ sf->pc = (uint32_t)t->t_func;
+ sf->r0 = (uint32_t)t->t_arg;
+
+ return (s);
+}
+
+void
+os_arch_init(void)
+{
+ os_init_idle_task();
+}
+
+__attribute__((always_inline))
+static inline void
+svc_os_arch_init(void)
+{
+ SVC_Arg0();
+ SVC_Call(os_arch_init);
+}
+
+os_error_t
+os_arch_os_init(void)
+{
+ os_error_t err;
+ int i;
+
+ /* Cannot be called within an ISR */
+ err = OS_ERR_IN_ISR;
+ if (__get_IPSR() == 0) {
+ err = OS_OK;
+
+ /* Drop priority for all interrupts */
+ for (i = 0; i < sizeof(NVIC->IP); i++) {
+ NVIC->IP[i] = 0xff;
+ }
+
+ NVIC_SetVector(SVCall_IRQn, (uint32_t)SVC_Handler);
+ NVIC_SetVector(PendSV_IRQn, (uint32_t)PendSV_Handler);
+ NVIC_SetVector(SysTick_IRQn, (uint32_t)SysTick_Handler);
+
+ /*
+ * Install default interrupt handler, which'll print out system
+ * state at the time of the interrupt, and few other regs which
+ * should help in trying to figure out what went wrong.
+ */
+ NVIC_SetVector(NonMaskableInt_IRQn, (uint32_t)os_default_irq_asm);
+ NVIC_SetVector(HardFault_IRQn, (uint32_t)os_default_irq_asm);
+ NVIC_SetVector(-13, (uint32_t)os_default_irq_asm); /* Hardfault */
+ for (i = 0; i < NVIC_NUM_VECTORS - NVIC_USER_IRQ_OFFSET; i++) {
+ NVIC_SetVector(i, (uint32_t)os_default_irq_asm);
+ }
+
+ /* Call bsp related OS initializations */
+ os_bsp_init();
+
+ /* Set the PendSV interrupt exception priority to the lowest priority */
+ NVIC_SetPriority(PendSV_IRQn, PEND_SV_PRIO);
+
+ /* Set the SVC interrupt to priority 0 (highest configurable) */
+ NVIC_SetPriority(SVCall_IRQn, SVC_PRIO);
+
+ /*
+ * Set the os environment. This will set stack pointers and, based
+ * on the contents of os_flags, will determine if the tasks run in
+ * priviliged or un-privileged mode.
+ */
+ os_set_env();
+
+ /* Check if privileged or not */
+ if ((__get_CONTROL() & 1) == 0) {
+ os_arch_init();
+ } else {
+ svc_os_arch_init();
+ }
+ }
+
+ return err;
+}
+
+uint32_t
+os_arch_start(void)
+{
+ struct os_task *t;
+
+ /* Get the highest priority ready to run to set the current task */
+ t = os_sched_next_task();
+ os_sched_set_current_task(t);
+
+ /* Adjust PSP so it looks like this task just took an exception */
+ __set_PSP((uint32_t)t->t_stackptr + offsetof(struct stack_frame, r0));
+
+ /* Intitialize and start system clock timer */
+ os_bsp_systick_init(OS_TICKS_PER_SEC);
+
+ /* Mark the OS as started, right before we run our first task */
+ g_os_started = 1;
+
+ /* Perform context switch */
+ os_arch_ctx_sw(t);
+
+ return (uint32_t)(t->t_arg);
+}
+
+__attribute__((always_inline))
+static inline void svc_os_arch_start(void)
+{
+ SVC_Arg0();
+ SVC_Call(os_arch_start);
+}
+
+/**
+ * Start the OS. First check to see if we are running with the correct stack
+ * pointer set (PSP) and privilege mode (PRIV).
+ *
+ *
+ * @return os_error_t
+ */
+os_error_t
+os_arch_os_start(void)
+{
+ os_error_t err;
+
+ err = OS_ERR_IN_ISR;
+ if (__get_IPSR() == 0) {
+ /*
+ * The following switch statement is really just a sanity check to
+ * insure that the os initialization routine was called prior to the
+ * os start routine.
+ */
+ err = OS_OK;
+ switch (__get_CONTROL() & 0x03) {
+ /*
+ * These two cases are for completeness. Thread mode should be set
+ * to use PSP already.
+ *
+ * Fall-through intentional!
+ */
+ case 0x00:
+ case 0x01:
+ err = OS_ERR_PRIV;
+ break;
+ case 0x02:
+ /*
+ * We are running in Privileged Thread mode w/SP = PSP but we
+ * are supposed to be un-privileged.
+ */
+ if ((os_flags & 1) == OS_RUN_UNPRIV) {
+ err = OS_ERR_PRIV;
+ }
+ break;
+ case 0x03:
+ /*
+ * We are running in Unprivileged Thread mode w/SP = PSP but we
+ * are supposed to be privileged.
+ */
+ if ((os_flags & 1) == OS_RUN_PRIV) {
+ err = OS_ERR_PRIV;
+ }
+ break;
+ }
+ if (err == OS_OK) {
+ /* Always start OS through SVC call */
+ svc_os_arch_start();
+ }
+ }
+
+ return err;
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/arch/cortex_m0/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m0/os_fault.c b/libs/os/src/arch/cortex_m0/os_fault.c
new file mode 100644
index 0000000..4c67f6c
--- /dev/null
+++ b/libs/os/src/arch/cortex_m0/os_fault.c
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <console/console.h>
+#include <hal/hal_system.h>
+#include "os/os.h"
+
+#include <stdint.h>
+#include <unistd.h>
+
+int os_die_line;
+const char *os_die_module;
+
+void __assert_func(const char *file, int line, const char *func, const char *e);
+
+void
+__assert_func(const char *file, int line, const char *func, const char *e)
+{
+ int sr;
+
+ OS_ENTER_CRITICAL(sr);
+ (void)sr;
+ os_die_line = line;
+ os_die_module = file;
+ console_blocking_mode();
+ console_printf("Assert %s; failed in %s:%d\n", e ? e : "", file, line);
+ system_reset();
+}
+
+struct exception_frame {
+ uint32_t r0;
+ uint32_t r1;
+ uint32_t r2;
+ uint32_t r3;
+ uint32_t r12;
+ uint32_t lr;
+ uint32_t pc;
+ uint32_t psr;
+};
+
+struct trap_frame {
+ struct exception_frame *ef;
+ uint32_t r4;
+ uint32_t r5;
+ uint32_t r6;
+ uint32_t r7;
+ uint32_t r8;
+ uint32_t r9;
+ uint32_t r10;
+ uint32_t r11;
+ uint32_t lr; /* this LR holds EXC_RETURN */
+};
+
+void
+os_default_irq(struct trap_frame *tf)
+{
+ console_blocking_mode();
+ console_printf("Unhandled interrupt (%ld), exception sp 0x%08lx\n",
+ SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk, (uint32_t)tf->ef);
+ console_printf(" r0:0x%08lx r1:0x%08lx r2:0x%08lx r3:0x%08lx\n",
+ tf->ef->r0, tf->ef->r1, tf->ef->r2, tf->ef->r3);
+ console_printf(" r4:0x%08lx r5:0x%08lx r6:0x%08lx r7:0x%08lx\n",
+ tf->r4, tf->r5, tf->r6, tf->r7);
+ console_printf(" r8:0x%08lx r9:0x%08lx r10:0x%08lx r11:0x%08lx\n",
+ tf->r8, tf->r9, tf->r10, tf->r11);
+ console_printf("r12:0x%08lx lr:0x%08lx pc:0x%08lx psr:0x%08lx\n",
+ tf->ef->r12, tf->ef->lr, tf->ef->pc, tf->ef->psr);
+ console_printf("ICSR:0x%08lx ",SCB->ICSR);
+ system_reset();
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s b/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
index dcde207..c5d5b57 100755
--- a/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
+++ b/libs/os/src/arch/cortex_m4/m4/HAL_CM4.s
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
/*----------------------------------------------------------------------------
@@ -55,7 +58,11 @@
/*--------------------------- os_set_env ------------------------------------*/
# void os_set_env (void);
- /* Switch to Unprivileged/Privileged Thread mode, use PSP. */
+#
+# Called to switch to privileged or unprivileged thread mode. The variable
+# 'os_flags' contains the CONTROL bit LSB to set the device into the
+# proper mode. We also use PSP so we set bit 1 (the SPSEL bit) to 1.
+#
.thumb_func
.type os_set_env, %function
@@ -64,14 +71,11 @@ os_set_env:
.fnstart
.cantunwind
- MOV R0,SP /* PSP = MSP */
+ MOV R0,SP /* Copy MSP to PSP */
MSR PSP,R0
LDR R0,=os_flags
LDRB R0,[R0]
- LSLS R0,#31
- ITE NE
- MOVNE R0,#0x02 /* Privileged Thread mode, use PSP */
- MOVEQ R0,#0x03 /* Unprivileged Thread mode, use PSP */
+ ADDS R0, R0, #2
MSR CONTROL,R0
ISB
BX LR
@@ -201,6 +205,7 @@ SysTick_Handler:
.fnend
.size SysTick_Handler, .-SysTick_Handler
+/*-------------------------- Defalt IRQ --------------------------------*/
.thumb_func
.type os_default_irq_asm, %function
.global os_default_irq_asm
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/arch/cortex_m4/m4/SVC_Table.s
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/m4/SVC_Table.s b/libs/os/src/arch/cortex_m4/m4/SVC_Table.s
index 8a252f7..99a618e 100755
--- a/libs/os/src/arch/cortex_m4/m4/SVC_Table.s
+++ b/libs/os/src/arch/cortex_m4/m4/SVC_Table.s
@@ -1,18 +1,21 @@
-; /**
-; * Copyright (c) 2015 Runtime Inc.
-; *
-; * Licensed under the Apache License, Version 2.0 (the "License");
-; * you may not use this file except in compliance with the License.
-; * You may obtain a copy of the License at
-; *
-; * http://www.apache.org/licenses/LICENSE-2.0
-; *
-; * Unless required by applicable law or agreed to in writing, software
-; * distributed under the License is distributed on an "AS IS" BASIS,
-; * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-; * See the License for the specific language governing permissions and
-; * limitations under the License.
-; */
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
;
;
;/*----------------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/arch/cortex_m4/os_arch_arm.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_arch_arm.c b/libs/os/src/arch/cortex_m4/os_arch_arm.c
index d941809..64ba05e 100755
--- a/libs/os/src/arch/cortex_m4/os_arch_arm.c
+++ b/libs/os/src/arch/cortex_m4/os_arch_arm.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include "os/os.h"
@@ -222,7 +225,7 @@ os_arch_os_init(void)
*/
os_set_env();
- /* Check if priviledged or not */
+ /* Check if privileged or not */
if ((__get_CONTROL() & 1) == 0) {
os_arch_init();
} else {
@@ -287,6 +290,13 @@ static inline void svc_os_arch_start(void)
SVC_Call(os_arch_start);
}
+/**
+ * Start the OS. First check to see if we are running with the correct stack
+ * pointer set (PSP) and privilege mode (PRIV).
+ *
+ *
+ * @return os_error_t
+ */
os_error_t
os_arch_os_start(void)
{
@@ -312,14 +322,20 @@ os_arch_os_start(void)
err = OS_ERR_PRIV;
break;
case 0x02:
- /* Privileged Thread mode w/SP = PSP */
- if ((os_flags & 1) == 0) {
+ /*
+ * We are running in Privileged Thread mode w/SP = PSP but we
+ * are supposed to be un-privileged.
+ */
+ if ((os_flags & 1) == OS_RUN_UNPRIV) {
err = OS_ERR_PRIV;
}
break;
case 0x03:
- /* Unpriviliged thread mode w/sp = PSP */
- if (os_flags & 1) {
+ /*
+ * We are running in Unprivileged Thread mode w/SP = PSP but we
+ * are supposed to be privileged.
+ */
+ if ((os_flags & 1) == OS_RUN_PRIV) {
err = OS_ERR_PRIV;
}
break;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/arch/cortex_m4/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/cortex_m4/os_fault.c b/libs/os/src/arch/cortex_m4/os_fault.c
index 63404ad..25ed5ca 100644
--- a/libs/os/src/arch/cortex_m4/os_fault.c
+++ b/libs/os/src/arch/cortex_m4/os_fault.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include <console/console.h>
@@ -53,7 +56,6 @@ struct exception_frame {
struct trap_frame {
struct exception_frame *ef;
- uint32_t sp;
uint32_t r4;
uint32_t r5;
uint32_t r6;
@@ -62,6 +64,7 @@ struct trap_frame {
uint32_t r9;
uint32_t r10;
uint32_t r11;
+ uint32_t lr; /* this LR holds EXC_RETURN */
};
void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/arch/sim/os_arch_sim.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/sim/os_arch_sim.c b/libs/os/src/arch/sim/os_arch_sim.c
index 25f3833..955ff05 100644
--- a/libs/os/src/arch/sim/os_arch_sim.c
+++ b/libs/os/src/arch/sim/os_arch_sim.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include "os/os.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/arch/sim/os_fault.c
----------------------------------------------------------------------
diff --git a/libs/os/src/arch/sim/os_fault.c b/libs/os/src/arch/sim/os_fault.c
index f6aa6cb..15c40fe 100644
--- a/libs/os/src/arch/sim/os_fault.c
+++ b/libs/os/src/arch/sim/os_fault.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include <stdio.h>
#include <string.h>
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os.c b/libs/os/src/os.c
index 581db1d..dd43cf0 100644
--- a/libs/os/src/os.c
+++ b/libs/os/src/os.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include "os/os.h"
@@ -59,9 +62,6 @@ os_init(void)
err = os_arch_os_init();
assert(err == OS_OK);
-
- err = os_info_init();
- assert(err == OS_OK);
}
void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os_callout.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_callout.c b/libs/os/src/os_callout.c
index d7ce772..5ffcd92 100644
--- a/libs/os/src/os_callout.c
+++ b/libs/os/src/os_callout.c
@@ -1,20 +1,22 @@
/**
- * Copyright (c) 2015 Runtime Inc.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-
#include "os/os.h"
#include <string.h>
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os_eventq.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_eventq.c b/libs/os/src/os_eventq.c
index ca729db..e3fe6e5 100644
--- a/libs/os/src/os_eventq.c
+++ b/libs/os/src/os_eventq.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os_heap.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_heap.c b/libs/os/src/os_heap.c
index 8198522..a94d3ad 100644
--- a/libs/os/src/os_heap.c
+++ b/libs/os/src/os_heap.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os_info.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_info.c b/libs/os/src/os_info.c
deleted file mode 100644
index 7697824..0000000
--- a/libs/os/src/os_info.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "os/os.h"
-
-#include "os/queue.h"
-
-#include "console/console.h"
-#ifdef SHELL_PRESENT
-#include "shell/shell.h"
-#endif
-
-#include <string.h>
-
-struct os_task_info_walk {
- struct os_task_info *info;
- int info_cnt;
-};
-
-#define OS_TASK_INFO_NAME_SIZE (32)
-struct os_task_info {
- uint8_t oti_tid;
- uint8_t oti_prio;
- uint8_t oti_state;
- uint8_t oti_pad1;
- uint16_t oti_flags;
- uint16_t oti_stack_size;
- uint32_t oti_csw_cnt;
- os_time_t oti_next_wakeup;
- os_time_t oti_run_time;
- char oti_name[OS_TASK_INFO_NAME_SIZE];
-};
-
-int os_task_info_get(struct os_task_info *info, int info_cnt);
-
-#ifdef SHELL_PRESENT
-struct shell_cmd shell_os_tasks_display_cmd;
-#endif
-
-
-#ifdef SHELL_PRESENT
-/* Code to register with shell, and display the results of os_getinfo()
- */
-
-
-int
-shell_os_tasks_display(int argc, char **argv)
-{
- struct os_task_info *info;
- char *name;
- int i;
- int found;
- int rc;
- uint8_t tcount;
-
- name = NULL;
- found = 0;
-
- if (argc > 1 && strcmp(argv[1], "")) {
- name = argv[1];
- }
-
- tcount = os_task_count();
-
- info = (struct os_task_info *) os_malloc(
- sizeof(struct os_task_info) * tcount);
- if (!info) {
- rc = -1;
- goto err;
- }
-
- rc = os_task_info_get(info, tcount);
-
- console_printf("%d tasks: \n", rc);
- for (i = 0; i < rc; i++) {
- if (name) {
- if (strcmp(name, info[i].oti_name)) {
- continue;
- } else {
- found = 1;
- }
- }
-
- console_printf(" %s (prio: %u, nw: %lu, flags: 0x%x, "
- "ssize: %u, cswcnt: %lu, tot_run_time: %lums)\n",
- info[i].oti_name, info[i].oti_prio,
- (unsigned long)info[i].oti_next_wakeup, info[i].oti_flags,
- info[i].oti_stack_size, (unsigned long)info[i].oti_csw_cnt,
- (unsigned long)info[i].oti_run_time);
-
- }
-
- if (name && !found) {
- console_printf("Couldn't find task with name %s\n", name);
- }
-
- os_free(info);
-
- return (0);
-err:
- return (rc);
-}
-
-
-#endif
-
-static int
-_os_task_copy_info(struct os_task *t, void *arg)
-{
- struct os_task_info_walk *walk;
-
- walk = (struct os_task_info_walk *) arg;
-
- if (walk->info_cnt == 0) {
- /* Stored all the elements we can fit, exit out */
- return (1);
- }
-
- walk->info->oti_tid = t->t_taskid;
- walk->info->oti_prio = t->t_prio;
- strncpy(walk->info->oti_name, t->t_name, OS_TASK_INFO_NAME_SIZE);
- walk->info->oti_state = (uint8_t) t->t_state;
- walk->info->oti_next_wakeup = t->t_next_wakeup;
- walk->info->oti_flags = t->t_flags;
- walk->info->oti_stack_size = t->t_stacksize;
- walk->info->oti_csw_cnt = t->t_ctx_sw_cnt;
- walk->info->oti_run_time = t->t_run_time;
-
- walk->info += 1;
- walk->info_cnt--;
-
- return (0);
-}
-
-int
-os_task_info_get(struct os_task_info *info, int info_cnt)
-{
- struct os_task_info_walk walk;
-
- walk.info = info;
- walk.info_cnt = info_cnt;
-
- os_sched_walk(_os_task_copy_info, (void *) &walk);
- return (info_cnt - walk.info_cnt);
-}
-
-
-int
-os_info_init(void)
-{
-#ifdef SHELL_PRESENT
- shell_cmd_register(&shell_os_tasks_display_cmd, "tasks",
- shell_os_tasks_display);
-#endif
- return (0);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os_mbuf.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mbuf.c b/libs/os/src/os_mbuf.c
index 9453960..6f24d8d 100644
--- a/libs/os/src/os_mbuf.c
+++ b/libs/os/src/os_mbuf.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
/*
@@ -145,6 +148,15 @@ os_msys_register(struct os_mbuf_pool *new_pool)
return (0);
}
+/**
+ * De-registers all mbuf pools from msys.
+ */
+void
+os_msys_reset(void)
+{
+ STAILQ_INIT(&g_msys_pool_list);
+}
+
static struct os_mbuf_pool *
_os_msys_find_pool(uint16_t dsize)
{
@@ -185,17 +197,19 @@ err:
struct os_mbuf *
-os_msys_get_pkthdr(uint16_t dsize, uint16_t pkthdr_len)
+os_msys_get_pkthdr(uint16_t dsize, uint16_t user_hdr_len)
{
+ uint16_t total_pkthdr_len;
struct os_mbuf *m;
struct os_mbuf_pool *pool;
- pool = _os_msys_find_pool(dsize + pkthdr_len);
+ total_pkthdr_len = user_hdr_len + sizeof(struct os_mbuf_pkthdr);
+ pool = _os_msys_find_pool(dsize + total_pkthdr_len);
if (!pool) {
goto err;
}
- m = os_mbuf_get_pkthdr(pool, pkthdr_len);
+ m = os_mbuf_get_pkthdr(pool, user_hdr_len);
return (m);
err:
return (NULL);
@@ -257,15 +271,15 @@ err:
/* Allocate a new packet header mbuf out of the os_mbuf_pool */
struct os_mbuf *
-os_mbuf_get_pkthdr(struct os_mbuf_pool *omp, uint8_t extra_pkthdr_len)
+os_mbuf_get_pkthdr(struct os_mbuf_pool *omp, uint8_t user_pkthdr_len)
{
struct os_mbuf_pkthdr *pkthdr;
struct os_mbuf *om;
om = os_mbuf_get(omp, 0);
if (om) {
- om->om_pkthdr_len = extra_pkthdr_len + sizeof(struct os_mbuf_pkthdr);
- om->om_data += extra_pkthdr_len + sizeof(struct os_mbuf_pkthdr);
+ om->om_pkthdr_len = user_pkthdr_len + sizeof(struct os_mbuf_pkthdr);
+ om->om_data += user_pkthdr_len + sizeof(struct os_mbuf_pkthdr);
pkthdr = OS_MBUF_PKTHDR(om);
pkthdr->omp_len = 0;
@@ -388,7 +402,7 @@ os_mbuf_append(struct os_mbuf *om, const void *data, uint16_t len)
space = remainder;
}
- memcpy(OS_MBUF_DATA(last, void *) + last->om_len , data, space);
+ memcpy(OS_MBUF_DATA(last, uint8_t *) + last->om_len , data, space);
last->om_len += space;
data += space;
@@ -405,7 +419,7 @@ os_mbuf_append(struct os_mbuf *om, const void *data, uint16_t len)
}
new->om_len = min(omp->omp_databuf_len, remainder);
- memcpy(OS_MBUF_DATA(om, void *), data, new->om_len);
+ memcpy(OS_MBUF_DATA(new, void *), data, new->om_len);
data += new->om_len;
remainder -= new->om_len;
SLIST_NEXT(last, om_next) = new;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os_mempool.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mempool.c b/libs/os/src/os_mempool.c
index 1fb05df..1e7428c 100644
--- a/libs/os/src/os_mempool.c
+++ b/libs/os/src/os_mempool.c
@@ -1,21 +1,32 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include "os/os.h"
+#include <string.h>
+#include <assert.h>
+
+#define OS_MEMPOOL_TRUE_BLOCK_SIZE(bsize) OS_ALIGN(bsize, OS_ALIGNMENT)
+
+STAILQ_HEAD(, os_mempool) g_os_mempool_list =
+ STAILQ_HEAD_INITIALIZER(g_os_mempool_list);
+
/**
* os mempool init
*
@@ -46,12 +57,13 @@ os_mempool_init(struct os_mempool *mp, int blocks, int block_size, void *membuf,
if (((uint32_t)membuf & (OS_ALIGNMENT - 1)) != 0) {
return OS_MEM_NOT_ALIGNED;
}
- true_block_size = OS_ALIGN(block_size, OS_ALIGNMENT);
+ true_block_size = OS_MEMPOOL_TRUE_BLOCK_SIZE(block_size);
/* Initialize the memory pool structure */
mp->mp_block_size = block_size;
mp->mp_num_free = blocks;
mp->mp_num_blocks = blocks;
+ mp->mp_membuf_addr = (uint32_t)membuf;
mp->name = name;
SLIST_FIRST(mp) = membuf;
@@ -68,6 +80,8 @@ os_mempool_init(struct os_mempool *mp, int blocks, int block_size, void *membuf,
/* Last one in the list should be NULL */
SLIST_NEXT(block_ptr, mb_next) = NULL;
+ STAILQ_INSERT_TAIL(&g_os_mempool_list, mp, mp_list);
+
return OS_OK;
}
@@ -120,14 +134,30 @@ os_memblock_get(struct os_mempool *mp)
os_error_t
os_memblock_put(struct os_mempool *mp, void *block_addr)
{
- struct os_memblock *block;
os_sr_t sr;
+ uint32_t end;
+ uint32_t true_block_size;
+ uint32_t baddr32;
+ struct os_memblock *block;
/* Make sure parameters are valid */
if ((mp == NULL) || (block_addr == NULL)) {
return OS_INVALID_PARM;
}
+ /* Check that the block we are freeing is a valid block! */
+ baddr32 = (uint32_t)block_addr;
+ true_block_size = OS_MEMPOOL_TRUE_BLOCK_SIZE(mp->mp_block_size);
+ end = mp->mp_membuf_addr + (mp->mp_num_blocks * true_block_size);
+ if ((baddr32 < mp->mp_membuf_addr) || (baddr32 >= end)) {
+ return OS_INVALID_PARM;
+ }
+
+ /* All freed blocks should be on true block size boundaries! */
+ if (((baddr32 - mp->mp_membuf_addr) % true_block_size) != 0) {
+ return OS_INVALID_PARM;
+ }
+
/*
* XXX: we should do boundary checks here! The block had better be within
* the pool. If it fails, do we return an error or assert()? Add this when
@@ -148,3 +178,28 @@ os_memblock_put(struct os_mempool *mp, void *block_addr)
return OS_OK;
}
+
+
+struct os_mempool *
+os_mempool_info_get_next(struct os_mempool *mp, struct os_mempool_info *omi)
+{
+ struct os_mempool *cur;
+
+ if (mp == NULL) {
+ cur = STAILQ_FIRST(&g_os_mempool_list);
+ } else {
+ cur = STAILQ_NEXT(mp, mp_list);
+ }
+
+ if (cur == NULL) {
+ return (NULL);
+ }
+
+ omi->omi_block_size = cur->mp_block_size;
+ omi->omi_num_blocks = cur->mp_num_blocks;
+ omi->omi_num_free = cur->mp_num_free;
+ strncpy(omi->omi_name, cur->name, sizeof(omi->omi_name));
+
+ return (cur);
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os_mutex.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mutex.c b/libs/os/src/os_mutex.c
index 0965be8..454f6ab 100644
--- a/libs/os/src/os_mutex.c
+++ b/libs/os/src/os_mutex.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include "os/os.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os_priv.h
----------------------------------------------------------------------
diff --git a/libs/os/src/os_priv.h b/libs/os/src/os_priv.h
index db2d7d3..93a0c3a 100644
--- a/libs/os/src/os_priv.h
+++ b/libs/os/src/os_priv.h
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#ifndef H_OS_PRIV_
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os_sanity.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_sanity.c b/libs/os/src/os_sanity.c
index 988cc37..0fb2450 100644
--- a/libs/os/src/os_sanity.c
+++ b/libs/os/src/os_sanity.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include <assert.h>
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os_sched.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_sched.c b/libs/os/src/os_sched.c
index f1c03c6..d5ce25d 100644
--- a/libs/os/src/os_sched.c
+++ b/libs/os/src/os_sched.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include "os/os.h"
@@ -70,44 +73,6 @@ err:
return (rc);
}
-/**
- * Walk all the active tasks currently being scheduled.
- *
- * @param walk_func The walk function to call for each task
- * @param arg The argument to pass the walk function
- *
- * @return 0 on success, < 0 on abort.
- */
-int
-os_sched_walk(os_sched_walk_func_t walk_func, void *arg)
-{
- struct os_task *t;
- os_sr_t sr;
- int rc;
-
- /* Go through tasks and fill out the info blocks
- */
- OS_ENTER_CRITICAL(sr);
- TAILQ_FOREACH(t, &g_os_run_list, t_os_list) {
- rc = walk_func(t, arg);
- if (rc != 0) {
- goto done;
- }
- }
-
- TAILQ_FOREACH(t, &g_os_sleep_list, t_os_list) {
- rc = walk_func(t, arg);
- if (rc != 0) {
- goto done;
- }
- }
-
-done:
- OS_EXIT_CRITICAL(sr);
-
- return (rc);
-}
-
void
os_sched_ctx_sw_hook(struct os_task *next_t)
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-tadpole/blob/8655cfe6/libs/os/src/os_sem.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_sem.c b/libs/os/src/os_sem.c
index 84464d3..f96efa7 100644
--- a/libs/os/src/os_sem.c
+++ b/libs/os/src/os_sem.c
@@ -1,17 +1,20 @@
/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
#include "os/os.h"