aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-11 18:02:20 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-11 18:02:20 +0000
commit58f1fe92ee9c68ffd08bccd19f67eafbbc968a71 (patch)
treefb593f55912ac98d9d82f9b5e70a3edc751b2fb6 /os
parent1ed89364ca6b9b6c89d13f6d39f7b2d085c8f8e4 (diff)
downloadChibiOS-58f1fe92ee9c68ffd08bccd19f67eafbbc968a71.tar.gz
ChibiOS-58f1fe92ee9c68ffd08bccd19f67eafbbc968a71.tar.bz2
ChibiOS-58f1fe92ee9c68ffd08bccd19f67eafbbc968a71.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3788 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/hal/platforms/Posix/hal_lld.c12
-rw-r--r--os/hal/platforms/Posix/serial_lld.c26
-rw-r--r--os/hal/platforms/STM32F1xx/hal_lld.c1
-rw-r--r--os/hal/platforms/STM32F2xx/hal_lld.c1
-rw-r--r--os/hal/platforms/STM32F4xx/hal_lld.c1
-rw-r--r--os/hal/platforms/STM32L1xx/hal_lld.c15
-rw-r--r--os/hal/platforms/Win32/hal_lld.c12
-rw-r--r--os/hal/platforms/Win32/serial_lld.c26
-rw-r--r--os/ports/GCC/SIMIA32/chcore.c17
-rw-r--r--os/ports/GCC/SIMIA32/chcore.h11
10 files changed, 92 insertions, 30 deletions
diff --git a/os/hal/platforms/Posix/hal_lld.c b/os/hal/platforms/Posix/hal_lld.c
index 8b59d992b..8e1c34939 100644
--- a/os/hal/platforms/Posix/hal_lld.c
+++ b/os/hal/platforms/Posix/hal_lld.c
@@ -78,8 +78,10 @@ void ChkIntSources(void) {
#if HAL_USE_SERIAL
if (sd_lld_interrupt_pending()) {
+ dbg_check_lock();
if (chSchIsPreemptionRequired())
chSchDoReschedule();
+ dbg_check_unlock();
return;
}
#endif
@@ -87,9 +89,19 @@ void ChkIntSources(void) {
gettimeofday(&tv, NULL);
if (timercmp(&tv, &nextcnt, >=)) {
timeradd(&nextcnt, &tick, &nextcnt);
+
+ CH_IRQ_PROLOGUE();
+
+ chSysLockFromIsr();
chSysTimerHandlerI();
+ chSysUnlockFromIsr();
+
+ CH_IRQ_EPILOGUE();
+
+ dbg_check_lock();
if (chSchIsPreemptionRequired())
chSchDoReschedule();
+ dbg_check_unlock();
}
}
diff --git a/os/hal/platforms/Posix/serial_lld.c b/os/hal/platforms/Posix/serial_lld.c
index 31be73825..5bf22bc76 100644
--- a/os/hal/platforms/Posix/serial_lld.c
+++ b/os/hal/platforms/Posix/serial_lld.c
@@ -120,7 +120,9 @@ static bool_t connint(SerialDriver *sdp) {
printf("%s: Unable to setup non blocking mode on data socket\n", sdp->com_name);
goto abort;
}
+ chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_CONNECTED);
+ chSysUnlockFromIsr();
return TRUE;
}
return FALSE;
@@ -146,7 +148,9 @@ static bool_t inint(SerialDriver *sdp) {
case 0:
close(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
+ chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_DISCONNECTED);
+ chSysUnlockFromIsr();
return FALSE;
case INVALID_SOCKET:
if (errno == EWOULDBLOCK)
@@ -155,8 +159,11 @@ static bool_t inint(SerialDriver *sdp) {
sdp->com_data = INVALID_SOCKET;
return FALSE;
}
- for (i = 0; i < n; i++)
+ for (i = 0; i < n; i++) {
+ chSysLockFromIsr();
sdIncomingDataI(sdp, data[i]);
+ chSysUnlockFromIsr();
+ }
return TRUE;
}
return FALSE;
@@ -171,7 +178,9 @@ static bool_t outint(SerialDriver *sdp) {
/*
* Input.
*/
+ chSysLockFromIsr();
n = sdRequestDataI(sdp);
+ chSysUnlockFromIsr();
if (n < 0)
return FALSE;
data[0] = (uint8_t)n;
@@ -180,7 +189,9 @@ static bool_t outint(SerialDriver *sdp) {
case 0:
close(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
+ chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_DISCONNECTED);
+ chSysUnlockFromIsr();
return FALSE;
case INVALID_SOCKET:
if (errno == EWOULDBLOCK)
@@ -256,10 +267,17 @@ void sd_lld_stop(SerialDriver *sdp) {
}
bool_t sd_lld_interrupt_pending(void) {
+ bool_t b;
+
+ CH_IRQ_PROLOGUE();
+
+ b = connint(&SD1) || connint(&SD2) ||
+ inint(&SD1) || inint(&SD2) ||
+ outint(&SD1) || outint(&SD2);
+
+ CH_IRQ_EPILOGUE();
- return connint(&SD1) || connint(&SD2) ||
- inint(&SD1) || inint(&SD2) ||
- outint(&SD1) || outint(&SD2);
+ return b;
}
#endif /* HAL_USE_SERIAL */
diff --git a/os/hal/platforms/STM32F1xx/hal_lld.c b/os/hal/platforms/STM32F1xx/hal_lld.c
index f5efeed5d..0112d7eaa 100644
--- a/os/hal/platforms/STM32F1xx/hal_lld.c
+++ b/os/hal/platforms/STM32F1xx/hal_lld.c
@@ -54,6 +54,7 @@ static void hal_lld_backup_domain_init(void) {
if ((RCC->BDCR & RCC_BDCR_LSEON) == 0) {
/* Backup domain reset.*/
RCC->BDCR = RCC_BDCR_BDRST;
+ RCC->BDCR = 0;
RCC->BDCR = RCC_BDCR_LSEON;
while ((RCC->BDCR & RCC_BDCR_LSERDY) == 0)
; /* Waits until LSE is stable. */
diff --git a/os/hal/platforms/STM32F2xx/hal_lld.c b/os/hal/platforms/STM32F2xx/hal_lld.c
index b9af01a92..7cc24f2a0 100644
--- a/os/hal/platforms/STM32F2xx/hal_lld.c
+++ b/os/hal/platforms/STM32F2xx/hal_lld.c
@@ -54,6 +54,7 @@ static void hal_lld_backup_domain_init(void) {
if ((RCC->BDCR & RCC_BDCR_LSEON) == 0) {
/* Backup domain reset.*/
RCC->BDCR = RCC_BDCR_BDRST;
+ RCC->BDCR = 0;
RCC->BDCR = RCC_BDCR_LSEON;
while ((RCC->BDCR & RCC_BDCR_LSERDY) == 0)
; /* Waits until LSE is stable. */
diff --git a/os/hal/platforms/STM32F4xx/hal_lld.c b/os/hal/platforms/STM32F4xx/hal_lld.c
index d26059d70..00c560f08 100644
--- a/os/hal/platforms/STM32F4xx/hal_lld.c
+++ b/os/hal/platforms/STM32F4xx/hal_lld.c
@@ -54,6 +54,7 @@ static void hal_lld_backup_domain_init(void) {
if ((RCC->BDCR & RCC_BDCR_LSEON) == 0) {
/* Backup domain reset.*/
RCC->BDCR = RCC_BDCR_BDRST;
+ RCC->BDCR = 0;
RCC->BDCR = RCC_BDCR_LSEON;
while ((RCC->BDCR & RCC_BDCR_LSERDY) == 0)
; /* Waits until LSE is stable. */
diff --git a/os/hal/platforms/STM32L1xx/hal_lld.c b/os/hal/platforms/STM32L1xx/hal_lld.c
index 01d61fbc2..4e1b385a3 100644
--- a/os/hal/platforms/STM32L1xx/hal_lld.c
+++ b/os/hal/platforms/STM32L1xx/hal_lld.c
@@ -51,11 +51,12 @@ static void hal_lld_backup_domain_init(void) {
/* If enabled then the LSE is started.*/
#if STM32_LSE_ENABLED
- if ((RCC->BDCR & RCC_BDCR_LSEON) == 0) {
+ if ((RCC->CSR & RCC_CSR_LSEON) == 0) {
/* Backup domain reset.*/
- RCC->BDCR = RCC_BDCR_BDRST;
- RCC->BDCR = RCC_BDCR_LSEON;
- while ((RCC->BDCR & RCC_BDCR_LSERDY) == 0)
+ RCC->CSR |= RCC_CSR_RTCRST;
+ RCC->CSR &= ~RCC_CSR_RTCRST;
+ RCC->CSR |= RCC_CSR_LSEON;
+ while ((RCC->CSR & RCC_CSR_LSERDY) == 0)
; /* Waits until LSE is stable. */
}
#endif
@@ -63,12 +64,12 @@ static void hal_lld_backup_domain_init(void) {
#if STM32_RTCSEL != STM32_RTCSEL_NOCLOCK
/* If the backup domain hasn't been initialized yet then proceed with
initialization.*/
- if ((RCC->BDCR & RCC_BDCR_RTCEN) == 0) {
+ if ((RCC->CSR & RCC_CSR_RTCEN) == 0) {
/* Selects clock source.*/
- RCC->BDCR = (RCC->BDCR & ~RCC_BDCR_RTCSEL) | STM32_RTCSEL;
+ RCC->CSR = (RCC->CSR & ~RCC_CSR_RTCSEL) | STM32_RTCSEL;
/* RTC clock enabled.*/
- RCC->BDCR |= RCC_BDCR_RTCEN;
+ RCC->CSR |= RCC_CSR_RTCEN;
}
#endif /* STM32_RTCSEL != STM32_RTCSEL_NOCLOCK */
diff --git a/os/hal/platforms/Win32/hal_lld.c b/os/hal/platforms/Win32/hal_lld.c
index 48d017f2f..183185c98 100644
--- a/os/hal/platforms/Win32/hal_lld.c
+++ b/os/hal/platforms/Win32/hal_lld.c
@@ -83,8 +83,10 @@ void ChkIntSources(void) {
#if HAL_USE_SERIAL
if (sd_lld_interrupt_pending()) {
+ dbg_check_lock();
if (chSchIsPreemptionRequired())
chSchDoReschedule();
+ dbg_check_unlock();
return;
}
#endif
@@ -93,9 +95,19 @@ void ChkIntSources(void) {
QueryPerformanceCounter(&n);
if (n.QuadPart > nextcnt.QuadPart) {
nextcnt.QuadPart += slice.QuadPart;
+
+ CH_IRQ_PROLOGUE();
+
+ chSysLockFromIsr();
chSysTimerHandlerI();
+ chSysUnlockFromIsr();
+
+ CH_IRQ_EPILOGUE();
+
+ dbg_check_lock();
if (chSchIsPreemptionRequired())
chSchDoReschedule();
+ dbg_check_unlock();
}
}
diff --git a/os/hal/platforms/Win32/serial_lld.c b/os/hal/platforms/Win32/serial_lld.c
index 6b76ebbc7..170067c4a 100644
--- a/os/hal/platforms/Win32/serial_lld.c
+++ b/os/hal/platforms/Win32/serial_lld.c
@@ -113,7 +113,9 @@ static bool_t connint(SerialDriver *sdp) {
printf("%s: Unable to setup non blocking mode on data socket\n", sdp->com_name);
goto abort;
}
+ chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_CONNECTED);
+ chSysUnlockFromIsr();
return TRUE;
}
return FALSE;
@@ -140,7 +142,9 @@ static bool_t inint(SerialDriver *sdp) {
case 0:
closesocket(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
+ chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_DISCONNECTED);
+ chSysUnlockFromIsr();
return FALSE;
case SOCKET_ERROR:
if (WSAGetLastError() == WSAEWOULDBLOCK)
@@ -149,8 +153,11 @@ static bool_t inint(SerialDriver *sdp) {
sdp->com_data = INVALID_SOCKET;
return FALSE;
}
- for (i = 0; i < n; i++)
+ for (i = 0; i < n; i++) {
+ chSysLockFromIsr();
sdIncomingDataI(sdp, data[i]);
+ chSysUnlockFromIsr();
+ }
return TRUE;
}
return FALSE;
@@ -165,7 +172,9 @@ static bool_t outint(SerialDriver *sdp) {
/*
* Input.
*/
+ chSysLockFromIsr();
n = sdRequestDataI(sdp);
+ chSysUnlockFromIsr();
if (n < 0)
return FALSE;
data[0] = (uint8_t)n;
@@ -174,7 +183,9 @@ static bool_t outint(SerialDriver *sdp) {
case 0:
closesocket(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
+ chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_DISCONNECTED);
+ chSysUnlockFromIsr();
return FALSE;
case SOCKET_ERROR:
if (WSAGetLastError() == WSAEWOULDBLOCK)
@@ -253,10 +264,17 @@ void sd_lld_stop(SerialDriver *sdp) {
}
bool_t sd_lld_interrupt_pending(void) {
+ bool_t b;
+
+ CH_IRQ_PROLOGUE();
+
+ b = connint(&SD1) || connint(&SD2) ||
+ inint(&SD1) || inint(&SD2) ||
+ outint(&SD1) || outint(&SD2);
+
+ CH_IRQ_EPILOGUE();
- return connint(&SD1) || connint(&SD2) ||
- inint(&SD1) || inint(&SD2) ||
- outint(&SD1) || outint(&SD2);
+ return b;
}
#endif /* HAL_USE_SERIAL */
diff --git a/os/ports/GCC/SIMIA32/chcore.c b/os/ports/GCC/SIMIA32/chcore.c
index 58f079ef5..fff2b22c4 100644
--- a/os/ports/GCC/SIMIA32/chcore.c
+++ b/os/ports/GCC/SIMIA32/chcore.c
@@ -69,17 +69,16 @@ void port_halt(void) {
}
/**
- * Threads return point, it just invokes @p chThdExit().
+ * @brief Start a thread by invoking its work function.
+ * @details If the work function returns @p chThdExit() is automatically
+ * invoked.
*/
-void threadexit(void) {
+__attribute__((cdecl, noreturn))
+void _port_thread_start(msg_t (*pf)(void *), void *p) {
-#if defined(WIN32) || defined (__APPLE__)
- asm volatile ("push %eax \n\t" \
- "call _chThdExit");
-#else
- asm volatile ("push %eax \n\t" \
- "call chThdExit");
-#endif
+ chSysUnlock();
+ chThdExit(pf(p));
+ while(1);
}
/** @} */
diff --git a/os/ports/GCC/SIMIA32/chcore.h b/os/ports/GCC/SIMIA32/chcore.h
index 8bfa719f8..636ae3886 100644
--- a/os/ports/GCC/SIMIA32/chcore.h
+++ b/os/ports/GCC/SIMIA32/chcore.h
@@ -105,13 +105,11 @@ struct context {
*/
#define SETUP_CONTEXT(workspace, wsize, pf, arg) { \
uint8_t *esp = (uint8_t *)workspace + wsize; \
- APUSH(esp, 0); \
- APUSH(esp, 0); \
- APUSH(esp, 0); \
APUSH(esp, arg); \
- APUSH(esp, threadexit); \
+ APUSH(esp, pf); \
+ APUSH(esp, 0); \
esp -= sizeof(struct intctx); \
- ((struct intctx *)esp)->eip = pf; \
+ ((struct intctx *)esp)->eip = _port_thread_start; \
((struct intctx *)esp)->ebx = 0; \
((struct intctx *)esp)->edi = 0; \
((struct intctx *)esp)->esi = 0; \
@@ -224,7 +222,8 @@ extern "C" {
#endif
__attribute__((fastcall)) void port_switch(Thread *ntp, Thread *otp);
__attribute__((fastcall)) void port_halt(void);
- void threadexit(void);
+ __attribute__((cdecl, noreturn)) void _port_thread_start(msg_t (*pf)(void *),
+ void *p);
void ChkIntSources(void);
#ifdef __cplusplus
}