Kévin Redon | 69b92d9 | 2019-01-24 16:39:20 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Code generated from Atmel Start. |
| 3 | * |
| 4 | * This file will be overwritten when reconfiguring your Atmel Start project. |
| 5 | * Please copy examples or other code you want to keep to a separate file |
| 6 | * to avoid losing it when reconfiguring. |
| 7 | */ |
| 8 | |
| 9 | #include "driver_examples.h" |
| 10 | #include "driver_init.h" |
| 11 | #include "utils.h" |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 12 | |
| 13 | /** |
Kévin Redon | 1f8ecef | 2019-01-31 13:36:12 +0100 | [diff] [blame] | 14 | * Example of using SIM0 to write "Hello World" using the IO abstraction. |
| 15 | * |
| 16 | * Since the driver is asynchronous we need to use statically allocated memory for string |
| 17 | * because driver initiates transfer and then returns before the transmission is completed. |
| 18 | * |
| 19 | * Once transfer has been completed the tx_cb function will be called. |
| 20 | */ |
| 21 | |
| 22 | static uint8_t example_SIM0[12] = "Hello World!"; |
| 23 | |
| 24 | static void tx_cb_SIM0(const struct usart_async_descriptor *const io_descr) |
| 25 | { |
| 26 | /* Transfer completed */ |
| 27 | } |
| 28 | |
| 29 | void SIM0_example(void) |
| 30 | { |
| 31 | struct io_descriptor *io; |
| 32 | |
| 33 | usart_async_register_callback(&SIM0, USART_ASYNC_TXC_CB, tx_cb_SIM0); |
| 34 | /*usart_async_register_callback(&SIM0, USART_ASYNC_RXC_CB, rx_cb); |
| 35 | usart_async_register_callback(&SIM0, USART_ASYNC_ERROR_CB, err_cb);*/ |
| 36 | usart_async_get_io_descriptor(&SIM0, &io); |
| 37 | usart_async_enable(&SIM0); |
| 38 | |
| 39 | io_write(io, example_SIM0, 12); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Example of using SIM1 to write "Hello World" using the IO abstraction. |
| 44 | * |
| 45 | * Since the driver is asynchronous we need to use statically allocated memory for string |
| 46 | * because driver initiates transfer and then returns before the transmission is completed. |
| 47 | * |
| 48 | * Once transfer has been completed the tx_cb function will be called. |
| 49 | */ |
| 50 | |
| 51 | static uint8_t example_SIM1[12] = "Hello World!"; |
| 52 | |
| 53 | static void tx_cb_SIM1(const struct usart_async_descriptor *const io_descr) |
| 54 | { |
| 55 | /* Transfer completed */ |
| 56 | } |
| 57 | |
| 58 | void SIM1_example(void) |
| 59 | { |
| 60 | struct io_descriptor *io; |
| 61 | |
| 62 | usart_async_register_callback(&SIM1, USART_ASYNC_TXC_CB, tx_cb_SIM1); |
| 63 | /*usart_async_register_callback(&SIM1, USART_ASYNC_RXC_CB, rx_cb); |
| 64 | usart_async_register_callback(&SIM1, USART_ASYNC_ERROR_CB, err_cb);*/ |
| 65 | usart_async_get_io_descriptor(&SIM1, &io); |
| 66 | usart_async_enable(&SIM1); |
| 67 | |
| 68 | io_write(io, example_SIM1, 12); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Example of using SIM2 to write "Hello World" using the IO abstraction. |
| 73 | * |
| 74 | * Since the driver is asynchronous we need to use statically allocated memory for string |
| 75 | * because driver initiates transfer and then returns before the transmission is completed. |
| 76 | * |
| 77 | * Once transfer has been completed the tx_cb function will be called. |
| 78 | */ |
| 79 | |
| 80 | static uint8_t example_SIM2[12] = "Hello World!"; |
| 81 | |
| 82 | static void tx_cb_SIM2(const struct usart_async_descriptor *const io_descr) |
| 83 | { |
| 84 | /* Transfer completed */ |
| 85 | } |
| 86 | |
| 87 | void SIM2_example(void) |
| 88 | { |
| 89 | struct io_descriptor *io; |
| 90 | |
| 91 | usart_async_register_callback(&SIM2, USART_ASYNC_TXC_CB, tx_cb_SIM2); |
| 92 | /*usart_async_register_callback(&SIM2, USART_ASYNC_RXC_CB, rx_cb); |
| 93 | usart_async_register_callback(&SIM2, USART_ASYNC_ERROR_CB, err_cb);*/ |
| 94 | usart_async_get_io_descriptor(&SIM2, &io); |
| 95 | usart_async_enable(&SIM2); |
| 96 | |
| 97 | io_write(io, example_SIM2, 12); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Example of using SIM3 to write "Hello World" using the IO abstraction. |
| 102 | * |
| 103 | * Since the driver is asynchronous we need to use statically allocated memory for string |
| 104 | * because driver initiates transfer and then returns before the transmission is completed. |
| 105 | * |
| 106 | * Once transfer has been completed the tx_cb function will be called. |
| 107 | */ |
| 108 | |
| 109 | static uint8_t example_SIM3[12] = "Hello World!"; |
| 110 | |
| 111 | static void tx_cb_SIM3(const struct usart_async_descriptor *const io_descr) |
| 112 | { |
| 113 | /* Transfer completed */ |
| 114 | } |
| 115 | |
| 116 | void SIM3_example(void) |
| 117 | { |
| 118 | struct io_descriptor *io; |
| 119 | |
| 120 | usart_async_register_callback(&SIM3, USART_ASYNC_TXC_CB, tx_cb_SIM3); |
| 121 | /*usart_async_register_callback(&SIM3, USART_ASYNC_RXC_CB, rx_cb); |
| 122 | usart_async_register_callback(&SIM3, USART_ASYNC_ERROR_CB, err_cb);*/ |
| 123 | usart_async_get_io_descriptor(&SIM3, &io); |
| 124 | usart_async_enable(&SIM3); |
| 125 | |
| 126 | io_write(io, example_SIM3, 12); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Example of using SIM4 to write "Hello World" using the IO abstraction. |
| 131 | * |
| 132 | * Since the driver is asynchronous we need to use statically allocated memory for string |
| 133 | * because driver initiates transfer and then returns before the transmission is completed. |
| 134 | * |
| 135 | * Once transfer has been completed the tx_cb function will be called. |
| 136 | */ |
| 137 | |
| 138 | static uint8_t example_SIM4[12] = "Hello World!"; |
| 139 | |
| 140 | static void tx_cb_SIM4(const struct usart_async_descriptor *const io_descr) |
| 141 | { |
| 142 | /* Transfer completed */ |
| 143 | } |
| 144 | |
| 145 | void SIM4_example(void) |
| 146 | { |
| 147 | struct io_descriptor *io; |
| 148 | |
| 149 | usart_async_register_callback(&SIM4, USART_ASYNC_TXC_CB, tx_cb_SIM4); |
| 150 | /*usart_async_register_callback(&SIM4, USART_ASYNC_RXC_CB, rx_cb); |
| 151 | usart_async_register_callback(&SIM4, USART_ASYNC_ERROR_CB, err_cb);*/ |
| 152 | usart_async_get_io_descriptor(&SIM4, &io); |
| 153 | usart_async_enable(&SIM4); |
| 154 | |
| 155 | io_write(io, example_SIM4, 12); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Example of using SIM5 to write "Hello World" using the IO abstraction. |
| 160 | * |
| 161 | * Since the driver is asynchronous we need to use statically allocated memory for string |
| 162 | * because driver initiates transfer and then returns before the transmission is completed. |
| 163 | * |
| 164 | * Once transfer has been completed the tx_cb function will be called. |
| 165 | */ |
| 166 | |
| 167 | static uint8_t example_SIM5[12] = "Hello World!"; |
| 168 | |
| 169 | static void tx_cb_SIM5(const struct usart_async_descriptor *const io_descr) |
| 170 | { |
| 171 | /* Transfer completed */ |
| 172 | } |
| 173 | |
| 174 | void SIM5_example(void) |
| 175 | { |
| 176 | struct io_descriptor *io; |
| 177 | |
| 178 | usart_async_register_callback(&SIM5, USART_ASYNC_TXC_CB, tx_cb_SIM5); |
| 179 | /*usart_async_register_callback(&SIM5, USART_ASYNC_RXC_CB, rx_cb); |
| 180 | usart_async_register_callback(&SIM5, USART_ASYNC_ERROR_CB, err_cb);*/ |
| 181 | usart_async_get_io_descriptor(&SIM5, &io); |
| 182 | usart_async_enable(&SIM5); |
| 183 | |
| 184 | io_write(io, example_SIM5, 12); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Example of using SIM6 to write "Hello World" using the IO abstraction. |
| 189 | * |
| 190 | * Since the driver is asynchronous we need to use statically allocated memory for string |
| 191 | * because driver initiates transfer and then returns before the transmission is completed. |
| 192 | * |
| 193 | * Once transfer has been completed the tx_cb function will be called. |
| 194 | */ |
| 195 | |
| 196 | static uint8_t example_SIM6[12] = "Hello World!"; |
| 197 | |
| 198 | static void tx_cb_SIM6(const struct usart_async_descriptor *const io_descr) |
| 199 | { |
| 200 | /* Transfer completed */ |
| 201 | } |
| 202 | |
| 203 | void SIM6_example(void) |
| 204 | { |
| 205 | struct io_descriptor *io; |
| 206 | |
| 207 | usart_async_register_callback(&SIM6, USART_ASYNC_TXC_CB, tx_cb_SIM6); |
| 208 | /*usart_async_register_callback(&SIM6, USART_ASYNC_RXC_CB, rx_cb); |
| 209 | usart_async_register_callback(&SIM6, USART_ASYNC_ERROR_CB, err_cb);*/ |
| 210 | usart_async_get_io_descriptor(&SIM6, &io); |
| 211 | usart_async_enable(&SIM6); |
| 212 | |
| 213 | io_write(io, example_SIM6, 12); |
| 214 | } |
| 215 | |
| 216 | /** |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 217 | * Example of using UART_debug to write "Hello World" using the IO abstraction. |
| 218 | */ |
| 219 | void UART_debug_example(void) |
| 220 | { |
| 221 | struct io_descriptor *io; |
Harald Welte | 361ed20 | 2019-02-24 21:15:39 +0100 | [diff] [blame] | 222 | usart_sync_get_io_descriptor(&UART_debug, &io); |
| 223 | usart_sync_enable(&UART_debug); |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 224 | |
Harald Welte | 361ed20 | 2019-02-24 21:15:39 +0100 | [diff] [blame] | 225 | io_write(io, (uint8_t *)"Hello World!", 12); |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 226 | } |