comparison bsp/abb+spi/spi_task.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*****************************************************************************/
2 /* */
3 /* Name spi_task.c */
4 /* */
5 /* Function this file contains the main SPI function: spi_core. */
6 /* It contains the body of the SPI task. */
7 /* It will initialize the SPI and then wait for messages */
8 /* or functions calls. */
9 /* */
10 /* Version 0.1 */
11 /* Author Candice Bazanegue */
12 /* */
13 /* Date Modification */
14 /* ------------------------------------ */
15 /* 20/08/2000 Create */
16 /* 01/09/2003 Modfication */
17 /* Author Pascal Puel */
18 /* */
19 /* (C) Copyright 2000 by Texas Instruments Incorporated, All Rights Reserved */
20 /*****************************************************************************/
21
22 #include "../../include/config.h"
23
24 #include "../iq.h"
25
26 #if 0 // FreeCalypso
27 #include "power/power.h" // for Switch_ON()
28 #endif
29
30 #include "../../riviera/rv/rv_defined_swe.h" // for RVM_PWR_SWE
31 #include "../../riviera/rvm/rvm_use_id_list.h"
32 #include "spi_env.h"
33 #include "spi_process.h"
34 #include "spi_task.h"
35
36 #ifdef RVM_PWR_SWE
37 #include "pwr/pwr_liion_cha.h"
38 #include "pwr/pwr_disch.h"
39 #include "pwr/pwr_process.h"
40 #include "pwr/pwr_env.h"
41 #endif
42
43
44
45 /*******************************************************************************
46 ** Function spi_core
47 **
48 ** Description Core of the spi task, which initiliazes the spi SWE and
49 ** waits for messages.
50 **
51 *******************************************************************************/
52 T_RV_RET spi_core(void)
53 {
54 BOOLEAN error_occured = FALSE;
55 T_RV_HDR * msg_ptr;
56
57 rvf_send_trace("SPI_task: Initialization", 24, NULL_PARAM,
58 RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID);
59 SPI_GBL_INFO_PTR->SpiTaskReady = TRUE;
60
61 #if CONFIG_INCLUDE_L1
62 /* Unmask External Interrupt once the SPI task is started */
63 #if (CHIPSET == 12)
64 // Unmask ABB ext interrupt
65 F_INTH_ENABLE_ONE_IT(C_INTH_ABB_IRQ_IT);
66 #else
67 // Unmask external (ABB) interrupt
68 IQ_Unmask(IQ_EXT);
69 #endif
70 #endif
71 #if 0 // FreeCalypso: deferring until UI integration
72 // Get the switch on cause from ABB.
73 Set_Switch_ON_Cause();
74 #endif
75
76 /* loop to process messages */
77 while (error_occured == FALSE)
78 {
79 /* Wait for the necessary events (infinite wait for a msg in the mailbox 0). */
80 UINT16 received_event = rvf_wait (0xffff, 0);
81
82 /* If an event related to mailbox 0 is received, then */
83 if (received_event & RVF_TASK_MBOX_0_EVT_MASK)
84 {
85 /* Read the message in the driver mailbox and delegate action..*/
86 msg_ptr = (T_RV_HDR *) rvf_read_mbox(SPI_MAILBOX);
87
88 #ifdef RVM_PWR_SWE
89 if(spi_process(msg_ptr))
90 {
91 pwr_process(msg_ptr);
92 }
93 #else
94 spi_process(msg_ptr);
95 #endif
96 }
97
98 #ifdef RVM_PWR_SWE
99 /* Timers */
100 if (received_event & SPI_TIMER0_WAIT_EVENT)
101 {
102 pwr_bat_test_timer_process();
103 }
104
105 if (received_event & SPI_TIMER1_WAIT_EVENT)
106 /* timer used to detect the end of the CI charge */
107 {
108 pwr_CI_charge_timer_process();
109 }
110
111 if (received_event & SPI_TIMER2_WAIT_EVENT)
112 /* timer used to detect the end of the CV charge */
113 {
114 pwr_CV_charge_timer_process();
115 }
116
117 if (received_event & SPI_TIMER3_WAIT_EVENT)
118 /* timer used to check the battery discharge level */
119 {
120 pwr_discharge_timer_process();
121 }
122 #endif
123 } // end of while
124 return RV_OK;
125 }
126
127
128
129 /*******************************************************************************
130 * Function : spi_adc_on
131 *
132 * Description : Put the variable is_adc_on of the T_SPI_GBL_INFO structure
133 * to TRUE.
134 * This variable is used for the battery management.
135 * This function is called by the CST entity.
136 *
137 * Parameters : None
138 *
139 * Return : None
140 *
141 *******************************************************************************/
142 void spi_adc_on (void)
143 {
144 SPI_GBL_INFO_PTR->is_adc_on = TRUE;
145
146 rvf_send_trace("SPI: ADC are on",15,
147 NULL_PARAM,
148 RV_TRACE_LEVEL_DEBUG_LOW,
149 SPI_USE_ID);
150 }