finish rtos blinky

This commit is contained in:
hathach committed 2017-01-06 18:51:37 +07:00
1 parent 11ee5666bd
commit d7bff70718
3 files changed
+57 -11

No files matched your search

+21 -4
View File
@@ -35,6 +35,8 @@ void yield( void ) ;
void setup( void ) ;
void loop( void ) ;
void setLoopStacksize(uint32_t size);
#include "WVariant.h"
#ifdef __cplusplus
@@ -50,8 +52,10 @@ void loop( void ) ;
#include "HardwareSerial.h"
#include "pulse.h"
#endif
#include "delay.h"
#include "binary.h"
#ifdef __cplusplus
#include "Uart.h"
#endif
@@ -65,6 +69,23 @@ void loop( void ) ;
#include "wiring_shift.h"
#include "WInterrupts.h"
// RTOS
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "queue.h"
#include "semphr.h"
enum
{
TASK_PRIO_HIGHEST = 0,
TASK_PRIO_HIGH = 1,
TASK_PRIO_NORMAL = 2,
TASK_PRIO_LOW = 3,
TASK_PRIO_LOWEST = 4
};
// undefine stdlib's abs if encountered
#ifdef abs
#undef abs
@@ -112,8 +133,4 @@ void loop( void ) ;
// Interrupts
#define digitalPinToInterrupt(P) ( P )
#ifdef __cplusplus
#include "Uart.h"
#endif // __cplusplus
#endif // Arduino_h
+2 -2
View File
@@ -96,9 +96,9 @@
#define configUSE_TICKLESS_IDLE 0
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ 1000
#define configMAX_PRIORITIES ( 3 )
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( 60 )
#define configTOTAL_HEAP_SIZE ( 4096 )
#define configTOTAL_HEAP_SIZE ( 4096 ) /* not used since we use malloc */
#define configMAX_TASK_NAME_LEN ( 4 )
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
+34 -5
View File
@@ -21,6 +21,27 @@
void initVariant() __attribute__((weak));
void initVariant() { }
TaskHandle_t _loopHandle;
uint32_t _loopStacksize = 1024*2;
void setLoopStacksize(uint32_t size)
{
_loopStacksize = size;
}
static void loop_task(void* arg)
{
(void) arg;
while (1)
{
loop();
// To compatible with most code where loop is not rtos-aware
taskYIELD();
}
}
/*
* \brief Main entry point of Arduino application
*/
@@ -34,11 +55,19 @@ int main( void )
setup();
for (;;)
{
loop();
if (serialEventRun) serialEventRun();
}
// Create a task for loop()
xTaskCreate( loop_task, "loop", _loopStacksize, NULL, TASK_PRIO_NORMAL, &_loopHandle);
// Start FreeRTOS scheduler.
vTaskStartScheduler();
NVIC_SystemReset();
// for (;;)
// {
// loop();
// if (serialEventRun) serialEventRun();
// }
return 0;
}