HWA
Bare metal programming with style
afioa_2.h
Go to the documentation of this file.
1 
2 /* This file is part of the HWA project.
3  * Copyright (c) 2019 Christophe Duparquet.
4  * All rights reserved. Read LICENSE.TXT for details.
5  */
6 
16 #define hw_class__afioa
17 
18 
19 /*******************************************************************************
20  * *
21  * Context *
22  * *
23  *******************************************************************************/
24 
25 #define _hwa_setup__afioa(o,a) \
26  _hwa_setup_map( hwa ); \
27  _hwa_setup_r( o, mapr )
28 
29 #define _hwa_init__afioa(o,a) \
30  _hwa_init_r( o, mapr, 0x00000000 )
31 
32 #define _hwa_commit__afioa(o,a) \
33  _hwa_commit_map( hwa ); \
34  _hwa_commit_r( o, mapr )
35 
36 
37 
38 HW_INLINE void _hwa_setup_map( hwa_t *hwa )
39 {
40  hwa->map.error = 0 ;
41  hwa->map.counter2_remap = -1 ;
42  hwa->map.counter2_etr = 0 ;
43  hwa->map.counter2_channel1 = 0 ;
44  hwa->map.counter2_channel2 = 0 ;
45  hwa->map.counter2_channel3 = 0 ;
46  hwa->map.counter2_channel4 = 0 ;
47 }
48 
49 
50 HW_INLINE void _hwa_commit_map( hwa_t *hwa )
51 {
52  if ( hwa->map.error )
53  return ;
54 
55  /* Counter 2
56  */
57  int8_t remap0 = -1 ;
58  int8_t remap1 = -1 ;
59 
60  if ( hwa->map.counter2_etr != 0 ) {
61  if ( hwa->map.counter2_etr == HW_ADDRESS((porta,0)) )
62  remap0 = 0 ;
63  else if ( hwa->map.counter2_etr == HW_ADDRESS((porta,15)) )
64  remap0 = 1 ;
65  else {
66  hwa->map.error = 1 ;
67  HWA_E(HW_EM_OMAP((counter2,etr))) ;
68  }
69  }
70 
71  if ( hwa->map.counter2_channel1 != 0 ) {
72  if ( hwa->map.counter2_channel1 == HW_ADDRESS((porta,0)) )
73  remap0 = 0 ;
74  else if ( hwa->map.counter2_channel1 == HW_ADDRESS((porta,15)) )
75  remap0 = 1 ;
76  else {
77  hwa->map.error = 1 ;
78  HWA_E(HW_EM_OMAP((counter2,channel1)));
79  }
80  }
81 
82  if ( hwa->map.counter2_channel2 != 0 ) {
83  if ( hwa->map.counter2_channel2 == HW_ADDRESS((porta,1)) && remap0 == -1 )
84  remap0 = 0 ;
85  else if ( hwa->map.counter2_channel2 == HW_ADDRESS((portb,3)) && remap0 == -1 )
86  remap0 = 1 ;
87  else {
88  hwa->map.error = 1 ;
89  HWA_E(HW_EM_OMAP((counter2,channel2)));
90  }
91  }
92 
93  if ( hwa->map.counter2_channel3 != 0 ) {
94  if ( hwa->map.counter2_channel3 == HW_ADDRESS((porta,2)) )
95  remap1 = 0 ;
96  else if ( hwa->map.counter2_channel3 == HW_ADDRESS((portb,10)) )
97  remap1 = 1 ;
98  else {
99  hwa->map.error = 1 ;
100  HWA_E(HW_EM_OMAP((counter2,channel3)));
101  }
102  }
103 
104  if ( hwa->map.counter2_channel4 != 0 ) {
105  if ( hwa->map.counter2_channel4 == HW_ADDRESS((porta,3)) && remap1 == -1 )
106  remap1 = 0 ;
107  else if ( hwa->map.counter2_channel4 == HW_ADDRESS((portb,11)) && remap1 == -1 )
108  remap1 = 1 ;
109  else {
110  hwa->map.error = 1 ;
111  HWA_E(HW_EM_OMAP((counter2,channel4)));
112  }
113  }
114 
115  if ( hwa->map.error )
116  return ;
117 
118  if ( remap0 != -1 || remap1 != -1 ) {
119  if ( remap0 == -1 ) remap0 = 0 ;
120  if ( remap1 == -1 ) remap1 = 0 ;
121  uint8_t remap = (remap1*2 + remap0) & 3 ;
122 
123  if ( hwa->map.counter2_remap != -1 && hwa->map.counter2_remap != remap )
124  HWA_E(HW_EM_OMAP(counter2));
125 
126  hwa->map.counter2_remap = remap ;
127  _hwa_write( afio, counter2_remap, remap );
128  }
129 }
hwa
#define hwa(...)
hwa( action, object [,...] ) stores an action for an object into a HWA context.
Definition: hwa_macros.h:552
HWA_E
#define HWA_E(...)
Trigger an error after code optimization.
Definition: hwa_2.h:17
HW_ADDRESS
#define HW_ADDRESS(...)
Returns the address of an object or -1 if the object does not exist.
Definition: hwa_1.h:454
_hwa_write
#define _hwa_write(o, r, v)
Write one register of an object.
Definition: hwa_2.h:181