Hilscher netX microcontroller driver  V0.0.5.0
Documentation of the netX driver package
netx_drv_mled.c
Go to the documentation of this file.
1 /**************************************************************************/
19 #include "netx_drv.h"
20 #ifdef DRV_MLED_MODULE_ENABLED
21 
22 /*lint -save -e685 */
23 /*lint -save -e568 */
24 
38 
42 #ifndef DRV_HANDLE_CHECK_INACTIVE
43 #define DRV_HANDLE_CHECK(handle);\
44  if((handle)==0){ \
45  return DRV_ERROR_PARAM; \
46  }\
47  if((handle)->ptDevice==0){ \
48  return DRV_ERROR_PARAM; \
49  }
50 #else
51 #define DRV_HANDLE_CHECK(handle) ;
52 #endif
53 
58 {
59  unsigned int i;
60  if(ptDriver == 0)
61  {
62  return DRV_ERROR_PARAM;
63  }
64  ptDriver->tLock = DRV_LOCK_INITIALIZER;
65  DRV_LOCK(ptDriver);
67  {
69  }
70  else
71  {
73  {
74  return DRV_ERROR_PARAM;
75  }
76  }
78  {
80  }
81  else
82  {
85  {
86  return DRV_ERROR_PARAM;
87  }
88  }
91  {
92  return DRV_ERROR_PARAM;
93  }
94  ptDriver->ptDevice = s_apChannelDeviceAddressTable[0];
95  ptDriver->ptDevice->mled_ctrl_app_cfg_b.enable = 1u;
97  {
98  for(i = 0; i <= DRV_MLED_ID_MAX; i++)
99  {
101  }
102  }
103  ptDriver->ptDevice->mled_ctrl_app_cfg_b.prescale_counter_max = ptDriver->tConfiguration.ePrescaleBorder - 1u;
104  ptDriver->ptDevice->mled_ctrl_app_cfg_b.blink_counter_max = ptDriver->tConfiguration.eBlinkBorder - 1u;
105  DRV_UNLOCK(ptDriver);
106  return DRV_OK;
107 }
108 
120 {
121  DRV_HANDLE_CHECK(ptDriver);
122  DRV_LOCK(ptDriver);
123  ptDriver->ptDevice->mled_ctrl_app_cfg_b.enable = 0u;
124  *ptDriver = (DRV_MLED_HANDLE_T ) { 0 };
125  return DRV_OK;
126 }
127 
132 {
133  DRV_HANDLE_CHECK(ptDriver);
134  DRV_LOCK(ptDriver);
135  if(uMledID > DRV_MLED_ID_MAX || uMledID < DRV_MLED_ID_MIN)
136  {
137  DRV_UNLOCK(ptDriver);
138  return DRV_ERROR_PARAM;
139  }
140  if(eMode > DRV_MLED_MODE_MAX)
141  {
142  DRV_UNLOCK(ptDriver);
143  return DRV_ERROR_PARAM;
144  }
145  ptDriver->ptDevice->mled_ctrl_app_output_sel[uMledID] = eMode << 1;
146  DRV_UNLOCK(ptDriver);
147  return DRV_OK;
148 }
149 
154 {
155  DRV_HANDLE_CHECK(ptDriver);
156  DRV_LOCK(ptDriver);
157  if(uMledID > DRV_MLED_ID_MAX || uMledID < DRV_MLED_ID_MIN)
158  {
159  DRV_UNLOCK(ptDriver);
160  return DRV_ERROR_PARAM;
161  }
162  if(uBrightness > DRV_MLED_BRIGHTNESS_MAX || uBrightness <= DRV_MLED_BRIGHTNESS_MIN)
163  {
164  DRV_UNLOCK(ptDriver);
165  return DRV_ERROR_PARAM;
166  }
167  ptDriver->ptDevice->mled_ctrl_app_output_on_time[uMledID] = uBrightness - 1u;
168  DRV_UNLOCK(ptDriver);
169  return DRV_OK;
170 }
171 
176 {
177  DRV_HANDLE_CHECK(ptDriver);
178  DRV_LOCK(ptDriver);
179  if(uMledID > DRV_MLED_ID_MAX || uMledID < DRV_MLED_ID_MIN)
180  {
181  DRV_UNLOCK(ptDriver);
182  return DRV_ERROR_PARAM;
183  }
184  unsigned int ulRegister;
185  do
186  {
187  ulRegister = __LDREXW(&(ptDriver->ptDevice->mled_ctrl_app_output_sel[uMledID]));
188  ulRegister ^= 1u;
189  } while(0 != __STREXW(ulRegister, &(ptDriver->ptDevice->mled_ctrl_app_output_sel[uMledID])));
190  DRV_UNLOCK(ptDriver);
191  return DRV_OK;
192 }
193 
198 {
199  DRV_HANDLE_CHECK(ptDriver);
200  DRV_LOCK(ptDriver);
201  if(uMledID > DRV_MLED_ID_MAX || uMledID < DRV_MLED_ID_MIN)
202  {
203  DRV_UNLOCK(ptDriver);
204  return DRV_ERROR_PARAM;
205  }
206  ptDriver->ptDevice->mled_ctrl_app_output_sel[uMledID] = 1u;
207  DRV_UNLOCK(ptDriver);
208  return DRV_OK;
209 }
210 
215 {
216  DRV_HANDLE_CHECK(ptDriver);
217  DRV_LOCK(ptDriver);
218  if(uMledID > DRV_MLED_ID_MAX || uMledID < DRV_MLED_ID_MIN)
219  {
220  DRV_UNLOCK(ptDriver);
221  return DRV_ERROR_PARAM;
222  }
223  ptDriver->ptDevice->mled_ctrl_app_output_sel[uMledID] = 0u;
224  DRV_UNLOCK(ptDriver);
225  return DRV_OK;
226 }
227 
232 {
233  DRV_HANDLE_CHECK(ptDriver);
234  DRV_LOCK(ptDriver);
235  unsigned int ulRegister;
236  uMledMSK &= ~uMask;
237  do
238  {
239  ulRegister = __LDREXW(&(ptDriver->ptDevice->mled_ctrl_app_line0));
240  ulRegister &= ~uMask;
241  ulRegister |= uMledMSK;
242  } while(0 != __STREXW(ulRegister, &(ptDriver->ptDevice->mled_ctrl_app_line0)));
243  DRV_UNLOCK(ptDriver);
244  return DRV_OK;
245 }
246 
251 {
252  DRV_HANDLE_CHECK(ptDriver);
253  DRV_LOCK(ptDriver);
254  unsigned int ulRegister;
255  do
256  {
257  ulRegister = __LDREXW(&(ptDriver->ptDevice->mled_ctrl_app_line0));
258  ulRegister |= uMledMSK;
259  } while(0 != __STREXW(ulRegister, &(ptDriver->ptDevice->mled_ctrl_app_line0)));
260  DRV_UNLOCK(ptDriver);
261  return DRV_OK;
262 }
263 
268 {
269  DRV_HANDLE_CHECK(ptDriver);
270  DRV_LOCK(ptDriver);
271  unsigned int ulRegister;
272  do
273  {
274  ulRegister = __LDREXW(&(ptDriver->ptDevice->mled_ctrl_app_line0));
275  ulRegister &= ~uMledMSK;
276  } while(0 != __STREXW(ulRegister, &(ptDriver->ptDevice->mled_ctrl_app_line0)));
277  DRV_UNLOCK(ptDriver);
278  return DRV_OK;
279 }
280 /* End of group MLED */
282 
283 /*lint -restore */
284 /*lint -restore */
285 
286 #endif /* DRV_MLED_MODULE_ENABLED */
#define DRV_MLED_DEVICE_LIST
#define DRV_MLED_ID_MIN
uint32_t DRV_MLED_ID_T
Type definition analog to the dio definition for the mleds by id.
Definition: netx_drv_mled.h:48
DRV_STATUS_E DRV_MLED_ChannelOutReset(DRV_MLED_HANDLE_T *const ptDriver, DRV_MLED_ID_T uMledID)
Sets the MLED to reset.
#define DRV_LOCK_INITIALIZER
Initializer of the type to be locked as rvalue is in default the mutex initializer.
The handle of the driver.
mled_ctrl_app (mled_ctrl_app)
Definition: netx90_app.h:24516
DRV_MLED_PRESCALE_BORDER_E ePrescaleBorder
DRV_MLED_MODE_E
The MLED modes.
Definition: netx_drv_mled.h:94
DRV_STATUS_E DRV_MLED_LineMaskedSet(DRV_MLED_HANDLE_T *const ptDriver, DRV_MLED_MSK_T uMask, DRV_MLED_MSK_T uMledMSK)
Manipulates the mled line and sets the bits given by the mask to the specified value.
DRV_STATUS_E DRV_MLED_ChannelSetBrightness(DRV_MLED_HANDLE_T *const ptDriver, DRV_MLED_ID_T uMledID, DRV_MLED_BRIGHTNESS_E uBrightness)
Sets the brightness of the MLED.
__IOM uint32_t mled_ctrl_app_output_on_time[16]
Definition: netx90_app.h:24565
DRV_MLED_BRIGHTNESS_E eBrightnessDefault
DRV_STATUS_E DRV_MLED_ChannelOutSet(DRV_MLED_HANDLE_T *const ptDriver, DRV_MLED_ID_T uMledID)
Sets the MLED to set.
DRV_MLED_DEVICE_T * ptDevice
#define DRV_MLED_ID_MAX
DRV_STATUS_E DRV_MLED_ChannelInvert(DRV_MLED_HANDLE_T *const ptDriver, DRV_MLED_ID_T uMledID)
Inverts the MLED.
struct mled_ctrl_app_Type::@5151::@5159 mled_ctrl_app_cfg_b
#define DRV_MLED_DEVICE_COUNT
#define DRV_LOCK(__HANDLE__)
A function calling the trylock of the mutex and returning locked in case it is blocked.
uint32_t DRV_MLED_MSK_T
Type definition analog to the dio definition for the mleds as mask.
Definition: netx_drv_mled.h:43
DRV_STATUS_E DRV_MLED_ChannelSetMode(DRV_MLED_HANDLE_T *const ptDriver, DRV_MLED_ID_T uMledID, DRV_MLED_MODE_E eMode)
Sets the mode of the MLED.
This file contains all the functions prototypes for the peripheral module driver. ...
DRV_STATUS_E DRV_MLED_LineOutReset(DRV_MLED_HANDLE_T *const ptDriver, DRV_MLED_MSK_T uMledMSK)
Manipulates the MLED line and resets the given bits.
DRV_MLED_BRIGHTNESS_E
The MLED brightness duty=([value]-1)/255.
Definition: netx_drv_mled.h:79
DRV_STATUS_E DRV_MLED_DeInit(DRV_MLED_HANDLE_T *const ptDriver)
Deinitializes the mled device and handle.
__IOM uint32_t mled_ctrl_app_output_sel[16]
Definition: netx90_app.h:24552
DRV_STATUS_E DRV_MLED_Init(DRV_MLED_HANDLE_T *const ptDriver)
Initializes the mled device and handle by the given configuration.
Definition: netx_drv_mled.c:57
#define DRV_HANDLE_CHECK(handle)
Definition: netx_drv_mled.c:43
DRV_STATUS_E
DRV Status structures definition.
Definition: netx_drv_def.h:53
static DRV_MLED_DEVICE_T *const s_apChannelDeviceAddressTable[DRV_MLED_DEVICE_COUNT]
Table of the device addresses.
Definition: netx_drv_mled.c:37
#define DRV_UNLOCK(__HANDLE__)
The release function used.
DRV_MLED_CONFIGURATION_T tConfiguration
__IOM uint32_t mled_ctrl_app_line0
Definition: netx90_app.h:24579
DRV_STATUS_E DRV_MLED_LineOutSet(DRV_MLED_HANDLE_T *const ptDriver, DRV_MLED_MSK_T uMledMSK)
Manipulates the MLED line and sets the given bits.
__IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
Definition: cmsis_iccarm.h:543
DRV_MLED_BLINK_BORDER_E eBlinkBorder
__IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
Definition: cmsis_iccarm.h:548