2016-07-23 05:59:54 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "board.h"
|
|
|
|
#include "ctx.h"
|
|
|
|
#include "stack.h"
|
|
|
|
#include "queue.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "schedule.h"
|
|
|
|
#include "isr.h"
|
|
|
|
#include "sys_tick.h"
|
|
|
|
|
2016-07-27 14:00:08 +00:00
|
|
|
#include "driver.h"
|
|
|
|
|
2016-07-23 05:59:54 +00:00
|
|
|
#define STACK_SIZE 256
|
|
|
|
stack_t tc_1_stack[STACK_SIZE];
|
|
|
|
struct thread_context tc_1;
|
|
|
|
|
|
|
|
void task1(void *arg)
|
|
|
|
{
|
2016-07-27 14:28:46 +00:00
|
|
|
char rd = '0';
|
2016-07-27 14:00:08 +00:00
|
|
|
open(&led_4);
|
2016-07-27 14:28:46 +00:00
|
|
|
write(&led_4, &rd, 1);
|
2016-07-23 05:59:54 +00:00
|
|
|
while(1) {
|
|
|
|
sleep_ms(1000);
|
2016-07-27 14:28:46 +00:00
|
|
|
read(&led_4, &rd, 1);
|
|
|
|
if(rd == '0')
|
|
|
|
rd = '1';
|
|
|
|
else
|
|
|
|
rd = '0';
|
|
|
|
write(&led_4, &rd, 1);
|
2016-07-27 14:00:08 +00:00
|
|
|
write(&uart_1, "Driver test\r\n", 13);
|
2016-07-23 05:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 13:23:31 +00:00
|
|
|
char rx_buf[80];
|
|
|
|
void task2(void *arg)
|
|
|
|
{
|
|
|
|
while(1) {
|
2016-07-27 14:00:08 +00:00
|
|
|
int i = read(&uart_1, rx_buf, 80);
|
2016-07-25 13:23:31 +00:00
|
|
|
if(i > 0) {
|
2016-07-27 14:00:08 +00:00
|
|
|
write(&uart_1, rx_buf, i);
|
2016-07-25 13:23:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stack_t tc_2_stack[STACK_SIZE];
|
|
|
|
struct thread_context tc_2;
|
2016-07-23 05:59:54 +00:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
board_init();
|
|
|
|
sys_tick_init(&timer_1);
|
2016-07-27 14:00:08 +00:00
|
|
|
open(&uart_1);
|
2016-07-23 05:59:54 +00:00
|
|
|
thread_create(&tc_1, tc_1_stack, STACK_SIZE, task1, NULL, THREAD_PRIO_LOW);
|
2016-07-25 13:23:31 +00:00
|
|
|
thread_create(&tc_2, tc_2_stack, STACK_SIZE, task2, NULL, THREAD_PRIO_LOW);
|
2016-07-23 05:59:54 +00:00
|
|
|
|
|
|
|
schedule_start();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|