comparison chipsetsw/services/lls/lls_functions.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /**
2 * @file lls_functions.c
3 *
4 * Implementation of LLS functions.
5 *
6 * @author Laurent Sollier (l-sollier@ti.com)
7 * @version 0.1
8 */
9
10 /*
11 * History:
12 *
13 * Date Author Modification
14 * ----------------------------------------
15 * 03/12/2002 L Sollier Create
16 *
17 *
18 * (C) Copyright 2002 by Texas Instruments Incorporated, All Rights Reserved
19 */
20
21 #ifndef _WINDOWS
22 #include "l1sw.cfg"
23 #include "chipset.cfg"
24 #endif
25
26 #include "lls/lls_i.h"
27 #include "lls/lls_api.h"
28
29 #include "spi/spi_api.h"
30 #include "rvf/rvf_api.h"
31
32
33 /* Number of available equipment's */
34 #define NUMBER_OF_EQUIPMENT 3
35
36 /* Parameters for each EQUIPMENT */
37 typedef struct
38 {
39 T_LLS_EQUIPMENT equipment_sort;
40 UINT16 page;
41 UINT16 address;
42 UINT8 bit;
43 } T_EQUIPMENT_PARAM;
44
45 /* Table of parameters for all the equipment's */
46 typedef T_EQUIPMENT_PARAM T_EQUIPMENT_PARAM_TABLE[NUMBER_OF_EQUIPMENT];
47
48 /* Definition of the parameters for the equipment */
49 #if (ANLG_FAM == 2)
50 static T_EQUIPMENT_PARAM_TABLE equipment_param_table =
51 { {LLS_LED_A, PAGE1, AUXLED, 0},
52 {LLS_BACKLIGHT, PAGE1, AUXLED, 1},
53 {LLS_PRECHARGE_LED, PAGE0, BCICTL2, 5}
54 };
55 #else
56 static T_EQUIPMENT_PARAM_TABLE equipment_param_table = {0};
57 #endif
58
59 /* Save of the action to perform */
60 typedef struct
61 {
62 T_LLS_EQUIPMENT equipment_index;
63 UINT8 action;
64 } T_ACTION;
65
66 static T_ACTION action_to_perform = {0};
67
68 /* Mutex used to protect perform only one action simultaneously */
69 static T_RVF_MUTEX mutex;
70
71
72 /**
73 * @name Functions implementation
74 *
75 */
76 /*@{*/
77
78 /**
79 * function: lls_initialize
80 */
81 T_RV_RET lls_initialize(void)
82 {
83 T_RV_RET ret = RV_OK;
84 UINT8 i;
85
86 /* Mutex initialization */
87 ret = rvf_initialize_mutex(&mutex);
88 if (ret != RVF_OK)
89 return RV_INTERNAL_ERR;
90
91 /* Initialisation of the equipment at SWITCH_OFF */
92 for (i = 0; i < NUMBER_OF_EQUIPMENT; i++)
93 {
94 ret = lls_switch_off(equipment_param_table[i].equipment_sort);
95 if (ret != RV_OK)
96 return RV_INTERNAL_ERR;
97 }
98
99 return RV_OK;
100 }
101
102
103 /**
104 * function: lls_kill_service
105 */
106 T_RV_RET lls_kill_service(void)
107 {
108 T_RV_RET ret = RV_OK;
109 ret = rvf_delete_mutex(&mutex);
110 if (ret != RVF_OK)
111 return RV_INTERNAL_ERR;
112
113 return ret;
114 }
115
116
117 /**
118 * function: lls_callback_equipment_status
119 */
120 void lls_callback_equipment_status(UINT16* equipment_status)
121 {
122 T_RV_RET ret = RV_OK;
123 UINT16 new_equipment_status = *equipment_status;
124
125 LLS_SEND_TRACE_PARAM("LLS: Received equipment status", (UINT32) new_equipment_status, RV_TRACE_LEVEL_DEBUG_LOW);
126
127 if (action_to_perform.action == SWITCH_ON)
128 new_equipment_status |= 1 << equipment_param_table[action_to_perform.equipment_index].bit;
129 else
130 new_equipment_status &= ~(1 << equipment_param_table[action_to_perform.equipment_index].bit);
131
132 LLS_SEND_TRACE_PARAM("LLS: New equipment status", (UINT32) new_equipment_status, RV_TRACE_LEVEL_DEBUG_LOW);
133
134 ret = spi_abb_write(equipment_param_table[action_to_perform.equipment_index].page,
135 equipment_param_table[action_to_perform.equipment_index].address,
136 new_equipment_status);
137
138 if (ret != RV_OK)
139 LLS_SEND_TRACE("LLS: Error on SPI read", RV_TRACE_LEVEL_ERROR);
140
141
142 rvf_unlock_mutex(&mutex);
143 }
144
145 /**
146 * function: lls_manage_equipment
147 */
148 T_RV_RET lls_manage_equipment(UINT8 equipment_index, UINT8 action)
149 {
150 T_RV_RET ret = RV_OK;
151
152 /* Lock mutex until response from SPI is received */
153 rvf_lock_mutex(&mutex);
154
155 /* Save action to do */
156 action_to_perform.equipment_index = equipment_index;
157 action_to_perform.action = action;
158
159 ret = spi_abb_read(equipment_param_table[equipment_index].page,
160 equipment_param_table[equipment_index].address,
161 lls_callback_equipment_status);
162
163 if (ret != RV_OK)
164 LLS_SEND_TRACE("LLS: Error on SPI read", RV_TRACE_LEVEL_ERROR);
165
166 return ret;
167 }
168
169 /**
170 * function: lls_search_index
171 */
172 T_RV_RET lls_search_index(T_LLS_EQUIPMENT equipment, UINT8* equipment_index)
173 {
174 T_RV_RET ret = RV_OK;
175 UINT8 i;
176
177 for (i = 0; i < NUMBER_OF_EQUIPMENT; i++)
178 if (equipment == equipment_param_table[i].equipment_sort)
179 {
180 *equipment_index = i;
181 return RV_OK;
182 }
183
184 return RV_INVALID_PARAMETER;
185 }
186
187
188
189 /*@}*/