@@ -47,7 +47,7 @@ struct sppp_device {
4747 struct clk * clk ;
4848};
4949
50- /* Array od SPPP clients */
50+ /* Array of SPPP clients */
5151static struct sppp_client * array_of_clients [MAX_CLIENTS ] = {NULL };
5252
5353/* baseint contains the address as a 32 bit integer */
@@ -58,11 +58,48 @@ static struct sppp_device sppp __initdata;
5858
5959/* Receive structure */
6060static sppp_rx_t sppp_rx_g ;
61+ static uint32_t sppp_status_lstn_ids = 0 ;
62+
63+ /*
64+ * Private SPPP client functions
65+ */
66+ static inline int sppp_client_is_registered (struct sppp_client * client )
67+ {
68+ return (client != NULL ) &&
69+ (client -> id < MAX_CLIENTS ) &&
70+ (array_of_clients [client -> id ] != NULL );
71+ }
72+
73+ static inline void sppp_client_mark_lstn (struct sppp_client * client )
74+ {
75+ sppp_status_lstn_ids |= (1 << client -> id );
76+ }
77+
78+ static inline int sppp_client_is_lstn (struct sppp_client * client )
79+ {
80+ return (sppp_status_lstn_ids & (1 << client -> id )) != 0 ;
81+ }
82+
83+ static inline void sppp_clr_lstn (void )
84+ {
85+ sppp_status_lstn_ids = 0 ;
86+ }
87+
88+ /*
89+ * Public SPPP client API
90+ */
91+ void sppp_client_status_listen (struct sppp_client * client )
92+ {
93+ if (sppp_client_is_registered (client ))
94+ sppp_client_mark_lstn (client );
95+ else
96+ printk (KERN_ERR "Unrecognized / invalid client!" );
97+ }
6198
6299/* Registers an SPPP client with the driver */
63100void sppp_client_register (struct sppp_client * client )
64101{
65- if (client -> id <= MAX_CLIENTS )
102+ if (client -> id < MAX_CLIENTS )
66103 array_of_clients [client -> id ] = client ;
67104 else
68105 printk (KERN_ERR "Wrong client id\n" );
@@ -72,13 +109,28 @@ EXPORT_SYMBOL(sppp_client_register);
72109/* Removes an SPPP client from the driver */
73110void sppp_client_remove (struct sppp_client * client )
74111{
75- if (client -> id <= MAX_CLIENTS )
112+ if (sppp_client_is_registered ( client ) )
76113 array_of_clients [client -> id ] = NULL ;
77114 else
78115 printk (KERN_ERR "Wrong client id\n" );
79116}
80117EXPORT_SYMBOL (sppp_client_remove );
81118
119+ static void send_status (void )
120+ {
121+ int i ;
122+ struct sppp_client * client ;
123+
124+ for (i = 0 ; i < MAX_CLIENTS ; ++ i ) {
125+ client = array_of_clients [i ];
126+ if (sppp_client_is_registered (client ) &&
127+ sppp_client_is_lstn (client ))
128+ client -> decode (& sppp_rx_g );
129+ }
130+
131+ sppp_clr_lstn ();
132+ }
133+
82134/* Process, identify and decode packet after full encapulated packet received */
83135static int decode (void )
84136{
@@ -135,6 +187,16 @@ static int decode(void)
135187 if (array_of_clients [KEYBOARD ] != NULL )
136188 array_of_clients [KEYBOARD ]-> decode (& sppp_rx_g );
137189 break ;
190+ case SPPP_VBAT_ID :
191+ if (array_of_clients [POWER ] != NULL )
192+ array_of_clients [POWER ]-> decode (& sppp_rx_g );
193+ break ;
194+ case SPPP_STATUS_ID :
195+ if (sppp_status_lstn_ids != 0 ) {
196+ send_status ();
197+ } else
198+ printk (KERN_ERR "STM status received, but no listeners!" );
199+ break ;
138200
139201 /* case SPPP_RTC_ID:
140202 if (array_of_clients[RTC] != NULL)
@@ -352,6 +414,26 @@ void _sppp_write(sppp_tx_t *sppp_tx, uint8_t data)
352414 serial_putc (data );
353415}
354416
417+ void sppp_client_send_start (struct sppp_client * client ,
418+ sppp_tx_t * sppp_tx , uint8_t pkg_id )
419+ {
420+ /* TOOD implement */
421+ return ;
422+ }
423+
424+ void sppp_client_send_data (struct sppp_client * client ,
425+ sppp_tx_t * sppp_tx , uint8_t data )
426+ {
427+ /* TOOD implement */
428+ return ;
429+ }
430+ void sppp_client_send_stop (struct sppp_client * client ,
431+ sppp_tx_t * sppp_tx )
432+ {
433+ /* TOOD implement */
434+ return ;
435+ }
436+
355437/* Send Start */
356438void sppp_start (sppp_tx_t * sppp_tx , uint8_t pkg_id )
357439{
0 commit comments