-
Notifications
You must be signed in to change notification settings - Fork 1
/
hal.h
74 lines (58 loc) · 2.23 KB
/
hal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*! @file
@brief
Hardware abstraction layer
for Microchip PIC32
<pre>
Copyright (C) 2018-2021 Kyushu Institute of Technology.
Copyright (C) 2018-2021 Shimane IT Open-Innovation Center.
This file is distributed under BSD 3-Clause License.
</pre>
*/
#ifndef MRBC_SRC_HAL_H_
#define MRBC_SRC_HAL_H_
/***** Feature test switches ************************************************/
/***** System headers *******************************************************/
#include <xc.h>
/***** Local headers ********************************************************/
/***** Constant values ******************************************************/
/***** Macros ***************************************************************/
#if !defined(MRBC_TICK_UNIT)
#define MRBC_TICK_UNIT_1_MS 1
#define MRBC_TICK_UNIT_2_MS 2
#define MRBC_TICK_UNIT_4_MS 4
#define MRBC_TICK_UNIT_10_MS 10
// You may be able to reduce power consumption if you configure
// MRBC_TICK_UNIT_2_MS or larger.
#define MRBC_TICK_UNIT MRBC_TICK_UNIT_1_MS
// Substantial timeslice value (millisecond) will be
// MRBC_TICK_UNIT * MRBC_TIMESLICE_TICK_COUNT (+ Jitter).
// MRBC_TIMESLICE_TICK_COUNT must be natural number
// (recommended value is from 1 to 10).
#define MRBC_TIMESLICE_TICK_COUNT 10
#endif
/***** Typedefs *************************************************************/
/***** Global variables *****************************************************/
/***** Function prototypes **************************************************/
#ifdef __cplusplus
extern "C" {
#endif
void mrbc_tick(void);
#if !defined(MRBC_NO_TIMER) // use hardware timer.
# define hal_init() ((void)0)
# define hal_enable_irq() __builtin_enable_interrupts()
# define hal_disable_irq() __builtin_disable_interrupts()
# define hal_idle_cpu() _wait()
#else // MRBC_NO_TIMER
# define hal_init() ((void)0)
# define hal_enable_irq() ((void)0)
# define hal_disable_irq() ((void)0)
# define hal_idle_cpu() ((__delay_ms(MRBC_TICK_UNIT)), mrbc_tick())
#endif
int hal_write(int fd, const void *buf, int nbytes);
int hal_flush(int fd);
void hal_abort(const char *s);
/***** Inline functions *****************************************************/
#ifdef __cplusplus
}
#endif
#endif // ifndef MRBC_SRC_HAL_H_