Fabio Utzig | d7f6c76 | 2017-07-27 20:50:50 -0300 | [diff] [blame^] | 1 | /** |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | #include <assert.h> |
| 21 | #include <string.h> |
| 22 | |
| 23 | #include "sysinit/sysinit.h" |
| 24 | #include "os/os.h" |
| 25 | #include "bsp/bsp.h" |
| 26 | #include "hal/hal_gpio.h" |
| 27 | #ifdef ARCH_sim |
| 28 | #include "mcu/mcu_sim.h" |
| 29 | #endif |
| 30 | |
| 31 | #define BLINKY_PRIO (8) |
| 32 | #define BLINKY_STACK_SIZE OS_STACK_ALIGN(128) |
| 33 | static struct os_task task1; |
| 34 | static volatile int g_task1_loops; |
| 35 | |
| 36 | /* For LED toggling */ |
| 37 | int g_led_pin; |
| 38 | |
| 39 | static void |
| 40 | blinky_handler(void *arg) |
| 41 | { |
| 42 | while (1) { |
| 43 | ++g_task1_loops; |
| 44 | |
| 45 | os_time_delay(OS_TICKS_PER_SEC / MYNEWT_VAL(BLINKY_TICKS_PER_SEC)); |
| 46 | |
| 47 | /* Toggle the LED */ |
| 48 | hal_gpio_toggle(g_led_pin); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | int |
| 53 | main(int argc, char **argv) |
| 54 | { |
| 55 | os_stack_t *pstack; |
| 56 | |
| 57 | #ifdef ARCH_sim |
| 58 | mcu_sim_parse_args(argc, argv); |
| 59 | #endif |
| 60 | |
| 61 | sysinit(); |
| 62 | |
| 63 | g_led_pin = LED_BLINK_PIN; |
| 64 | hal_gpio_init_out(g_led_pin, 1); |
| 65 | |
| 66 | pstack = malloc(sizeof(os_stack_t) * BLINKY_STACK_SIZE); |
| 67 | assert(pstack); |
| 68 | |
| 69 | os_task_init(&task1, "blinky", blinky_handler, NULL, |
| 70 | BLINKY_PRIO, OS_WAIT_FOREVER, pstack, BLINKY_STACK_SIZE); |
| 71 | |
| 72 | while (1) { |
| 73 | os_eventq_run(os_eventq_dflt_get()); |
| 74 | } |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |